Follow the new API

This commit is contained in:
Jean-André Santoni 2015-02-23 01:14:37 +01:00
parent e6f7a276a4
commit 6a94a96abf
4 changed files with 23 additions and 24 deletions

View File

@ -25,7 +25,7 @@ function animation:update(dt)
end
function animation:draw(x, y)
lutro.graphics.drawq(
lutro.graphics.drawt(
self.image,
x, y,
self.width, self.height,

View File

@ -15,11 +15,13 @@ local add_entity_from_map = function(object)
end
function lutro.load()
bg1 = lutro.graphics.newImage(lutro.path .. "assets/forestbackground.png")
bg2 = lutro.graphics.newImage(lutro.path .. "assets/foresttrees.png")
font = lutro.graphics.newImageFont(lutro.path .. "assets/font.png",
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",
" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/")
map = tiled_load(lutro.path .. "assets/pagode.json")
lutro.graphics.setFont(font)
map = tiled_load("assets/pagode.json")
tiled_load_objects(map, add_entity_from_map)
table.insert(entities, newNinja())
end
@ -34,7 +36,7 @@ function lutro.update(dt)
end
function lutro.draw()
lutro.graphics.clear(0xff000000)
lutro.graphics.clear()
for i=0, 1 do
lutro.graphics.draw(bg1, i*bg1:getWidth() + lutro.camera_x/6, 0)
@ -49,5 +51,5 @@ function lutro.draw()
end
tiled_draw_layer(map.layers[2])
lutro.graphics.print(font, "Hello world!", 3, 1)
lutro.graphics.print("Hello world!", 3, 1)
end

View File

@ -19,35 +19,35 @@ function newNinja()
n.animations = {
stand = {
left = newAnimation(lutro.graphics.newImage(lutro.path ..
left = newAnimation(lutro.graphics.newImage(
"assets/ninja_stand_left.png"), 48, 48, 100, 10),
right = newAnimation(lutro.graphics.newImage(lutro.path ..
right = newAnimation(lutro.graphics.newImage(
"assets/ninja_stand_right.png"), 48, 48, 100, 10)
},
run = {
left = newAnimation(lutro.graphics.newImage(lutro.path ..
left = newAnimation(lutro.graphics.newImage(
"assets/ninja_run_left.png"), 48, 48, 1, 10),
right = newAnimation(lutro.graphics.newImage(lutro.path ..
right = newAnimation(lutro.graphics.newImage(
"assets/ninja_run_right.png"), 48, 48, 1, 10)
},
jump = {
left = newAnimation(lutro.graphics.newImage(lutro.path ..
left = newAnimation(lutro.graphics.newImage(
"assets/ninja_jump_left.png"), 48, 48, 1, 10),
right = newAnimation(lutro.graphics.newImage(lutro.path ..
right = newAnimation(lutro.graphics.newImage(
"assets/ninja_jump_right.png"), 48, 48, 1, 10)
},
fall = {
left = newAnimation(lutro.graphics.newImage(lutro.path ..
left = newAnimation(lutro.graphics.newImage(
"assets/ninja_fall_left.png"), 48, 48, 1, 10),
right = newAnimation(lutro.graphics.newImage(lutro.path ..
right = newAnimation(lutro.graphics.newImage(
"assets/ninja_fall_right.png"), 48, 48, 1, 10)
},
}
n.anim = n.animations[n.stance][n.direction]
n.sfx = {
jump = lutro.audio.newSource(lutro.path .. "assets/jump.wav"),
step = lutro.audio.newSource(lutro.path .. "assets/step.wav")
jump = lutro.audio.newSource("assets/jump.wav"),
step = lutro.audio.newSource("assets/step.wav")
}
return setmetatable(n, ninja)
end

View File

@ -1,15 +1,12 @@
local json = require("dkjson")
function tiled_load(filename)
local f = assert(io.open(filename, "r"))
local str = f:read("*all")
f:close()
local map, pos, err = json.decode(str, 1, nil)
local str = lutro.filesystem.read(filename)
local map, pos, err = json.decode(str, 1, nil)
for i = 1, #map.tilesets do
local tileset = map.tilesets[i]
local path = lutro.path .. "assets/" .. tileset.image
tileset.surface = lutro.graphics.newImage(path)
tileset.surface = lutro.graphics.newImage("assets/" .. tileset.image)
end
return map
@ -35,7 +32,7 @@ function tiled_draw_layer(layer)
local t = tiled_get_tileset(map, id)
if (id > 0) then
lutro.graphics.drawq(t.surface, x, y,
lutro.graphics.drawt(t.surface, x, y,
map.tilewidth, map.tileheight,
id - t.firstgid+1)
end