- [NEW] Batman es pinta en el layer que toca cada vegada
- [WIP] Grappling hook implementat
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
batman = {
|
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,
|
x = 7*8,
|
||||||
y = 14*8,
|
y = 14*8,
|
||||||
surface = nil,
|
surface = nil,
|
||||||
@@ -10,6 +10,8 @@ batman = {
|
|||||||
state = 1,
|
state = 1,
|
||||||
jump_counter = 0,
|
jump_counter = 0,
|
||||||
ignore_first_tile = 0,
|
ignore_first_tile = 0,
|
||||||
|
layer = 1,
|
||||||
|
grappling_length = 0,
|
||||||
|
|
||||||
init = function()
|
init = function()
|
||||||
batman.surface = surf.load("batman.gif")
|
batman.surface = surf.load("batman.gif")
|
||||||
@@ -20,9 +22,13 @@ batman = {
|
|||||||
surf.source(batman.surface)
|
surf.source(batman.surface)
|
||||||
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)
|
||||||
local tx1, tx2, ty = ((batman.x+4)//8), ((batman.x+10)//8), ((batman.y+16)//8)
|
if batman.grappling_length>0 then
|
||||||
draw.rect((tx1)*8,ty*8,8,8, 4)
|
draw.rect(batman.x+3, batman.y+7-batman.grappling_length*4, 1, batman.grappling_length*4, 64)
|
||||||
draw.rect((tx2)*8,ty*8,8,8, 4)
|
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,
|
end,
|
||||||
|
|
||||||
update = function()
|
update = function()
|
||||||
@@ -43,7 +49,7 @@ batman = {
|
|||||||
elseif key.down(key.DOWN) then
|
elseif key.down(key.DOWN) then
|
||||||
local tx, ty = ((batman.x+4)//8), ((batman.y+8)//8)
|
local tx, ty = ((batman.x+4)//8), ((batman.y+8)//8)
|
||||||
if (mapa.isStairs(tx,ty)) then
|
if (mapa.isStairs(tx,ty)) then
|
||||||
batman.state = batman.states.STAIRS_IDLE
|
batman.state = batman.states.STAIRS
|
||||||
batman.frames = {10}
|
batman.frames = {10}
|
||||||
batman.frame = 1
|
batman.frame = 1
|
||||||
batman.x = ((batman.x+4)//8)*8
|
batman.x = ((batman.x+4)//8)*8
|
||||||
@@ -55,19 +61,23 @@ batman = {
|
|||||||
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 = 4
|
||||||
|
batman.layer = 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif key.down(key.UP) then
|
elseif key.down(key.UP) then
|
||||||
local tx, ty = ((batman.x+4)//8), ((batman.y)//8)
|
local tx, ty = ((batman.x+4)//8), ((batman.y)//8)
|
||||||
if (mapa.isStairs(tx,ty)) then
|
if (mapa.isStairs(tx,ty)) then
|
||||||
batman.state = batman.states.STAIRS_IDLE
|
batman.state = batman.states.STAIRS
|
||||||
batman.frames = {10}
|
batman.frames = {10}
|
||||||
batman.frame = 1
|
batman.frame = 1
|
||||||
--batman.x = (batman.x//8)*8
|
|
||||||
batman.x = ((batman.x+4)//8)*8
|
batman.x = ((batman.x+4)//8)*8
|
||||||
if (mapa.isStairs(tx-1,ty)) then
|
if (mapa.isStairs(tx-1,ty)) then
|
||||||
batman.x = batman.x - 8
|
batman.x = batman.x - 8
|
||||||
end
|
end
|
||||||
|
elseif key.down(key.Z) then
|
||||||
|
batman.state = batman.states.GRAPPLING
|
||||||
|
batman.frames = {6}
|
||||||
|
batman.frame = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Mirem si ha de caure
|
-- 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)
|
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.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.state = batman.states.FALL
|
||||||
batman.frames = {4}
|
batman.frames = {4}
|
||||||
batman.frame = 1
|
batman.frame = 1
|
||||||
@@ -158,7 +172,7 @@ batman = {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if batman.state == batman.states.STAIRS_IDLE then
|
if batman.state == batman.states.STAIRS then
|
||||||
local moving = false
|
local moving = false
|
||||||
if key.down(key.DOWN) then
|
if key.down(key.DOWN) then
|
||||||
moving = true
|
moving = true
|
||||||
@@ -198,6 +212,32 @@ batman = {
|
|||||||
batman.frame = 1
|
batman.frame = 1
|
||||||
end
|
end
|
||||||
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,
|
end,
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -20,8 +20,9 @@ game = {
|
|||||||
|
|
||||||
surf.cls(66)
|
surf.cls(66)
|
||||||
mapa.draw(1)
|
mapa.draw(1)
|
||||||
batman.draw()
|
if batman.layer==1 then batman.draw() end
|
||||||
mapa.draw(2)
|
mapa.draw(2)
|
||||||
|
if batman.layer==2 then batman.draw() end
|
||||||
|
|
||||||
if sys.beat() then
|
if sys.beat() then
|
||||||
batman.update()
|
batman.update()
|
||||||
|
|||||||
Reference in New Issue
Block a user