Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Zombie Sprite Collision Help

Author
Message
FireIndy
17
Years of Service
User Offline
Joined: 17th Jan 2007
Location: US of A
Posted: 9th Jun 2011 23:53 Edited at: 9th Jun 2011 23:59
I recently started working on my 2d top down zombie shooter again. I am having some issues trying to get my collision between zombies to work correctly. The collision between zombies is handled in Main.cpp. I'm right now just trying to make sure that they both are hitting. Currently with this code, if 2 zombies overlap, then 1 of them has "HIT" above their head. However, I want both to have that, so I can move both of them after they collide. Here\'s my code:

Main.cpp


Zombie.cpp


Player.cpp


Any help is appreciated.

Image of what I'm talking about.http://i51.tinypic.com/n6s3dk.jpg Those sprites are touching, but only one of them has the text above them.

Dev team portal Email me to join the dev team!

Dashiznitz
13
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 17th Jun 2011 20:48
It looks like the second assignment where:
for(int k = 0; k <= ZOMBIE_AMOUNT - 1; k++)
{
if (dbSpriteCollision(zombArray[k].spriteNum, zombArray[i].spriteNum))
{
if( zombArray[k].spriteNum != zombArray[i].spriteNum )
{
zombArray[i].text = "HIT";
->>>> zombArray[k].text = "HIT";

is getting overwritten because get to a point where the statement above is initially then later in the loop is true again and overwrites the value. you should start k = i+1 so you never compare the same element.

One question, for your player and zombie classes, are the Xpos, Ypos, health public members?

I like how you used the loop for creating multiple zombie objects for the array side. I was contemplating on how I was going to do this as well. I have a similar project dragon slayer. So far I have the player and one dragon that bounces around the walls of the screen. I have a function also where the player faces the mouse but i used the dbAtan not ATanfull... was a pain to get the angle right for all quadrants using a long if-else, where you did it in two lines.

-Trying to get better

Login to post a reply

Server time is: 2024-11-19 10:22:05
Your offset time is: 2024-11-19 10:22:05