Cacaus volant!
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
-- TO DO: Afegir un contador per a saber quan de temps está parat el abad per a traure al Imp
|
||||
|
||||
keysdown = {}
|
||||
-- local arcade_config = require("arcade_config")
|
||||
cw = arcade_config.character_width
|
||||
ch = arcade_config.character_height
|
||||
@@ -53,6 +53,9 @@ function abad_init()
|
||||
jump_in_half_block=0,
|
||||
jump_in_half_block_used = false,
|
||||
max_shoot_cooldown=24,
|
||||
cacau_power=1,
|
||||
cacau_num_shots=1,
|
||||
cacau_type_shot=type_shot.linear,
|
||||
shoot_cooldown=25,
|
||||
anim={0,1,0,2},
|
||||
bb={x=8,y=0,w=16,h=32},
|
||||
@@ -140,10 +143,13 @@ function abad_do_jump ( jumpfwd )
|
||||
end
|
||||
|
||||
function abad_shot_cacau ()
|
||||
sound.play(audio_abad_shot)
|
||||
abad.update=abad_state_fire
|
||||
abad.wait=0
|
||||
cacau.init(abad.hab,abad.x+8,abad.y+8,abad.flip)
|
||||
if cacau:available(abad.cacau_num_shots, abad.cacau_type_shot) then
|
||||
sound.play(audio_abad_shot)
|
||||
abad.update=abad_state_fire
|
||||
abad.wait=0
|
||||
-- cacau.init(abad.hab,abad.x+8,abad.y+8,abad.flip)
|
||||
cacau.init(abad.x+abad.bb.w, abad.y+(abad.bb.h>>1), abad.flip, abad.cacau_power, abad.cacau_num_shots, abad.cacau_type_shot)
|
||||
end
|
||||
end
|
||||
|
||||
function abad_jump()
|
||||
@@ -296,11 +302,22 @@ function abad_state_normal()
|
||||
abad.update=abad_state_crouch
|
||||
--elseif btn(KEY_Z) then
|
||||
-- abad.respawning=240
|
||||
elseif key.down(keyShoot) or pad.down(btnShoot) and cacau.hab==-1 then
|
||||
elseif key_release(keyShoot) or pad.down(btnShoot) and cacau.hab==-1 then
|
||||
abad_shot_cacau()
|
||||
end
|
||||
end
|
||||
|
||||
function key_release(keyid)
|
||||
-- if keysdown[keyid] then print("Pressed "..keyid) end
|
||||
if key.down(keyid) then
|
||||
keysdown[keyid] = true
|
||||
elseif keysdown[keyid] then
|
||||
keysdown[keyid] = false
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function abad_state_crouch()
|
||||
abad.bb.y=8
|
||||
abad.bb.h=24
|
||||
|
||||
168
data/cacau.lua
168
data/cacau.lua
@@ -1,59 +1,125 @@
|
||||
local arcade_config = require("arcade_config")
|
||||
o2aX = arcade_config.org2arc_escala
|
||||
-- local arcade_config = require("arcade_config")
|
||||
|
||||
cacau={ hab=-1,
|
||||
x=0,
|
||||
y=0,
|
||||
wait=0,
|
||||
flip=false,
|
||||
bb={x=0,y=0,w=4,h=4},
|
||||
alive=false }
|
||||
type_shot={linear=1, rear=2, way3=3}
|
||||
|
||||
function cacau.init(_hab,_x,_y,_flip)
|
||||
if cacau.hab ~= -1 then return end
|
||||
cacau.hab=_hab
|
||||
cacau.x=_x
|
||||
cacau.y=_y
|
||||
cacau.flip=_flip
|
||||
cacau.alive = true
|
||||
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 }
|
||||
}
|
||||
|
||||
-- function cacau.init(_hab,_x,_y,_flip)
|
||||
-- if cacau.hab ~= -1 then return end
|
||||
-- cacau.hab=_hab
|
||||
-- cacau.x=_x
|
||||
-- cacau.y=_y
|
||||
-- cacau.flip=_flip
|
||||
-- cacau.alive = true
|
||||
-- end
|
||||
|
||||
function cacau.init(_x,_y,_flip,_power,_num_shots,_type_shot)
|
||||
if _type_shot==type_shot.linear then
|
||||
for ns=1,_num_shots do
|
||||
if cacau[ns].alive == true then break end
|
||||
cacau[ns].x=_x
|
||||
cacau[ns].y=_y
|
||||
cacau[ns].flip=_flip
|
||||
cacau[ns].alive = true
|
||||
cacau[ns].power = _power
|
||||
end
|
||||
elseif _type_shot==type_shot.rear then
|
||||
|
||||
elseif _type_shot==type_shot.way3 then
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
function cacau:available(_num_shots,_type_shot)
|
||||
local avail_shots = false
|
||||
if _type_shot==type_shot.linear then
|
||||
for ns=1,_num_shots do
|
||||
if cacau[ns].alive == false then avail_shots = true end
|
||||
end
|
||||
elseif _type_shot==type_shot.rear then
|
||||
|
||||
elseif _type_shot==type_shot.way3 then
|
||||
|
||||
end
|
||||
|
||||
return avail_shots
|
||||
end
|
||||
|
||||
function cacau.draw()
|
||||
draw.circf(cacau.x*o2aX,cacau.y*o2aX,2*o2aX,16)
|
||||
draw.circf((cacau.x+2)*o2aX,cacau.y*o2aX,2*o2aX,16)
|
||||
draw.circf(cacau.x*o2aX,cacau.y*o2aX,1*o2aX,6)
|
||||
draw.circf((cacau.x+2)*o2aX,cacau.y*o2aX,1*o2aX,6)
|
||||
end
|
||||
|
||||
function cacau.update()
|
||||
if cacau.hab == -1 then
|
||||
cacau.alive = false
|
||||
return
|
||||
end
|
||||
cacau.wait=cacau.wait+1
|
||||
|
||||
if cacau.wait==3 then
|
||||
cacau.wait=0
|
||||
|
||||
if cacau.x>96 then
|
||||
cacau.hab=-1
|
||||
cacau.alive = false
|
||||
return
|
||||
elseif check_tile(cacau.hab,cacau.x,cacau.y)<tiletype.block then
|
||||
if cacau.flip then
|
||||
cacau.x=cacau.x-4
|
||||
else
|
||||
cacau.x=cacau.x+4
|
||||
end
|
||||
if cacau.x<-4 then
|
||||
cacau.hab=-1
|
||||
cacau.alive = false
|
||||
return
|
||||
end
|
||||
else
|
||||
cacau.hab=-1
|
||||
cacau.alive = false
|
||||
return
|
||||
for ns=1,3 do
|
||||
if cacau[ns].alive==true then
|
||||
local cx, cy = viewp:screen_coords(cacau[ns].x, cacau[ns].y)
|
||||
draw.circf( cx, cy, 4,16)
|
||||
draw.circf( cx+4, cy, 4,16)
|
||||
draw.circf( cx , cy, 2,6)
|
||||
draw.circf( cx+4, cy, 2,6)
|
||||
end
|
||||
end
|
||||
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
|
||||
cacau[ns].hab=-1
|
||||
cacau[ns].alive=false
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
cacau[ns].wait=cacau[ns].wait+1
|
||||
|
||||
if cacau[ns].wait == 3 then cacau[ns].wait = 0 end
|
||||
|
||||
if arc_check_tile(cacau[ns].x,cacau[ns].y)<tiletype.block then
|
||||
local step=3
|
||||
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
|
||||
cacau[ns].alive=false
|
||||
break
|
||||
end
|
||||
else
|
||||
cacau[ns].hab=-1
|
||||
cacau[ns].alive = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- function cacau.update()
|
||||
-- if cacau.hab == -1 then
|
||||
-- cacau.alive = false
|
||||
-- return
|
||||
-- end
|
||||
-- cacau.wait=cacau.wait+1
|
||||
--
|
||||
-- if cacau.wait==3 then
|
||||
-- cacau.wait=0
|
||||
--
|
||||
-- if cacau.x>96 then
|
||||
-- cacau.hab=-1
|
||||
-- cacau.alive = false
|
||||
-- return
|
||||
-- elseif check_tile(cacau.hab,cacau.x,cacau.y)<tiletype.block then
|
||||
-- if cacau.flip then
|
||||
-- cacau.x=cacau.x-4
|
||||
-- else
|
||||
-- cacau.x=cacau.x+4
|
||||
-- end
|
||||
-- if cacau.x<-4 then
|
||||
-- cacau.hab=-1
|
||||
-- cacau.alive = false
|
||||
-- return
|
||||
-- end
|
||||
-- else
|
||||
-- cacau.hab=-1
|
||||
-- cacau.alive = false
|
||||
-- return
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
arcade_config = require("arcade_config")
|
||||
viewport= require("viewport")
|
||||
|
||||
require "fps"
|
||||
require "mapa"
|
||||
require "abad"
|
||||
require "cacau"
|
||||
|
||||
local viewport= require("viewport")
|
||||
|
||||
local tile_w = arcade_config.tiles_width
|
||||
local tile_h = arcade_config.tiles_height
|
||||
local res_w = arcade_config.resolucion.width
|
||||
@@ -117,6 +116,7 @@ function update_game()
|
||||
-- end
|
||||
--end
|
||||
end
|
||||
cacau.update()
|
||||
switches.update()
|
||||
|
||||
local vp_x = viewp.x
|
||||
@@ -141,6 +141,7 @@ function update_game()
|
||||
actor:draw()
|
||||
end
|
||||
end
|
||||
cacau:draw()
|
||||
|
||||
fps_print()
|
||||
viewp:print()
|
||||
|
||||
@@ -13,7 +13,8 @@ function viewport.new()
|
||||
room=viewport.coord2room,
|
||||
roomXY= viewport.room2coord,
|
||||
tile= viewport.coord2tile,
|
||||
screen_coords = viewport.screen_coords }
|
||||
screen_coords = viewport.screen_coords,
|
||||
inside = viewport.inside }
|
||||
end
|
||||
|
||||
function viewport:screen_coords ( x, y )
|
||||
@@ -22,6 +23,12 @@ function viewport:screen_coords ( x, y )
|
||||
return scr_x, scr_y
|
||||
end
|
||||
|
||||
function viewport:inside( x, y )
|
||||
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
|
||||
return result
|
||||
end
|
||||
|
||||
function viewport:coord2tile ()
|
||||
local tw = arcade_config.tiles_width
|
||||
local th = arcade_config.tiles_height
|
||||
|
||||
Reference in New Issue
Block a user