Costume and Bullet Help

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
CrocDev
Prole
Posts: 25
Joined: Tue Jun 11, 2013 7:42 pm

Costume and Bullet Help

Post 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
Attachments
game.love
(59.68 KiB) Downloaded 131 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Costume and Bullet Help

Post 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. ;))
Help us help you: attach a .love.
CrocDev
Prole
Posts: 25
Joined: Tue Jun 11, 2013 7:42 pm

Re: Costume and Bullet Help

Post 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
User avatar
Jimanzium
Party member
Posts: 103
Joined: Sun Jun 03, 2012 2:39 pm
Contact:

Re: Costume and Bullet Help

Post 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.
Attachments
NewGame.love
(59.12 KiB) Downloaded 138 times
CrocDev
Prole
Posts: 25
Joined: Tue Jun 11, 2013 7:42 pm

Re: Costume and Bullet Help

Post 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
User avatar
Jimanzium
Party member
Posts: 103
Joined: Sun Jun 03, 2012 2:39 pm
Contact:

Re: Costume and Bullet Help

Post by Jimanzium »

Indeed, change "local changeTime = 1" to "local changeTime = 0.5"
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: Costume and Bullet Help

Post 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.
twitter | steam | indieDB

Check out quadrant on Steam!
CrocDev
Prole
Posts: 25
Joined: Tue Jun 11, 2013 7:42 pm

Re: Costume and Bullet Help

Post 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")
User avatar
Jimanzium
Party member
Posts: 103
Joined: Sun Jun 03, 2012 2:39 pm
Contact:

Re: Costume and Bullet Help

Post by Jimanzium »

I got your back

Moved the player.animreset(key) stuff to be in player.update(dt)
Attachments
NewNewGame.love
(59.11 KiB) Downloaded 123 times
CrocDev
Prole
Posts: 25
Joined: Tue Jun 11, 2013 7:42 pm

Re: Costume and Bullet Help

Post 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:
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest