Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Trouble with Collision in Program
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
sk8boarder1414




PostPosted: Wed May 07, 2008 10:22 am   Post subject: Trouble with Collision in Program

Too long of a program to paste on the forum but I posted it on rafb.net at the link below

http://rafb.net/p/vbC06056.html

When you run the program it keeps detecting the user and sending it back in the 3rd box regardless of whether a flame is there or if its a blank white space. I'm trying to get the user to be sent back when a flame appears on it or when it goes over a flame and if its a blank space they can proceed on to the next.
Sponsor
Sponsor
Sponsor
sponsor
HellblazerX




PostPosted: Wed May 07, 2008 1:23 pm   Post subject: Re: Trouble with Collision in Program

Use a boolean to keep track of whether that flame is there or not. If the flame isn't there, then don't run the collision detection.

Also, in your code:
code:
if (carX+50 >= check1-3 && carX<= check1+63 || carX+50 >= check2-3 && carX<= check2+63 || carX+50 >= check3-3 && carX<= check3+63)
                                {
                                        FlameX1 = 145;
                                        FlameX2 = 285;
                                        FlameX3 = 425;
 
                                        carX = 70;
                                        life--;   
                                        draw.repaint();
                                }
                                else
                                {                                          
                                        FlameX1 = 145;
                                        FlameX2 = 285;
                                        FlameX3 = 425;
                                }            

If you're going change the values of FlameX1-3 in both cases, why not just did it outside the if statement?
sk8boarder1414




PostPosted: Wed May 07, 2008 7:48 pm   Post subject: Re: Trouble with Collision in Program

HellblazerX @ Wed May 07, 2008 1:23 pm wrote:
Use a boolean to keep track of whether that flame is there or not. If the flame isn't there, then don't run the collision detection.

Also, in your code:
code:
if (carX+50 >= check1-3 && carX<= check1+63 || carX+50 >= check2-3 && carX<= check2+63 || carX+50 >= check3-3 && carX<= check3+63)
                                {
                                        FlameX1 = 145;
                                        FlameX2 = 285;
                                        FlameX3 = 425;
 
                                        carX = 70;
                                        life--;   
                                        draw.repaint();
                                }
                                else
                                {                                          
                                        FlameX1 = 145;
                                        FlameX2 = 285;
                                        FlameX3 = 425;
                                }            

If you're going change the values of FlameX1-3 in both cases, why not just did it outside the if statement?




Thanks for the if statement catch, didn't see that it occurs in both situations lol.

About the collision detection though, you said if the flame isnt there then don't run the collision detection, so I'm guessing you mean run it when it is there, but if the car isn't on the flame then the collision will happen and then it won't work properly
Aziz




PostPosted: Thu May 08, 2008 10:27 am   Post subject: RE:Trouble with Collision in Program

I think he means only [i]check[i] if the flame is there. The check doesn't mean collide, it means check to see if the car is in the same spot.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: