diff --git a/data/caco.lua b/data/caco.lua index 5a29601..785e5bb 100644 --- a/data/caco.lua +++ b/data/caco.lua @@ -18,6 +18,11 @@ function caco.new(_hab,_x,_y,_flip) frame=19, wait=0, step=0, + warping=false, + shrink=1, + d_shrink=0.1, + angle=0, + d_angle=5, hit=caco.hit, update=caco.update_normal, draw=caco.draw, @@ -30,9 +35,24 @@ 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.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 + 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 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) + 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 @@ -96,21 +116,44 @@ function caco:update_hit() 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=21 - else - self.frame=-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 + 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 + if self.step%2==0 then + self.frame=21 + else + self.frame=-1 + end + elseif self.step>=40 then + self.frame=19 + self.step=0 + self.wait=0 + self.update=caco.update_normal end - elseif self.step>=40 then - self.frame=19 - self.step=0 - self.wait=0 - self.update=caco.update_normal end end end function caco:hit() self.update=caco.update_hit + self.warping=true + self.shrink=1 + self.angle=0 end diff --git a/data/game.lua b/data/game.lua index 0285c52..7c329a7 100644 --- a/data/game.lua +++ b/data/game.lua @@ -23,8 +23,6 @@ local view_checking_tile = false viewp = viewport.new(arcade_config.resolucion.width, arcade_config.resolucion.height) viewp:position(0,0) -local warp_rot = 0 - actors={} function game_init(menu) @@ -89,7 +87,7 @@ function game_init(menu) abad_make_safe( true ) local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y) - + game_update=update_game end @@ -187,6 +185,7 @@ function update_game() if cacau_shot.alive and collision(actor,cacau_shot) then if actor.hit ~= nil then actor:hit() + warp.open(actor.x, actor.y) cacau:kill(cacau_shot) end end @@ -196,6 +195,7 @@ function update_game() cacau.update() switches.update() + warp.update_all() -- Moure el viewport local vp_x = viewp.x @@ -216,22 +216,22 @@ function update_game() -- Pintar la finestra del mon render_map(sf_mapa, tiles, vp_x, vp_y) + for key,warp in pairs(warp.warp_list) do + if viewp:inside(warp.x, warp.y, warp.w, warp.h) then + warp:draw() + end + end + for key,actor in pairs(actors) do if viewp:inside(actor.x, actor.y, actor.w, actor.h) then actor:draw() end end + cacau:draw() - + score.draw() - - -- Proves de warp - surf.source(warp) - -- draw.surf(0,0,32,32,0,0) - draw.surfrot(0,0,32,32,0,0,warp_rot) - warp_rot=warp_rot+5 - if warp_rot>=360 then warp_rot=0 end - + fps_print() -- viewp:print() -- msg_print(0,14,"ABAD= "..abad.x..", "..abad.y, true) diff --git a/data/main.lua b/data/main.lua index a395d5c..a9080b4 100644 --- a/data/main.lua +++ b/data/main.lua @@ -11,6 +11,7 @@ require "logo" require "intro" require "game" require "switches" +require "warp" -- require "scenes" coords.set_config({ @@ -68,14 +69,7 @@ function mini.init() pal.set(paleta) -- Crear el warp - warp=surf.new(32,32) - surf.source(tiles) - surf.target(warp) - draw.surfrot(11*16,15*16,16,16,0,0,0) - draw.surfrot(11*16,15*16,16,16,15,0,90) - draw.surfrot(11*16,15*16,16,16,0,15,270) - draw.surfrot(11*16,15*16,16,16,15,15,180) - + warp.init() logo=surf.new(arcade_config.logo_sf.width,arcade_config.logo_sf.height) back=surf.new(arcade_config.surface.width,arcade_config.surface.height) diff --git a/data/tiles.gif b/data/tiles.gif index e8c9a39..d27e22d 100644 Binary files a/data/tiles.gif and b/data/tiles.gif differ diff --git a/data/warp.lua b/data/warp.lua new file mode 100644 index 0000000..431c6cb --- /dev/null +++ b/data/warp.lua @@ -0,0 +1,159 @@ +warp={ + max_warps=50, + warp_list={}, + update=update_all, +} + +function warp.init() + warp_sf=surf.new(32,32) + surf.source(tiles) + 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) +end + +function warp.new(world_x, world_y) + -- local world_x, world_y = coords.room_to_world(_hab,_x,_y) + return {name="warp", + hab=_hab, + x=world_x, + y=world_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} +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() + surf.source(warp_sf) + draw.surfrot(0,0,32,32,scr_x,scr_y,self.angle) + surf.source(curr_sf) +end + +function warp:update() + 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(world_x,world_y) + for _, w in ipairs(warp.warp_list) do + if not w.alive then + w.alive = true + w.x = world_x + w.y = world_y + return e; -- reutilitzar + end + end + + table.insert(warp.warp_list, warp.new(world_x, world_y) ) +end + + +function warp.update_all() + for _, w in ipairs(warp.warp_list) do + if w.alive then + w:update() + end + end +end + +-- function warp:draw() +-- 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 + +-- function warp:update_normal() +-- self.wait=self.wait+1 +-- +-- if self.wait==18 then +-- self.wait=0 +-- self.step=(self.step+1)%4 +-- self.frame=self.anim[self.step+1] +-- end +-- +-- local step = 1 +-- if self.flip then step = -step end +-- local inc = 0 +-- if self.flip then inc = self.bb.w end +-- +-- local check_x = self.x+self.bb.x+step +-- local check_ywall = self.y+self.h-2 +-- local check_yhole = self.y+self.h+1 +-- if not self.flip then +-- check_x = self.x+self.bb.w+self.bb.x+step +-- end +-- +-- local check_no_wall= arc_check_tile(check_x,check_ywall)=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 +-- end +-- elseif self.step>=40 then +-- self.step=0 +-- self.wait=0 +-- self.update=warp.update_normal +-- end +-- end +-- end +-- +-- function warp:hit() +-- self.update=warp.update_hit +-- end