[WIP] Moviment de l'Abad pel mapa
This commit is contained in:
317
data/abad.lua
317
data/abad.lua
@@ -1,3 +1,5 @@
|
|||||||
|
-- TO DO: Afegir un contador per a saber quan de temps está parat el abad per a traure al Imp
|
||||||
|
|
||||||
local arcade_config = require("arcade_config")
|
local arcade_config = require("arcade_config")
|
||||||
o2aX = arcade_config.org2arc_escala
|
o2aX = arcade_config.org2arc_escala
|
||||||
cxr = arcade_config.character_per_row-1
|
cxr = arcade_config.character_per_row-1
|
||||||
@@ -7,23 +9,25 @@ ch = arcade_config.character_height
|
|||||||
|
|
||||||
require "dead"
|
require "dead"
|
||||||
|
|
||||||
abad={ x=40, y=24,
|
-- abad={ x=40, y=24,
|
||||||
flip=false,
|
-- flip=false,
|
||||||
frame=1,
|
-- frame=1,
|
||||||
wait=0,
|
-- wait=0,
|
||||||
respawning=0,
|
-- respawning=0,
|
||||||
hab=10,
|
-- hab=10,
|
||||||
vides=3,
|
-- vides=3,
|
||||||
energia=40,
|
-- energia=40,
|
||||||
falling=0,
|
-- falling=0,
|
||||||
step=0,
|
-- step=0,
|
||||||
mustep=1,
|
-- mustep=1,
|
||||||
hurting=0,
|
-- hurting=0,
|
||||||
update=nil,
|
-- update=nil,
|
||||||
jumpfwd=false,
|
-- jumpfwd=false,
|
||||||
anim={0,1,0,2},
|
-- anim={0,1,0,2},
|
||||||
bb={x=4,y=0,w=8,h=16},
|
-- bb={x=8,y=0,w=16,h=32},
|
||||||
safe={hab=10,x=40,y=24} }
|
-- safe={hab=10,x=40,y=24} }
|
||||||
|
|
||||||
|
abad={}
|
||||||
|
|
||||||
function abad_nop()
|
function abad_nop()
|
||||||
end
|
end
|
||||||
@@ -40,12 +44,19 @@ function abad_init()
|
|||||||
falling=0,
|
falling=0,
|
||||||
step=0,
|
step=0,
|
||||||
mustep=1,
|
mustep=1,
|
||||||
|
stairs_flip=false,
|
||||||
draw=abad.draw,
|
draw=abad.draw,
|
||||||
hurting=0,
|
hurting=0,
|
||||||
update=nil,
|
update=nil,
|
||||||
jumpfwd=false,
|
jumpfwd=false,
|
||||||
|
step_length=1,
|
||||||
|
vmove_space=1,
|
||||||
|
max_jump_height=24,
|
||||||
|
jump_height=0,
|
||||||
|
max_shoot_cooldown=24,
|
||||||
|
shoot_cooldown=25,
|
||||||
anim={0,1,0,2},
|
anim={0,1,0,2},
|
||||||
bb={x=4,y=0,w=8,h=16},
|
bb={x=8,y=0,w=16,h=32},
|
||||||
safe={hab=10,x=40,y=24},
|
safe={hab=10,x=40,y=24},
|
||||||
move=abad.move }
|
move=abad.move }
|
||||||
abad.update=abad_state_normal
|
abad.update=abad_state_normal
|
||||||
@@ -60,12 +71,15 @@ end
|
|||||||
function abad:draw()
|
function abad:draw()
|
||||||
local flip = abad.flip
|
local flip = abad.flip
|
||||||
if abad.update==abad_state_stairs then
|
if abad.update==abad_state_stairs then
|
||||||
flip=(((abad.x>>1)+(abad.y>>1))%2)==0
|
flip=abad.stairs_flip
|
||||||
|
-- flip=(((abad.x>>1)+(abad.y>>1))%2)==0
|
||||||
|
if ((abad.x+abad.y)%12)==0 then abad.stairs_flip=not abad.stairs_flip end
|
||||||
|
local msg = "-- "..abad.x.." "..abad.y
|
||||||
|
if flip then msg = "FLIP"..abad.x.." "..abad.y end
|
||||||
|
msg_print(0,35,msg,true)
|
||||||
end
|
end
|
||||||
if (abad.respawning==0) or (math.floor(abad.respawning/15)%2==0) then
|
if (abad.respawning==0) or (math.floor(abad.respawning/15)%2==0) then
|
||||||
-- draw.surf(abad.frame*16,0,16,16,abad.x,abad.y,16,16,flip)
|
|
||||||
local x, y = viewp:screen_coords(self.x, self.y)
|
local x, y = viewp:screen_coords(self.x, self.y)
|
||||||
-- draw.surf(abad.frame*cw,0,cw,ch,abad.x*o2aX,abad.y*o2aX,cw,ch,flip)
|
|
||||||
draw.surf(abad.frame*cw,0,cw,ch,x,y,cw,ch,flip)
|
draw.surf(abad.frame*cw,0,cw,ch,x,y,cw,ch,flip)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -82,6 +96,7 @@ function abad_make_safe()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function abad_hurt(howmuch)
|
function abad_hurt(howmuch)
|
||||||
if abad.hurting == 0 and abad.respawning==0 then
|
if abad.hurting == 0 and abad.respawning==0 then
|
||||||
sound.play(audio_abad_hit)
|
sound.play(audio_abad_hit)
|
||||||
@@ -112,22 +127,76 @@ function abad_hurt(howmuch)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function abad_do_jump ( jumpfwd )
|
||||||
|
jumpfwd = jumpfwd or false
|
||||||
|
abad.jump_height = 0
|
||||||
|
abad.update=abad_state_jumping
|
||||||
|
abad.step=0
|
||||||
|
abad.jumpfwd=jumpfwd
|
||||||
|
if abad.jump then
|
||||||
|
sound.stop(abad.jump)
|
||||||
|
abad.jump=nil
|
||||||
|
end
|
||||||
|
sound.play(audio_abad_jump)
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
|
||||||
|
function abad_land ()
|
||||||
|
-- abad.x
|
||||||
|
-- abad.y
|
||||||
|
end
|
||||||
|
|
||||||
|
function abad_advance()
|
||||||
|
local step_length=abad.step_length; --lo que avança l'abad cada pas
|
||||||
|
local limit=tiletype.block
|
||||||
|
|
||||||
|
if abad.update~=abad_state_walking then limit=tiletype.half end
|
||||||
|
|
||||||
|
local x_check = abad.x+abad.bb.x+abad.bb.w+step_length
|
||||||
|
if abad.flip then
|
||||||
|
step_length = -step_length
|
||||||
|
x_check = abad.x+abad.bb.x+step_length
|
||||||
|
end
|
||||||
|
local y_check = abad.y+abad.bb.h-4
|
||||||
|
|
||||||
|
if arc_check_tile(x_check, y_check)<limit then
|
||||||
|
abad.x=abad.x+step_length
|
||||||
|
end
|
||||||
|
|
||||||
|
if arc_check_tile(abad.x+abad.bb.x,abad.y+abad.bb.h)==tiletype.stair then
|
||||||
|
abad.update=abad_state_stairs
|
||||||
|
elseif abad.update==abad_state_stairs then
|
||||||
|
abad.update=abad_state_normal
|
||||||
|
abad.frame=0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Controlador principal de l'abad
|
||||||
function abad_state_normal()
|
function abad_state_normal()
|
||||||
abad.frame=0
|
abad.frame=0
|
||||||
abad.wait=0
|
abad.wait=0
|
||||||
abad.step=0
|
abad.step=0
|
||||||
|
abad.shoot_cooldown = abad.shoot_cooldown + 1
|
||||||
abad.jumpfwd=false
|
abad.jumpfwd=false
|
||||||
|
abad.jump_height = 0
|
||||||
if abad.hurting > 0 then
|
if abad.hurting > 0 then
|
||||||
abad.hurting=abad.hurting-1
|
abad.hurting=abad.hurting-1
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if abad.falling>0 then
|
if abad.falling>0 then
|
||||||
if abad.falling>12 then
|
if abad.falling>(abad.max_jump_height<<1) then
|
||||||
abad_hurt(abad.falling-12)
|
abad_hurt(abad.falling-(abad.max_jump_height>>1))
|
||||||
end
|
end
|
||||||
abad.falling=0
|
abad.falling=0
|
||||||
end
|
end
|
||||||
|
|
||||||
abad_make_safe()
|
abad_make_safe()
|
||||||
|
|
||||||
if key.down(keyRight) or pad.down(btnRight) then
|
if key.down(keyRight) or pad.down(btnRight) then
|
||||||
@@ -137,44 +206,34 @@ function abad_state_normal()
|
|||||||
abad.update=abad_state_walking
|
abad.update=abad_state_walking
|
||||||
abad.flip=true
|
abad.flip=true
|
||||||
elseif key.down(keyJump) or pad.down(btnJump) then
|
elseif key.down(keyJump) or pad.down(btnJump) then
|
||||||
abad.update=abad_state_jumping
|
abad_do_jump()
|
||||||
abad.step=0
|
|
||||||
abad.jumpfwd=false
|
|
||||||
if abad.jump then
|
|
||||||
sound.stop(abad.jump)
|
|
||||||
abad.jump=nil
|
|
||||||
end
|
|
||||||
sound.play(audio_abad_jump)
|
|
||||||
elseif key.down(keyDown) or pad.down(btnDown) then
|
elseif key.down(keyDown) or pad.down(btnDown) then
|
||||||
abad.update=abad_state_crouch
|
abad.update=abad_state_crouch
|
||||||
--elseif btn(KEY_Z) then
|
--elseif btn(KEY_Z) then
|
||||||
-- abad.respawning=240
|
-- abad.respawning=240
|
||||||
elseif key.down(keyShoot) or pad.down(btnShoot) and cacau.hab==-1 then
|
elseif key.down(keyShoot) or pad.down(btnShoot) and cacau.hab==-1 then
|
||||||
sound.play(audio_abad_shot)
|
abad_shot_cacau()
|
||||||
abad.update=abad_state_fire
|
|
||||||
abad.wait=0
|
|
||||||
cacau.init(abad.hab,abad.x+8,abad.y+8,abad.flip)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function abad_state_crouch()
|
function abad_state_crouch()
|
||||||
abad.bb.y=8
|
abad.bb.y=8
|
||||||
abad.bb.h=8
|
abad.bb.h=24
|
||||||
abad.frame=5
|
abad.frame=5
|
||||||
abad.wait=0
|
abad.wait=0
|
||||||
abad.step=0
|
abad.step=0
|
||||||
abad.jumpfwd=false
|
abad.jumpfwd=false
|
||||||
|
abad.jump_height=0
|
||||||
|
|
||||||
if not (key.down(keyDown) or pad.down(btnDown)) then
|
if not (key.down(keyDown) or pad.down(btnDown)) then
|
||||||
abad.update=abad_state_normal
|
abad.update=abad_state_normal
|
||||||
abad.bb.y=0
|
abad.bb.y=0
|
||||||
abad.bb.h=16
|
abad.bb.h=32
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function abad_state_fire()
|
function abad_state_fire()
|
||||||
abad.frame=6
|
abad.frame=6
|
||||||
|
|
||||||
abad.wait=abad.wait+1
|
abad.wait=abad.wait+1
|
||||||
|
|
||||||
if abad.wait==6 then
|
if abad.wait==6 then
|
||||||
@@ -183,37 +242,11 @@ function abad_state_fire()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function abad_advance()
|
|
||||||
local inc=12 if abad.flip then inc=2 end
|
|
||||||
local limit=tiletype.block
|
|
||||||
if abad.update~=abad_state_walking then limit=tiletype.half end
|
|
||||||
if not abad.flip and abad.x==84 then
|
|
||||||
abad.hab=abad.hab+1
|
|
||||||
-- imp.reset()
|
|
||||||
abad.x=-4
|
|
||||||
elseif arc_check_tile(abad.x+inc,abad.y+14)<limit then
|
|
||||||
if abad.flip then
|
|
||||||
abad.x=abad.x-2
|
|
||||||
else
|
|
||||||
abad.x=abad.x+2
|
|
||||||
end
|
|
||||||
if abad.x<-4 then
|
|
||||||
abad.hab=abad.hab-1
|
|
||||||
-- imp.reset()
|
|
||||||
abad.x=84
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if arc_check_tile(abad.x+6,abad.y+8)==tiletype.stair then
|
|
||||||
abad.update=abad_state_stairs
|
|
||||||
elseif abad.update==abad_state_stairs then
|
|
||||||
abad.update=abad_state_normal
|
|
||||||
abad.frame=0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function abad_state_walking()
|
function abad_state_walking()
|
||||||
|
-- Limitar la velocitat de moviment
|
||||||
abad.wait=abad.wait+1
|
abad.wait=abad.wait+1
|
||||||
|
|
||||||
|
-- representació del moviment
|
||||||
if abad.wait==6 then
|
if abad.wait==6 then
|
||||||
abad.wait=0
|
abad.wait=0
|
||||||
abad.step=(abad.step+1)%2
|
abad.step=(abad.step+1)%2
|
||||||
@@ -223,37 +256,34 @@ function abad_state_walking()
|
|||||||
if abad.mustep == 5 then abad.mustep=1 end
|
if abad.mustep == 5 then abad.mustep=1 end
|
||||||
end
|
end
|
||||||
abad.frame=abad.anim[abad.step+1]
|
abad.frame=abad.anim[abad.step+1]
|
||||||
|
end
|
||||||
abad_advance()
|
-- Comprovar dos punts de contacte de l'abad en el piso a vore si cau
|
||||||
|
local x1_check = abad.x+abad.bb.x
|
||||||
if arc_check_tile(abad.x+4,abad.y+16)==tiletype.void and ((abad.x+4)&7==0 or arc_check_tile(abad.x+12,abad.y+16)==tiletype.void) then
|
local x2_check = x1_check+abad.bb.w
|
||||||
|
local y_check = abad.y+abad.bb.h; -- base de l'abad
|
||||||
|
local tile1 = arc_check_tile(x1_check,y_check)
|
||||||
|
local tile2 = arc_check_tile(x2_check,y_check)
|
||||||
|
if tile1==tiletype.void and tile2==tiletype.void then
|
||||||
abad.update=abad_state_falling
|
abad.update=abad_state_falling
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
abad_advance()
|
||||||
|
|
||||||
|
-- guardar punt segur
|
||||||
abad_make_safe()
|
abad_make_safe()
|
||||||
|
|
||||||
|
-- Gestionar accions mentre es camina
|
||||||
if key.down(keyJump) or pad.down(btnJump) then
|
if key.down(keyJump) or pad.down(btnJump) then
|
||||||
if true then return end
|
abad_do_jump(true); -- jumping forward
|
||||||
abad.update=abad_state_jumping
|
|
||||||
abad.step=0
|
|
||||||
abad.jumpfwd=true
|
|
||||||
if abad.jump then
|
|
||||||
sound.stop(abad.jump)
|
|
||||||
abad.jump=nil
|
|
||||||
end
|
|
||||||
sound.play(audio_abad_jump)
|
|
||||||
return
|
return
|
||||||
elseif key.down(keyDown) or pad.down(btnDown) then
|
elseif key.down(keyDown) or pad.down(btnDown) then
|
||||||
abad.update=abad_state_crouch
|
abad.update=abad_state_crouch
|
||||||
elseif key.down(keyShoot) or pad.down(btnShoot) and cacau.hab==-1 then
|
elseif key.down(keyShoot) or pad.down(btnShoot) and cacau.hab==-1 then
|
||||||
sound.play(audio_abad_shot)
|
abad_shot_cacau()
|
||||||
abad.update=abad_state_fire
|
|
||||||
abad.wait=0
|
|
||||||
cacau.init(abad.hab,abad.x+8,abad.y+8,abad.flip)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- "Flipar" a l'Abad
|
||||||
if key.down(keyRight) or pad.down(btnRight) then
|
if key.down(keyRight) or pad.down(btnRight) then
|
||||||
abad.flip=false
|
abad.flip=false
|
||||||
elseif key.down(keyLeft) or pad.down(btnLeft) then
|
elseif key.down(keyLeft) or pad.down(btnLeft) then
|
||||||
@@ -265,51 +295,33 @@ function abad_state_walking()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function abad_state_jumping()
|
function abad_state_jumping()
|
||||||
|
local vspace = abad.vmove_space
|
||||||
|
local step_length = abad.step_length
|
||||||
abad.frame=3
|
abad.frame=3
|
||||||
abad.wait=abad.wait+1
|
abad.wait=abad.wait+1
|
||||||
--print(abad.x,1,50)
|
|
||||||
--print(abad.y,10,50)
|
|
||||||
if abad.wait==6 then
|
|
||||||
abad.wait=0
|
abad.wait=0
|
||||||
|
|
||||||
if abad.jumpfwd then abad_advance() end
|
if abad.jump_height<abad.max_jump_height then
|
||||||
|
if arc_check_tile(abad.x+step_length,abad.y-vspace)~=tiletype.block then
|
||||||
--local xx=math.floor((abad.x+4)/8)
|
if arc_check_tile(abad.x+abad.bb.x+abad.bb.w,abad.y-vspace)~=tiletype.block then
|
||||||
--local yy=math.floor(abad.y/8)
|
if arc_check_tile(abad.x+abad.bb.x,abad.y-vspace)==tiletype.switch then
|
||||||
--rect(xx*8,yy*8, (xx+2)*8,(yy+1)*8)
|
|
||||||
if abad.step<6 then
|
|
||||||
if abad.y>0 then
|
|
||||||
if check_tile(abad.hab,abad.x+4,abad.y-2)~=tiletype.block then
|
|
||||||
if (abad.x+4)&7==0 or check_tile(abad.hab,abad.x+12,abad.y-2)~=tiletype.block then
|
|
||||||
|
|
||||||
if check_tile(abad.hab,abad.x+4,abad.y-2)==tiletype.switch then
|
|
||||||
-- Executar el switch
|
-- Executar el switch
|
||||||
local xx=math.min(11,math.max(0,math.floor((abad.x+4)/8)))
|
|
||||||
local yy=math.min(5,math.max(0,math.floor((abad.y-2)/8)))
|
|
||||||
switches.start(abad.hab,1+xx+yy*12)
|
switches.start(abad.hab,1+xx+yy*12)
|
||||||
--cls(4)
|
|
||||||
elseif (abad.x+4)&7~=0 and check_tile(abad.hab,abad.x+12,abad.y-2)==tiletype.switch then
|
|
||||||
-- Executar el switch
|
|
||||||
local xx=math.min(11,math.max(0,math.floor((abad.x+12)/8)))
|
|
||||||
local yy=math.min(5,math.max(0,math.floor((abad.y-2)/8)))
|
|
||||||
switches.start(abad.hab,1+xx+yy*12)
|
|
||||||
--cls(4)
|
|
||||||
else
|
else
|
||||||
abad.y=abad.y-2
|
abad.jump_height = abad.jump_height+1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
abad.hab=abad.hab-10
|
-- Canviar a mode caure
|
||||||
imp.reset()
|
|
||||||
abad.y=32
|
|
||||||
end
|
|
||||||
elseif abad.step>6 then
|
|
||||||
abad.update=abad_state_falling
|
abad.update=abad_state_falling
|
||||||
abad.jump=sound.play(audio_abad_fall)
|
abad.jump=sound.play(audio_abad_fall)
|
||||||
end
|
end
|
||||||
abad.step=abad.step+1
|
abad.step=abad.step+1
|
||||||
end
|
abad.y=abad.y-vspace
|
||||||
|
|
||||||
|
if abad.jumpfwd then abad_advance() end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -320,63 +332,68 @@ function abad_state_falling()
|
|||||||
if abad.wait==6 then
|
if abad.wait==6 then
|
||||||
abad.wait=0
|
abad.wait=0
|
||||||
|
|
||||||
if abad.jumpfwd then abad_advance() end
|
-- if abad.y<32 then
|
||||||
|
-- if (abad.y+16)&7==0 and
|
||||||
|
-- (arc_check_tile(abad.x+4,abad.y+16)>=tiletype.half or
|
||||||
|
-- ((abad.x+4)&7~=0 and
|
||||||
|
-- arc_check_tile(abad.x+12,abad.y+16)>=tiletype.half)
|
||||||
|
-- ) then
|
||||||
|
-- abad.update=abad_state_normal
|
||||||
|
-- return
|
||||||
|
-- end
|
||||||
|
-- abad.y=abad.y+2
|
||||||
|
-- abad.falling=abad.falling+1
|
||||||
|
-- else
|
||||||
|
-- abad.hab=abad.hab+10
|
||||||
|
-- -- imp.reset()
|
||||||
|
-- abad.y=0
|
||||||
|
-- end
|
||||||
|
end
|
||||||
|
|
||||||
local xx=math.floor((abad.x+4)/8)
|
local x_check = abad.x+abad.bb.x
|
||||||
local yy=math.floor((abad.y+16)/8)
|
local y_check = abad.y+abad.bb.h
|
||||||
|
local curr_tile = arc_check_tile(x_check,y_check)
|
||||||
|
local next_tile = arc_check_tile(x_check+abad.bb.w,y_check)
|
||||||
|
|
||||||
if abad.y<32 then
|
local check_floor_curr_tile = curr_tile>=tiletype.half
|
||||||
if (abad.y+16)&7==0 and (check_tile(abad.hab,abad.x+4,abad.y+16)>=tiletype.half or ((abad.x+4)&7~=0 and check_tile(abad.hab,abad.x+12,abad.y+16)>=tiletype.half)) then
|
local check_floor_next_tile = next_tile>=tiletype.half
|
||||||
|
|
||||||
|
if check_floor_curr_tile or check_floor_next_tile then
|
||||||
abad.update=abad_state_normal
|
abad.update=abad_state_normal
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
abad.y=abad.y+2
|
|
||||||
|
abad.y=abad.y+1
|
||||||
|
abad.jump_height = abad.jump_height-1
|
||||||
abad.falling=abad.falling+1
|
abad.falling=abad.falling+1
|
||||||
else
|
if abad.jumpfwd then abad_advance() end
|
||||||
abad.hab=abad.hab+10
|
|
||||||
-- imp.reset()
|
|
||||||
abad.y=0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function abad_state_stairs()
|
function abad_state_stairs()
|
||||||
abad.frame=4
|
abad.frame=4
|
||||||
abad.wait=abad.wait+1
|
abad.wait=abad.wait+1
|
||||||
|
|
||||||
if abad.wait==6 then
|
|
||||||
abad.wait=0
|
|
||||||
|
|
||||||
if key.down(keyRight) or pad.down(btnRight) then
|
if key.down(keyRight) or pad.down(btnRight) then
|
||||||
abad.flip=false
|
abad.flip=false
|
||||||
abad_advance()
|
abad_advance()
|
||||||
sound.play(audio_low)
|
if abad.wait==6 then sound.play(audio_low) end
|
||||||
elseif key.down(keyLeft) or pad.down(btnLeft) then
|
elseif key.down(keyLeft) or pad.down(btnLeft) then
|
||||||
abad.flip=true
|
abad.flip=true
|
||||||
abad_advance()
|
abad_advance()
|
||||||
sound.play(audio_low)
|
if abad.wait==6 then sound.play(audio_low) end
|
||||||
elseif key.down(keyUp) or pad.down(btnUp) then
|
elseif key.down(keyUp) or pad.down(btnUp) then
|
||||||
if abad.y>0 then
|
if arc_check_tile(abad.x+4,abad.y+8)==tiletype.stair and
|
||||||
if check_tile(abad.hab,abad.x+4,abad.y+8)==tiletype.stair or (abad.x+4)&7~=0 and check_tile(abad.hab,abad.x+12,abad.y+8)==tiletype.stair then
|
arc_check_tile(abad.x+12,abad.y+8)==tiletype.stair then
|
||||||
abad.y=abad.y-2
|
abad.y=abad.y-1
|
||||||
sound.play(audio_low)
|
if abad.wait==6 then sound.play(audio_low) end
|
||||||
end
|
|
||||||
else
|
|
||||||
abad.hab=abad.hab-10
|
|
||||||
imp.reset()
|
|
||||||
abad.y=32
|
|
||||||
end
|
end
|
||||||
elseif key.down(keyDown) or pad.down(btnDown) then
|
elseif key.down(keyDown) or pad.down(btnDown) then
|
||||||
if abad.y<32 then
|
if arc_check_tile(abad.x+4,abad.y+abad.bb.h)==tiletype.stair and
|
||||||
if check_tile(abad.hab,abad.x+4,abad.y+16)==tiletype.stair or (abad.x+4)&7~=0 and check_tile(abad.hab,abad.x+12,abad.y+16)==tiletype.stair then
|
arc_check_tile(abad.x+12,abad.y+abad.bb.h)==tiletype.stair then
|
||||||
abad.y=abad.y+2
|
abad.y=abad.y+1
|
||||||
sound.play(audio_low)
|
if abad.wait==6 then sound.play(audio_low) end
|
||||||
end
|
|
||||||
else
|
|
||||||
abad.hab=abad.hab+10
|
|
||||||
imp.reset()
|
|
||||||
abad.y=0
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if abad.wait==6 then abad.wait=0 end
|
||||||
end
|
end
|
||||||
59
data/cacau.lua
Normal file
59
data/cacau.lua
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
local arcade_config = require("arcade_config")
|
||||||
|
o2aX = arcade_config.org2arc_escala
|
||||||
|
|
||||||
|
cacau={ hab=-1,
|
||||||
|
x=0,
|
||||||
|
y=0,
|
||||||
|
wait=0,
|
||||||
|
flip=false,
|
||||||
|
bb={x=0,y=0,w=4,h=4},
|
||||||
|
alive=false }
|
||||||
|
|
||||||
|
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.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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
require "fps"
|
require "fps"
|
||||||
require "mapa"
|
require "mapa"
|
||||||
require "abad"
|
require "abad"
|
||||||
|
require "cacau"
|
||||||
|
|
||||||
local viewport= require("viewport")
|
local viewport= require("viewport")
|
||||||
|
|
||||||
@@ -10,6 +11,9 @@ local tile_h = arcade_config.tiles_height
|
|||||||
local res_w = arcade_config.resolucion.width
|
local res_w = arcade_config.resolucion.width
|
||||||
local res_h = arcade_config.resolucion.height
|
local res_h = arcade_config.resolucion.height
|
||||||
|
|
||||||
|
local view_tile_id = false
|
||||||
|
local view_checking_tile = false
|
||||||
|
|
||||||
viewp = viewport.new()
|
viewp = viewport.new()
|
||||||
viewp:position(0,0)
|
viewp:position(0,0)
|
||||||
|
|
||||||
@@ -85,13 +89,15 @@ function update_game()
|
|||||||
|
|
||||||
if key.press(key.N1) then
|
if key.press(key.N1) then
|
||||||
local hab = math.random(0, 79)
|
local hab = math.random(0, 79)
|
||||||
local abad_x, abad_y = arc_mapa_get_coords ( hab, 4, 3 )
|
local hab_x = math.random(0, mapa_room_cols-1)
|
||||||
|
local hab_y = math.random(0, mapa_room_rows-1)
|
||||||
|
local abad_x, abad_y = arc_mapa_get_coords ( hab, hab_x, hab_y)
|
||||||
print(abad_x..", "..abad_y)
|
print(abad_x..", "..abad_y)
|
||||||
abad:move(abad_x, abad_y)
|
abad:move(abad_x, abad_y)
|
||||||
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
|
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
|
||||||
end
|
end
|
||||||
if key.press(key.N0) then
|
if key.press(key.N0) then
|
||||||
local abad_x, abad_y = arc_mapa_get_coords ( 10, 4, 3 )
|
local abad_x, abad_y = arc_mapa_get_coords ( 24, 1, 3 )
|
||||||
print(abad_x..", "..abad_y)
|
print(abad_x..", "..abad_y)
|
||||||
abad:move(abad_x, abad_y)
|
abad:move(abad_x, abad_y)
|
||||||
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
|
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
|
||||||
@@ -132,11 +138,86 @@ function update_game()
|
|||||||
|
|
||||||
fps_print()
|
fps_print()
|
||||||
viewp:print()
|
viewp:print()
|
||||||
msg_print(0,14,"ABAD= "..abad.x..", "..abad.y)
|
msg_print(0,14,"ABAD= "..abad.x..", "..abad.y, true)
|
||||||
msg_print(0,21,"VIEW= "..vp_x..", "..vp_y)
|
msg_print(0,21,"VIEW= "..vp_x..", "..vp_y, true)
|
||||||
|
local hab, xx, yy = arc_mapa_get_map_coords(abad.x, abad.y)
|
||||||
|
msg_print(0,28,hab.." ( "..xx..", "..yy.." )", true)
|
||||||
|
-- msg_print(0,35,hab.." ( "..xx..", "..yy.." )", true)
|
||||||
|
msg_print(0,42," JH= "..abad.jump_height,true)
|
||||||
|
|
||||||
|
-- view_coord(abad.x+8, abad.y+0, 16, 32, 6)
|
||||||
|
--- view_coord(abad.x+abad.bb.x, abad.y+abad.bb.h, 2, 2, 4)
|
||||||
|
--- view_coord(abad.x+abad.bb.x+abad.bb.w, abad.y+abad.bb.h, 2, 2, 2)
|
||||||
|
--- view_coord(abad.x, abad.y, 2, 2, 3)
|
||||||
|
|
||||||
|
if key.press(key.T) then
|
||||||
|
view_tile_id = not view_tile_id
|
||||||
|
view_checking_tile = false
|
||||||
|
end
|
||||||
|
if key.press(key.C) then
|
||||||
|
view_checking_tile = not view_checking_tile
|
||||||
|
view_tile_id = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function msg_print(x, y, msg )
|
if view_tile_id then
|
||||||
draw.rectf(x,y,45,14,16)
|
write_tile(abad.x, abad.y, 0, true, "R")
|
||||||
draw.text(msg,x+1,y+1,2)
|
write_tile(abad.x, abad.y+16, 0, true, "R")
|
||||||
|
write_tile(abad.x, abad.y+32, 0, true, "R")
|
||||||
|
|
||||||
|
write_tile(abad.x+16, abad.y+32, 0, true, "C")
|
||||||
|
|
||||||
|
write_tile(abad.x+32, abad.y, 0, true, "L")
|
||||||
|
write_tile(abad.x+32, abad.y+16, 0, true, "L")
|
||||||
|
write_tile(abad.x+32, abad.y+32, 0, true, "L")
|
||||||
|
end
|
||||||
|
|
||||||
|
if view_checking_tile then
|
||||||
|
local msg = "FLIP= true"
|
||||||
|
if not abad.flip then
|
||||||
|
msg ="FLIP= false"
|
||||||
|
view_coord(abad.x+abad.bb.w+abad.bb.x-1, abad.y+abad.bb.h-4, 2, 2, 2)
|
||||||
|
else
|
||||||
|
view_coord(abad.x+abad.bb.x-1, abad.y+abad.bb.h-4, 2, 2, 2)
|
||||||
|
end
|
||||||
|
msg_print(abad.x, abad.y-8,msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function msg_print(x, y, msg, direct_print )
|
||||||
|
local scr_x, scr_y
|
||||||
|
direct_print = direct_print or false
|
||||||
|
if direct_print then
|
||||||
|
scr_x = x
|
||||||
|
scr_y = y
|
||||||
|
else
|
||||||
|
scr_x, scr_y = viewp:screen_coords(x, y)
|
||||||
|
end
|
||||||
|
draw.rectf(scr_x,scr_y,45,7,16)
|
||||||
|
draw.text(msg,scr_x+1,scr_y+1,2)
|
||||||
|
end
|
||||||
|
|
||||||
|
function view_coord(x, y, w, h, color)
|
||||||
|
local scr_x, scr_y = viewp:screen_coords(x, y)
|
||||||
|
draw.rect(scr_x, scr_y, w, h, color)
|
||||||
|
end
|
||||||
|
|
||||||
|
function write_tile(x, y, yplus, print_type, align )
|
||||||
|
local scr_x, scr_y = viewp:screen_coords(x, y)
|
||||||
|
local hab, xx, yy = arc_mapa_get_map_coords(x, y)
|
||||||
|
|
||||||
|
yplus = yplus or 0
|
||||||
|
print_type = print_type or false
|
||||||
|
align = align or "R"
|
||||||
|
|
||||||
|
local txt_offset = -7
|
||||||
|
if align=="R" then txt_offset = -14
|
||||||
|
elseif align=="L" then txt_offset = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
draw.rectf(scr_x+txt_offset,scr_y+yplus,14,7,16)
|
||||||
|
local msg = mapa_get_tile(hab,xx,yy)
|
||||||
|
if print_type then
|
||||||
|
msg = msg.." "..arc_check_tile(x, y)
|
||||||
|
end
|
||||||
|
draw.text(msg,scr_x+txt_offset+1,scr_y+1+yplus,2)
|
||||||
end
|
end
|
||||||
@@ -132,26 +132,31 @@ function mapa_cycle_colors(hab)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function check_tile(hab,x,y)
|
-- function check_tile(hab,x,y)
|
||||||
local xx=math.min(11,math.max(0,math.floor(x/8)))
|
-- msg_print(0,35,"c_t( "..hab..", "..x..", "..y.." )")
|
||||||
local yy=math.min(5,math.max(0,math.floor(y/8)))
|
-- print("c_t( "..hab..", "..x..", "..y.." )")
|
||||||
--rect(xx*8,yy*8,xx*8+8,yy*8+8,3)
|
-- -- local xx=math.min(11,math.max(0,math.floor(x/16)))
|
||||||
|
-- -- local yy=math.min(5,math.max(0,math.floor(y/16)))
|
||||||
local tile=mapa_get_tile(hab,xx,yy)
|
-- --rect(xx*8,yy*8,xx*8+8,yy*8+8,3)
|
||||||
if tile<8 then
|
--
|
||||||
return tiletype.half
|
-- -- tiletype => void=0 / nonpc=1 / stair=2 /
|
||||||
elseif tile<15 then
|
-- -- switch=3 / half=4 / block=5
|
||||||
return tiletype.stair
|
--
|
||||||
elseif tile==15 then
|
-- local tile=mapa_get_tile(hab,x,y)
|
||||||
return tiletype.switch
|
-- if tile<8 then
|
||||||
elseif tile<64 then
|
-- return tiletype.half
|
||||||
return tiletype.block
|
-- elseif tile<15 then
|
||||||
elseif tile==111 then
|
-- return tiletype.stair
|
||||||
return tiletype.nonpc
|
-- elseif tile==15 then
|
||||||
else
|
-- return tiletype.switch
|
||||||
return tiletype.void
|
-- elseif tile<64 then
|
||||||
end
|
-- return tiletype.block
|
||||||
end
|
-- elseif tile==111 then
|
||||||
|
-- return tiletype.nonpc
|
||||||
|
-- else
|
||||||
|
-- return tiletype.void
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
|
||||||
function arc_mapa_get_coords ( hab, tile_x , tile_y )
|
function arc_mapa_get_coords ( hab, tile_x , tile_y )
|
||||||
-- La primera habitació es la 0
|
-- La primera habitació es la 0
|
||||||
@@ -176,12 +181,17 @@ function arc_mapa_get_map_coords ( x, y )
|
|||||||
return calc_room, calc_col, calc_row
|
return calc_room, calc_col, calc_row
|
||||||
end
|
end
|
||||||
|
|
||||||
function arc_check_tile(x,y)
|
function arc_check_tile(world_x,world_y)
|
||||||
-- local xx=math.min(11,math.max(0,math.floor(x/8)))
|
-- local xx=math.min(11,math.max(0,math.floor(x/8)))
|
||||||
-- local yy=math.min(5,math.max(0,math.floor(y/8)))
|
-- local yy=math.min(5,math.max(0,math.floor(y/8)))
|
||||||
--rect(xx*8,yy*8,xx*8+8,yy*8+8,3)
|
--rect(xx*8,yy*8,xx*8+8,yy*8+8,3)
|
||||||
local hab, xx, yy = arc_mapa_get_map_coords(x, y)
|
|
||||||
|
-- tiletype => void=0 / nonpc=1 / stair=2 /
|
||||||
|
-- switch=3 / half=4 / block=5
|
||||||
|
|
||||||
|
local hab, xx, yy = arc_mapa_get_map_coords(world_x, world_y)
|
||||||
local tile=mapa_get_tile(hab,xx,yy)
|
local tile=mapa_get_tile(hab,xx,yy)
|
||||||
|
-- print("ARC_CT= "..hab.."> "..x..", "..y.." => "..tile)
|
||||||
if tile<8 then
|
if tile<8 then
|
||||||
return tiletype.half
|
return tiletype.half
|
||||||
elseif tile<15 then
|
elseif tile<15 then
|
||||||
|
|||||||
BIN
data/tiles.gif
BIN
data/tiles.gif
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Reference in New Issue
Block a user