diff --git a/data/batman.lua b/data/batman.lua new file mode 100644 index 0000000..572acce --- /dev/null +++ b/data/batman.lua @@ -0,0 +1,15 @@ +batman = { + x = 7*8, + y = 14*8, + surface = nil, + flip = false, + + init = function() + batman.surface = surf.load("batman.gif") + end, + + draw = function() + surf.source(batman.surface) + draw.surf(0,0,16,16,batman.x,batman.y,16,16,batman.flip) + end +} \ No newline at end of file diff --git a/data/editor.lua b/data/editor.lua index b6cf42c..09694b9 100644 --- a/data/editor.lua +++ b/data/editor.lua @@ -1,3 +1,4 @@ + editor = { num = 1, map_surf = {nil,nil}, @@ -5,6 +6,8 @@ editor = { current_tile = 1, ox = 0, oy = 0, + mx = 0, + my = 0, init = function(level_name) game_update = editor.update @@ -63,13 +66,19 @@ editor = { view.origin(editor.ox,editor.oy) surf.cls(66) pal.trans(0) + surf.source(tiles) map.surf(editor.map_surf[1]) map.draw() + + --batman.draw() + + surf.source(tiles) map.surf(editor.map_surf[2]) map.draw() map.surf(editor.map_surf[editor.current_layer]) + local mx,my = mouse.pos() local tx = (mx//8)*8 local ty = (my//8)*8 @@ -106,6 +115,20 @@ editor = { end view.origin(0,0) + draw.text(tostring(mx//8)..","..tostring(my//8),50,0,22) + + mx,my = mouse.pos() + if key.down(key.SPACE) then + if editor.mx == -1 then + editor.mx,editor.my = mx,my + end + editor.ox = editor.ox + 8*(mx-editor.mx) + editor.oy = editor.oy + 8*(my-editor.my) + editor.mx,editor.my = mx,my + else + editor.mx = -1 + end + text(tostring(editor.current_layer),0,0,22,42) end, diff --git a/data/game.lua b/data/game.lua new file mode 100644 index 0000000..06ff861 --- /dev/null +++ b/data/game.lua @@ -0,0 +1,78 @@ +require "batman" + +game = { + num = 1, + map_surf = {nil,nil}, + current_layer = 1, + current_tile = 1, + + init = function(level_name) + game_update = game.update + game.load(1) + batman.init() + end, + + load = function(level) + local base_name = "level" .. tostring(level) + local file = io.open("data/" .. base_name .. ".lev", "r") + if file then + for line in file:lines() do + local key,value = line:match("^(.+)=(.+)$") + if key and value then + --if key == "start-x" then + -- editor.ox = tonumber(value) + --elseif key == "start-y" then + -- editor.oy = tonumber(value) + --end + end + end + game.num = level + if game.map_surf[1] then surf.free(game.map_surf[1]) end + if game.map_surf[2] then surf.free(game.map_surf[2]) end + game.map_surf[1] = surf.load(base_name .. "_1.gif") + game.map_surf[2] = surf.load(base_name .. "_2.gif") + else + print("No s'ha trobat l'arxiu!") + end + end, + + update = function() + --view.origin(editor.ox,editor.oy) + local cam_x, cam_y = -(batman.x-7*8),-(batman.y-6*8) + if (cam_x>0) then cam_x=0 end + if (cam_y>0) then cam_y=0 end + view.origin(cam_x,cam_y) + surf.cls(66) + pal.trans(0) + + surf.source(tiles) + map.surf(game.map_surf[1]) + map.draw() + + batman.draw() + + surf.source(tiles) + map.surf(game.map_surf[2]) + map.draw() + map.surf(game.map_surf[game.current_layer]) + + + if key.press(key.TAB) then + --game_update = editor.tile_picker_update + elseif key.down(key.RIGHT) then + batman.x = batman.x + 1 + elseif key.down(key.LEFT) then + batman.x = batman.x - 1 + elseif key.down(key.DOWN) then + batman.y = batman.y + 1 + elseif key.down(key.UP) then + batman.y = batman.y - 1 + end + + --view.origin(0,0) + --draw.text(tostring(mx//8)..","..tostring(my//8),50,0,22) + + --text(tostring(editor.current_layer),0,0,22,42) + end, + +} \ No newline at end of file diff --git a/data/level1.lev b/data/level1.lev index 99f6b1c..72dfba0 100644 --- a/data/level1.lev +++ b/data/level1.lev @@ -1,2 +1,2 @@ -start-x=-24 -start-y=-24 +start-x=-984 +start-y=8 diff --git a/data/level1_1.gif b/data/level1_1.gif index c29b3da..b6d496f 100644 Binary files a/data/level1_1.gif and b/data/level1_1.gif differ diff --git a/data/level1_2.gif b/data/level1_2.gif index 27f3b88..40b3e58 100644 Binary files a/data/level1_2.gif and b/data/level1_2.gif differ diff --git a/data/main.lua b/data/main.lua index ff6b8ee..a5d3f27 100644 --- a/data/main.lua +++ b/data/main.lua @@ -1,6 +1,7 @@ require "editor" +require "game" -function mini.init() +function loadSurfaces() sprites=surf.load("batman.gif") tiles=surf.load("tiles01.gif") @@ -8,8 +9,11 @@ function mini.init() local paleta=pal.load("tiles01.gif") pal.set(paleta) +end - editor.init(1); +function mini.init() + loadSurfaces() + editor.init(1) end function mini.update() @@ -21,6 +25,10 @@ function mini.update() local fs = win.fullscreen() win.fullscreen(not fs) win.cursor(fs) + elseif key.press(key.F4) then + surf.free(sprites) + surf.free(tiles) + loadSurfaces() end if (game_update) then game_update() end diff --git a/data/tiles01.gif b/data/tiles01.gif index c98a027..2493eb5 100644 Binary files a/data/tiles01.gif and b/data/tiles01.gif differ