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

Username:   Password: 
 RegisterRegister   
 WhatDotColour and Collision detection
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
slogger




PostPosted: Tue Oct 16, 2007 7:07 pm   Post subject: WhatDotColour and Collision detection

I am trying to make car game. The point of the game is to move around a map on the roads to a destination within a given amount of time in order to move on to the next level. To make things simpler, I want to make maps in Microsoft Paint (green for grass, grey for roads). I need to prevent the car from driving over the grass.

The general technical premise of the game is that the car image is always drawn in the middle of the screen, and the background moves when the user presses the keys on the keyboard. This way, the car appears to move around the map. When a key is being pressed the car (or really the background) moves 'x' units in the direction of key. This works quite well.

My current collision detection system involves checking the colours just outside the four corners of the car (the car is square) to see if they are over grass (green), and if any of them are over grass, move the car back to the position it was previously (before it was over the grass). While this seems to work fine, when two keys are pressed, the car will pass through the grass (though instead of travelling diagonally, as would be normal when two adjacent keys are pressed), it travels straight down or straight up through the grass.

The basic code is here (modified to be easier to read)

code:


if (View.WhatDotColour(point1x,point1y) = green) then
carX := carX_Old
carY := carY_Old
end if
if (View.WhatDotColour(point2x,point2y) = green) then
carX := carX_Old
carY := carY_Old
end if
if (View.WhatDotColour(point3x,point3y) = green) then
carX := carX_Old
carY := carY_Old
end if
if (View.WhatDotColour(point4x,point4y) = green) then
carX := carX_Old
carY := carY_Old
end if



The car is then drawn accordingly. In my real code, I have used one big statement (if this dot or this dot or this dot or this dot equals green, move to old position). Anyway, I cannot figure out what it wrong and would appreciate some help in the matter.

Thanks.
Sponsor
Sponsor
Sponsor
sponsor
isaiahk9




PostPosted: Wed May 07, 2008 7:53 pm   Post subject: RE:WhatDotColour and Collision detection

Why did you go :
if (View.WhatDotColour(point1x,point1y) = green) then
? Why not :
if View.WhatDotColour,(point1x,point1y) = green then
CodeMonkey2000




PostPosted: Wed May 07, 2008 8:26 pm   Post subject: RE:WhatDotColour and Collision detection

That doesn't matter as it's not the problem. It's just a personal preference.
isaiahk9




PostPosted: Thu May 08, 2008 5:51 am   Post subject: RE:WhatDotColour and Collision detection

Oh. Thought slogger had just gotten the code wrong.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: