ef87fd3c25
[WIP] Stage 2 ja 'arranca'
161 lines
4.4 KiB
Lua
161 lines
4.4 KiB
Lua
warp={
|
|
max_warps=50,
|
|
warp_list={},
|
|
update=update_all,
|
|
}
|
|
|
|
function warp.init(tiles_sf)
|
|
local curr_source = surf.source()
|
|
local curr_target = surf.target()
|
|
warp_sf=surf.new(32,32)
|
|
surf.source(tiles_sf)
|
|
surf.target(warp_sf)
|
|
local sprite_x = 11*16
|
|
local sprite_y = 15*16
|
|
draw.surfrot(sprite_x, sprite_y, 16, 16, 0, 0, 0)
|
|
draw.surfrot(sprite_x, sprite_y, 16, 16, 15, 0, 90)
|
|
draw.surfrot(sprite_x, sprite_y, 16, 16, 15, 15, 180)
|
|
draw.surfrot(sprite_x, sprite_y, 16, 16, 0, 15, 270)
|
|
surf.source(curr_source)
|
|
surf.target(curr_target)
|
|
end
|
|
|
|
function warp.close()
|
|
surf.free(warp_sf)
|
|
end
|
|
|
|
function warp.new(_actor)
|
|
-- local world_x, world_y = coords.room_to_world(_hab,_x,_y)
|
|
return {name="warp",
|
|
hab=_hab,
|
|
x=_actor.x,
|
|
y=_actor.y,
|
|
w=arcade_config.sprite_size.w,
|
|
h=arcade_config.sprite_size.h,
|
|
frame=0,
|
|
wait=0,
|
|
step=0,
|
|
angle=0,
|
|
d_angle=5,
|
|
update=warp.update,
|
|
draw=warp.draw,
|
|
alive=true,
|
|
actor=_actor}
|
|
end
|
|
|
|
function warp:draw()
|
|
if not self.alive then return end
|
|
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
|
|
local curr_sf=surf.source()
|
|
local target_sf=surf.target()
|
|
surf.source(warp_sf)
|
|
surf.target(0)
|
|
draw.surfrot(0,0,32,32,scr_x,scr_y,self.angle)
|
|
surf.source(curr_sf)
|
|
surf.target(target_sf)
|
|
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
|
|
if self.wait==10 then
|
|
self.d_angle=self.d_angle+1
|
|
self.wait = 0
|
|
end
|
|
if self.d_angle==20 then
|
|
self.d_angle=5
|
|
self.alive = false
|
|
end
|
|
|
|
if self.angle>=360 then self.angle=self.angle % 360 end
|
|
end
|
|
|
|
function warp.open(actor)
|
|
for _, w in ipairs(warp.warp_list) do
|
|
if not w.alive then
|
|
w.alive = true
|
|
w.x = actor.x
|
|
w.y = actor.y
|
|
w.actor = actor
|
|
w.frame = 0
|
|
w.wait = 0
|
|
w.step = 0
|
|
w.angle = 0
|
|
w.d_angle = 5
|
|
return e; -- reutilitzar
|
|
end
|
|
end
|
|
|
|
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
|
|
w:update()
|
|
end
|
|
end
|
|
end
|
|
|
|
function actor_warp_draw(actor)
|
|
local shrink_w = actor.w*actor.shrink
|
|
local shrink_h = actor.h*actor.shrink
|
|
local offset_x = math.floor((actor.w-shrink_w)/2)
|
|
local offset_y = math.floor((actor.h-shrink_h)/2)
|
|
local scr_x, scr_y = viewp:screen_coords( actor.x+offset_x, actor.y+offset_y )
|
|
shrink_w = math.floor(shrink_w)
|
|
shrink_h = math.floor(shrink_h)
|
|
|
|
if shrink_w>0 and shrink_h>0 then
|
|
draw.surfrot((actor.frame&7)*cw, (actor.frame>>cxr2)*ch,
|
|
cw, ch,
|
|
scr_x, scr_y,
|
|
actor.angle,
|
|
shrink_w, shrink_h,
|
|
actor.flip)
|
|
end
|
|
end
|
|
|
|
function actor_warp_update(actor)
|
|
-- warp, wait, respawn
|
|
if actor.warping then
|
|
if actor.step<actor.death_time then
|
|
actor.shrink=actor.shrink-actor.d_shrink
|
|
actor.angle=actor.angle+actor.d_angle
|
|
if actor.angle>=360 then actor.angle = actor.angle % 360 end
|
|
if actor.shrink<=0 then
|
|
actor.shrink=1
|
|
actor.d_shrink=1
|
|
actor.angle=0
|
|
actor.d_angle=1
|
|
actor.warping = false
|
|
actor.frame = -1
|
|
actor.step = 0
|
|
if actor.energy~=nil then
|
|
actor.energy = actor.max_energy
|
|
end
|
|
end
|
|
end
|
|
elseif actor.step<actor.death_time/2 then
|
|
actor.frame = -1
|
|
elseif actor.step<actor.death_time then
|
|
if actor.step%2==0 then
|
|
actor.frame=actor.anim[#actor.anim]
|
|
else
|
|
actor.frame=-1
|
|
end
|
|
elseif actor.step>=actor.death_time then
|
|
actor.frame=actor.anim[1]
|
|
actor.step=0
|
|
actor.wait=0
|
|
if actor.name=="caco" then
|
|
actor.update=caco.update_normal
|
|
elseif actor.name=="zombie" then
|
|
actor.update=zombie.update_normal
|
|
end
|
|
actor.dying = false
|
|
end
|
|
end
|