Cacos interdimensionals done!

This commit is contained in:
2026-03-31 21:03:58 +02:00
parent c9a4313e04
commit 1708be71a8
3 changed files with 79 additions and 44 deletions

View File

@@ -1,5 +1,3 @@
local arcade_config = require("arcade_config")
o2aX = arcade_config.org2arc_escala
cxr2 = arcade_config.character_per_row_base2
cw = arcade_config.character_width
ch = arcade_config.character_height
@@ -18,15 +16,18 @@ function caco.new(_hab,_x,_y,_flip)
frame=19,
wait=0,
step=0,
can_warp=true,
warping=false,
shrink=1,
d_shrink=0.1,
d_shrink=1,
angle=0,
d_angle=5,
d_angle=15,
hit=caco.hit,
update=caco.update_normal,
draw=caco.draw,
jumpfwd=false,
dying=false,
death_time=40,
anim={19,19,20,21},
bb={x=4,y=4,w=24,h=16} }
end
@@ -34,20 +35,23 @@ end
function caco:draw()
-- if self.frame>0 then draw.surf((self.frame&7)*16,(self.frame>>3)*16,16,16,self.x,self.y,16,16,self.flip) end
-- if self.frame>0 then draw.surf((self.frame&7)*cw,(self.frame>>cxr2)*ch,cw,ch,self.x*o2aX,self.y*o2aX,cw,ch,self.flip) end
if self.warping then
local shrink_w = self.w*self.shrink
local shrink_h = self.h*self.shrink
local offset_x = (self.w-shrink_w)/2
local offset_y = (self.h-shrink_h)/2
local offset_x = math.floor((self.w-shrink_w)/2)
local offset_y = math.floor((self.h-shrink_h)/2)
local scr_x, scr_y = viewp:screen_coords( self.x+offset_x, self.y+offset_y )
draw.surfrot((self.frame&7)*cw, (self.frame>>cxr2)*ch,
cw, ch,
scr_x, scr_y,
self.angle,
shrink_w, shrink_h,
self.flip)
shrink_w = math.floor(shrink_w)
shrink_h = math.floor(shrink_h)
-- print(shrink_w..", "..shrink_h..", "..offset_x..", "..offset_y..", "..scr_x..", "..scr_y)
if shrink_w>0 and shrink_h>0 then
draw.surfrot((self.frame&7)*cw, (self.frame>>cxr2)*ch,
cw, ch,
scr_x, scr_y,
self.angle,
shrink_w, shrink_h,
self.flip)
end
else
if self.frame>0 then
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
@@ -111,41 +115,62 @@ function caco:update_normal()
end
function caco:update_hit()
local step_time = self.death_time
if self.can_warp then
step_time = self.death_time/3; -- warp, wait, appear
end
self.wait=self.wait+1
if self.wait>=6 then
self.wait=0
self.step=self.step+1
if self.warping then
if self.step<40 then
self.shrink=self.shrink-self.d_shrink
if self.shrink<0 then self.shrink=0 end
self.angle=self.angle+self.d_angle
if self.angle>=360 then
self.angle = 0
if self.can_warp then
-- warp, wait, respawn
if self.warping then
if self.step<self.death_time then
self.shrink=self.shrink-self.d_shrink
self.angle=self.angle+self.d_angle
if self.angle>=360 then self.angle = self.angle % 360 end
if self.shrink<=0 then
self.shrink=1
self.d_shrink=1
self.angle=0
self.d_angle=1
self.warping = false
self.frame = -1
self.step = 0
end
end
elseif self.step>=40 then
self.shrink=1
self.angle=0
self.frame=19
self.step=0
self.wait=0
self.warping = false
self.update=caco.update_normal
end
else
if self.step<40 then
elseif self.step<self.death_time/2 then
self.frame = -1
elseif self.step<self.death_time then
if self.step%2==0 then
self.frame=21
else
self.frame=-1
end
elseif self.step>=40 then
elseif self.step>=self.death_time then
self.frame=19
self.step=0
self.wait=0
self.update=caco.update_normal
self.dying = false
end
else
if self.step<self.death_time then
if self.step%2==0 then
self.frame=21
else
self.frame=-1
end
elseif self.step>=self.death_time then
self.frame=19
self.step=0
self.wait=0
self.update=caco.update_normal
self.dying = false
end
end
end
@@ -156,4 +181,12 @@ function caco:hit()
self.warping=true
self.shrink=1
self.angle=0
self.dying=true
-- calcular velocitat per al warp
local warp_time = self.death_time/3
-- print(warp_time); -- 13.33
self.d_angle = 720 / warp_time; -- 720 = 2 voltes
-- print(self.d_angle); -- 54
self.d_shrink = self.shrink / warp_time
-- print(self.d_shrink); -- 2.4
end

View File

@@ -183,9 +183,9 @@ function update_game()
if viewp:inside(actor.x, actor.y, actor.w, actor.h) and actor~=abad then
for _, cacau_shot in pairs(cacau.shots()) do
if cacau_shot.alive and collision(actor,cacau_shot) then
if actor.hit ~= nil then
if actor.hit ~= nil and not actor.dying then
actor:hit()
warp.open(actor.x, actor.y)
if actor.can_warp then warp.open(actor) end
cacau:kill(cacau_shot)
end
end

View File

@@ -16,12 +16,12 @@ function warp.init()
draw.surfrot(sprite_x, sprite_y, 16, 16, 0, 15, 270)
end
function warp.new(world_x, world_y)
function warp.new(_actor)
-- local world_x, world_y = coords.room_to_world(_hab,_x,_y)
return {name="warp",
hab=_hab,
x=world_x,
y=world_y,
x=_actor.x,
y=_actor.y,
w=arcade_config.sprite_size.w,
h=arcade_config.sprite_size.h,
frame=0,
@@ -31,7 +31,8 @@ function warp.new(world_x, world_y)
d_angle=5,
update=warp.update,
draw=warp.draw,
alive=true}
alive=true,
actor=_actor}
end
function warp:draw()
@@ -44,6 +45,7 @@ function warp:draw()
end
function warp:update()
if not self.actor.warping then self.alive=false end
if not self.alive then return end
self.wait=self.wait+1
self.angle=self.angle+self.d_angle
@@ -59,20 +61,20 @@ function warp:update()
if self.angle>=360 then self.angle=self.angle % 360 end
end
function warp.open(world_x,world_y)
function warp.open(actor)
for _, w in ipairs(warp.warp_list) do
if not w.alive then
w.alive = true
w.x = world_x
w.y = world_y
w.x = actor.x
w.y = actor.y
w.actor = actor
return e; -- reutilitzar
end
end
table.insert(warp.warp_list, warp.new(world_x, world_y) )
table.insert(warp.warp_list, warp.new(actor) )
end
function warp.update_all()
for _, w in ipairs(warp.warp_list) do
if w.alive then