Page 1 of 1

Shooting collision help needed!

Posted: Wed May 04, 2011 1:18 am
by Alecal
Hello LÖVE-users!
I need help with some shooting in a zombie game me and a friend of mine made (with alot of help from LÖVE user schme16)
Basically we just need help with the shooting in the game!
I've made the graphics and my friend the music.
We've both been coding but we just cant seem to get the shooting to work!
We want so that when you shoot 2-3 bullets on the zombie it dies and you get +1 score or something.
So if anyone can help us without changing the code too much, we would love you long time!

Here is how the game looks:
Image

We need help ASAP.

Thank you!
regards, alecal

Re: Shooting collision help needed!

Posted: Wed May 04, 2011 4:49 am
by nevon
If I were you, I'd move all the health pickups, the enemy management (this might be its own class, even) and the bullet handling into the level class. That way you don't have to clutter up love.update.

Basically for each frame you'll need to get the bullet's X, Y and Z position and compare it to each zombie's hit-cube. If it's a hit, have the level or the enemy management class subtract N hp, and remove an enemy when their HP is <=0.

Re: Shooting collision help needed!

Posted: Wed May 04, 2011 8:13 am
by kikito
I think you might be getting a bit confused by your perspective & (very nice!) graphics.

The first thing you need to realize is that your game is actually a 2d game; "depth" and "width" are relevant to gameplay, but "height" is only there for aesthetic purposes. (At least on the screenshot you showed)

What I'm trying to say is that your game can be imagined as happening "on the ground".

Let me illustrate. I'm going to highlight the depth and width of every character and item on the scene you showed (I'm also adding a bullet). Notice how everything has a "footprint" on the ground, with its depth and width.
entity footprints
entity footprints
coal1.png (124.33 KiB) Viewed 1614 times
Those "footprints" are really the only important pieces of your game (collision-wise). In other words, you can imagine your game space like this:
entity footprints, sans graphics
entity footprints, sans graphics
coal2.png (1.52 KiB) Viewed 1614 times
Now it should be simpler to understand how the collision detection might work: You just have to check that the yellow footprint intersects with any green footprints. Incidentally, this can also be used for health pickup detection (player footprint intersects with a mauve footprint) or enemy hitting the player (enemy footprint intersects with player footprint).

This snippet will help you check that two rectangles intersect easily.

If I were you, I'd activate a "debug key" that showed all footprints, at least while developing the game.

Finally, a minor thing: notice that your two zombie footprints are intersecting. This should not happen, it's a perspective error.

Re: Shooting collision help needed!

Posted: Thu May 12, 2011 11:42 am
by miko
Alecal wrote:We want so that when you shoot 2-3 bullets on the zombie it dies and you get +1 score or something.
So if anyone can help us without changing the code too much, we would love you long time!
I like the graphics (maybe because I can't do such nice drawing myself, I am just a programmer). Have you got any help yet? If not, here is my version. Note, I have changed the code (still hope it was not "too much"). Press "d" for debug. Otherwise it works as the original (except some improvements).

If you need more help, please use english in comments, as I am not able to read scandinavian languages (I don't know which one it was). You may use the code as you wish.