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

Username:   Password: 
 RegisterRegister   
 collision detection problem help!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
staticlike




PostPosted: Fri Apr 29, 2005 12:07 pm   Post subject: collision detection problem help!

I'm having a tad bit of trouble with my collision detection on the game that i am creating. the only thing is, i don't understand why it is giving me trouble. here's my collision detection code:
code:
if walls (mx, my) = 1 then
            if rockettype = 1 then
                walls (mx, my) := 0
            elsif rockettype = 2 then
                for i : -1 .. 1
                    for o : -1 .. 1
                        walls (mx + i, my + o) := 0
                    end for
                end for
            elsif rockettype = 3 then
                for i : -2 .. 2
                    for o : -2 .. 2
                        walls (mx + i, my + o) := 0
                    end for
                end for
            end if
            launchm := false
            mx := -5
            my := -5
        end if


mx and my are the missile's coordinates, walls is a 2d array of int, a 1 signifies a wall, launchm is the check that a there is a launched missile, rockettype is the kind of rocket the player is using.

The problem is when the player shoots the rocket right next to a wall. it will destroy the wall and keep going, as if the wall wasn't there, and get destroyed when it hits the next wall. Any idea on why it does this?
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Fri Apr 29, 2005 8:14 pm   Post subject: (No subject)

I don't see an incorporation of the launchm boolean anywhere. You might want to enclose your code with:

code:

if launchm then
%...
end if
staticlike




PostPosted: Mon May 02, 2005 11:46 am   Post subject: (No subject)

It already is enclosed inside of it, alongside the moving of it, so it can immediately destroy the wall if it moves into it.

oh yea, i found out the problem, though i don't remember what it was because i'm usually quite forgetful, plus it's been a few days after i fixed it. Razz
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: