Cacaus volant!

This commit is contained in:
2026-03-23 22:59:50 +01:00
parent cb03264568
commit e28e053cb4
4 changed files with 151 additions and 60 deletions

View File

@@ -1,5 +1,5 @@
-- TO DO: Afegir un contador per a saber quan de temps está parat el abad per a traure al Imp -- TO DO: Afegir un contador per a saber quan de temps está parat el abad per a traure al Imp
keysdown = {}
-- local arcade_config = require("arcade_config") -- local arcade_config = require("arcade_config")
cw = arcade_config.character_width cw = arcade_config.character_width
ch = arcade_config.character_height ch = arcade_config.character_height
@@ -53,6 +53,9 @@ function abad_init()
jump_in_half_block=0, jump_in_half_block=0,
jump_in_half_block_used = false, jump_in_half_block_used = false,
max_shoot_cooldown=24, max_shoot_cooldown=24,
cacau_power=1,
cacau_num_shots=1,
cacau_type_shot=type_shot.linear,
shoot_cooldown=25, shoot_cooldown=25,
anim={0,1,0,2}, anim={0,1,0,2},
bb={x=8,y=0,w=16,h=32}, bb={x=8,y=0,w=16,h=32},
@@ -140,10 +143,13 @@ function abad_do_jump ( jumpfwd )
end end
function abad_shot_cacau () function abad_shot_cacau ()
sound.play(audio_abad_shot) if cacau:available(abad.cacau_num_shots, abad.cacau_type_shot) then
abad.update=abad_state_fire sound.play(audio_abad_shot)
abad.wait=0 abad.update=abad_state_fire
cacau.init(abad.hab,abad.x+8,abad.y+8,abad.flip) abad.wait=0
-- cacau.init(abad.hab,abad.x+8,abad.y+8,abad.flip)
cacau.init(abad.x+abad.bb.w, abad.y+(abad.bb.h>>1), abad.flip, abad.cacau_power, abad.cacau_num_shots, abad.cacau_type_shot)
end
end end
function abad_jump() function abad_jump()
@@ -296,11 +302,22 @@ function abad_state_normal()
abad.update=abad_state_crouch abad.update=abad_state_crouch
--elseif btn(KEY_Z) then --elseif btn(KEY_Z) then
-- abad.respawning=240 -- abad.respawning=240
elseif key.down(keyShoot) or pad.down(btnShoot) and cacau.hab==-1 then elseif key_release(keyShoot) or pad.down(btnShoot) and cacau.hab==-1 then
abad_shot_cacau() abad_shot_cacau()
end end
end end
function key_release(keyid)
-- if keysdown[keyid] then print("Pressed "..keyid) end
if key.down(keyid) then
keysdown[keyid] = true
elseif keysdown[keyid] then
keysdown[keyid] = false
return true
end
return false
end
function abad_state_crouch() function abad_state_crouch()
abad.bb.y=8 abad.bb.y=8
abad.bb.h=24 abad.bb.h=24

View File

@@ -1,59 +1,125 @@
local arcade_config = require("arcade_config") -- local arcade_config = require("arcade_config")
o2aX = arcade_config.org2arc_escala
cacau={ hab=-1, type_shot={linear=1, rear=2, way3=3}
x=0,
y=0,
wait=0,
flip=false,
bb={x=0,y=0,w=4,h=4},
alive=false }
function cacau.init(_hab,_x,_y,_flip) cacau={
if cacau.hab ~= -1 then return end { hab=-1, x=0, y=0, wait=0, flip=false, bb={x=0,y=0,w=4,h=4}, alive=false, power=1 },
cacau.hab=_hab { hab=-1, x=0, y=0, wait=0, flip=false, bb={x=0,y=0,w=4,h=4}, alive=false, power=1 },
cacau.x=_x { hab=-1, x=0, y=0, wait=0, flip=false, bb={x=0,y=0,w=4,h=4}, alive=false, power=1 }
cacau.y=_y }
cacau.flip=_flip
cacau.alive = true -- function cacau.init(_hab,_x,_y,_flip)
-- if cacau.hab ~= -1 then return end
-- cacau.hab=_hab
-- cacau.x=_x
-- cacau.y=_y
-- cacau.flip=_flip
-- cacau.alive = true
-- end
function cacau.init(_x,_y,_flip,_power,_num_shots,_type_shot)
if _type_shot==type_shot.linear then
for ns=1,_num_shots do
if cacau[ns].alive == true then break end
cacau[ns].x=_x
cacau[ns].y=_y
cacau[ns].flip=_flip
cacau[ns].alive = true
cacau[ns].power = _power
end
elseif _type_shot==type_shot.rear then
elseif _type_shot==type_shot.way3 then
end
end
function cacau:available(_num_shots,_type_shot)
local avail_shots = false
if _type_shot==type_shot.linear then
for ns=1,_num_shots do
if cacau[ns].alive == false then avail_shots = true end
end
elseif _type_shot==type_shot.rear then
elseif _type_shot==type_shot.way3 then
end
return avail_shots
end end
function cacau.draw() function cacau.draw()
draw.circf(cacau.x*o2aX,cacau.y*o2aX,2*o2aX,16) for ns=1,3 do
draw.circf((cacau.x+2)*o2aX,cacau.y*o2aX,2*o2aX,16) if cacau[ns].alive==true then
draw.circf(cacau.x*o2aX,cacau.y*o2aX,1*o2aX,6) local cx, cy = viewp:screen_coords(cacau[ns].x, cacau[ns].y)
draw.circf((cacau.x+2)*o2aX,cacau.y*o2aX,1*o2aX,6) draw.circf( cx, cy, 4,16)
end draw.circf( cx+4, cy, 4,16)
draw.circf( cx , cy, 2,6)
function cacau.update() draw.circf( cx+4, cy, 2,6)
if cacau.hab == -1 then
cacau.alive = false
return
end
cacau.wait=cacau.wait+1
if cacau.wait==3 then
cacau.wait=0
if cacau.x>96 then
cacau.hab=-1
cacau.alive = false
return
elseif check_tile(cacau.hab,cacau.x,cacau.y)<tiletype.block then
if cacau.flip then
cacau.x=cacau.x-4
else
cacau.x=cacau.x+4
end
if cacau.x<-4 then
cacau.hab=-1
cacau.alive = false
return
end
else
cacau.hab=-1
cacau.alive = false
return
end end
end end
end end
function cacau.update()
for ns=1,3 do
if cacau[ns].alive==true then
if viewp:inside(cacau[ns].x, cacau[ns].y)==false then
cacau[ns].hab=-1
cacau[ns].alive=false
break
end
end
cacau[ns].wait=cacau[ns].wait+1
if cacau[ns].wait == 3 then cacau[ns].wait = 0 end
if arc_check_tile(cacau[ns].x,cacau[ns].y)<tiletype.block then
local step=3
if cacau[ns].flip then step=-step end
cacau[ns].x=cacau[ns].x+step
if viewp:inside(cacau[ns].x, cacau[ns].y)==false then
cacau[ns].alive=false
break
end
else
cacau[ns].hab=-1
cacau[ns].alive = false
end
end
end
-- function cacau.update()
-- if cacau.hab == -1 then
-- cacau.alive = false
-- return
-- end
-- cacau.wait=cacau.wait+1
--
-- if cacau.wait==3 then
-- cacau.wait=0
--
-- if cacau.x>96 then
-- cacau.hab=-1
-- cacau.alive = false
-- return
-- elseif check_tile(cacau.hab,cacau.x,cacau.y)<tiletype.block then
-- if cacau.flip then
-- cacau.x=cacau.x-4
-- else
-- cacau.x=cacau.x+4
-- end
-- if cacau.x<-4 then
-- cacau.hab=-1
-- cacau.alive = false
-- return
-- end
-- else
-- cacau.hab=-1
-- cacau.alive = false
-- return
-- end
-- end
-- end

View File

@@ -1,12 +1,11 @@
arcade_config = require("arcade_config") arcade_config = require("arcade_config")
viewport= require("viewport")
require "fps" require "fps"
require "mapa" require "mapa"
require "abad" require "abad"
require "cacau" require "cacau"
local viewport= require("viewport")
local tile_w = arcade_config.tiles_width local tile_w = arcade_config.tiles_width
local tile_h = arcade_config.tiles_height local tile_h = arcade_config.tiles_height
local res_w = arcade_config.resolucion.width local res_w = arcade_config.resolucion.width
@@ -117,6 +116,7 @@ function update_game()
-- end -- end
--end --end
end end
cacau.update()
switches.update() switches.update()
local vp_x = viewp.x local vp_x = viewp.x
@@ -141,6 +141,7 @@ function update_game()
actor:draw() actor:draw()
end end
end end
cacau:draw()
fps_print() fps_print()
viewp:print() viewp:print()

View File

@@ -13,7 +13,8 @@ function viewport.new()
room=viewport.coord2room, room=viewport.coord2room,
roomXY= viewport.room2coord, roomXY= viewport.room2coord,
tile= viewport.coord2tile, tile= viewport.coord2tile,
screen_coords = viewport.screen_coords } screen_coords = viewport.screen_coords,
inside = viewport.inside }
end end
function viewport:screen_coords ( x, y ) function viewport:screen_coords ( x, y )
@@ -22,6 +23,12 @@ function viewport:screen_coords ( x, y )
return scr_x, scr_y return scr_x, scr_y
end end
function viewport:inside( x, y )
local result = false
if x>=self.x and x<=self.x+self.width and y>=self.y and y<=self.y+self.height then result = true end
return result
end
function viewport:coord2tile () function viewport:coord2tile ()
local tw = arcade_config.tiles_width local tw = arcade_config.tiles_width
local th = arcade_config.tiles_height local th = arcade_config.tiles_height