Hi everyone! I’m new to Corona, and I’m hung up on how to structure my game so that I can keep my basic interactions separate from level-specific logic. I’ll try to provide a barebones example of what I need.
Let’s say we’re making a simple dodging game where the main character (a circle) must dodge the bad guys, (the squares). The circle is controlled by the player, and the squares are generated and moved in different ways based on the level (e.g level 1 might have falling squares, and level 2 might have squares coming in from the sides).
The “core mechanics” here are that the circle is controlled by the player, and that if the circle touches any of the squares, it’s game over. What is the right way to structure the game code so that these core mechanics can be included in every level with little duplication?
That’s it for the question, but here’s what I’m thinking so far (I could be totally off):
circle.lua : exposes a method to create a new circle, and takes care of player control.
square.lua : exposes methods to create and move a square as a level might require.
collisions.lua : handles collisions between the circle and squares.
level (x).lua: the level-specific files that will include the above three.
The challenge with this approach is in the “collisions.lua” file. It needs to know the location of the circle and every square in the scene so that it can determine when there is a collision. I’m not confident enough to guess the best way to make that happen.
Any insight you can offer to put me in the right direction is appreciated!