|
Collision Detection |
zavirax
Member #8,634
May 2007
|
Hi, Can anyone please read through the source code of my program here?:
Sorry that It's a mess I'm very new to it. I'm trying to crate air hockey, but I'm stuck at getting things to collide. Can i have suggestions please. NOTICE: My Playerone and Playertwo are not images they are text essentially. '+' Thanks guys.;D |
ImLeftFooted
Member #3,935
October 2003
|
Generally, when pasting source code its nice to encapsulate them in [code] tags. Like so: <code> void foobar(int); int var = 5; foobar(5 * 2); </code>
|
zavirax
Member #8,634
May 2007
|
I said I was a noob. Thanks but how does this help my code???? |
ImLeftFooted
Member #3,935
October 2003
|
Because then people will actually read your code and possibly even try to help. |
Onewing
Member #6,152
August 2005
|
Quote: Because then people will actually read your code and possibly even try to help. He's right, I really don't want to read it myself. Fix it up and I might take a look. Yeah, I know, it's not really nice, but I just can't stand to look at that conglomeration above... ------------ |
HardTranceFan
Member #7,317
June 2006
|
There's no point at the moment of doing any collision detection - you're writing the line "Air Hockey" where the puck should be, and drawing the puck at a fixed position. Once you get round to the collision detection, have a search for bounding boxes. -- |
BAF
Member #2,981
December 2002
|
You should draw the puck at the end, after the rest of the playing field has been drawn. Make sure you are drawing stuff in the right order (z-ordering). |
zavirax
Member #8,634
May 2007
|
ok ill try to fix it up, Here's it now i know it's not perfect:
i changed the puck to a square just for easiness. My problem now is getting it to move right( Haven't done the up and down...it should move right and left(it only goes left)) thanks guys |
Albin Engström
Member #8,110
December 2006
|
Edit your post before someone sees it . they've told you already: USE CODE TAGS. Here's how you do it(again): crap, i can't make an example but many has already.. it will look like this:
Be happy |
spellcaster
Member #1,493
September 2001
|
Use code tags, indent your code. Use braces for each and every code block, even if it's a single line. Oh, and use speaking variable names. -- |
HardTranceFan
Member #7,317
June 2006
|
I'll say it too - there are posting protocols. Ignoring this advice is breaking one of them. Please update your post and use the [code]...[/code] tags. I'll help this time, but no more if you don't use tags. 1. Use meaningful variable names. It takes ages to work out and remember what a, b, c... x, y are all for. Use names like xPuck, yPuck, xPlayer1, yPlayer1, xPlayer2 etc. It makes the whole thing easier to understand. [edit]Or, as spellcaster pointed out, use structs with meaningful names[/edit] 2. The line (x==a&&x<c&&y<=b&&y>=d) is wrong, and is why the puck won't go right. There is never a situation when the player position will be above and below the puck at the same time, and x==a is not the test condition you want to perform. -- |
zavirax
Member #8,634
May 2007
|
How do i do the code tags again? umm Let's try this: (if you can't read it tell me what to improve again...thanks for the help again)
|
Albin Engström
Member #8,110
December 2006
|
A much nicer view . btw, what's the problem? ran your game but i don't know what should work and not.. |
zavirax
Member #8,634
May 2007
|
Well what It Is, Is that I cant get the puck to move the way i want so i don't know what i should do..can't find any help anywhere except here. By the way im on a deadline, this is a school course...I'm dumb!.:) |
Paul whoknows
Member #5,081
September 2004
|
Quote: ...I'm dumb!:) A happy one.::) ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
HardTranceFan
Member #7,317
June 2006
|
Quote: Well what It Is, Is that I cant get the puck to move the way i want so i don't know what i should do..can't find any help anywhere except here. By the way im on a deadline, this is a school course...I'm dumb!:) Here is an allegro pong tutorial, which you can adapt to 4 way movement and collision detection. -- |
zavirax
Member #8,634
May 2007
|
Sorry but, Im not sure what i should do with it...is there nothing you would suggest for my code? |
Three Harris
Member #6,226
September 2005
|
I suggest you don't create the buffer in the main loop and not destroy it. That is a massive memory leak. |
Paul whoknows
Member #5,081
September 2004
|
Quote: but I'm stuck at getting things to collide
inline bool collide(int x1, int y1, int x2, int y2, int xx1, int yy1, int xx2, int yy2) { if (x2 <= xx1) return false; else if (x1 >= xx2) return false; else if (y2 <= yy1) return false; else if (y1 >= yy2) return false; else return true; }
____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
HardTranceFan
Member #7,317
June 2006
|
Quote: Sorry but, I'm not sure what i should do with it... Sorry, my bad - the page I linked to and my suggestions didn't match (there is a link to the pong tutorial down that page if you looked). Here is the correct link to the pong tutorial. -- |
zavirax
Member #8,634
May 2007
|
Yeah I already found It on there, don't worry about It. btw how would i use that boolean expression thing, could you show in my code please. thanks Here's my code so far i can push around...any ideas how to make it slide so i only have to hit it not push ... also how would i get it rebound of the sides ... also how can i make a hole in the outside of the field so that it can go in the goal... and also ... however i think i know how, how can make a scoreboard? lots of questions hehe sorry to be such a stupid person. |
|