diff --git a/data/caco.lua b/data/caco.lua index d93a2ec..9f111e7 100644 --- a/data/caco.lua +++ b/data/caco.lua @@ -36,22 +36,23 @@ 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.warping then - local shrink_w = self.w*self.shrink - local shrink_h = self.h*self.shrink - 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 ) - 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 + -- local shrink_w = self.w*self.shrink + -- local shrink_h = self.h*self.shrink + -- 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 ) + -- shrink_w = math.floor(shrink_w) + -- shrink_h = math.floor(shrink_h) + -- + -- 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 + actor_warp_draw(self) else if self.frame>0 then local scr_x, scr_y = viewp:screen_coords( self.x, self.y ) @@ -127,46 +128,49 @@ function caco:update_hit() self.step=self.step+1 if self.can_warp then - -- warp, wait, respawn - if self.warping then - if self.step=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=self.death_time then - self.frame=19 - self.step=0 - self.wait=0 - self.update=caco.update_normal - self.dying = false - end + -- -- warp, wait, respawn + -- if self.warping then + -- if self.step=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=self.death_time then + -- self.frame=19 + -- self.step=0 + -- self.wait=0 + -- self.update=caco.update_normal + -- self.dying = false + -- end + actor_warp_update(self) else if self.step=self.death_time then - self.frame=19 + -- self.frame=19 + self.frame=self.anim[1] self.step=0 self.wait=0 self.update=caco.update_normal @@ -178,15 +182,13 @@ end function caco:hit() self.update=caco.update_hit - self.warping=true + + if self.can_warp then self.warping=true end 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 diff --git a/data/game.lua b/data/game.lua index df5b071..aa5e303 100644 --- a/data/game.lua +++ b/data/game.lua @@ -23,6 +23,63 @@ local view_checking_tile = false viewp = viewport.new(arcade_config.resolucion.width, arcade_config.resolucion.height) viewp:position(0,0) +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=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 + end + 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 + actors={} function game_init(menu) diff --git a/data/zombie.lua b/data/zombie.lua index 76271a4..49eade6 100644 --- a/data/zombie.lua +++ b/data/zombie.lua @@ -21,15 +21,27 @@ function zombie.new(_hab,_x,_y,_flip) draw=zombie.draw, jumpfwd=false, anim={16,17,16,18}, - bb={x=4,y=0,w=26,h=32}} + bb={x=4,y=0,w=26,h=32}, + can_warp=true, + warping=false, + shrink=1, + d_shrink=1, + angle=0, + d_angle=15, + dying=false, + death_time=40} end function zombie: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.frame>0 then - local scr_x, scr_y = viewp:screen_coords( self.x, self.y ) - draw.surf((self.frame&7)*cw, (self.frame>>cxr2)*ch, cw, ch, scr_x, scr_y, cw, ch, self.flip) + if self.warping then + actor_warp_draw(self) + else + if self.frame>0 then + local scr_x, scr_y = viewp:screen_coords( self.x, self.y ) + draw.surf((self.frame&7)*cw, (self.frame>>cxr2)*ch, cw, ch, scr_x, scr_y, cw, ch, self.flip) + end end end @@ -79,26 +91,44 @@ function zombie:update_normal() --end end -function zombie:update_hit() +function zombie:update_hit() self.wait=self.wait+1 if self.wait>=6 then self.wait=0 self.step=self.step+1 - if self.step<40 then - if self.step%2==0 then - self.frame=16 - else - self.frame=-1 + + if self.can_warp then + actor_warp_update(self) + else + if self.step=self.death_time then + self.frame=self.anim[0] + self.step=0 + self.wait=0 + self.update=caco.update_normal + self.dying = false end - elseif self.step>=40 then - self.step=0 - self.wait=0 - self.update=zombie.update_normal end - end + end + + end function zombie:hit() self.update=zombie.update_hit + + if self.can_warp then self.warping=true end + self.shrink=1 + self.angle=0 + self.dying=true + -- calcular velocitat per al warp + local warp_time = self.death_time/3 + self.d_angle = 720 / warp_time; -- 720 = 2 voltes + self.d_shrink = self.shrink / warp_time end