[WIP] Fase 2 [NEW] En l'editor, es pot moure per la fase amb SPACE+ratolí [WIP] mòdul GAME [WIP] mòdul BATMAN [NEW] F4 recarrega les textures
78 lines
2.2 KiB
Lua
78 lines
2.2 KiB
Lua
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,
|
|
|
|
} |