- [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:
@@ -3,36 +3,46 @@ require "mapa"
|
||||
batarang = {
|
||||
items = {},
|
||||
cooldown = 0,
|
||||
dx = 8,
|
||||
frame_time = 0.0,
|
||||
dx = 160,
|
||||
|
||||
draw = function()
|
||||
surf.source(batman.surface)
|
||||
for i, k in pairs(batarang.items) do
|
||||
k.blink = not k.blink
|
||||
local flip_h, flip_v = false, false
|
||||
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.blink then pal.subpal(65,22) end
|
||||
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,
|
||||
|
||||
update = function()
|
||||
local d = sys.delta()
|
||||
|
||||
if batarang.cooldown > 0 then batarang.cooldown = batarang.cooldown - 1 end
|
||||
for i, k in pairs(batarang.items) do
|
||||
local tx, ty = ((k.x+2)//8), ((k.y+2)//8)
|
||||
if (mapa.isSolid(tx,ty)) then
|
||||
batarang.items[i] = nil
|
||||
else
|
||||
k.x = k.x + k.dx
|
||||
k.x = k.x + k.dx*d
|
||||
batarang.frame_time = batarang.frame_time + d
|
||||
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,
|
||||
|
||||
new = function(x,y,flip)
|
||||
--if batarang.cooldown == 0 then
|
||||
table.insert(batarang.items, {x=x, y=y, s=0, dx=flip and -8 or 8})
|
||||
-- batarang.cooldown = 5
|
||||
table.insert(batarang.items, {x=x, y=y, s=0, dx=flip and -160 or 160, blink=false})
|
||||
batarang.cooldown = 10
|
||||
--end
|
||||
end,
|
||||
|
||||
|
||||
153
data/batman.lua
153
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()
|
||||
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,8 +279,49 @@ 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
|
||||
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
|
||||
@@ -251,13 +335,16 @@ batman = {
|
||||
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
|
||||
|
||||
|
||||
@@ -26,10 +26,10 @@ game = {
|
||||
mapa.draw(2)
|
||||
if batman.layer==2 then batman.draw() end
|
||||
|
||||
if sys.beat() then
|
||||
--if sys.beat() then
|
||||
batman.update()
|
||||
batarang.update()
|
||||
end
|
||||
--end
|
||||
|
||||
--view.origin(0,0)
|
||||
--draw.text(tostring(mx//8)..","..tostring(my//8),50,0,22)
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
start-x=-984
|
||||
start-y=8
|
||||
start-x=-808
|
||||
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 |
@@ -77,7 +77,7 @@ mapa = {
|
||||
|
||||
isSolid = function(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,
|
||||
|
||||
isBlock = function(x, y)
|
||||
@@ -85,9 +85,19 @@ mapa = {
|
||||
return (tile == 32)
|
||||
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)
|
||||
local tile = map.tile(x, y)
|
||||
return (tile>33) and (tile<40)
|
||||
end,
|
||||
|
||||
isRope = function(x, y)
|
||||
local tile = map.tile(x, y)
|
||||
return (tile==40) or (tile==41)
|
||||
end,
|
||||
|
||||
}
|
||||
BIN
data/tiles01.gif
BIN
data/tiles01.gif
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.7 KiB |
Reference in New Issue
Block a user