I'm a beginner to programming (I know pretty much all of the basics in Python and am just confused about a few things in Lua) and I am trying to learn how to make games on my own, without just following tutorials and copying code.
The game I'm trying to create for practice is where you essentially dodge shapes with your mouse and if you hit one you die and it restarts. The shapes are all different sizes speeds. So far I have a green circle that sticks to your mouse coordinates and a single random rectangle that spawns above the screen and falls down.
But I could not figure out anything beyond that. Looking all of my problems up online just gave me answers very specific to other's code that I couldn't understand.
So I have quite a few questions here. The first one being:
1. Where do I put things in my code?
In a tutorial I watched to get the basics of Love, they brought up the main 3 'game functions' (for lack of better terminology) but they didn't really explain it. The
Code: Select all
function love.load()
Code: Select all
function love.update(dt)
Code: Select all
function love.draw()
I vaguely understand where to put basic things, like drawing rectangles in the love.draw function and dealing with movement/controls in the love.update function but when I'm trying to do more complex things I get lost. Such as new functions. Do you/can you write functions inside of functions? (Should you do that? (Most of the time I try to put functions at the top but I always get nil values.)) Furthermore, is love.load, update, and draw even that important? I.e.: Is it more like a guideline or does stuff just not work if you don't have it?
And now the more specific problems:
Spawning multiple objects, collision, and a game over sequence?
These are mainly the things I said I couldn't find good examples of online. For collision, I have no idea what love.physics is; it looks crazy complex and complicated at a glance. For the game over sequence, I haven't actually tried. I know how to do such in Pygame, for the most part, but again, not sure where I would put it. (Or if I can/could actually do it in the same way.)
https://pastebin.com/vJ6HeRhM
^ Here's what I have so far. (Sorry if pastebin links are frowned upon - I don't know how to 'package' my game)
Further things, more with Lua, is that I don't quite understand tables. If I could get some explanation of this as well or if someone could direct me to a great (free) place for learning Lua then that would be much appreciated!
Sorry for such a long post. I try not to post my questions online until I'm totally stuck and I'd rather not post multiple at once.