I have been working on a prototype for my game and have been making a lot of progress. However, I am doing ALL of my coding directly in main.lua. I have a massive pile of spaghetti code in main and I know this is not good practice, and I should be creating different lua files pertaining to different aspects of the game. Player.lua, Enemy.lua, Level.lua, etc…
My question is how do I approach splitting all of my working code out into separate modules without breaking things?
Specifically I am confused about the following:
-
I have code which acts like a camera and follows the player everywhere he moves (by moving the world display group in opposite direction). When I start pulling out code into separate files, isn’t that going to break how the camera functions?
-
I have sprites and animations created directly in main. What happens when those end up in another file?
-
I am using Tiled and have one map being loaded. When I start to add scenes and now have to decide which levels are loaded, how do I make sure this separate code integrates well with the rest of the game?
-
Collision detection and physics code is currently all in main. How would I go about separating it out?
To summarize, I would like to take the next step and go from prototype (with all code in main.lua) to complete game with multiple levels, enemies, etc, but I kind of have no idea of where to even start…
Would any one be able to give a concrete example of how I can begin to approach this?