diff --git a/data/cacau.lua b/data/cacau.lua index f92949e..282d210 100644 --- a/data/cacau.lua +++ b/data/cacau.lua @@ -3,9 +3,9 @@ type_shot={linear=1, rear=2, way3=3} cacau={ - { hab=-1, x=0, y=0, wait=0, flip=false, bb={x=0,y=0,w=4,h=4}, alive=false, power=1 }, - { hab=-1, x=0, y=0, wait=0, flip=false, bb={x=0,y=0,w=4,h=4}, alive=false, power=1 }, - { hab=-1, x=0, y=0, wait=0, flip=false, bb={x=0,y=0,w=4,h=4}, alive=false, power=1 } + { hab=-1, x=0, y=0, w=12 ,h=8 ,wait=0, flip=false, bb={x=0,y=0,w=4,h=4}, alive=false, power=1 }, + { hab=-1, x=0, y=0, w=12 ,h=8 ,wait=0, flip=false, bb={x=0,y=0,w=4,h=4}, alive=false, power=1 }, + { hab=-1, x=0, y=0, w=12 ,h=8 ,wait=0, flip=false, bb={x=0,y=0,w=4,h=4}, alive=false, power=1 } } -- function cacau.init(_hab,_x,_y,_flip) @@ -64,7 +64,7 @@ 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 + if viewp:inside(cacau[ns].x, cacau[ns].y, cacau[ns].w, cacau[ns].h)==false then cacau[ns].hab=-1 cacau[ns].alive=false break @@ -80,7 +80,7 @@ function cacau.update() 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 + if viewp:inside(cacau[ns].x, cacau[ns].y, cacau[ns].w, cacau[ns].h)==false then cacau[ns].alive=false break end diff --git a/data/caco.lua b/data/caco.lua new file mode 100644 index 0000000..48ca356 --- /dev/null +++ b/data/caco.lua @@ -0,0 +1,92 @@ +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 + +caco={} + +function caco.new(_hab,_x,_y,_flip) + local world_x, world_y = arc_mapa_get_coords(_hab,_x,_y) + return {hab=_hab, + x=world_x, + y=world_y, + w=arcade_config.sprite_size.w, + h=arcade_config.sprite_size.h, + flip=_flip, + frame=19, + wait=0, + step=0, + hit=caco.hit, + update=caco.update_normal, + draw=caco.draw, + jumpfwd=false, + anim={19,19,20,21}, + bb={x=2,y=4,w=12,h=8} } +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.frame>0 and viewp:inside(self.x, self.y, self.w, self.h) 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 caco:update_normal() + self.wait=0 + self.step=self.step+1 + if self.step<50 then + self.frame=19 + elseif self.step==70 then + self.frame=20 + elseif self.step==80 then + self.frame=21 + elseif self.step==90 then + self.step=0 + end + local step = 1 + if self.flip then step = -step end + if arc_check_tile(self.x+step,self.y+self.h)=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 +end diff --git a/data/game.lua b/data/game.lua index 858b060..25adf6c 100644 --- a/data/game.lua +++ b/data/game.lua @@ -5,6 +5,7 @@ require "fps" require "mapa" require "abad" require "cacau" +require "caco" local tile_w = arcade_config.tiles_width local tile_h = arcade_config.tiles_height @@ -23,8 +24,17 @@ function game_init(menu) abad_init() table.insert(actors,abad) + table.insert( actors, caco.new(13,3,2,true ) ) + table.insert( actors, caco.new(17,3,2,false) ) + table.insert( actors, caco.new(20,3,2,false) ) + table.insert( actors, caco.new(26,3,2,false) ) + table.insert( actors, caco.new(37,3,2,false) ) + table.insert( actors, caco.new(41,3,2,false) ) + table.insert( actors, caco.new(50,3,2,false) ) + table.insert( actors, caco.new(57,3,2,false) ) + table.insert( actors, caco.new(61,3,2,false) ) + local abad_x, abad_y = arc_mapa_get_coords ( 10, 4, 3 ) - -- print(abad_x..", "..abad_y) abad:move(abad_x, abad_y) local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y) diff --git a/data/viewport.lua b/data/viewport.lua index 3cf8062..f2b4140 100644 --- a/data/viewport.lua +++ b/data/viewport.lua @@ -23,9 +23,9 @@ function viewport:screen_coords ( x, y ) return scr_x, scr_y end -function viewport:inside( x, y ) +function viewport:inside( x, y, w, h ) 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 + if self.x<=x+w and self.x+self.width>=x and self.y<=y+h and self.y+self.height>=y then result = true end return result end