- [NEW] Batman es pinta en el layer que toca cada vegada

- [WIP] Grappling hook implementat
This commit is contained in:
2025-11-07 14:54:17 +01:00
parent 14dc8a0948
commit 40342b858e
2 changed files with 51 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
batman = {
states = {IDLE=1, WALK=2, JUMP=3, FALL=4, FALLTHROUGH=5, STAIRS_IDLE=6, STAIRS_MOVING=7},
states = {IDLE=1, WALK=2, JUMP=3, FALL=4, STAIRS=5, GRAPPLING=6, PROPELLED=7},
x = 7*8,
y = 14*8,
surface = nil,
@@ -10,6 +10,8 @@ batman = {
state = 1,
jump_counter = 0,
ignore_first_tile = 0,
layer = 1,
grappling_length = 0,
init = function()
batman.surface = surf.load("batman.gif")
@@ -20,9 +22,13 @@ batman = {
surf.source(batman.surface)
local f = batman.frames[batman.frame]
draw.surf((f%8)*16,(f//8)*16,16,16,batman.x,batman.y,16,16,batman.flip)
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((tx2)*8,ty*8,8,8, 4)
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+2, batman.y+7-batman.grappling_length*4, 3, batman.grappling_length*4, 66)
end
--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((tx2)*8,ty*8,8,8, 4)
end,
update = function()
@@ -43,7 +49,7 @@ batman = {
elseif key.down(key.DOWN) then
local tx, ty = ((batman.x+4)//8), ((batman.y+8)//8)
if (mapa.isStairs(tx,ty)) then
batman.state = batman.states.STAIRS_IDLE
batman.state = batman.states.STAIRS
batman.frames = {10}
batman.frame = 1
batman.x = ((batman.x+4)//8)*8
@@ -55,19 +61,23 @@ batman = {
if (not mapa.isSolid(tx,ty)) then
batman.state = batman.states.FALL
batman.ignore_first_tile = 4
batman.layer = 2
end
end
elseif key.down(key.UP) then
local tx, ty = ((batman.x+4)//8), ((batman.y)//8)
if (mapa.isStairs(tx,ty)) then
batman.state = batman.states.STAIRS_IDLE
batman.state = batman.states.STAIRS
batman.frames = {10}
batman.frame = 1
--batman.x = (batman.x//8)*8
batman.x = ((batman.x+4)//8)*8
if (mapa.isStairs(tx-1,ty)) then
batman.x = batman.x - 8
end
elseif key.down(key.Z) then
batman.state = batman.states.GRAPPLING
batman.frames = {6}
batman.frame = 1
end
end
-- Mirem si ha de caure
@@ -145,7 +155,11 @@ batman = {
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 then batman.ignore_first_tile = batman.ignore_first_tile - 1 end
if batman.ignore_first_tile>0 then
batman.ignore_first_tile = batman.ignore_first_tile - 1
else
batman.layer = 1
end
batman.state = batman.states.FALL
batman.frames = {4}
batman.frame = 1
@@ -158,7 +172,7 @@ batman = {
end
end
if batman.state == batman.states.STAIRS_IDLE then
if batman.state == batman.states.STAIRS then
local moving = false
if key.down(key.DOWN) then
moving = true
@@ -198,6 +212,32 @@ batman = {
batman.frame = 1
end
end
if batman.state == batman.states.GRAPPLING then
batman.grappling_length = batman.grappling_length + 1
local tx, ty = ((batman.x+2)//8), ((batman.y+7-batman.grappling_length*4)//8)
if mapa.isSolid(tx, ty) then
if mapa.isBlock(tx,ty) then
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
if batman.state == batman.states.PROPELLED then
batman.grappling_length = batman.grappling_length - 1
batman.y = batman.y - 4
if batman.grappling_length == 0 then
batman.state = batman.states.JUMP
batman.jump_counter = 0
end
end
end,
}