[FIX] Els warps reutilitzats mantenien l'estat anterior [NEW] Funcio distancia(a, b)
203 lines
6.3 KiB
Lua
203 lines
6.3 KiB
Lua
function imp:do_jump ( jumpfwd )
|
|
if DEBUG_FN_NAME then print("do_jump") end
|
|
-- msg_print(0,0,"do_jump",true)
|
|
-- Inicialització de fer el salt
|
|
jumpfwd = jumpfwd or false
|
|
self.jump_height = 0
|
|
-- self.moure=imp.state_jumping
|
|
self:_moure(imp.state_jumping,"state_jumping (states)")
|
|
self.step=0
|
|
self.jumpfwd=jumpfwd
|
|
self.action=""
|
|
end
|
|
|
|
function imp:state_jumping()
|
|
if self.mood==self.moods.stop then return self.mood end
|
|
if DEBUG_FN_NAME then print("state_jumping") end
|
|
-- msg_print(0,0,"state_jumping",true)
|
|
-- ??
|
|
self.wait=self.wait+1
|
|
self.wait=0
|
|
|
|
-- Pujar o caure
|
|
if self.jump_height<self.max_jump_height then
|
|
-- Comprovar que pasa en l'aire
|
|
self:jump()
|
|
else
|
|
-- Canviar a mode caure
|
|
-- self.moure=imp.state_falling
|
|
self:_moure(imp.state_falling,"state_falling (states)")
|
|
end
|
|
self.step=self.step+1
|
|
|
|
-- cap endavant?
|
|
if self.jumpfwd then self:advance() end
|
|
end
|
|
|
|
function imp:jump()
|
|
if DEBUG_FN_NAME then print("jump") end
|
|
-- msg_print(0,0,"jump",true)
|
|
local vspace = self.vmove_space
|
|
-- Els dos punts de dalt del personatge
|
|
local x1_check = self.x+self.bb.x
|
|
local x2_check = self.x+self.bb.x+self.bb.w
|
|
local y_check = self.y-vspace; -- posicio de dalt
|
|
|
|
-- 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
|
|
|
|
-- Fer l'acció que correspon
|
|
if not_block_tile then
|
|
-- Ascendir
|
|
self.y=self.y-vspace
|
|
else
|
|
-- Si es un bloc permetre gastar l'espai no pintat
|
|
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(map_to_editor_tile(tile1_hit))
|
|
local half_block2 = mapa_is_half_block_tile(map_to_editor_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
|
|
-- 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 self.jump_in_half_block==0 and not self.jump_in_half_block_used then
|
|
self.jump_in_half_block = arcade_config.tiles_height / 2
|
|
end
|
|
if self.jump_in_half_block>0 then
|
|
self.y=self.y-vspace
|
|
self.jump_in_half_block = self.jump_in_half_block-1
|
|
self.jump_in_half_block_used = true
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Registrar el desplaçament
|
|
self.jump_height = self.jump_height+1
|
|
end
|
|
|
|
function imp:state_walking()
|
|
if self.mood==self.moods.stop then return end
|
|
if not DEBUG_FN_NAME then print("state_walking") end
|
|
-- msg_print(16,48,"state_walking",true)
|
|
|
|
-- Limitar la velocitat de moviment
|
|
self.wait=self.wait+1
|
|
|
|
-- Funció de selecció de frame
|
|
self.next_frame = imp.walking_next_frame
|
|
|
|
-- Comprovar dos punts de contacte del personatge en el piso a vore si cau
|
|
local x1_check = self.x+self.bb.x
|
|
local x2_check = x1_check+self.bb.w
|
|
local y_check = self.y+self.bb.h; -- base del personatge
|
|
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
|
|
-- si no hi ha piso, caure
|
|
-- self.moure=imp.state_falling
|
|
self:_moure(imp.state_falling, "state_falling (states)")
|
|
return
|
|
end
|
|
|
|
self:advance()
|
|
end
|
|
|
|
function imp:state_falling()
|
|
if DEBUG_FN_NAME then print("state_falling") end
|
|
-- msg_print(16,16,"state_falling",true)
|
|
|
|
self.frame=30
|
|
self.wait=self.wait+1
|
|
|
|
-- Si toca terra canviar el mode
|
|
if self:land() then
|
|
-- self.moure=imp.state_normal
|
|
self:_moure(imp.state_normal,"state_normal (states)")
|
|
return
|
|
end
|
|
|
|
-- Seguir caiguent
|
|
self.y=self.y+1
|
|
self.jump_height = self.jump_height-1
|
|
self.falling=self.falling+1
|
|
|
|
-- Caiguent cap endavant?
|
|
if self.jumpfwd then self:advance() end
|
|
end
|
|
|
|
function imp:land ()
|
|
if DEBUG_FN_NAME then print("land") end
|
|
-- msg_print(16,32,"land",true)
|
|
-- Els dos punts de baix de l'abad
|
|
local x1_check = self.x+self.bb.x
|
|
local x2_check = self.x+self.bb.x+self.bb.w
|
|
local y_check = self.y+self.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
|
|
self.jump_in_half_block_used = false
|
|
self.jump_height = 0
|
|
self.action_event = "land"
|
|
end
|
|
|
|
return can_land
|
|
end
|
|
|
|
function imp:advance()
|
|
if DEBUG_FN_NAME then print("advance") end
|
|
-- msg_print(10,20,"advance",true)
|
|
local step_length=self.step_length; --lo que avança el imp cada pas
|
|
local limit=tiletype.block
|
|
|
|
if self.moure~=imp.state_walking then limit=tiletype.half end
|
|
|
|
local x_check = self.x+self.bb.x+self.bb.w+step_length
|
|
-- if self.flip then
|
|
-- step_length = -step_length
|
|
-- x_check = self.x+self.bb.x+step_length
|
|
-- end
|
|
|
|
-- self.action=="right"
|
|
-- if self.action=="left" then
|
|
-- print("ADVANCE => "..self.movement)
|
|
if self.movement==self.actions.left then
|
|
step_length = -step_length
|
|
x_check = self.x+self.bb.x+step_length
|
|
end
|
|
|
|
local y_check = self.y+self.bb.h-4
|
|
|
|
if arc_check_tile(x_check, y_check)<limit then
|
|
self.x=self.x+step_length
|
|
end
|
|
|
|
local hab,xx, yy = coords.world_to_tile(self.x, self.y)
|
|
self.hab = hab
|
|
-- self.movement = ""
|
|
end
|
|
|
|
-- Controlador principal del personatge
|
|
function imp:state_normal()
|
|
if DEBUG_FN_NAME then print("state_normal") end
|
|
self.frame=28
|
|
self.wait=0
|
|
self.step=0
|
|
self.jumpfwd=false
|
|
self.jump_height = 0
|
|
end |