[WIP] El Abad ja arounda mes o menys be. Afegida capacitat per a entrar dins de tiles que el dibuix es només la meitat d'alt
This commit is contained in:
115
data/abad.lua
115
data/abad.lua
@@ -1,9 +1,6 @@
|
||||
-- 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")
|
||||
o2aX = arcade_config.org2arc_escala
|
||||
cxr = arcade_config.character_per_row-1
|
||||
cxr2 = arcade_config.character_per_row_base2
|
||||
-- local arcade_config = require("arcade_config")
|
||||
cw = arcade_config.character_width
|
||||
ch = arcade_config.character_height
|
||||
|
||||
@@ -53,6 +50,8 @@ function abad_init()
|
||||
vmove_space=1,
|
||||
max_jump_height=24,
|
||||
jump_height=0,
|
||||
jump_in_half_block=0,
|
||||
jump_in_half_block_used = false,
|
||||
max_shoot_cooldown=24,
|
||||
shoot_cooldown=25,
|
||||
anim={0,1,0,2},
|
||||
@@ -147,9 +146,90 @@ function abad_shot_cacau ()
|
||||
cacau.init(abad.hab,abad.x+8,abad.y+8,abad.flip)
|
||||
end
|
||||
|
||||
function abad_jump()
|
||||
local vspace = abad.vmove_space
|
||||
-- Els dos punts de dalt de l'abad
|
||||
local x1_check = abad.x+abad.bb.x
|
||||
local x2_check = abad.x+abad.bb.x+abad.bb.w
|
||||
local y_check = abad.y-vspace
|
||||
|
||||
-- Comprovar on està pegant
|
||||
local tile1_hit_type= arc_check_tile(x1_check, y_check )
|
||||
local tile2_hit_type= arc_check_tile(x2_check, y_check)
|
||||
local not_block_tile = tile1_hit_type ~= tiletype.block and tile2_hit_type ~= tiletype.block
|
||||
local switch_tile = tile1_hit_type == tiletype.switch or tile2_hit_type == tiletype.switch
|
||||
-- print("JUMP > "..x1_check..", "..x2_check..", "..y_check)
|
||||
-- print("T1= "..tile1_hit_type.." / T2= "..tile2_hit_type)
|
||||
-- local msg = "BLOCK TILE HITTED"
|
||||
-- if not_block_tile then msg="not block" end
|
||||
-- print(msg)
|
||||
-- Fer l'acció que correspon
|
||||
if not_block_tile then
|
||||
if switch_tile then
|
||||
-- Executar el switch
|
||||
switches.start(abad.hab,1+xx+yy*12)
|
||||
else
|
||||
abad.y=abad.y-vspace
|
||||
end
|
||||
else
|
||||
local tile1_hit = arc_get_tile(x1_check, y_check )
|
||||
local tile2_hit = arc_get_tile(x2_check, y_check)
|
||||
local half_block1 = mapa_is_half_block_tile(tile1_hit)
|
||||
local half_block2 = mapa_is_half_block_tile(tile2_hit)
|
||||
local full_block1 = tile1_hit_type == tiletype.block and not half_block1
|
||||
local full_block2 = tile2_hit_type == tiletype.block and not half_block2
|
||||
local full_block = full_block1 and full_block2
|
||||
local half_block = half_block1 or half_block2
|
||||
-- print("BLOCK TILE")
|
||||
-- msg = tile1_hit.." "..tile2_hit.." >> "
|
||||
-- if half_block1 then msg= msg.."half_block1 " end
|
||||
-- if half_block2 then msg= msg.."half_block2 " end
|
||||
-- if full_block1 then msg= msg.."full_block1 " end
|
||||
-- if full_block2 then msg= msg.."full_block2 " end
|
||||
-- if full_block then msg= msg.."full_block " end
|
||||
-- if half_block then msg= msg.."half_block " end
|
||||
-- if abad.jump_in_half_block_used then msg= msg.."jump_in_half_block_used " end
|
||||
-- print(msg)
|
||||
-- Si ninguno dels tiles tocats es un block complet
|
||||
-- i almenys un dels tiles tocats es mig tile
|
||||
-- permetre continuar en el salt
|
||||
if not full_block and half_block then
|
||||
if abad.jump_in_half_block==0 and not abad.jump_in_half_block_used then
|
||||
abad.jump_in_half_block = arcade_config.tiles_height>>1
|
||||
end
|
||||
if abad.jump_in_half_block>0 then
|
||||
abad.y=abad.y-vspace
|
||||
abad.jump_in_half_block = abad.jump_in_half_block-1
|
||||
end
|
||||
end
|
||||
end
|
||||
abad.jump_height = abad.jump_height+1
|
||||
abad.jump_in_half_block_used = true
|
||||
end
|
||||
|
||||
function abad_land ()
|
||||
-- abad.x
|
||||
-- abad.y
|
||||
-- Els dos punts de baix de l'abad
|
||||
local x1_check = abad.x+abad.bb.x
|
||||
local x2_check = abad.x+abad.bb.x+abad.bb.w
|
||||
local y_check = abad.y+abad.bb.h
|
||||
|
||||
-- Comprovar on està aterrant
|
||||
local tile1_hit= arc_check_tile(x1_check, y_check )
|
||||
local tile2_hit= arc_check_tile(x2_check, y_check)
|
||||
local floor_tile = tile1_hit>=tiletype.half or tile2_hit>=tiletype.half
|
||||
|
||||
-- Encara que siga un tile de piso s'ha de comprovar que
|
||||
-- la y es un múltiple de l'alt dels tiles
|
||||
local over_tile = (y_check & 0xF) == 0
|
||||
|
||||
local can_land = floor_tile and over_tile
|
||||
|
||||
if can_land then
|
||||
abad.jump_in_half_block_used = false
|
||||
abad.jump_height = 0
|
||||
end
|
||||
|
||||
return can_land
|
||||
end
|
||||
|
||||
function abad_advance()
|
||||
@@ -295,7 +375,6 @@ function abad_state_walking()
|
||||
end
|
||||
|
||||
function abad_state_jumping()
|
||||
local vspace = abad.vmove_space
|
||||
local step_length = abad.step_length
|
||||
abad.frame=3
|
||||
abad.wait=abad.wait+1
|
||||
@@ -303,23 +382,13 @@ function abad_state_jumping()
|
||||
abad.wait=0
|
||||
|
||||
if abad.jump_height<abad.max_jump_height then
|
||||
if arc_check_tile(abad.x+step_length,abad.y-vspace)~=tiletype.block then
|
||||
if arc_check_tile(abad.x+abad.bb.x+abad.bb.w,abad.y-vspace)~=tiletype.block then
|
||||
if arc_check_tile(abad.x+abad.bb.x,abad.y-vspace)==tiletype.switch then
|
||||
-- Executar el switch
|
||||
switches.start(abad.hab,1+xx+yy*12)
|
||||
else
|
||||
abad.jump_height = abad.jump_height+1
|
||||
end
|
||||
end
|
||||
end
|
||||
abad_jump()
|
||||
else
|
||||
-- Canviar a mode caure
|
||||
abad.update=abad_state_falling
|
||||
abad.jump=sound.play(audio_abad_fall)
|
||||
end
|
||||
abad.step=abad.step+1
|
||||
abad.y=abad.y-vspace
|
||||
|
||||
if abad.jumpfwd then abad_advance() end
|
||||
|
||||
@@ -350,15 +419,7 @@ function abad_state_falling()
|
||||
-- end
|
||||
end
|
||||
|
||||
local x_check = abad.x+abad.bb.x
|
||||
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)
|
||||
|
||||
local check_floor_curr_tile = curr_tile>=tiletype.half
|
||||
local check_floor_next_tile = next_tile>=tiletype.half
|
||||
|
||||
if check_floor_curr_tile or check_floor_next_tile then
|
||||
if abad_land() then
|
||||
abad.update=abad_state_normal
|
||||
return
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
arcade_config = require("arcade_config")
|
||||
|
||||
require "fps"
|
||||
require "mapa"
|
||||
require "abad"
|
||||
@@ -5,7 +7,6 @@ require "cacau"
|
||||
|
||||
local viewport= require("viewport")
|
||||
|
||||
local arcade_config = require("arcade_config")
|
||||
local tile_w = arcade_config.tiles_width
|
||||
local tile_h = arcade_config.tiles_height
|
||||
local res_w = arcade_config.resolucion.width
|
||||
@@ -146,9 +147,9 @@ function update_game()
|
||||
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)
|
||||
-- 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
|
||||
|
||||
@@ -5,6 +5,18 @@ local arcade_config = require("arcade_config")
|
||||
tiletype={void=0,nonpc=1,stair=2,switch=3,half=4,block=5}
|
||||
mapa.wait=0
|
||||
mapa.step=0
|
||||
|
||||
half_block_set={
|
||||
[20] = true, [21] = true,
|
||||
[22] = true, [28] = true,
|
||||
[29] = true, [36] = true,
|
||||
[37] = true, [44] = true,
|
||||
[45] = true}
|
||||
|
||||
function mapa_is_half_block_tile (ntile)
|
||||
return half_block_set[ntile]==true
|
||||
end
|
||||
|
||||
function mapa_do_backup()
|
||||
mapa_backup={}
|
||||
for i=1,#mapa do
|
||||
@@ -181,7 +193,7 @@ function arc_mapa_get_map_coords ( x, y )
|
||||
return calc_room, calc_col, calc_row
|
||||
end
|
||||
|
||||
function arc_check_tile(world_x,world_y)
|
||||
function arc_get_tile(world_x,world_y)
|
||||
-- local xx=math.min(11,math.max(0,math.floor(x/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)
|
||||
@@ -190,8 +202,16 @@ function arc_check_tile(world_x,world_y)
|
||||
-- switch=3 / half=4 / block=5
|
||||
|
||||
local hab, xx, yy = arc_mapa_get_map_coords(world_x, world_y)
|
||||
-- print("ARC_GT= "..hab.."> "..x..", "..y.." => "..tile)
|
||||
local tile=mapa_get_tile(hab,xx,yy)
|
||||
-- print("ARC_CT= "..hab.."> "..x..", "..y.." => "..tile)
|
||||
return tile
|
||||
end
|
||||
|
||||
function arc_check_tile(world_x,world_y)
|
||||
-- tiletype => void=0 / nonpc=1 / stair=2 /
|
||||
-- switch=3 / half=4 / block=5
|
||||
|
||||
local tile=arc_get_tile(world_x, world_y)
|
||||
if tile<8 then
|
||||
return tiletype.half
|
||||
elseif tile<15 then
|
||||
|
||||
Reference in New Issue
Block a user