Computer Science Canada Game Help - Sprite Collision Detection |
| Author: | jolly50 [ Thu Nov 08, 2007 7:52 pm ] | ||
| Post subject: | Game Help - Sprite Collision Detection | ||
Hey, I'm writing a game, but I need help with the collision detection. My game involves this little football ref that has to avoid and shoot footballs at opposing football running backs what I would like to do is have it so that when the footballs hit a runningback....that the running back dissappears. and if the running back hits the ref then its game over..... so here is what i have so far...
...sorry its a little messy....and it does have one issue right now..the running back leaves a trail right behind him, but i'm currently working on it... what should I add to my code to make it work? |
|||
| Author: | CodeMonkey2000 [ Thu Nov 08, 2007 8:37 pm ] |
| Post subject: | RE:Game Help - Sprite Collision Detection |
Do you know how a rectangle to rectangle collision works? Just apply that for sprites. |
|
| Author: | Zampano [ Thu Nov 08, 2007 8:43 pm ] |
| Post subject: | Re: Game Help - Sprite Collision Detection |
On that note, here is a link to a tutorial on collision detection. http://compsci.ca/v3/viewtopic.php?t=13661 |
|
| Author: | jolly50 [ Thu Nov 08, 2007 9:21 pm ] |
| Post subject: | RE:Game Help - Sprite Collision Detection |
I read the tutorial on collision detection and I'm still a little confused....how would i relate the x1,x2,y1,y2 concept to my sprites..... |
|
| Author: | Zampano [ Fri Nov 09, 2007 2:54 am ] |
| Post subject: | Re: Game Help - Sprite Collision Detection |
To the best of my very limited understanding, your sprite should be approximated as a rectangle and the corners of the rectangle should be declared beased on their distance from other corners of the same sprite. I other words, each corner of the sprite picture is a corner used in the collision detection. I have a sneaking feeling that I am not grasping what you are actually asking though. |
|
| Author: | jolly50 [ Fri Nov 09, 2007 5:02 pm ] | ||
| Post subject: | RE:Game Help - Sprite Collision Detection | ||
you sort of got my drift, but what I was really looking for was... in my code...i have
how would i change that code to put in x1, x2, y1, y2 so that I can use the detection feature |
|||
| Author: | Nick [ Fri Nov 09, 2007 5:20 pm ] |
| Post subject: | RE:Game Help - Sprite Collision Detection |
well x1 wil be x let y1 be y that leaves x2 and y2 use Pic.Height and Pic.Width to find x2 and y2 x2=x+Pic.Width(spriteman) y2=y+Pic.Height(spriteman) |
|
| Author: | jolly50 [ Fri Nov 09, 2007 9:42 pm ] |
| Post subject: | RE:Game Help - Sprite Collision Detection |
ok....lol I'm confused beyond belief..... I have no clue what i'm doing.... ...can someone help walk me through this? |
|
| Author: | CodeMonkey2000 [ Fri Nov 09, 2007 9:55 pm ] |
| Post subject: | RE:Game Help - Sprite Collision Detection |
Mabey this is too advanced for you? Think about how x2 relates to x1. |
|
| Author: | jolly50 [ Fri Nov 09, 2007 10:13 pm ] | ||
| Post subject: | RE:Game Help - Sprite Collision Detection | ||
ok..... this might be too advanced...but eventually I have to learn about this.... so...I went into the tutorial about rectangle collision detection and I incorporated my own sprites like this:
First, am i going in the right direction? Second, when I try to run the program...my sprites don't move.... What do I have to do to make my code work? |
|||
| Author: | Nick [ Fri Nov 09, 2007 10:36 pm ] | ||
| Post subject: | RE:Game Help - Sprite Collision Detection | ||
redeclare x2 and y2 in ur main loop
alse the sprite module does not work on some versions of turing what version are u running? |
|||
| Author: | jolly50 [ Sat Nov 10, 2007 7:17 am ] |
| Post subject: | RE:Game Help - Sprite Collision Detection |
I tried your code and it does say "sack!", but the sprites don't move!?!?!?!? ... and I'm running 4.1 |
|
| Author: | jolly50 [ Sat Nov 10, 2007 11:41 am ] | ||
| Post subject: | RE:Game Help - Sprite Collision Detection | ||
...also...I tried to fix my Game's code and this is what I got...
What is wrong with my collison detection's "if statement.....because the game ends when the running back touches the original x coordinate... instead of the new coordinate |
|||
| Author: | CodeMonkey2000 [ Sat Nov 10, 2007 12:06 pm ] |
| Post subject: | RE:Game Help - Sprite Collision Detection |
How are you able to use the sprite module? And if you are going to copy/steal code at least give credit. |
|
| Author: | jolly50 [ Sat Nov 10, 2007 6:30 pm ] |
| Post subject: | RE:Game Help - Sprite Collision Detection |
ummm...I never copy or stole any code!!!!!...Even if I did I would give credit.....I NEVER COPIED OR STOLE ANY CODE...I wrote this entire code with the help of some of my friends in my comp. eng. class |
|