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