[WIP] Més tiles

[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
This commit is contained in:
2025-11-06 17:29:44 +01:00
parent fc99ad06a4
commit cc2f1803a4
8 changed files with 128 additions and 4 deletions

15
data/batman.lua Normal file
View File

@@ -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
}

View File

@@ -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,

78
data/game.lua Normal file
View File

@@ -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,
}

View File

@@ -1,2 +1,2 @@
start-x=-24
start-y=-24
start-x=-984
start-y=8

Binary file not shown.

Before

Width:  |  Height:  |  Size: 493 B

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 451 B

After

Width:  |  Height:  |  Size: 637 B

View File

@@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 884 B

After

Width:  |  Height:  |  Size: 1.4 KiB