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

Username:   Password: 
 RegisterRegister   
 Best way to detect collision
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
tjmoore1993




PostPosted: Fri May 15, 2009 8:05 pm   Post subject: Best way to detect collision

I have this game called Fantastic Story, it includes a lot of features. One of the features I am working on at the moment is traveling. When my character walks I want it so that he is always on the GROUND.

I want to have it so when my character comes across a slope it doesn't go straight through it but instead climb up that slope. If any help can be given on this I would gratefully appreciate it.
Sponsor
Sponsor
Sponsor
sponsor
DtY




PostPosted: Fri May 15, 2009 9:12 pm   Post subject: RE:Best way to detect collision

The easiest way in Turing is probably to check the colour of the pixel where you're trying to move to.
corriep




PostPosted: Fri May 15, 2009 9:16 pm   Post subject: Re: Best way to detect collision

This shouldn't be hard, you need to know 2 things:
  • The (x, y) coords of the player
  • The two (x, y) coords on the slope
After that its just a matter of checking if the player's x value is between the 2 of the slope (meaning he is on the slope) and then setting the y-value to the intercept of the player's x and the line.
tjmoore1993




PostPosted: Fri May 15, 2009 9:40 pm   Post subject: Re: Best way to detect collision

corriep @ Fri May 15, 2009 9:16 pm wrote:
This shouldn't be hard, you need to know 2 things:
  • The (x, y) coords of the player
  • The two (x, y) coords on the slope
After that its just a matter of checking if the player's x value is between the 2 of the slope (meaning he is on the slope) and then setting the y-value to the intercept of the player's x and the line.


The problem there is I do not want to define every piece of land.
zero-impact




PostPosted: Fri May 15, 2009 10:47 pm   Post subject: RE:Best way to detect collision

Ok so how are you actually storing the data for the landscape? The method you use for collision detection will depend primarily on that.
tjmoore1993




PostPosted: Sat May 16, 2009 10:04 am   Post subject: Re: Best way to detect collision

I want to achieve this

Posted Image, might have been reduced in size. Click Image to view fullscreen.

But I want it to look like this


Posted Image, might have been reduced in size. Click Image to view fullscreen.
Dusk Eagle




PostPosted: Sat May 16, 2009 3:33 pm   Post subject: Re: Best way to detect collision

Without programming this entire thing myself, here's a general overview of one way I've thought of to do it with whatdotcolor. I know whatdotcolor is scorned upon, but this is a simple way of doing things in this case IMO. A more experienced programmer might point out a better way.

In between the time when you clear the screen and the time when the background is drawn to the screen, draw a picture which outlines the ground and walls of your map area. Then do collision detection (using whatdotcolor) - if any of your character is going through the ground, elevate him to the top of the ground, and if any of your character is touching a wall, do not let the character move in that direction. When that is done, draw the real background on top of your collision background. I'm a bit worried that this way might cause flickering, but I'm not about to code all this just to test that (It'd be easier to do it this way if Turing supported multiple run windows, which I don't think it does).
tjmoore1993




PostPosted: Sat May 16, 2009 3:53 pm   Post subject: Re: Best way to detect collision

Dusk Eagle @ Sat May 16, 2009 3:33 pm wrote:
Without programming this entire thing myself, here's a general overview of one way I've thought of to do it with whatdotcolor. I know whatdotcolor is scorned upon, but this is a simple way of doing things in this case IMO. A more experienced programmer might point out a better way.

In between the time when you clear the screen and the time when the background is drawn to the screen, draw a picture which outlines the ground and walls of your map area. Then do collision detection (using whatdotcolor) - if any of your character is going through the ground, elevate him to the top of the ground, and if any of your character is touching a wall, do not let the character move in that direction. When that is done, draw the real background on top of your collision background. I'm a bit worried that this way might cause flickering, but I'm not about to code all this just to test that (It'd be easier to do it this way if Turing supported multiple run windows, which I don't think it does).


I do not need to worry about anti - flicker. I have a work around that is more efficient then View.Update and executes faster. Also I have tried "whatdotcolour". The problem with "whatdotcolour" is that you can't use it in my case because of my updating method.

I can't share my code because it has taken a while to write it and I am handing this in as a project.

Also I think I might just make flat grounds...
Sponsor
Sponsor
Sponsor
sponsor
tjmoore1993




PostPosted: Sat May 16, 2009 3:59 pm   Post subject: RE:Best way to detect collision

I have solved the problem...

Posted Image, might have been reduced in size. Click Image to view fullscreen.
zero-impact




PostPosted: Sat May 16, 2009 4:14 pm   Post subject: RE:Best way to detect collision

Mind sharing what you did? Just explaining it?
tjmoore1993




PostPosted: Sat May 16, 2009 5:35 pm   Post subject: RE:Best way to detect collision

I replaced the pictures with flat ground so I only need to define a Y co-ordinate.

Simple fix and it is easier to maintain. Smile
corriep




PostPosted: Sat May 16, 2009 8:29 pm   Post subject: RE:Best way to detect collision

K.I.S.S

works every time
tjmoore1993




PostPosted: Sat May 16, 2009 9:35 pm   Post subject: Re: Best way to detect collision

Someone said that there would be flickering problems


Posted Image, might have been reduced in size. Click Image to view fullscreen.

I did not get a flicker of any sort I even added virtual lag to the program and no flicker.
corriep




PostPosted: Sat May 16, 2009 9:57 pm   Post subject: RE:Best way to detect collision

Dude, your an amazing artist to make those background what program did you use?
Dusk Eagle




PostPosted: Sat May 16, 2009 10:14 pm   Post subject: Re: Best way to detect collision

I only said there might be flickering problems if you followed my way of doing things. Since you've made the ground flat, I don't see why there'd be any problems.

PS: Once you've received a grade on your summative, can you release your improved version of View.Update? I'm quite interested to see what you did.
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 2  [ 18 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: