- [NEW] Passat a delta time

- [NEW] Nous tiles
- [NEW] Batman ja puja i baixa per cordes/cadenes
- [NEW] El batarang es mes visible
- [NEW] el ganxo es mes visible
This commit is contained in:
2025-11-10 12:19:17 +01:00
parent 8aa6631a8a
commit 16b45ecf45
8 changed files with 163 additions and 56 deletions

View File

@@ -3,36 +3,46 @@ require "mapa"
batarang = { batarang = {
items = {}, items = {},
cooldown = 0, cooldown = 0,
dx = 8, frame_time = 0.0,
dx = 160,
draw = function() draw = function()
surf.source(batman.surface) surf.source(batman.surface)
for i, k in pairs(batarang.items) do for i, k in pairs(batarang.items) do
k.blink = not k.blink
local flip_h, flip_v = false, false local flip_h, flip_v = false, false
if k.s==1 or k.s==2 then flip_v = true end if k.s==1 or k.s==2 then flip_v = true end
if k.s==2 or k.s==3 then flip_h = true end if k.s==2 or k.s==3 then flip_h = true end
if k.blink then pal.subpal(65,22) end
draw.surf(123,27,5,5,k.x,k.y,5,5, flip_h, flip_v) draw.surf(123,27,5,5,k.x,k.y,5,5, flip_h, flip_v)
if k.blink then pal.subpal(65) end
end end
end, end,
update = function() update = function()
local d = sys.delta()
if batarang.cooldown > 0 then batarang.cooldown = batarang.cooldown - 1 end if batarang.cooldown > 0 then batarang.cooldown = batarang.cooldown - 1 end
for i, k in pairs(batarang.items) do for i, k in pairs(batarang.items) do
local tx, ty = ((k.x+2)//8), ((k.y+2)//8) local tx, ty = ((k.x+2)//8), ((k.y+2)//8)
if (mapa.isSolid(tx,ty)) then if (mapa.isSolid(tx,ty)) then
batarang.items[i] = nil batarang.items[i] = nil
else else
k.x = k.x + k.dx k.x = k.x + k.dx*d
k.s = k.s + 1 batarang.frame_time = batarang.frame_time + d
if (k.s==4) then k.s = 0 end if batarang.frame_time >= 0.06 then
batarang.frame_time = 0.0
k.s = k.s + 1
if (k.s==4) then k.s = 0 end
end
end end
end end
end, end,
new = function(x,y,flip) new = function(x,y,flip)
--if batarang.cooldown == 0 then --if batarang.cooldown == 0 then
table.insert(batarang.items, {x=x, y=y, s=0, dx=flip and -8 or 8}) table.insert(batarang.items, {x=x, y=y, s=0, dx=flip and -160 or 160, blink=false})
-- batarang.cooldown = 5 batarang.cooldown = 10
--end --end
end, end,

View File

@@ -2,16 +2,19 @@
require "batarang" require "batarang"
batman = { batman = {
states = {IDLE=1, WALK=2, JUMP=3, FALL=4, STAIRS=5, GRAPPLING=6, PROPELLED=7, SHOOT=8}, states = {IDLE=1, WALK=2, JUMP=3, FALL=4, STAIRS=5, GRAPPLING=6, PROPELLED=7, SHOOT=8, ROPE=9},
x = 7*8, x = 104*8,
y = 14*8, y = 6*8,
surface = nil, surface = nil,
flip = false, flip = false,
frames = {0}, frames = {0},
frame = 1, frame = 1,
frame_time = 0.0,
state = 1, state = 1,
dy = 0.0,
jump_counter = 0, jump_counter = 0,
ignore_first_tile = 0, ignore_first_tile = 0,
ignore_rope = 0,
layer = 1, layer = 1,
grappling_length = 0, grappling_length = 0,
@@ -25,8 +28,8 @@ batman = {
local f = batman.frames[batman.frame] local f = batman.frames[batman.frame]
draw.surf((f%8)*16,(f//8)*16,16,16,batman.x,batman.y,16,16,batman.flip) draw.surf((f%8)*16,(f//8)*16,16,16,batman.x,batman.y,16,16,batman.flip)
if batman.grappling_length>0 then if batman.grappling_length>0 then
draw.rect(batman.x+3, batman.y+7-batman.grappling_length*4, 1, batman.grappling_length*4, 64) draw.rect(batman.x+3, batman.y+7-batman.grappling_length*4, 1, batman.grappling_length*4, 8)
draw.rect(batman.x+2, batman.y+7-batman.grappling_length*4, 3, batman.grappling_length*4, 66) --draw.rect(batman.x+2, batman.y+7-batman.grappling_length*4, 3, batman.grappling_length*4, 66)
end end
--local tx1, tx2, ty = ((batman.x+4)//8), ((batman.x+10)//8), ((batman.y+16)//8) --local tx1, tx2, ty = ((batman.x+4)//8), ((batman.x+10)//8), ((batman.y+16)//8)
--draw.rect((tx1)*8,ty*8,8,8, 4) --draw.rect((tx1)*8,ty*8,8,8, 4)
@@ -34,18 +37,30 @@ batman = {
end, end,
update = function() update = function()
batman.frame = batman.frame + 1 local d = sys.delta()
if batman.frame > #batman.frames then batman.frame = 1 end
batman.frame_time = batman.frame_time + d
if batman.frame_time >= 0.06 then
batman.frame_time = 0.0
batman.frame = batman.frame + 1
if batman.frame > #batman.frames then batman.frame = 1 end
end
if (batman.ignore_rope>0) then
batman.ignore_rope = batman.ignore_rope - 40*d
if batman.ignore_rope<0 then batman.ignore_rope=0 end
end
if batman.state == batman.states.SHOOT then if batman.state == batman.states.SHOOT then
if batman.frame == 3 then if batman.frame == 3 then
batarang.new(batman.x+8, batman.y+8, batman.flip) if batarang.cooldown == 0 then batarang.new(batman.x+8, batman.y+8, batman.flip) end
elseif batman.frame == 5 then elseif batman.frame == 5 then
batman.state = batman.states.IDLE batman.state = batman.states.IDLE
batman.frames = {0} batman.frames = {0}
batman.frame = 1 batman.frame = 1
end end
end end
-- Si està IDLE -- Si està IDLE
if batman.state == batman.states.IDLE then if batman.state == batman.states.IDLE then
-- Mirem si comença a caminar -- Mirem si comença a caminar
@@ -71,7 +86,7 @@ batman = {
local tx, ty = ((batman.x+4)//8), ((batman.y+24)//8) local tx, ty = ((batman.x+4)//8), ((batman.y+24)//8)
if (not mapa.isSolid(tx,ty)) then if (not mapa.isSolid(tx,ty)) then
batman.state = batman.states.FALL batman.state = batman.states.FALL
batman.ignore_first_tile = 4 batman.ignore_first_tile = 32
batman.layer = 2 batman.layer = 2
end end
end end
@@ -91,11 +106,11 @@ batman = {
batman.frame = 1 batman.frame = 1
end end
elseif key.down(key.Z) then elseif key.down(key.Z) then
--if batarang.cooldown==0 then if batarang.cooldown==0 then
batman.state = batman.states.SHOOT batman.state = batman.states.SHOOT
batman.frames = {5,6,7,7,7} batman.frames = {5,6,7,7,7}
batman.frame = 1 batman.frame = 1
--end end
end end
-- Mirem si ha de caure -- Mirem si ha de caure
local tx1, tx2, ty = ((batman.x+4)//8), ((batman.x+10)//8), ((batman.y+16)//8) local tx1, tx2, ty = ((batman.x+4)//8), ((batman.x+10)//8), ((batman.y+16)//8)
@@ -105,7 +120,8 @@ batman = {
-- Mirem si comença a botar -- Mirem si comença a botar
if (batman.state ~= batman.states.FALL) and (key.down(key.X)) then if (batman.state ~= batman.states.FALL) and (key.down(key.X)) then
batman.state = batman.states.JUMP batman.state = batman.states.JUMP
batman.jump_counter = 0 batman.dy = -90
--batman.jump_counter = 0
end end
end end
@@ -115,12 +131,12 @@ batman = {
batman.state = batman.states.WALK batman.state = batman.states.WALK
batman.flip=false batman.flip=false
local tx, ty = ((batman.x+12)//8), ((batman.y+8)//8) local tx, ty = ((batman.x+12)//8), ((batman.y+8)//8)
if not mapa.isSolid(tx,ty) then batman.x = batman.x + 2 end if not mapa.isSolid(tx,ty) then batman.x = batman.x + 40*d end
elseif key.down(key.LEFT) then elseif key.down(key.LEFT) then
batman.state = batman.states.WALK batman.state = batman.states.WALK
batman.flip=true batman.flip=true
local tx, ty = ((batman.x+3)//8), ((batman.y+8)//8) local tx, ty = ((batman.x+3)//8), ((batman.y+8)//8)
if not mapa.isSolid(tx,ty) then batman.x = batman.x - 2 end if not mapa.isSolid(tx,ty) then batman.x = batman.x - 40*d end
else else
-- Ha parat de caminar -- Ha parat de caminar
batman.state = batman.states.IDLE batman.state = batman.states.IDLE
@@ -135,21 +151,26 @@ batman = {
-- Mirem si comença a botar -- Mirem si comença a botar
if key.down(key.X) then if key.down(key.X) then
batman.state = batman.states.JUMP batman.state = batman.states.JUMP
batman.jump_counter = 0 batman.dy = -90
--batman.jump_counter = 0
elseif key.down(key.Z) then elseif key.down(key.Z) then
--if batarang.cooldown==0 then if batarang.cooldown==0 then
batman.state = batman.states.SHOOT batman.state = batman.states.SHOOT
batman.frames = {5,6,7,7,7} batman.frames = {5,6,7,7,7}
batman.frame = 1 batman.frame = 1
-- end end
end end
end end
if batman.state == batman.states.JUMP then if batman.state == batman.states.JUMP then
batman.y = batman.y - 4 batman.y = batman.y + batman.dy*d
batman.jump_counter = batman.jump_counter + 1 batman.dy = batman.dy + 4
if batman.jump_counter == 5 then batman.frames = {4}
batman.jump_counter = 0 batman.frame = 1
--batman.jump_counter = batman.jump_counter + 1
--if batman.jump_counter == 5 then
if batman.dy >= 0 then
--batman.jump_counter = 0
batman.state = batman.states.FALL batman.state = batman.states.FALL
batman.frames = {4} batman.frames = {4}
batman.frame = 1 batman.frame = 1
@@ -157,11 +178,19 @@ batman = {
if key.down(key.RIGHT) then if key.down(key.RIGHT) then
batman.flip=false batman.flip=false
local tx, ty = ((batman.x+12)//8), ((batman.y+8)//8) local tx, ty = ((batman.x+12)//8), ((batman.y+8)//8)
if not mapa.isBlock(tx,ty) then batman.x = batman.x + 2 end if not mapa.isBlock(tx,ty) then batman.x = batman.x + 40*d end
elseif key.down(key.LEFT) then elseif key.down(key.LEFT) then
batman.flip=true batman.flip=true
local tx, ty = ((batman.x+3)//8), ((batman.y+8)//8) local tx, ty = ((batman.x+3)//8), ((batman.y+8)//8)
if not mapa.isBlock(tx,ty) then batman.x = batman.x - 2 end if not mapa.isBlock(tx,ty) then batman.x = batman.x - 40*d end
end
local tx, ty = ((batman.x+4)//8), ((batman.y+8)//8)
if mapa.isRope(tx,ty) and batman.ignore_rope==0 then
batman.state = batman.states.ROPE
batman.ignore_rope=10
batman.frames = {10}
batman.frame = 1
batman.x = (((batman.x+4)//8)*8)-4
end end
end end
@@ -169,15 +198,15 @@ batman = {
if key.down(key.RIGHT) then if key.down(key.RIGHT) then
batman.flip=false batman.flip=false
local tx, ty = ((batman.x+12)//8), ((batman.y+8)//8) local tx, ty = ((batman.x+12)//8), ((batman.y+8)//8)
if not mapa.isSolid(tx,ty) then batman.x = batman.x + 2 end if not mapa.isSolid(tx,ty) then batman.x = batman.x + 40*d end
elseif key.down(key.LEFT) then elseif key.down(key.LEFT) then
batman.flip=true batman.flip=true
local tx, ty = ((batman.x+3)//8), ((batman.y+8)//8) local tx, ty = ((batman.x+3)//8), ((batman.y+8)//8)
if not mapa.isSolid(tx,ty) then batman.x = batman.x - 2 end if not mapa.isSolid(tx,ty) then batman.x = batman.x - 40*d end
end end
local tx1, tx2, ty = ((batman.x+4)//8), ((batman.x+10)//8), ((batman.y+16)//8) local tx1, tx2, ty = ((batman.x+4)//8), ((batman.x+10)//8), ((batman.y+16)//8)
if (batman.ignore_first_tile>0) or ((not mapa.isSolid(tx1,ty)) and (not mapa.isSolid(tx2,ty))) then
if (batman.ignore_first_tile>0) or ((not mapa.isPlatform(tx1,ty)) and (not mapa.isPlatform(tx2,ty))) then
if batman.ignore_first_tile>0 then if batman.ignore_first_tile>0 then
batman.ignore_first_tile = batman.ignore_first_tile - 1 batman.ignore_first_tile = batman.ignore_first_tile - 1
else else
@@ -186,13 +215,27 @@ batman = {
batman.state = batman.states.FALL batman.state = batman.states.FALL
batman.frames = {4} batman.frames = {4}
batman.frame = 1 batman.frame = 1
batman.y = batman.y + 4
batman.dy = batman.dy + 4
if batman.dy > 80 then batman.dy=80 end
batman.y = batman.y + batman.dy*d
--batman.y = batman.y + 80*d
else else
batman.y = (batman.y//8)*8 batman.y = (batman.y//8)*8
batman.dy = 0
batman.state = batman.states.IDLE batman.state = batman.states.IDLE
batman.frames = {0} batman.frames = {0}
batman.frame = 1 batman.frame = 1
end end
local ty2 = ((batman.y+8)//8)
if mapa.isRope(tx1,ty2) and batman.ignore_rope==0 then
batman.state = batman.states.ROPE
batman.ignore_rope=10
batman.frames = {10}
batman.frame = 1
batman.x = (((batman.x+4)//8)*8)-4
end
end end
if batman.state == batman.states.STAIRS then if batman.state == batman.states.STAIRS then
@@ -205,7 +248,7 @@ batman = {
batman.frames = {8,10,9,10} batman.frames = {8,10,9,10}
batman.frame = 1 batman.frame = 1
end end
batman.y = batman.y + 2; batman.y = batman.y + 40*d;
else else
batman.state = batman.states.IDLE batman.state = batman.states.IDLE
batman.frames = {0} batman.frames = {0}
@@ -219,7 +262,7 @@ batman = {
batman.frames = {8,10,9,10} batman.frames = {8,10,9,10}
batman.frame = 1 batman.frame = 1
end end
batman.y = batman.y - 2; batman.y = batman.y - 40*d;
else else
batman.state = batman.states.IDLE batman.state = batman.states.IDLE
batman.frames = {0} batman.frames = {0}
@@ -236,28 +279,72 @@ batman = {
end end
end end
if batman.state == batman.states.ROPE then
local moving = false
if key.down(key.DOWN) then
moving = true
local tx, ty = ((batman.x+4)//8), ((batman.y+8)//8)
if (mapa.isRope(tx,ty)) then
if #batman.frames==1 then
batman.frames = {8,10,9,10}
batman.frame = 1
end
batman.y = batman.y + 40*d;
end
elseif key.down(key.UP) then
moving = true
local tx, ty = ((batman.x+4)//8), ((batman.y-1)//8)
if (mapa.isRope(tx,ty)) then
if #batman.frames==1 then
batman.frames = {8,10,9,10}
batman.frame = 1
end
batman.y = batman.y - 40*d;
end
elseif key.down(key.X) and batman.ignore_rope==0 then
if key.down(key.LEFT) then batman.flip = true end
if key.down(key.RIGHT) then batman.flip = false end
batman.state = batman.states.JUMP
batman.ignore_rope=10
batman.dy = -100
end
if not moving then
batman.frames = {10}
batman.frame = 1
end
end
if batman.state == batman.states.GRAPPLING then if batman.state == batman.states.GRAPPLING then
batman.grappling_length = batman.grappling_length + 1 batman.grappling_length = batman.grappling_length + 40*d
local tx, ty = ((batman.x+2)//8), ((batman.y+7-batman.grappling_length*4)//8) if batman.grappling_length >= 12 then
if mapa.isSolid(tx, ty) then batman.grappling_length = 0
if mapa.isBlock(tx,ty) then batman.state = batman.states.IDLE
batman.grappling_length = 0 batman.frames = {0}
batman.state = batman.states.IDLE batman.frame = 1
batman.frames = {0} else
batman.frame = 1 local tx, ty = ((batman.x+2)//8), ((batman.y+7-batman.grappling_length*4)//8)
else if mapa.isSolid(tx, ty) then
batman.layer = 2 if mapa.isBlock(tx,ty) then
batman.state = batman.states.PROPELLED batman.grappling_length = 0
batman.state = batman.states.IDLE
batman.frames = {0}
batman.frame = 1
else
batman.layer = 2
batman.state = batman.states.PROPELLED
end
end end
end end
end end
if batman.state == batman.states.PROPELLED then if batman.state == batman.states.PROPELLED then
batman.grappling_length = batman.grappling_length - 1 batman.grappling_length = batman.grappling_length - 40*d
batman.y = batman.y - 4 batman.y = batman.y - 160*d
if batman.grappling_length == 0 then if batman.grappling_length <= 0 then
batman.grappling_length = 0
batman.state = batman.states.JUMP batman.state = batman.states.JUMP
batman.jump_counter = 0 --batman.jump_counter = 0
batman.dy = -100
end end
end end

View File

@@ -26,10 +26,10 @@ game = {
mapa.draw(2) mapa.draw(2)
if batman.layer==2 then batman.draw() end if batman.layer==2 then batman.draw() end
if sys.beat() then --if sys.beat() then
batman.update() batman.update()
batarang.update() batarang.update()
end --end
--view.origin(0,0) --view.origin(0,0)
--draw.text(tostring(mx//8)..","..tostring(my//8),50,0,22) --draw.text(tostring(mx//8)..","..tostring(my//8),50,0,22)

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 637 B

After

Width:  |  Height:  |  Size: 629 B

View File

@@ -77,7 +77,7 @@ mapa = {
isSolid = function(x, y) isSolid = function(x, y)
local tile = map.tile(x, y) local tile = map.tile(x, y)
return (tile == 32) or (tile == 33) or (tile==36) or (tile==37) return (tile == 32) or (tile == 33) or (tile==36) or (tile==37) or (tile==42) or (tile==44) or (tile==45) or (tile==47)
end, end,
isBlock = function(x, y) isBlock = function(x, y)
@@ -85,9 +85,19 @@ mapa = {
return (tile == 32) return (tile == 32)
end, end,
isPlatform = function(x, y)
local tile = map.tile(x, y)
return (tile == 33) or (tile==36) or (tile==37)
end,
isStairs = function(x, y) isStairs = function(x, y)
local tile = map.tile(x, y) local tile = map.tile(x, y)
return (tile>33) and (tile<40) return (tile>33) and (tile<40)
end, end,
isRope = function(x, y)
local tile = map.tile(x, y)
return (tile==40) or (tile==41)
end,
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB