Skip to main content
GameDev.net gamedev.net
🔒 Locked

2d Terrain/Object Detection

Started by stormrunner Oct 29, 2004 at 5:48 PM 0 replies 800+ views
Original Post
stormrunner
stormrunner
well, I'm working on a 2d top-down game for my cs class, and am currently setting up the terrain. However, I've run into a problem. To spare you a confusing explanation, I've taken the liberty of using ASCII to draw a diagram. :

		
		
		,,,,,</font><font color = "yellow">"</font><font color = "gray">|||||||</font><font color = "yellow">"</font><font color = "white">,,,,,,,,
		,,,,,</font><font color = "yellow">"</font><font color = "gray">|||||||</font><font color = "yellow">"</font><font color = "white">,,,,,,,,</font><font color = "orange">
		""""""""""""""""""""""
		""""""""""""""""""""""
		"     """""""        "
		""""""" </font><font color = "cyan">* *</font><font color = "orange"> """"""""""
		</font><font color = "white">,,,,,</font><font color = "yellow">"</font><font color = "gray">|||||||</font><font color = "yellow">"</font><font color = "white">,,,,,,,,
		,,,,,</font><font color = "yellow">"</font><font color = "gray">|||||||</font><font color = "yellow">"</font><font color = "white">,,,,,,,,

                ,,,,,</font><font color = "yellow">"</font><font color = "gray">|||||||</font><font color = "yellow">"</font><font color = "white">,,,,,
		,,,,,</font><font color = "yellow">"</font><font color = "gray">||</font><font color = "red">^</font><font color = "gray">||||</font><font color = "yellow">"</font><font color = "white">,,,,,,,,
		</font><font color = "orange">"""""""</font><font color = "red">/_\</font><font color = "orange">"""""""""
		"""""""</font><font color = "cyan">* *</font><font color = "orange">"""""""""
		"     """"""        "
		"""""""    """""""""
		</font><font color = "white">,,,,,</font><font color = "yellow">"</font><font color = "gray">|||||||</font><font color = "yellow">"</font><font color = "white">,,,,,		,,,,,"|||||||",,,,,
		,,,,,</font><font color = "yellow">"</font><font color = "gray">|||||||</font><font color = "yellow">"</font><font color = "white">,,,,,
		
The obvious problem is determining when a) the vehicle is beneath the bridge/object - the vehicle drawn first, then the bridge, and when it is it is over it (i.e. flying) - the bridge drawn first, vehicle last. The best I could think of was to make an ordered list of objects to draw (sorted by [y] value - those past a certain [y] are simply not drawn, but are included because collisions have to be checked for) to make it more efficient and to keep the drawing centralized. I'm using java with swing [straight up], so I need to minimize the drawing calls. Then use two [for] loops, checking for collisions and then switching the position of the two objects if one needs to be infront. that seems a little inefficient, though, and error prone. does anyone have a better thought/idea/solution ? any help is appreciated. [Edited by - stormrunner on October 29, 2004 6:05:18 PM]
stormrunner
The_Nerd
The_Nerd
Just give every object a z value. So your car would always have a z value of 0, the bridge would have a z value of 1, and the ground a z value of -1. This way you can know how to draw (and do collision testing too).
-- I waz here --

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.