Page 1 of 1

Costume and Bullet Help

Posted: Wed Jul 09, 2014 5:46 pm
by CrocDev
hi, i have a problem regarding bullets and costume changing in my game.

so, in my game if you press any of the arrow keys while not moving then the player switches costume and the bullet flies in that direction. But, if your moving.for example if you hold left and you press the right arrow to shoot right, the bullet comes out of his back because the costume hasnt changed.

if thats confusing here is my .love file so see for yourself

please help

Re: Costume and Bullet Help

Posted: Wed Jul 09, 2014 6:08 pm
by Robin
So what do you want to happen?

Should the wizard keep going if he is running north and then fires south? Or should he stop to shoot the bullet?

For how long should he stop? And if not stopping, how long should the animation stay in he "south" position, with the wizard backwards before turning back to the "north" position again?

The answer of your question depends on the answers to those questions. (The important part of "how long" is whether you want it to be a frame or x seconds, so you don't have to know the exact number of milliseconds. ;))

Re: Costume and Bullet Help

Posted: Thu Jul 10, 2014 6:15 pm
by CrocDev
i just want it to keep moving the same direction but just switch costume to the direction of the arrow key then switch back tothe original costume

Re: Costume and Bullet Help

Posted: Sun Jul 13, 2014 5:34 pm
by Jimanzium
Hello, made a few changes to what you already had to get this to work, the new .love is attached and the changes are below.

Code: Select all

local lastShot = 1
local changeTime = 1

function player.update(dt)
	-- stuff

	if(lastShot <= changeTime) then
		lastShot = lastShot + dt
	end
end

function love.keypressed(key) -- Instead of love.keyreleased(key)
	--stuff
end

function player.animreset(key)
	if(lastShot > changeTime) then
		-- stuff
	end
end

function player.shoot(key)
	-- stuff

	if(key == "up" or key == "down" or key == "left" or key == "right") then
		lastShot = 0
	end
end
lastShot is the time since the player last fired.
changeTime is how long the player will stay with the costume of shooting in the last direction if they stop shooting.
lastShot is set to zero when the player shoots and their costume is changed to be facing that direction.
lastShot has delta time added to it until it is greater than changeTime.
The players costume can only be changed by walking if lastShot is greater than changeTime.

Re: Costume and Bullet Help

Posted: Mon Jul 14, 2014 5:06 pm
by CrocDev
thank you so much, but is there a way for it to wait half a second then switch back to the original costume?

thanks

Re: Costume and Bullet Help

Posted: Mon Jul 14, 2014 6:45 pm
by Jimanzium
Indeed, change "local changeTime = 1" to "local changeTime = 0.5"

Re: Costume and Bullet Help

Posted: Tue Jul 15, 2014 2:09 am
by undef
The way the bullets fly is not physically correct by the way, while walking left and shooting down the bullets should still fly left.
If you want physically correct, that is.

Re: Costume and Bullet Help

Posted: Tue Jul 15, 2014 4:11 pm
by CrocDev
the costume changing isnt really working.

im holding down "d" and i then press right arrow. i switch costume but then i stay in the switched costume (while still holding "d")

Re: Costume and Bullet Help

Posted: Tue Jul 15, 2014 5:39 pm
by Jimanzium
I got your back

Moved the player.animreset(key) stuff to be in player.update(dt)

Re: Costume and Bullet Help

Posted: Wed Jul 16, 2014 4:18 pm
by CrocDev
I would like tothank every1 who helped me.


THANKS!!!!


:awesome: :awesome: :awesome: :awesome: :awesome: :awesome: :awesome: :awesome: :crazy: :crazy: :crazy: :crazy: :crazy: :crazy: :crazy: :crazy: :cool: :cool: :cool: :cool: