lutro-platformer/main.lua

64 lines
1.4 KiB
Lua
Raw Normal View History

2015-02-17 19:17:09 +00:00
require "global"
require "tiled"
require "anim"
require "ninja"
function lutro.conf(t)
t.width = SCREEN_WIDTH
t.height = SCREEN_HEIGHT
end
local add_entity_from_map = function(object)
if object.type == "ground" then
table.insert(entities, object)
end
end
function lutro.load()
camera_x = 0
camera_y = 0
2015-02-23 00:14:37 +00:00
lutro.graphics.setBackgroundColor(0, 0, 0)
bg1 = lutro.graphics.newImage("assets/forestbackground.png")
bg2 = lutro.graphics.newImage("assets/foresttrees.png")
font = lutro.graphics.newImageFont("assets/font.png",
2015-02-19 16:37:26 +00:00
" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/")
2015-02-23 00:14:37 +00:00
lutro.graphics.setFont(font)
map = tiled_load("assets/pagode.json")
2015-02-17 19:17:09 +00:00
tiled_load_objects(map, add_entity_from_map)
table.insert(entities, newNinja())
end
function lutro.update(dt)
for i=1, #entities do
if entities[i].update then
entities[i]:update(dt)
end
end
detect_collisions()
end
function lutro.draw()
2015-02-23 00:14:37 +00:00
lutro.graphics.clear()
2015-02-17 19:56:16 +00:00
for i=0, 4 do
lutro.graphics.draw(bg1, i*bg1:getWidth() + camera_x / 6, 0)
lutro.graphics.draw(bg2, i*bg2:getWidth() + camera_x / 3, 0)
2015-02-17 19:56:16 +00:00
end
lutro.graphics.push()
lutro.graphics.translate(camera_x, camera_y)
2015-02-17 19:17:09 +00:00
tiled_draw_layer(map.layers[1])
for i=1, #entities do
if entities[i].draw then
entities[i]:draw(dt)
end
end
tiled_draw_layer(map.layers[2])
2015-02-19 16:37:26 +00:00
lutro.graphics.pop()
2015-02-23 00:14:37 +00:00
lutro.graphics.print("Hello world!", 3, 1)
2015-02-17 19:17:09 +00:00
end