0
\$\begingroup\$

I've finished programming the car (acceleration, etc) and now I'll start developing a track editor of some sort. The thing is: I have no idea how I'm going to do that. How would you do it? Perhaps design the tracks on GIMP and use some sort of pixel collision detection, or perhaps use multidimensional arrays to store track data like walls and "dirt". I'm open to suggestions.

\$\endgroup\$
2
\$\begingroup\$

The way I would approach this is to create at least two tiles (dirt and road) on GIMP as you suggested (pixel size depending on the size of your car). Then I would keep track of the "board" of a certain size, where the number represents the number of tiles, using a matrix or a list of lists (IDK what engine/language/platform you are using so I'm keeping it vague). This would let me lay out the board pseudo-randomly with just a couple of for loops. By pseudo-random I am referring to the fact that the road must be connected. Maybe even consider laying out the road and then filling up the rest of the matrix with dirt.

for example an 10x10 board gives you 8x8 tiles to work with and it would look like this (s=start; e=end; d=dirt; r=road):
_ _ _ _ _ _ _ _ _ _
| d d d d d d d e |
| d d d d d d d r |
| d d d d d d r r |
| d d d d d d r d |
| d d d d r r r d |
| d d r r r d d d |
| d d r d d d d d |
| d s r d d d d d |
| _ _ _ _ _ _ _ _ |

This Unity 2D tutorial is where I got the idea: https://www.youtube.com/watch?v=bvvaqAbpPjc&t=321s

TBH I am pretty new to this myself... just started to learn recently, but i thought I could be helpful here.

\$\endgroup\$
  • \$\begingroup\$ Yeah, it actually gave me a pretty good idea on how to go on with the data structure. By the way, I'm developing it in Python with Pygame. \$\endgroup\$ – Ericson Willians Oct 26 '17 at 18:58
  • \$\begingroup\$ I see. I'm not sure if Pygame has anything specific for this... But you might be able to use a numpy matrix for keeping track of positions. \$\endgroup\$ – Balry Oct 31 '17 at 16:50
  • \$\begingroup\$ I found my way through it. Have a look at the test track file inside the tracks folder. I store the ground data, waypoints and objects in different matrixes. I'm not using numpy, I'm doing it quite manually. The game is working / moving on. The next challenge is to determine the player position in the race (Starting to develop the actual racing system, laps and so on). \$\endgroup\$ – Ericson Willians Nov 1 '17 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.