Attacking Functions.Please Help![.love]

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
User avatar
baconhawka7x
Party member
Posts: 484
Joined: Mon Nov 21, 2011 7:05 am
Contact:

Attacking Functions.Please Help![.love]

Post by baconhawka7x » Sat Dec 24, 2011 6:46 pm

I have made a flat grass plane, and put two zombies and steve(my character) inside of it. To draw the zombies I use..

Code: Select all

function spawnZombie(x,y,speed,health,detection)
		table.insert(enemies, {x = x, y = y, speed = speed, health = health, detection = detection, pic = love.graphics.newImage("pics/zombie.png")})
		
	end
and inside of love draw I put..

Code: Select all

for i,v in ipairs(enemies) do
		love.graphics.draw(v.pic, v.x, v.y)
		
		
	end
I will put my .love up for everyone to look at. But the problem is with the way I make the player attack the zombies. The code for the enemy attacking the player is at the bottom of "tables.lua" under the "enemy_attack" function. And the Code for steve attacking the enemy is in controlls.lua.


For some reason you can only attack the second zombie drawn. I think I know why though. I'm pretty sure it has to do with this little bit of code right here..

Code: Select all

if key == "j" and
			side == right and
			steve.x > v.x - steve.reach and
			steve.x < v.x + steve.reach then
				v.health = v.health - steve.damage
				v.x = v.x - 30
				v.y = v.y - 15
			end
sence there are two "v"'s I'm pretty sure it's messing that up. So how would I re-write that?

Any and all help is appreciated:)

P.S. use "a,d" to move, "w" to fly(temp), and "J" to attack
Attachments
Archive.love
DOWNLOAD
(66.14 KiB) Downloaded 101 times
Last edited by baconhawka7x on Mon Dec 26, 2011 9:14 pm, edited 4 times in total.

User avatar
osgeld
Party member
Posts: 303
Joined: Sun Nov 23, 2008 10:13 pm

Re: two zombies one room.

Post by osgeld » Sat Dec 24, 2011 7:16 pm

I was able to attack the first zombie after killing the second :crazy:

User avatar
baconhawka7x
Party member
Posts: 484
Joined: Mon Nov 21, 2011 7:05 am
Contact:

Re: two zombies one room.

Post by baconhawka7x » Sat Dec 24, 2011 7:24 pm

osgeld wrote:I was able to attack the first zombie after killing the second :crazy:
I know, but I want them to be able to kill them in any order haha:)

User avatar
All0utWar
Prole
Posts: 17
Joined: Tue Dec 06, 2011 12:36 am

Re: two zombies one room.

Post by All0utWar » Sat Dec 24, 2011 7:26 pm

Couldn't you just make it so the second zombie goes into the room first?

User avatar
baconhawka7x
Party member
Posts: 484
Joined: Mon Nov 21, 2011 7:05 am
Contact:

Re: two zombies one room.

Post by baconhawka7x » Sat Dec 24, 2011 7:39 pm

All0utWar wrote:Couldn't you just make it so the second zombie goes into the room first?
Well not exactly. Because what if the player jumps over the first zombie and goes to the second?(I haven't gotten to writing jumping yet lol). Also I think it would be best for the future of the game, like if there is a zombie on either side of the player.

User avatar
Lafolie
Inner party member
Posts: 805
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: two zombies one room.

Post by Lafolie » Sat Dec 24, 2011 9:02 pm

You can save lots of memory by doing this instead:

Code: Select all

--...in love.load
img_zombie = love.graphics.newImage("pics/zombie.png")

--...spawn function
function spawnZombie(x,y,speed,health,detection)
      table.insert(enemies, {x = x, y = y, speed = speed, health = health, detection = detection, pic = img_zombie})
end
It'll help cut lag too since loading images during 'gameplay' could potentially cause a short pause.

I'm pretty certain you could use pairs instead of ipairs in the draw loop too.

To fix the attacking thing you need to iterate through all the zombies you put in the enemies table and check them all. You did this with the draw loop, it's exactly the same principal.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.

User avatar
baconhawka7x
Party member
Posts: 484
Joined: Mon Nov 21, 2011 7:05 am
Contact:

Re: two zombies one room.

Post by baconhawka7x » Sat Dec 24, 2011 9:43 pm

Lafolie wrote:To fix the attacking thing you need to iterate through all the zombies you put in the enemies table and check them all. You did this with the draw loop, it's exactly the same principal.
I did though. That's why I'm confused. and thanks for that pre loaded pic. Totally slipped my mind.

Post Reply

Who is online

Users browsing this forum: Google [Bot], ivan, pgimeno and 29 guests