Lab: Collision
Build this on top of your 2D game engine, or the beginning of the fancy sprites lab.
Implement a tiny platformer game where you can jump on stuff and bump into things. In a world with a downwards acceleration due to gravity, jumping could mean setting an upwards velocity; typical tricks here are to maintain a constant upwards velocity while the button is held down (like a jetpack, often only up to a certain maximum duration of a few fractions of a second) or increase effective gravity after the apex of the jump.
For full points, do one of the following:
- Make it so the character can only jump while touching the ground (NOT a wall or ceiling!)
- Define the level as a tilemap and implement collision against tilemaps
- Implement a moving platform that is "sticky" for the player and enemies (i.e., if you stand still on it you don't slide off)
Efficiency tip: You will need to track a Vec
of contacts every frame. It would be a good idea to have one vec which you clear and fill up again every frame rather than creating a new Vec
every frame.