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.
1 Answer
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.
-
\$\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\$ Commented Oct 26, 2017 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\$– BalryCommented Oct 31, 2017 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\$ Commented Nov 1, 2017 at 9:37