Today my goal was to finish implementing levels. Levels need to be larger than a single screen for the game I'm designing so this means I not only need to load multiple screens from my level files, but I also need a camera that will scroll across them following the player. Loading multiple screens is simple enough for now. After loading the first screen from the screen table the program simply goes over each adjacent screen coordinate and then if a screen exists in the screen table with those coordinates it gets added to a list of screens to be loaded. Then every game update a set number of screens from the list get read into the background layers and eventually the objects placed on that screen be will spawned in.
Next up is the camera system and while I was working on that I also got to work on basic physics and collisions. The movement and collision system isn't terribly fancy. It simply decomposes movement into X-axis movement and Y-axis movement, then for each it scans along the objects movement vector to see if there is a solid tile blocking the way. If there is then the object moves up to the solid tile, otherwise it just moves across the entire movement vector. Despite being simple I still had a some trouble working it out and had to write some of it out on paper and refer to previous projects to finally get it working.
For the camera system I wanted the camera to smoothly follow the player and also not react much to small movements. So I defined some boundaries that if the player moves outside of the camera will move to be centered over the player again. Another important thing was to make sure the camera doesn't move into screens that don't exist in the level. The background that screens get loaded into is only big enough to fit 16 screens on each axis and since levels will likely be much larger than this. When the level wraps around the background it'll only overwrite screens if they exist within the level file so it's possible that sometimes screens from earlier in the level may still be hanging around. So I want to make sure that the camera won't make these visible.
And finally putting it all together. The player can now move, jump, and collide with the terrain and the camera will follow the player as they move across the level. Also at some point I added a small menu to the title screen. Still left to do is vertical camera movement and loading more screens as the player travels through the level. My next goals in no particular order are.
- Finish player control by adding an air dash
- Create an animation system
- Draw animations for the player
- Finish camera movement
- Finish screen loading
- Create game objects
However those will all have to wait for the next day.