- [NEW] Batman ja dispara batarangs

This commit is contained in:
2025-11-07 18:16:25 +01:00
parent 40342b858e
commit 8aa6631a8a
4 changed files with 66 additions and 1 deletions

39
data/batarang.lua Normal file
View File

@@ -0,0 +1,39 @@
require "mapa"
batarang = {
items = {},
cooldown = 0,
dx = 8,
draw = function()
surf.source(batman.surface)
for i, k in pairs(batarang.items) do
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
draw.surf(123,27,5,5,k.x,k.y,5,5, flip_h, flip_v)
end
end,
update = function()
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.s = k.s + 1
if (k.s==4) then k.s = 0 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
--end
end,
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -1,6 +1,8 @@
require "batarang"
batman = {
states = {IDLE=1, WALK=2, JUMP=3, FALL=4, STAIRS=5, GRAPPLING=6, PROPELLED=7},
states = {IDLE=1, WALK=2, JUMP=3, FALL=4, STAIRS=5, GRAPPLING=6, PROPELLED=7, SHOOT=8},
x = 7*8,
y = 14*8,
surface = nil,
@@ -35,6 +37,15 @@ batman = {
batman.frame = batman.frame + 1
if batman.frame > #batman.frames then batman.frame = 1 end
if batman.state == batman.states.SHOOT then
if batman.frame == 3 then
batarang.new(batman.x+8, batman.y+8, batman.flip)
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
@@ -79,6 +90,12 @@ batman = {
batman.frames = {6}
batman.frame = 1
end
elseif key.down(key.Z) then
--if batarang.cooldown==0 then
batman.state = batman.states.SHOOT
batman.frames = {5,6,7,7,7}
batman.frame = 1
--end
end
-- Mirem si ha de caure
local tx1, tx2, ty = ((batman.x+4)//8), ((batman.x+10)//8), ((batman.y+16)//8)
@@ -119,6 +136,12 @@ batman = {
if key.down(key.X) then
batman.state = batman.states.JUMP
batman.jump_counter = 0
elseif key.down(key.Z) then
--if batarang.cooldown==0 then
batman.state = batman.states.SHOOT
batman.frames = {5,6,7,7,7}
batman.frame = 1
-- end
end
end

View File

@@ -1,5 +1,6 @@
require "mapa"
require "batman"
require "batarang"
game = {
num = 1,
@@ -20,12 +21,14 @@ game = {
surf.cls(66)
mapa.draw(1)
batarang.draw()
if batman.layer==1 then batman.draw() end
mapa.draw(2)
if batman.layer==2 then batman.draw() end
if sys.beat() then
batman.update()
batarang.update()
end
--view.origin(0,0)