Alright, that makes sense.
Basically what I've got is 4 days' work since I just started learning Lua/Love (I've programmed in other languages before.) I save a backup at then end of each day.
Right now I have 5 main files:
classes.lua holds the Screen class, with it you can create 'screens.' Screens are things that can be positioned and paused and stuff. Right now I use one Screen to hold one Game. Game is another class the deals with the game, such as loading maps, adding objects, events, and so on. Might make another class for game objects but I don't know if it'd be worth it.
definitions.lua holds references to all the images and the types of tiles and if they collide, are a slope, or have friction (+ anything else.)
functions.lua This one contains just functions for anything, like a check-point-overlap-quad function, check-quad-overlap-quad function, ...
main.lua does all the startup and setup work.
game.lua is like a level file. It holds all object types and what they do but it will probably turn into something that other level files can include (like level generics.)
Here's the player update function as of now:
Code: Select all
function player(o, game)
o.yv = o.yv / (1 + 0.05 * game.speed) + game.gravity * game.speed
o.xv = o.xv / (1 + 0.05 * game.speed)
if love.keyboard.isDown('left') then o.xv = o.xv - 0.2 * game.speed ; o.facing = 0 end
if love.keyboard.isDown('right') then o.xv = o.xv + 0.2 * game.speed ; o.facing = 10 end
if love.keyboard.isDown('2') then game.map.scale = game.map.scale * 1.1 end
if love.keyboard.isDown('1') then game.map.scale = game.map.scale / 1.1 end
o.x2 = o.x
o.y2 = o.y
o.x = o.x + o.xv * game.speed
o.y = o.y + o.yv * game.speed
c = collideQQ(game.map.tiles.foreground, o, game)
if string.find(c, 'd') then
if love.keyboard.isDown('z') or love.keyboard.isDown('up') then o.yv = -6 end
if math.abs(o.xv) > 0.2 then o.img = 1 + (game.timer / 8) % 2 else o.img = 1 end
else
o.img = 2
end
game:setMapOffset(o.x + o.w / 2, o.y + o.h / 2)
end
The game passes the current object and itself to this function
player every frame, because...
...the player was added earlier with this code:
Code: Select all
game:addObject('player', player, drawPlayer)
Here I added an object that updates with function
player and draws with function
drawPlayer. The first parameter means nothing, but it may be useful for something later on, who knows...
I don't just post everything cause it's all subject to change and it spoils any surprises!
-remove useless link-