Shooting collision help needed!

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
Alecal
Prole
Posts: 5
Joined: Mon Nov 15, 2010 9:51 pm

Shooting collision help needed!

Post 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
Attachments
coal4.love
The game
(4.15 MiB) Downloaded 100 times
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Shooting collision help needed!

Post 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.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Shooting collision help needed!

Post 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 1599 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 1599 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.
When I write def I mean function.
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Shooting collision help needed!

Post 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.
Attachments
coal4_new.love
(4.15 MiB) Downloaded 107 times
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests