[WIP] Treballant en el jefe. Per fi! Ja comença a funcionar de nou
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
function imp:_moure( foo, name )
|
||||
name = name or "anonymous"
|
||||
if not foo then
|
||||
print_dbg(name.." not found")
|
||||
else
|
||||
print_dbg(name)
|
||||
end
|
||||
-- name = name or "anonymous"
|
||||
-- if not foo then
|
||||
-- print_dbg(name.." not found")
|
||||
-- else
|
||||
-- print_dbg(name)
|
||||
-- end
|
||||
self.moure = foo
|
||||
end
|
||||
|
||||
@@ -24,6 +24,23 @@ if DEBUG_FN_NAME then print_dbg("reduce_timers") end
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------
|
||||
--
|
||||
-------------------------------
|
||||
function imp:reset_timer( timer )
|
||||
if self.mood == self.moods.stop then return end
|
||||
if DEBUG_FN_NAME then print_dbg("reduce_timers") end
|
||||
local time = 0
|
||||
if timer=="mood" then time = 150
|
||||
elseif timer=="target" then time = 250
|
||||
elseif timer=="shot" then time = 100
|
||||
elseif timer=="super" then time = 200
|
||||
elseif timer=="flip_wait" then time = 50
|
||||
end
|
||||
|
||||
if time > 0 then self.timers[timer] = time end
|
||||
end
|
||||
|
||||
-------------------------------
|
||||
--
|
||||
-------------------------------
|
||||
@@ -32,7 +49,7 @@ function imp:analyze_env() --OK
|
||||
if DEBUG_FN_NAME then print_dbg("analyze_env") end
|
||||
-- Distancia fins a l'abad
|
||||
local r = distancia(self,abad)
|
||||
-- msg_print(10,20,r,true)
|
||||
|
||||
self.analisis.can_chase_abad = false
|
||||
if r<=100 then
|
||||
self.analisis.can_chase_abad=true
|
||||
@@ -60,23 +77,47 @@ if DEBUG_FN_NAME then print_dbg("analyze_env") end
|
||||
-- Acces a la zona central (només si el super està preparat)
|
||||
x1_check = self.x+self.bb.x
|
||||
x2_check = self.x+self.bb.x+self.bb.w
|
||||
y_check = self.y+self.bb.h
|
||||
y_check = self.y+self.bb.h+8
|
||||
self.analisis.can_go_altar = false
|
||||
local hab1, tx1, ty1 = coords.world_to_tile(x1_check, y_check)
|
||||
local hab2, tx2, ty2 = coords.world_to_tile(x2_check, y_check)
|
||||
hab1, tx1, ty1 = coords.world_to_tile(x1_check, y_check)
|
||||
hab2, tx2, ty2 = coords.world_to_tile(x2_check, y_check)
|
||||
if (hab1==44 and tx1==6 and ty1==4) or (hab2==44 and tx2==7 and ty2==4)
|
||||
or (hab1==45 and tx1==7 and ty1==3) or (hab2==45 and tx2==8 and ty2==3)then
|
||||
if self.analisis.can_super then self.analisis.can_go_altar = true end
|
||||
end
|
||||
|
||||
-- Caiguent
|
||||
self.analisis.falling = false
|
||||
local tile_type1, tile_code1= arc_check_tile(x1_check,y_check)
|
||||
local tile_type2, tile_code2= arc_check_tile(x2_check,y_check)
|
||||
if tile_type1==tiletype.void and tile_type2==tiletype.void then
|
||||
self.analisis.falling = true
|
||||
end
|
||||
|
||||
-- Cau al següent moviment?
|
||||
self.analisis.going_to_fall = false
|
||||
local step_length = self.step_length
|
||||
if self.movement==self.actions.left then step_length = -step_length end
|
||||
local tile_type1, tile_code1= arc_check_tile(x1_check+self.step_length,y_check)
|
||||
local tile_type2, tile_code2= arc_check_tile(x2_check+self.step_length,y_check)
|
||||
if tile_type1==tiletype.void and tile_type2==tiletype.void then
|
||||
self.analisis.going_to_fall = true
|
||||
if not self.analisis.falling then
|
||||
local step_length = self.step_length
|
||||
|
||||
-- default movent-se cap a la dreta
|
||||
x1_check = self.x+self.bb.x+(self.bb.w/2)
|
||||
x2_check = self.x+self.bb.x+self.bb.w
|
||||
if self.x_old>self.x then
|
||||
-- movent-se cap a l'esquerra
|
||||
step_length = -step_length
|
||||
x1_check = self.x+self.bb.x
|
||||
x2_check = x1_check+(self.bb.w/2)
|
||||
elseif self.x_old==self.x then
|
||||
-- quet
|
||||
step_length = 0
|
||||
x1_check = self.x+self.bb.x
|
||||
x2_check = self.x+self.bb.x+self.bb.w
|
||||
end
|
||||
local tile_type1, tile_code1= arc_check_tile(x1_check+step_length,y_check)
|
||||
local tile_type2, tile_code2= arc_check_tile(x2_check+step_length,y_check)
|
||||
if tile_type1==tiletype.void and tile_type2==tiletype.void then
|
||||
self.analisis.going_to_fall = true
|
||||
end
|
||||
end
|
||||
|
||||
-- Ha arribat a destí
|
||||
@@ -84,42 +125,67 @@ if DEBUG_FN_NAME then print_dbg("analyze_env") end
|
||||
if not empty_table(self.pattern:target_node()) then
|
||||
-- Target reached
|
||||
if self.pattern:in_target(self) then self.analisis.target_reached=true end
|
||||
-- if collision(self, self.pattern:target_node()) then self.analisis.target_reached=true end
|
||||
end
|
||||
end
|
||||
|
||||
function imp:update_action_events()
|
||||
if self.analisis.going_to_fall then
|
||||
self:add_action_event("prefall")
|
||||
end
|
||||
|
||||
if self.analisis.falling then
|
||||
self:add_action_event("falling")
|
||||
end
|
||||
|
||||
if self.analisis.target_reached then
|
||||
self:add_action_event("target")
|
||||
end
|
||||
|
||||
if self.analisis.can_go_altar then
|
||||
self:add_action_event("super_init")
|
||||
end
|
||||
|
||||
if self.x_old>self.x then
|
||||
self:add_action_event("left")
|
||||
end
|
||||
|
||||
if self.x_old<self.x then
|
||||
self:add_action_event("right")
|
||||
end
|
||||
end
|
||||
|
||||
function imp:check_action_event ( event )
|
||||
for _, v in ipairs(self.action_event) do
|
||||
-- print_dbg(v)
|
||||
if v == event then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function imp:add_action_event ( event )
|
||||
table.insert(self.action_event, event)
|
||||
end
|
||||
|
||||
-------------------------------
|
||||
--
|
||||
-------------------------------
|
||||
function imp:choose_action() -- antic imp:move
|
||||
if self.mood==self.moods.stop then return self.mood end
|
||||
if DEBUG_FN_NAME then print_dbg("choose_action "..self.mood) end
|
||||
|
||||
local next_action = self.actions.no_action
|
||||
|
||||
if DEBUG_FN_NAME then print_dbg("choose_action "..self.mood.." / "..self.moods.stop) end
|
||||
-- if self.mood==self.moods.stop then return self.mood end
|
||||
-- Si no te ganes de fer res, no moure
|
||||
if self.mood==self.moods.stop then return self.actions.no_action end
|
||||
|
||||
if self.analisis.going_to_fall then table.insert(self.action_event, "prefall") end
|
||||
-- if self.analisis.target_reached then self.action_event="target" end
|
||||
if self.analisis.can_go_altar then self:super_ready() end
|
||||
-- if self.fight_mode == self.fight_modes["super"] then self.action_event="super" end
|
||||
-- if self.fight_mode == self.fight_modes["end_super"] then self.action_event="end_super" end
|
||||
|
||||
next_action = self:next_action()
|
||||
local next_action = self:next_action()
|
||||
|
||||
if self.analisis.target_reached and next_action=="super" then
|
||||
-- print("Super READY!")
|
||||
table.insert(self.action_event, "super_ready")
|
||||
self.add_action_event("super ready")
|
||||
-- next_action = self:next_action()
|
||||
self:super()
|
||||
end
|
||||
|
||||
if self.old_action~=next_action then
|
||||
self.old_action=next_action
|
||||
-- print(self.old_action)
|
||||
end
|
||||
|
||||
self.action = next_action
|
||||
|
||||
return next_action
|
||||
@@ -132,28 +198,46 @@ end
|
||||
-------------------------------
|
||||
function imp:controller_input()
|
||||
if DEBUG_FN_NAME then print_dbg("controller_input") end
|
||||
-- for k,v in pairs(self.actions) do
|
||||
-- if v==self.action then print("CONTROLLER => "..self.action.." / "..k) end
|
||||
-- end
|
||||
|
||||
--To Do: JumpFWD
|
||||
if (self.moure~=imp.state_falling and self.moure~=imp.state_jumping and
|
||||
self.moure~=imp.state_super) and
|
||||
(self.action == self.actions.right or self.action == self.actions.left) then
|
||||
self.movement = self.action
|
||||
-- self.moure=imp.state_walking
|
||||
self:_moure(imp.state_walking, "state_walking (movement)")
|
||||
elseif (self.moure~=imp.state_falling and self.moure~=imp.state_jumping and
|
||||
self.moure~=imp.state_super) and self.action == self.actions.jump then
|
||||
self:do_jump()
|
||||
elseif (self.moure~=imp.state_falling and self.moure~=imp.state_jumping and
|
||||
self.moure~=imp.state_super) and self.action == self.actions.jumpfwd then
|
||||
self:do_jump(true)
|
||||
elseif self.action == self.actions.shot then
|
||||
if (self.action == self.actions.right or
|
||||
self.action == self.actions.left) then
|
||||
if self.moure == imp.state_normal or self.moure == imp.state_walking then
|
||||
self:_moure(imp.state_walking, "")
|
||||
end
|
||||
elseif (self.action == self.actions.jump) then
|
||||
if self.moure == imp.state_normal or self.moure == imp.state_walking then
|
||||
self:jump()
|
||||
end
|
||||
elseif (self.action == self.actions.jumpfwd) then
|
||||
if self.moure == imp.state_normal or self.moure == imp.state_walking then
|
||||
self:jump(true)
|
||||
end
|
||||
elseif (self.action == self.actions.shot) then
|
||||
self:shot()
|
||||
elseif (self.moure~=imp.state_falling and self.moure~=imp.state_jumping and
|
||||
self.moure~=imp.state_super) and self.action == self.actions.super then
|
||||
self.moure=imp.state_super
|
||||
elseif (self.action == self.actions.super) then
|
||||
|
||||
end
|
||||
|
||||
-- if --(self.moure==imp.state_normal or self.moure==imp.state_walking) and
|
||||
-- (self.action == self.actions.right or self.action == self.actions.left) then
|
||||
-- -- self.moure=imp.state_walking
|
||||
-- self:_moure(imp.state_walking, "state_walking (movement)")
|
||||
-- elseif (self.moure~=imp.state_falling and self.moure~=imp.state_jumping and
|
||||
-- self.moure~=imp.state_super) and self.action == self.actions.jump then
|
||||
-- self:jump()
|
||||
-- elseif (self.moure==imp.state_normal or self.moure==imp.state_walking) and self.action == self.actions.jumpfwd then
|
||||
-- self:jump(true)
|
||||
-- elseif self.action == self.actions.shot then
|
||||
-- self:shot()
|
||||
-- elseif (self.moure~=imp.state_falling and self.moure~=imp.state_jumping and
|
||||
-- self.moure~=imp.state_super) and self.action == self.actions.super then
|
||||
-- self.moure=imp.state_super
|
||||
-- end
|
||||
self.old_action = self.action
|
||||
self.action = self.actions.no_action
|
||||
self.action_event = {}
|
||||
end
|
||||
|
||||
-------------------------------
|
||||
@@ -171,6 +255,28 @@ if DEBUG_FN_NAME then print_dbg("fight") end
|
||||
|
||||
self.mood=self.moods.chase
|
||||
self:pattern_movement()
|
||||
self:_moure(imp.state_normal,"")
|
||||
end
|
||||
|
||||
-------------------------------
|
||||
--
|
||||
-------------------------------
|
||||
function imp:shot(actor)
|
||||
if DEBUG_FN_NAME then print("shot") end
|
||||
self:do_flip(abad)
|
||||
-- print_dbg("FIREBALL!!")
|
||||
|
||||
local flip = false
|
||||
local x_ini = self.x+self.bb.x+self.bb.w+4
|
||||
if self.x>abad.x then
|
||||
flip=true
|
||||
x_ini = self.x-4
|
||||
end
|
||||
local hab, tx, ty, off_x, off_y = coords.world_to_tile(x_ini,self.y+(self.h/4))
|
||||
fireball.init(hab, tx, ty, flip, off_x, off_y)
|
||||
sound.play(audio_hit)
|
||||
|
||||
self:reset_timer("shot")
|
||||
end
|
||||
|
||||
-------------------------------
|
||||
@@ -180,9 +286,9 @@ function imp:create_hot_points() --OK
|
||||
self.pattern.node[1] = point.new(44, 6, 3, 0, 0,"P1")
|
||||
self.pattern.node[2] = point.new(45, 7, 3, 0, 0,"P2")
|
||||
self.pattern.node[3] = point.new(44,12, 5, 8, 0,"P3")
|
||||
self.pattern.node[4] = point.new(54, 5, 4, -8, 0,"P4")
|
||||
self.pattern.node[4] = point.new(54, 5, 4, 0, 0,"P4")
|
||||
self.pattern.node[5] = point.new(54,12, 4, 8, 0,"P5")
|
||||
self.pattern.node[6] = point.new(55, 8, 4, 8, 0,"P6")
|
||||
self.pattern.node[6] = point.new(55, 8, 4, 0, 0,"P6")
|
||||
self.pattern.node[7] = point.new(55, 8, 0, 0, 0,"P7")
|
||||
self.pattern.node[8] = point.new(54, 5, 0, 0, 0,"P8")
|
||||
self.pattern.node[9] = point.new(54, 9, 1, 0, 0,"P9")
|
||||
@@ -200,7 +306,8 @@ function imp:load_pattern_paths() --OK
|
||||
{target=3, actions= {{action="right" , event="prefall"},
|
||||
{action="jumpfwd", event="land"},
|
||||
{action="right" , event="target"}}},
|
||||
{target=4, actions= {{action="right" , event="land"},
|
||||
{target=4, actions= {{action="" , event="land"},
|
||||
{action="right" , event="land"},
|
||||
{action="left" , event="target"}}},
|
||||
{target=4, actions= {{action="right" , event="prefall"},
|
||||
{action="jumpfwd", event="land"},
|
||||
@@ -221,11 +328,21 @@ function imp:load_pattern_paths() --OK
|
||||
{target=3, actions= {{action="left" , event="prefall"},
|
||||
{action="jumpfwd", event="land"},
|
||||
{action="left" , event="target"}}},
|
||||
{target=6, actions= {{action="left" , event="land"},
|
||||
{target=6, actions= {{action="" , event="land"},
|
||||
{action="left" , event="land"},
|
||||
{action="right" , event="target"}}},
|
||||
{target=6, actions= {{action="left" , event="prefall"},
|
||||
{action="jumpfwd", event="land"},
|
||||
{action="right" , event="target"}}},
|
||||
{target=6, actions= {{action="left" , event="prefall"},
|
||||
{action="jumpfwd", event="land"},
|
||||
{action="left" , event="land"},
|
||||
{action="right" , event="target"}}},
|
||||
{target=6, actions= {{action="left" , event="prefall"},
|
||||
{action="jumpfwd", event="land"},
|
||||
{action="right" , event="land"},
|
||||
{action="left" , event="land"},
|
||||
{action="right" , event="target"}}},
|
||||
{target=9, actions= {{action="left" , event="prefall"},
|
||||
{action="jumpfwd", event="land"},
|
||||
{action="left" , event="target"}}},
|
||||
@@ -276,21 +393,30 @@ function imp:load_pattern_paths() --OK
|
||||
{target=5, actions={{action="left" , event="prefall"},
|
||||
{action="jumpfwd", event="land"},
|
||||
{action="left" , event="target"}}},
|
||||
{target=10,actions={{action="left" , event="prefall"},
|
||||
{action="jumpfwd", event="land"},
|
||||
{action="left" , event="target"}}},
|
||||
{target=2, actions={{action="jump" , event="target"}}}
|
||||
{target=10,actions={{action="" , event="land"},
|
||||
{action="left" , event="land"},
|
||||
{action="left" , event="prefall"},
|
||||
{action="jumpfwd", event="land"},
|
||||
{action="left" , event="target"}}},
|
||||
{target=2, actions={{action="jump" , event="target"}}},
|
||||
{target=6, actions={{action="" , event="land"},
|
||||
{action="left" , event="land"},
|
||||
{action="left" , event="land"},
|
||||
{action="right", event="target"}}},
|
||||
|
||||
}
|
||||
self.pattern.path[8] = {
|
||||
{target=5, actions={{action="right" , event="prefall"},
|
||||
{action="jumpfwd" , event="land"},
|
||||
{action="right" , event="target"}}},
|
||||
{target=9, actions={{action="right" , event="land"},
|
||||
{target=9, actions={{action="" , event="land"},
|
||||
{action="right" , event="land"},
|
||||
{action="jumpfwd" , event="land"},
|
||||
{action="right" , event="target"}}},
|
||||
{target=1, actions={{action="jump" , event="target"}}}
|
||||
}
|
||||
self.pattern.path[9] = {
|
||||
{target=6, actions={{action="right" , event="target"}}},
|
||||
{target=5, actions={{action="right" , event="target"}}},
|
||||
{target=1, actions={{action="left" , event="prefall"},
|
||||
{action="jumpfwd" , event="land"},
|
||||
@@ -301,10 +427,12 @@ function imp:load_pattern_paths() --OK
|
||||
self.pattern.path[10] = {
|
||||
{target=5, actions={{action="left" , event="target"}}},
|
||||
{target=2, actions={{action="right" , event="prefall"},
|
||||
{action="jumpfwd" , event="land"},
|
||||
{action="right" , event="prefall"},
|
||||
{action="jump" , event="target"}}},
|
||||
{target=6, actions={{action="right" , event="target"}}}
|
||||
{action="jumpfwd" , event="land"},
|
||||
{action="right" , event="prefall"},
|
||||
{action="jump" , event="target"}}},
|
||||
{target=6, actions={{action="right" , event="target"}}},
|
||||
{target=6, actions={{action="left" , event="land"},
|
||||
{action="right" , event = "target"}}}
|
||||
}
|
||||
self.pattern.path[11] = {
|
||||
{target=4, actions={{action="left", event="target"}}}
|
||||
@@ -330,12 +458,10 @@ function imp:next_action()
|
||||
local next_action = self.actions.no_action
|
||||
|
||||
-- Si el blanc està a tir disparar
|
||||
if self.timers.shot<=0 then
|
||||
if h_collision(self, self.shot_target) then
|
||||
next_action = self.actions.shot
|
||||
end
|
||||
if self.timers.shot<=0 and h_collision(self, self.shot_target) then
|
||||
next_action = "shot"
|
||||
end
|
||||
|
||||
|
||||
-- Resta d'accions
|
||||
if next_action==self.actions.no_action then
|
||||
if self.move_type==self.move_types.free then
|
||||
@@ -343,40 +469,43 @@ function imp:next_action()
|
||||
-- next_action = self:free_next_action()
|
||||
elseif self.move_type==self.move_types.pattern then
|
||||
-- PATTERN
|
||||
local in_target = self.pattern:in_target(self)
|
||||
local action_event_done = in_table(self.action_event, self.pattern:event())
|
||||
if in_target or action_event_done then
|
||||
local action_event_done = self:check_action_event(self.pattern:event())
|
||||
-- local str_aev = ""
|
||||
-- for k,v in pairs(self.action_event) do str_aev=str_aev..", "..v end
|
||||
if action_event_done then
|
||||
next_action=self.pattern:next_action()
|
||||
print("TARGET => "..next_action)
|
||||
-- print_dbg("NEXT ACTION "..next_action)
|
||||
else
|
||||
next_action=self.pattern:action()
|
||||
print("ON WAY => "..next_action)
|
||||
-- print_dbg("HOLD ACTION "..next_action)
|
||||
end
|
||||
elseif self.move_type==self.move_types.super then
|
||||
-- SUPER
|
||||
--
|
||||
end
|
||||
end
|
||||
self.action_event = {}
|
||||
|
||||
-- next_action es text, traduir
|
||||
return self.actions[next_action]
|
||||
end
|
||||
|
||||
function imp:do_jump ( jumpfwd )
|
||||
function imp:jump ( jumpfwd )
|
||||
if DEBUG_FN_NAME then print_dbg("") end
|
||||
-- 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=""
|
||||
self:_moure(imp.state_jumping,"")
|
||||
-- self.action=""
|
||||
end
|
||||
|
||||
function imp:state_jumping()
|
||||
if self.mood==self.moods.stop then return self.mood end
|
||||
if DEBUG_FN_NAME then print_dbg("state_jumping") end
|
||||
-- print_dbg(">>>>>>>>>> state_jumping")
|
||||
-- ??
|
||||
self.wait=self.wait+1
|
||||
self.wait=0
|
||||
@@ -384,7 +513,7 @@ if DEBUG_FN_NAME then print_dbg("state_jumping") end
|
||||
-- Pujar o caure
|
||||
if self.jump_height<self.max_jump_height then
|
||||
-- Comprovar que pasa en l'aire
|
||||
self:jump()
|
||||
self:do_jump()
|
||||
else
|
||||
-- Canviar a mode caure
|
||||
-- self.moure=imp.state_falling
|
||||
@@ -396,7 +525,7 @@ if DEBUG_FN_NAME then print_dbg("state_jumping") end
|
||||
if self.jumpfwd then self:advance() end
|
||||
end
|
||||
|
||||
function imp:jump()
|
||||
function imp:do_jump()
|
||||
if DEBUG_FN_NAME then print_dbg("jump") end
|
||||
|
||||
local vspace = self.vmove_space
|
||||
@@ -413,6 +542,7 @@ if DEBUG_FN_NAME then print_dbg("jump") end
|
||||
-- Fer l'acció que correspon
|
||||
if not_block_tile then
|
||||
-- Ascendir
|
||||
self.old_y = self.y
|
||||
self.y=self.y-vspace
|
||||
else
|
||||
-- Si es un bloc permetre gastar l'espai no pintat
|
||||
@@ -432,6 +562,7 @@ if DEBUG_FN_NAME then print_dbg("jump") end
|
||||
self.jump_in_half_block = arcade_config.tiles_height / 2
|
||||
end
|
||||
if self.jump_in_half_block>0 then
|
||||
self.old_y = self.y
|
||||
self.y=self.y-vspace
|
||||
self.jump_in_half_block = self.jump_in_half_block-1
|
||||
self.jump_in_half_block_used = true
|
||||
@@ -440,57 +571,67 @@ if DEBUG_FN_NAME then print_dbg("jump") end
|
||||
end
|
||||
|
||||
-- Registrar el desplaçament
|
||||
self.jump_height = self.jump_height+1
|
||||
self.jump_height = self.jump_height+vspace
|
||||
end
|
||||
|
||||
function imp:advance()
|
||||
if DEBUG_FN_NAME then print_dbg("advance") end
|
||||
|
||||
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
|
||||
local step_length=self.step_length; --lo que avança el imp cada pas
|
||||
local x_check = 0
|
||||
local y_check = self.y+self.bb.h-1
|
||||
|
||||
-- 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
|
||||
if (self.old_action == self.actions.right or
|
||||
self.old_action == self.actions.left) then
|
||||
-- orientació des de control
|
||||
if self.old_action == self.actions.left then
|
||||
step_length = -step_length
|
||||
x_check = self.x+self.bb.x
|
||||
else
|
||||
x_check = self.x+self.bb.x+self.bb.w
|
||||
end
|
||||
x_check = x_check + step_length
|
||||
else
|
||||
-- detectar orientacio des del movimentl
|
||||
if self.x_old>self.x then
|
||||
step_length = -step_length
|
||||
x_check = self.x+self.bb.x
|
||||
else
|
||||
x_check = self.x+self.bb.x+self.bb.w
|
||||
end
|
||||
|
||||
x_check = x_check + step_length
|
||||
end
|
||||
|
||||
local y_check = self.y+self.bb.h-4
|
||||
|
||||
if arc_check_tile(x_check, y_check)<limit then
|
||||
self.x_old = self.x
|
||||
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
|
||||
|
||||
function imp:state_falling()
|
||||
if DEBUG_FN_NAME then print_dbg("state_falling") end
|
||||
-- msg_print(16,16,"state_falling",true)
|
||||
|
||||
self.frame=30
|
||||
-- print_dbg(">>>>>>>>>> state_falling")
|
||||
-- self.frame=30
|
||||
self.wait=self.wait+1
|
||||
self.next_frame=imp.falling_next_frame
|
||||
-- Si toca terra canviar el mode
|
||||
if self:land() then
|
||||
-- self.moure=imp.state_normal
|
||||
self:_moure(imp.state_normal,"state_normal (states)")
|
||||
self.jumpfwd = false
|
||||
return
|
||||
end
|
||||
-- print_dbg("FALLING!")
|
||||
|
||||
-- Seguir caiguent
|
||||
self.old_y = self.y
|
||||
self.y=self.y+1
|
||||
self.jump_height = self.jump_height-1
|
||||
self.falling=self.falling+1
|
||||
@@ -501,7 +642,6 @@ end
|
||||
|
||||
function imp:land ()
|
||||
if DEBUG_FN_NAME then print_dbg("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
|
||||
@@ -521,7 +661,7 @@ if DEBUG_FN_NAME then print_dbg("land") end
|
||||
if can_land then
|
||||
self.jump_in_half_block_used = false
|
||||
self.jump_height = 0
|
||||
table.insert(self.action_event, "land")
|
||||
self:add_action_event("land")
|
||||
end
|
||||
-- if can_land then print_dbg ("LANDED") end
|
||||
return can_land
|
||||
@@ -529,8 +669,8 @@ 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)
|
||||
if DEBUG_FN_NAME then print("state_walking") end
|
||||
-- print_dbg(">>>>>>>>>> state_walking")
|
||||
|
||||
-- Limitar la velocitat de moviment
|
||||
self.wait=self.wait+1
|
||||
@@ -546,7 +686,7 @@ if not DEBUG_FN_NAME then print("state_walking") end
|
||||
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
|
||||
self:_moure(imp.state_falling, "state_falling (states-walking)")
|
||||
return
|
||||
end
|
||||
@@ -556,6 +696,7 @@ end
|
||||
|
||||
function imp:state_normal()
|
||||
if DEBUG_FN_NAME then print_dbg("state_normal") end
|
||||
-- print_dbg(">>>>>>>>>> state_normal")
|
||||
self.frame=28
|
||||
self.wait=0
|
||||
self.step=0
|
||||
@@ -567,7 +708,7 @@ end
|
||||
-- imp.next_frame()
|
||||
function imp:walking_next_frame()
|
||||
-- Selecció de frame
|
||||
if self.wait==6 then
|
||||
if self.wait>=6 then
|
||||
self.wait=0
|
||||
self.step=(self.step+1)%4
|
||||
self.frame=self.anim[self.step+1]
|
||||
|
||||
Reference in New Issue
Block a user