- Imp and fireball implemented

This commit is contained in:
2022-10-28 11:14:48 +02:00
parent 5587c3bd72
commit c1367b3c75
5 changed files with 156 additions and 2 deletions

View File

@@ -71,6 +71,7 @@ function abad_advance()
if abad.update~=abad_state_walking then limit=tiletype.half end if abad.update~=abad_state_walking then limit=tiletype.half end
if not abad.flip and abad.x==84 then if not abad.flip and abad.x==84 then
abad.hab=abad.hab+1 abad.hab=abad.hab+1
imp.reset()
abad.x=-4 abad.x=-4
elseif check_tile(abad.hab,abad.x+inc,abad.y+14)<limit then elseif check_tile(abad.hab,abad.x+inc,abad.y+14)<limit then
if abad.flip then if abad.flip then
@@ -80,6 +81,7 @@ function abad_advance()
end end
if abad.x<-4 then if abad.x<-4 then
abad.hab=abad.hab-1 abad.hab=abad.hab-1
imp.reset()
abad.x=84 abad.x=84
end end
end end
@@ -167,6 +169,7 @@ function abad_state_jumping()
end end
else else
abad.hab=abad.hab-10 abad.hab=abad.hab-10
imp.reset()
abad.y=32 abad.y=32
end end
elseif abad.step>6 then elseif abad.step>6 then
@@ -197,6 +200,7 @@ function abad_state_falling()
abad.y=abad.y+2 abad.y=abad.y+2
else else
abad.hab=abad.hab+10 abad.hab=abad.hab+10
imp.reset()
abad.y=0 abad.y=0
end end
end end
@@ -222,6 +226,7 @@ function abad_state_stairs()
end end
else else
abad.hab=abad.hab-10 abad.hab=abad.hab-10
imp.reset()
abad.y=32 abad.y=32
end end
elseif btn(KEY_DOWN) then elseif btn(KEY_DOWN) then
@@ -231,6 +236,7 @@ function abad_state_stairs()
end end
else else
abad.hab=abad.hab+10 abad.hab=abad.hab+10
imp.reset()
abad.y=0 abad.y=0
end end
end end

50
fireball.lua Normal file
View File

@@ -0,0 +1,50 @@
fireball={hab=-1,x=0,y=0,wait=0,flip=false,bb={x=0,y=0,w=4,h=4}}
function fireball.init(_hab,_x,_y,_flip)
if fireball.hab ~= -1 then return end
fireball.hab=_hab
fireball.x=_x
fireball.y=_y
fireball.flip=_flip
end
function fireball:draw()
circfill(fireball.x,fireball.y,3,16)
circfill(fireball.x,fireball.y,2,3)
circfill(fireball.x,fireball.y,1,8)
end
function fireball:update()
if fireball.hab == -1 then return end
fireball.wait=fireball.wait+1
if fireball.wait==3 then
fireball.wait=0
if fireball.x>96 then
fireball.hab=-1
return
elseif check_tile(fireball.hab,fireball.x,fireball.y)<tiletype.block then
if fireball.flip then
fireball.x=fireball.x-4
else
fireball.x=fireball.x+4
end
if fireball.x<-4 then
fireball.hab=-1
return
end
else
fireball.hab=-1
return
end
if fireball.hab==abad.hab then
if aabb(fireball,abad) and abad.update~=abad_state_crouch then
fireball.hab=-1
if abad.energia>0 then abad.energia=abad.energia-1 end
cls(3)
end
end
end
end

View File

@@ -2,4 +2,4 @@ title=Cacaus
width=128 width=128
height=96 height=96
zoom=5 zoom=5
files=scenes.lua,starter.lua,score.lua,switches.lua,map.lua,mapa.lua,cacau.lua,gps.lua,peu.lua,gorro.lua,batman.lua,elalien.lua,premiere.lua,caco.lua,zombie.lua,abad.lua,main.lua files=scenes.lua,starter.lua,score.lua,switches.lua,map.lua,mapa.lua,fireball.lua,cacau.lua,imp.lua,gps.lua,peu.lua,gorro.lua,batman.lua,elalien.lua,premiere.lua,caco.lua,zombie.lua,abad.lua,main.lua

92
imp.lua Normal file
View File

@@ -0,0 +1,92 @@
imp={hab=75,x=24,y=24,flip=true,enabled=false,counter=100,frame=28,wait=0,step=0,anim={28,29,28,30},bb={x=4,y=0,w=8,h=16},scene_intro=false,scene_object=false}
function imp.reset()
imp.hit=imp.hit
imp.update=imp.update
imp.draw=imp.draw
imp.hab=abad.hab
imp.enabled=false
imp.counter=100
end
function imp.init()
imp.enabled=false
imp.hit=imp.hit
imp.update=imp.update
imp.draw=imp.draw
imp.hab=abad.hab
if abad.x<40 then
if check_tile(imp.hab,92,38)<tiletype.half and
check_tile(imp.hab,84,38)<tiletype.half and
check_tile(imp.hab,92,30)<tiletype.half and
check_tile(imp.hab,84,30)<tiletype.half and
check_tile(imp.hab,92,46)>=tiletype.half then
imp.enabled=true
imp.flip=true
imp.x=92
else
imp.reset()
end
else
if check_tile(imp.hab,0,38)<tiletype.half and
check_tile(imp.hab,8,38)<tiletype.half and
check_tile(imp.hab,0,30)<tiletype.half and
check_tile(imp.hab,0,30)<tiletype.half and
check_tile(imp.hab,0,46)>=tiletype.half then
imp.enabled=true
imp.flip=false
imp.x=-12
else
imp.reset()
end
end
end
function imp.draw()
if imp.enabled then
sspr((imp.frame&7)*16,(imp.frame>>3)*16,16,16,imp.x,imp.y,16,16,imp.flip)
end
end
function imp.hit()
end
function imp.update()
imp.wait=imp.wait+1
if imp.wait==6 then
imp.wait=0
if not imp.enabled then
imp.counter=imp.counter-1
local r = rnd(imp.counter)
print(r)
if imp.counter==1 or r==1 then
imp.init()
end
return
end
imp.step=(imp.step+1)%4
imp.frame=imp.anim[imp.step+1]
if imp.flip then
imp.x=imp.x-2
if imp.x==78 then
fireball.init(imp.hab,imp.x+8,imp.y+4,imp.flip)
imp.flip=not imp.flip
elseif imp.x==-12 then
imp.reset()
end
else
imp.x=imp.x+2
if imp.x==4 then
fireball.init(imp.hab,imp.x+8,imp.y+4,imp.flip)
imp.flip=not imp.flip
elseif imp.x==92 then
imp.reset()
end
end
end
end

View File

@@ -24,7 +24,7 @@ function _init()
local pal=loadpal("tiles.gif") local pal=loadpal("tiles.gif")
setpal(pal) setpal(pal)
--mapa_new() -- ACTORS PRINCIPALS
abad_init() abad_init()
table.insert(actors,abad) table.insert(actors,abad)
@@ -46,11 +46,13 @@ function _init()
batman.init() batman.init()
table.insert(actors,batman) table.insert(actors,batman)
-- MALOTES PERSISTENTS
z = zombie.new() z = zombie.new()
table.insert(actors,z) table.insert(actors,z)
c=caco.new(13,24,16,true) c=caco.new(13,24,16,true)
table.insert(actors,c) table.insert(actors,c)
-- STARTERS
table.insert(actors,starter.new(10,44,32,scenes.abad_inici)) table.insert(actors,starter.new(10,44,32,scenes.abad_inici))
table.insert(actors,starter.new(11,16,32,scenes.abad_corfes)) table.insert(actors,starter.new(11,16,32,scenes.abad_corfes))
score.create() score.create()
@@ -89,7 +91,9 @@ function draw_hab(hab,x,y,editing)
actor:draw() actor:draw()
end end
end end
if imp.hab==hab then imp.draw() end
if cacau.hab==hab then cacau:draw() end if cacau.hab==hab then cacau:draw() end
if fireball.hab==hab then fireball:draw() end
end end
camera(0,0) camera(0,0)
end end
@@ -196,7 +200,9 @@ function update_game()
end end
end end
end end
imp.update()
cacau.update() cacau.update()
fireball.update()
switches.update() switches.update()
if btnp(KEY_RETURN) then if btnp(KEY_RETURN) then