Thanks!
The stages are tile maps (doesn't really matter but in this case the maps were created in Tiled and loaded in via the bit.tiled module). There are 4 terrain tiles the vehicle can drive across.
To make it so the wheels traced the terrain I just created a simple data structure to define the y offsets from the top of the tile rectangles to the top of the actual terrain image contained within the tiles.
Actually, the source code is fairly well commented, so let me just paste that into here:
' This is just a simple data structure that allows the wheels to trace the terrain.
' There are several ways to achieve this result from throwing out ray casts and so forth
' and I always go with the simple method because... well... simpler is better.
' The data structure defines the offset from the top of tile rectangle to the top of the terrain image.
' Tiles are 32 pixels wide.
' LeftHalf defines the offset of the left side.
' RightHalf defines the offset of the right side.
' To make the player vehicle trace the terrain as it moves, I simply call a method (GetTileTopOffset below)
' passing in the pixel x position of each wheel (one at a time).
' The GetTileTopOffset method takes the current scrolling x offset into account, looks up
' the top (offset) of the tile at this position and returns it.
' That bit of information is all that is needed to position the wheel correctly on the ground.
' The average of the wheel offsets is taken to provide the amount of lift to the vehicle frame.
' This produces a nice effect where the wheels trace the ground and the frame adjusts accordingly simulating
' the suspension system of the vehicle reacting to the uneven terrain.
Class TileTopClass
Public
Field LeftHalf:Int
Field RightHalf:Int
End Class
I will be releasing the full Monkey X source code as soon as I get my website updated.
|