[WIP] Treballant en el jefe. Per fi torna a ser jugable! Ara a pels detalls
This commit is contained in:
@@ -133,7 +133,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function abad_hurt(howmuch)
|
function abad_hurt(howmuch)
|
||||||
howmuch = 0
|
-- howmuch = 0
|
||||||
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)
|
||||||
abad.energia=abad.energia-howmuch
|
abad.energia=abad.energia-howmuch
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ function load_boss_stage()
|
|||||||
stage_draw_back = stages["stage"..stage.."_draw_back"]
|
stage_draw_back = stages["stage"..stage.."_draw_back"]
|
||||||
stage_draw_middle = stages["stage"..stage.."_draw_middle"]
|
stage_draw_middle = stages["stage"..stage.."_draw_middle"]
|
||||||
stage_draw_front = stages["stage"..stage.."_draw_front"]
|
stage_draw_front = stages["stage"..stage.."_draw_front"]
|
||||||
|
stage_boss_end = stages["stage"..stage.."_boss_end"]
|
||||||
stage_boss()
|
stage_boss()
|
||||||
print("Stage "..stage.." Boss loaded")
|
print("Stage "..stage.." Boss loaded")
|
||||||
else
|
else
|
||||||
@@ -219,7 +220,9 @@ end
|
|||||||
function world_draw()
|
function world_draw()
|
||||||
-- Pintar la finestra del mon
|
-- Pintar la finestra del mon
|
||||||
render_map(sf_mapa, tiles, viewp.x, viewp.y)
|
render_map(sf_mapa, tiles, viewp.x, viewp.y)
|
||||||
|
|
||||||
if stages.boss_loaded then stage_draw_back() end
|
if stages.boss_loaded then stage_draw_back() end
|
||||||
|
|
||||||
-- pintar warps
|
-- pintar warps
|
||||||
for key,warp in pairs(warp.warp_list) do
|
for key,warp in pairs(warp.warp_list) do
|
||||||
if viewp:inside(warp.x, warp.y, warp.w, warp.h) then
|
if viewp:inside(warp.x, warp.y, warp.w, warp.h) then
|
||||||
@@ -244,7 +247,19 @@ end
|
|||||||
|
|
||||||
function update_game()
|
function update_game()
|
||||||
if stage~=stage_loaded then load_stage() end
|
if stage~=stage_loaded then load_stage() end
|
||||||
if stages.boss_ready and not stages.boss_loaded then load_boss_stage() end
|
|
||||||
|
if stages.boss_ready and not stages.boss_loaded then
|
||||||
|
load_boss_stage()
|
||||||
|
end
|
||||||
|
|
||||||
|
if stages.boss_ready and stages.boss_finished then
|
||||||
|
stage_boss_end()
|
||||||
|
stage_update = nil
|
||||||
|
stage_draw_back = nil
|
||||||
|
stage_draw_middle = nil
|
||||||
|
stage_draw_front = nil
|
||||||
|
stage_boss_end = nil
|
||||||
|
end
|
||||||
|
|
||||||
surf.target(0)
|
surf.target(0)
|
||||||
surf.cls(16)
|
surf.cls(16)
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ function remove_actor(actor)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function set_actors_enabled_by_room(_enabled, _reason, room0, room1)
|
function set_actors_enabled_by_room(_enabled, _reason, room0, room1)
|
||||||
print("set_actors_enabled_by_room")
|
-- print("set_actors_enabled_by_room")
|
||||||
print(" hab_list")
|
-- print(" hab_list")
|
||||||
room1 = room1 or room0
|
room1 = room1 or room0
|
||||||
local rw=(room1-room0)%mapa_rooms_per_piso
|
local rw=(room1-room0)%mapa_rooms_per_piso
|
||||||
local hab_list = {}
|
local hab_list = {}
|
||||||
@@ -68,25 +68,25 @@ print(" hab_list")
|
|||||||
while y<=room1 do
|
while y<=room1 do
|
||||||
for x=y, y+rw do
|
for x=y, y+rw do
|
||||||
hab_list[x]=true
|
hab_list[x]=true
|
||||||
print(" "..x)
|
-- print(" "..x)
|
||||||
end
|
end
|
||||||
y = y+mapa_rooms_per_piso
|
y = y+mapa_rooms_per_piso
|
||||||
end
|
end
|
||||||
|
|
||||||
for index, actor in pairs(actors) do
|
for index, actor in pairs(actors) do
|
||||||
if hab_list[actor.hab] and actor~=abad then
|
if hab_list[actor.hab] and actor~=abad then
|
||||||
if actor.name then print(" "..actor.name) end
|
-- if actor.name then print(" "..actor.name) end
|
||||||
if actor.disable_reason then print(" "..actor.disable_reason) end
|
-- if actor.disable_reason then print(" "..actor.disable_reason) end
|
||||||
if actor.enabled then print("ENABLED") end
|
-- if actor.enabled then print("ENABLED") end
|
||||||
|
|
||||||
if not _enabled then
|
if not _enabled then
|
||||||
print("DISABLE ACTORS")
|
-- print("DISABLE ACTORS")
|
||||||
-- disable
|
-- disable
|
||||||
if actor.enabled then
|
if actor.enabled then
|
||||||
-- Si el actor està actiu -> deshabilitar amb motiu
|
-- Si el actor està actiu -> deshabilitar amb motiu
|
||||||
actor.enabled=_enabled
|
actor.enabled=_enabled
|
||||||
actor.disable_reason = _reason
|
actor.disable_reason = _reason
|
||||||
print("-> ".._reason)
|
-- print("-> ".._reason)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- enable
|
-- enable
|
||||||
|
|||||||
1188
data/imp.lua
1188
data/imp.lua
File diff suppressed because it is too large
Load Diff
683
data/imp2.lua
683
data/imp2.lua
@@ -1,683 +0,0 @@
|
|||||||
require "pattern"
|
|
||||||
|
|
||||||
imp = {}
|
|
||||||
|
|
||||||
local DEBUG_FN_NAME = false
|
|
||||||
|
|
||||||
function imp.reset()
|
|
||||||
imp.hit=imp.hit
|
|
||||||
imp.update=imp.update
|
|
||||||
imp.draw=imp.draw
|
|
||||||
imp.hab=abad.hab
|
|
||||||
imp.enabled=false
|
|
||||||
imp.counter=500
|
|
||||||
end
|
|
||||||
|
|
||||||
-- function imp.new(_hab, _x, _y)
|
|
||||||
-- local world_x, world_y = coords.room_to_world(_hab,_x,_y)
|
|
||||||
-- _fight_modes={"chase","away","super","end_super","shot"}
|
|
||||||
-- for i,v in ipairs(_fight_modes) do _fight_modes[v] = i end
|
|
||||||
--
|
|
||||||
-- return { name="imp",
|
|
||||||
-- hab=_hab,
|
|
||||||
-- x=world_x, y=world_y,
|
|
||||||
-- w=32, h=32,
|
|
||||||
-- flip=true,
|
|
||||||
-- frame=28,
|
|
||||||
-- wait=0,
|
|
||||||
-- vides=1,
|
|
||||||
-- energia=21,
|
|
||||||
-- max_energia=21,
|
|
||||||
-- falling=0,
|
|
||||||
-- step=0,
|
|
||||||
-- hurting=0,
|
|
||||||
-- jumpfwd=false,
|
|
||||||
-- step_length=1,
|
|
||||||
-- 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,
|
|
||||||
-- shot_power=1,
|
|
||||||
-- shot_num_shots=1,
|
|
||||||
-- shoot_cooldown=25,
|
|
||||||
-- anim={28,29,28,30},
|
|
||||||
-- bb={x=8,y=0,w=16,h=32},
|
|
||||||
-- -- scene_intro=false,
|
|
||||||
-- -- scene_object=false,
|
|
||||||
-- enabled=true,
|
|
||||||
-- disable_reason="",
|
|
||||||
-- can_warp=false,
|
|
||||||
-- -- Atributs de jefe
|
|
||||||
-- movement_type="", -- Mode de moviment {pattern, free}
|
|
||||||
-- action="", -- Acció a realitzar en el "pad"
|
|
||||||
-- movement="", -- Cap on es mou independentment de si està "flipat"
|
|
||||||
-- fight_modes=_fight_modes, -- mode de lluita (Llevar?)
|
|
||||||
-- fight_mode="stop", -- mode de lluita actiu
|
|
||||||
-- fight_mode_cooldown=1500, -- cicles fins al canvi de mode
|
|
||||||
-- -- super_cooldown=2000, -- cicles fins a Super actiu
|
|
||||||
-- super_cooldown=200, -- cicles fins a Super actiu
|
|
||||||
-- shot_cooldown=100, -- cicles fina a poder disparar
|
|
||||||
-- hot_points={}, -- llista de punts del mapa on anar
|
|
||||||
-- target={}, -- següent punt on anar
|
|
||||||
-- old_target={}, -- target anterior
|
|
||||||
-- paths={}, -- Llista de "camins" a fer des d'un hot_point
|
|
||||||
-- path={}, -- Cami actiu
|
|
||||||
-- path_curr_action=1, -- Index d'acció dins del cami actiu
|
|
||||||
-- action_event="", -- Event d'acció que ha passat
|
|
||||||
-- analisis={}, -- Resultat de la informació extreta de l'entorn
|
|
||||||
-- old_action="-",
|
|
||||||
-- invencible=false,
|
|
||||||
-- invencible_time=50,
|
|
||||||
-- flip_wait=100, -- Temps per a forçar un flip
|
|
||||||
-- super_wait=200,
|
|
||||||
-- zoom=1,
|
|
||||||
-- super_pal={[13]=13,[14]=14,[15]=15},
|
|
||||||
-- super_fired = false,
|
|
||||||
-- -- direccio=imp.direccio,
|
|
||||||
-- draw=imp.draw,
|
|
||||||
-- hit=imp.hit,
|
|
||||||
-- do_jump=imp.do_jump,
|
|
||||||
-- jump=imp.jump,
|
|
||||||
-- state_jumping=imp.state_jumping,
|
|
||||||
-- update=imp.state_normal,
|
|
||||||
-- land=imp.land,
|
|
||||||
-- advance=imp.advance,
|
|
||||||
-- -- Funcions de jefe
|
|
||||||
-- fight=imp.fight, -- Inicialització per al combat. Crea el punts, carrega els paths, etc.
|
|
||||||
-- -- chase=imp.chase,
|
|
||||||
-- -- away=imp.away,
|
|
||||||
-- move=imp.move, -- Determina el següent moviment a fer (dreta, esq, bot, etc...)
|
|
||||||
-- super=imp.super, -- Activa el mode super poder
|
|
||||||
-- state_super=imp.state_super, -- Entra en estat super poder
|
|
||||||
-- shot=imp.shot, -- Dispara
|
|
||||||
-- do_flip=imp.do_flip, -- Orienta a l'imp cap a l'actor
|
|
||||||
-- -- mode_controller=imp.mode_controller,
|
|
||||||
-- reduce_cooldown=imp.reduce_cooldown, -- Decrementa els cooldown
|
|
||||||
-- reset_fight_mode_cooldown=imp.reset_fight_mode_cooldown, -- Asignar un valor a fight_mode_cooldown (per a mantindre una coherència cada volta que es crida)
|
|
||||||
-- controller_input=imp.controller_input, -- Traduir l'accio en moviment
|
|
||||||
-- actualitzar_comportament=imp.actualitzar_comportament, -- "Pensar" que fer
|
|
||||||
-- analyze_env=imp.analyze_env, -- Analitza l'entorn a vore que està pasant
|
|
||||||
--
|
|
||||||
-- path_reset=imp.path_reset, -- Elimina el path actiu
|
|
||||||
-- path_next_action=imp.path_next_action, -- Següent acció del path actiu
|
|
||||||
-- path_action=imp.path_action, -- Acció actual del path actiu
|
|
||||||
--
|
|
||||||
-- pattern_movement=imp.pattern_movement, -- Pasar a mode de moviment per patró
|
|
||||||
-- pattern_next_action=imp.pattern_next_action, -- Següent acció en mode pattern
|
|
||||||
-- pattern_next_target=imp.pattern_next_target, -- Següent target en mode pattern
|
|
||||||
-- pattern_recovery=imp.pattern_recovery, -- Si per algun motiu perd el mode pattern recuperar-lo
|
|
||||||
--
|
|
||||||
-- -- Al afegir pattern_recovery el moviment lliure no te sentit (ni es gasta en este moment), se queda ara per si de cas
|
|
||||||
-- free_movement=imp.free_movement, -- Pasar a mode de moviment lliure
|
|
||||||
-- free_next_action=imp.free_next_action, -- Següent acció en mode lliure
|
|
||||||
-- free_next_target=imp.free_next_target, -- Següent target en mode free
|
|
||||||
--
|
|
||||||
-- super_ready=imp.super_ready,
|
|
||||||
-- super_movement=imp.super_movement,
|
|
||||||
-- super_next_action=imp.super_next_action,
|
|
||||||
-- super_next_target=imp.super_next_target,
|
|
||||||
--
|
|
||||||
-- next_action=imp.next_action, -- Següent acció en qualsevol mode de moviment
|
|
||||||
-- next_target=imp.next_target, -- Següent target en qualsevol mode de moviment
|
|
||||||
--
|
|
||||||
-- -- imp.enabled=false
|
|
||||||
-- -- imp.counter=500
|
|
||||||
-- }
|
|
||||||
-- end
|
|
||||||
--
|
|
||||||
|
|
||||||
function imp.new(_hab,_x,_y)
|
|
||||||
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
|
|
||||||
return {
|
|
||||||
-- Venia de caco
|
|
||||||
name="imp",
|
|
||||||
hab=_hab,
|
|
||||||
x=world_x, y=world_y,
|
|
||||||
w=32, h=32,
|
|
||||||
flip=true,
|
|
||||||
frame=28,
|
|
||||||
wait=0,
|
|
||||||
step=0,
|
|
||||||
can_warp=true,
|
|
||||||
warping=false,
|
|
||||||
shrink=1,
|
|
||||||
d_shrink=1,
|
|
||||||
angle=0,
|
|
||||||
d_angle=15,
|
|
||||||
hit=imp.hit,
|
|
||||||
update=imp.update_normal,
|
|
||||||
draw=imp.draw,
|
|
||||||
jumpfwd=false,
|
|
||||||
dying=false,
|
|
||||||
death_time=40,
|
|
||||||
anim={28,29,28,30}, -- seqüencia de frames
|
|
||||||
bb={x=8,y=0,w=16,h=32},
|
|
||||||
enabled= true,
|
|
||||||
disable_reason="",
|
|
||||||
-- Ve de imp1
|
|
||||||
energia=21,
|
|
||||||
max_energia=21,
|
|
||||||
actions={no_action=0, up=1, down=2, left=4, right=8, jump=16, shot=32, super=64},
|
|
||||||
moods={stop=0, chase=1, avoid=2, neutral=4},
|
|
||||||
mood=0, --anterior fight_mode
|
|
||||||
timers={mood=150,target=250, shot=2500, super=20000, flip_wait=50}, --anterior *_cooldown
|
|
||||||
move_types={free=0, pattern=1, super=2},
|
|
||||||
move_type=1, -- anterior movement_type
|
|
||||||
|
|
||||||
-- hot_points={}, -- llista de punts del mapa on anar
|
|
||||||
-- paths={}, -- Llista de "camins" a fer des d'un hot_point
|
|
||||||
-- -- paths_active = 0, -- Número de path seleccionat
|
|
||||||
-- pattern={}, -- Instruccions per a moviment per patró, anterior path
|
|
||||||
-- pattern_point=1, -- anterior path_curr_action
|
|
||||||
-- target={}, -- Punt al que anar
|
|
||||||
|
|
||||||
shot_target=nil, -- a qui disparar
|
|
||||||
analisis = {}, -- memoria per a guardar el resultat de l'analisis
|
|
||||||
step_length=1,
|
|
||||||
falling = 0,
|
|
||||||
action_event="", -- Event d'acció que ha passat
|
|
||||||
jump_height=0,
|
|
||||||
max_jump_height=24,
|
|
||||||
pattern= pattern.new(),
|
|
||||||
vmove_space = 1,
|
|
||||||
-- funcions
|
|
||||||
next_frame = imp.staying_next_frame, -- funcio de seleccio del frame
|
|
||||||
choose_mood = imp.choose_mood,
|
|
||||||
analyze_env = imp.analyze_env,
|
|
||||||
choose_target = imp.choose_target,
|
|
||||||
choose_action = imp.choose_action,
|
|
||||||
do_flip = imp.do_flip,
|
|
||||||
colisions = imp.colisions,
|
|
||||||
fight = imp.fight,
|
|
||||||
create_hot_points = imp.create_hot_points,
|
|
||||||
load_pattern_paths= imp.load_pattern_paths,
|
|
||||||
free_movement = imp.free_movement,
|
|
||||||
pattern_movement = imp.pattern_movement,
|
|
||||||
next_action = imp.next_action,
|
|
||||||
pattern_next_action = imp.pattern_next_action,
|
|
||||||
pattern_action = imp.pattern_action,
|
|
||||||
moure = imp.state_normal,
|
|
||||||
controller_input = imp.controller_input,
|
|
||||||
reduce_timers = imp.reduce_timers,
|
|
||||||
reset_mood_timer = imp.reset_mood_timer,
|
|
||||||
path_reset = imp.path_reset,
|
|
||||||
next_target = imp.next_target,
|
|
||||||
free_next_target = imp.free_next_target,
|
|
||||||
pattern_next_target = imp.pattern_next_target,
|
|
||||||
super_next_target = imp.super_next_target,
|
|
||||||
pattern_recovery = imp.pattern_recovery,
|
|
||||||
pattern_get_next_path = imp.pattern_get_next_path,
|
|
||||||
do_jump = imp.do_jump,
|
|
||||||
land = imp.land,
|
|
||||||
shot = imp.shot,
|
|
||||||
advance=imp.advance,
|
|
||||||
jump=imp.jump,
|
|
||||||
reset_target_timer=imp.reset_target_timer,
|
|
||||||
_moure=imp._moure, -- temporal debug
|
|
||||||
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:draw() --OK
|
|
||||||
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
|
|
||||||
|
|
||||||
-- Modo super
|
|
||||||
if self.moure==self.state_super then
|
|
||||||
-- rotar paleta
|
|
||||||
for col=13,15 do
|
|
||||||
local newc = self.super_pal[col]
|
|
||||||
if self.super_wait%6 == 0 then
|
|
||||||
newc = newc+1
|
|
||||||
if newc>15 then newc=13 end
|
|
||||||
end
|
|
||||||
pal.subpal(col,newc)
|
|
||||||
self.super_pal[col]=newc
|
|
||||||
end
|
|
||||||
-- pintar
|
|
||||||
draw.surf(96, 32, self.w, self.h,
|
|
||||||
scr_x, scr_y-self.h*(self.zoom-1),
|
|
||||||
self.w*self.zoom, self.h*self.zoom,
|
|
||||||
self.flip)
|
|
||||||
-- restaurar paleta
|
|
||||||
for col=13,15 do pal.subpal(col) end
|
|
||||||
else
|
|
||||||
-- Modo normal
|
|
||||||
if self.invencible then
|
|
||||||
pal.subpal(5,1)
|
|
||||||
end
|
|
||||||
draw.surf((self.frame&7)*self.w, (self.frame>>cxr2)*self.h, self.w, self.h, scr_x, scr_y, self.w, self.h, self.flip)
|
|
||||||
pal.subpal(5)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:hit() -- OK
|
|
||||||
if DEBUG_FN_NAME then print("hit") end
|
|
||||||
if not self.invencible then
|
|
||||||
self.energia = self.energia -1
|
|
||||||
if distancia(self, abad)<50 and self.invencible_time<=0 then
|
|
||||||
self.invencible = true
|
|
||||||
self.invencible_time = 50
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.energia==1 then self.can_warp=true end
|
|
||||||
|
|
||||||
if self.energia <= 0 then
|
|
||||||
self.energia = 0
|
|
||||||
-- self.enabled = false
|
|
||||||
print("END BOSS")
|
|
||||||
|
|
||||||
if self.can_warp then self.warping=true end
|
|
||||||
self.shrink=1
|
|
||||||
self.angle=0
|
|
||||||
self.dying=true
|
|
||||||
-- calcular velocitat per al warp
|
|
||||||
local warp_time = self.death_time/3
|
|
||||||
self.d_angle = 720 / warp_time; -- 720 = 2 voltes
|
|
||||||
self.d_shrink = self.shrink / warp_time
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:update_hit()
|
|
||||||
if not self.enabled then return end
|
|
||||||
-- Que pasa quan "mor"
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:update_normal()
|
|
||||||
print("-------------------------------------------------")
|
|
||||||
print("")
|
|
||||||
if self.mood~=self.moods.stop then print("TARGET= "..self.pattern:target()) end
|
|
||||||
if self.mood~=self.moods.stop then print("ACTIONS= "..#self.pattern:actions()) end
|
|
||||||
print("TARGET TIMER= "..self.timers.target)
|
|
||||||
self:reduce_timers()
|
|
||||||
|
|
||||||
-- Ajustar mood (emocions)
|
|
||||||
-- self:choose_mood()
|
|
||||||
|
|
||||||
-- self:choose_target()
|
|
||||||
|
|
||||||
-- analisis
|
|
||||||
self:analyze_env()
|
|
||||||
|
|
||||||
-- decisio
|
|
||||||
self:choose_action()
|
|
||||||
|
|
||||||
-- moviment
|
|
||||||
self:controller_input()
|
|
||||||
self:moure()
|
|
||||||
|
|
||||||
-- Logica per a selecció de frame
|
|
||||||
-- self:next_frame()
|
|
||||||
|
|
||||||
-- colisions en personatges
|
|
||||||
-- self:colisions()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- imp.next_frame()
|
|
||||||
function imp:walking_next_frame()
|
|
||||||
-- Selecció de frame
|
|
||||||
if self.wait==6 then
|
|
||||||
self.wait=0
|
|
||||||
self.step=(self.step+1)%4
|
|
||||||
self.frame=self.anim[self.step+1]
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Orientar
|
|
||||||
self:do_flip()
|
|
||||||
|
|
||||||
-- Aguantar el flip
|
|
||||||
if self.timers.flip_wait<=0 then
|
|
||||||
if self.mood==self.moods.chase then
|
|
||||||
self:do_flip(abad)
|
|
||||||
else
|
|
||||||
self:do_flip(self.target)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:jumping_next_frame()
|
|
||||||
self.frame=30
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:falling_next_frame()
|
|
||||||
self.frame=30
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:staying_next_frame()
|
|
||||||
self.frame=28
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:super_next_frame()
|
|
||||||
self.frame=11
|
|
||||||
end
|
|
||||||
-- /imp.next_frame()
|
|
||||||
|
|
||||||
|
|
||||||
-- imp.move()
|
|
||||||
function walking_move()
|
|
||||||
-- comprovar colsions en l'entorn en cas de moure
|
|
||||||
|
|
||||||
-- moure el personatge
|
|
||||||
end
|
|
||||||
|
|
||||||
function jumping_move()
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function falling_move()
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function staying_move()
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function super_move()
|
|
||||||
|
|
||||||
end
|
|
||||||
-- /imp.move()
|
|
||||||
|
|
||||||
function imp:do_flip( actor )
|
|
||||||
actor = actor or self.target
|
|
||||||
-- enllaçat a actor
|
|
||||||
if actor.x<self.x then self.flip=true else self.flip=false end
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:colisions()
|
|
||||||
if empty_table(self.target) then return end
|
|
||||||
if collision(self, self.target) then
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:analyze_env() --OK
|
|
||||||
if self.mood==self.moods.stop then return end
|
|
||||||
if DEBUG_FN_NAME then print("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
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Els dos punts de cintura per a saber si es pot escalar
|
|
||||||
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-4
|
|
||||||
local tile_type1, tile_code1= arc_check_tile(x1_check,y_check)
|
|
||||||
local tile_type2, tile_code2= arc_check_tile(x2_check,y_check)
|
|
||||||
self.analisis.can_climb = false
|
|
||||||
if tile_type1~=tiletype.void or tile_type2~=tiletype.void then
|
|
||||||
self.analisis.can_climb = true
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Abad a tir
|
|
||||||
self.analisis.can_shot = false
|
|
||||||
if h_collision(self,abad) then self.analisis.can_shot=true end
|
|
||||||
|
|
||||||
-- Super preparat
|
|
||||||
self.analisis.can_super = false
|
|
||||||
if self.timers.super<=0 then self.analisis.can_super=true 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
|
|
||||||
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)
|
|
||||||
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
|
|
||||||
|
|
||||||
-- 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
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Ha arribat a destí
|
|
||||||
self.analisis.target_reached = false
|
|
||||||
print("TARGET= "..self.pattern:target())
|
|
||||||
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:path_reset() --OK
|
|
||||||
if DEBUG_FN_NAME then print("path_reset") end
|
|
||||||
self.path={}
|
|
||||||
self.path_point=0;
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:reset_target_timer( value ) -- OK
|
|
||||||
if DEBUG_FN_NAME then print("reset_target_timer") end
|
|
||||||
value = value or 250
|
|
||||||
self.timers.target = value
|
|
||||||
return value
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:pattern_get_next_path()
|
|
||||||
if not DEBUG_FN_NAME then print("pattern_get_next_path") end
|
|
||||||
-- obtindre uno dels possibles camins des del target en el que està
|
|
||||||
-- Si el camí s'ha acabat estarà en el punt self.path.target
|
|
||||||
local next_path_idx = math.random(#self.paths[self.pattern.target])
|
|
||||||
|
|
||||||
self.pattern = self.paths[self.pattern.target][next_path_idx]
|
|
||||||
self.pattern_point = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:create_hot_points() --OK
|
|
||||||
self.pattern.node[1] = point.new(44, 5, 1, 0, 8,"P1")
|
|
||||||
self.pattern.node[2] = point.new(45, 8, 1, 0, 8,"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[5] = point.new(54,12, 4, 8, 0,"P5")
|
|
||||||
self.pattern.node[6] = point.new(55, 8, 4, 8, 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")
|
|
||||||
self.pattern.node[10] = point.new(55, 4, 1, 0, 0,"P10")
|
|
||||||
-- self.hot_points[11] = abad
|
|
||||||
-- self.hot_points[11] = point.new(45, 1, 5, 8, 0,"altar-R")
|
|
||||||
-- self.hot_points[12] = point.new(44,11, 5, 0, 0,"altar-L")
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:load_pattern_paths() --OK
|
|
||||||
self.pattern.path[1] = {
|
|
||||||
{target=3, actions= {{action="right" , event="prefall"},
|
|
||||||
{action="jumpfwd", event="land"},
|
|
||||||
{action="right" , event="target"}}},
|
|
||||||
{target=4, actions= {{action="right" , event="land"},
|
|
||||||
{action="left" , event="target"}}},
|
|
||||||
{target=4, actions= {{action="right" , event="prefall"},
|
|
||||||
{action="jumpfwd", event="land"},
|
|
||||||
{action="left" , event="target"}}},
|
|
||||||
{target=10, actions= {{action="right" , event="prefall"},
|
|
||||||
{action="jumpfwd", event="land"},
|
|
||||||
{action="right" , event="target"}}},
|
|
||||||
{target=6, actions= {{action="right" , event="prefall"},
|
|
||||||
{action="jumpfwd", event="land"},
|
|
||||||
{action="right" , event="target"}}},
|
|
||||||
{target=5, actions= {{action="right" , event="prefall"},
|
|
||||||
{action="jumpfwd", event="land"},
|
|
||||||
{action="right" , event="land"},
|
|
||||||
{action="left" , event="target"}}},
|
|
||||||
{target=5, actions= {{action="right" , event="target"}}}
|
|
||||||
}
|
|
||||||
self.pattern.path[2] = {
|
|
||||||
{target=3, actions= {{action="left" , event="prefall"},
|
|
||||||
{action="jumpfwd", event="land"},
|
|
||||||
{action="left" , event="target"}}},
|
|
||||||
{target=6, actions= {{action="left" , event="land"},
|
|
||||||
{action="right" , event="target"}}},
|
|
||||||
{target=6, actions= {{action="left" , event="prefall"},
|
|
||||||
{action="jumpfwd", event="land"},
|
|
||||||
{action="right" , event="target"}}},
|
|
||||||
{target=9, actions= {{action="left" , event="prefall"},
|
|
||||||
{action="jumpfwd", event="land"},
|
|
||||||
{action="left" , event="target"}}},
|
|
||||||
{target=4, actions= {{action="left" , event="prefall"},
|
|
||||||
{action="jumpfwd", event="land"},
|
|
||||||
{action="left" , event="target"}}},
|
|
||||||
{target=5, actions= {{action="left" , event="prefall"},
|
|
||||||
{action="jumpfwd", event="land"},
|
|
||||||
{action="left" , event="land"},
|
|
||||||
{action="right" , event="target"}}},
|
|
||||||
{target=5, actions= {{action="left" , event="target"}}}
|
|
||||||
}
|
|
||||||
self.pattern.path[3] = {
|
|
||||||
{target=1, actions={{action="left" , event="prefall"},
|
|
||||||
{action="jumpfwd", event="land"},
|
|
||||||
{action="left" , event="prefall"},
|
|
||||||
{action="jump" , event="target"}}},
|
|
||||||
{target=2, actions={{action="right" , event="prefall"},
|
|
||||||
{action="jumpfwd", event="land"},
|
|
||||||
{action="right" , event="prefall"},
|
|
||||||
{action="jump" , event="target"}}},
|
|
||||||
{target=4, actions={{action="left" , event="prefall"},
|
|
||||||
{action="jumpfwd", event="land"},
|
|
||||||
{action="right" , event="land"},
|
|
||||||
{action="left" , event="target"}}},
|
|
||||||
{target=5, actions={{action="left" , event="land"},
|
|
||||||
{action="right" , event="target"}}},
|
|
||||||
{target=6, actions={{action="left" , event="land"},
|
|
||||||
{action="right" , event="target"}}}
|
|
||||||
}
|
|
||||||
self.pattern.path[4] = {
|
|
||||||
{target=1, actions={{action="jump" , event="target"}}},
|
|
||||||
{target=5, actions={{action="right", event="target"}}},
|
|
||||||
{target=6, actions={{action="right", event="target"}}},
|
|
||||||
{target=8, actions={{action="jump" , event="target"}}},
|
|
||||||
}
|
|
||||||
self.pattern.path[5] = {
|
|
||||||
{target=4, actions={{action="left" , event="target"}}},
|
|
||||||
{target=6, actions={{action="right", event="target"}}}
|
|
||||||
}
|
|
||||||
self.pattern.path[6] = {
|
|
||||||
{target=2, actions={{action="jump", event="target"}}},
|
|
||||||
{target=5, actions={{action="left", event="target"}}},
|
|
||||||
{target=7, actions={{action="jump", event="target"}}},
|
|
||||||
{target=4, actions={{action="left", event="target"}}}
|
|
||||||
}
|
|
||||||
self.pattern.path[7] = {
|
|
||||||
{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"}}}
|
|
||||||
}
|
|
||||||
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="prefall"},
|
|
||||||
{action="jumpfwd" , event="land"},
|
|
||||||
{action="right" , event="target"}}},
|
|
||||||
{target=1, actions={{action="jump" , event="target"}}}
|
|
||||||
}
|
|
||||||
self.pattern.path[9] = {
|
|
||||||
{target=5, actions={{action="right" , event="target"}}},
|
|
||||||
{target=1, actions={{action="left" , event="prefall"},
|
|
||||||
{action="jumpfwd" , event="land"},
|
|
||||||
{action="left" , event="prefall"},
|
|
||||||
{action="jump" , event="target"}}},
|
|
||||||
{target=4, actions={{action="left" , event="target"}}}
|
|
||||||
}
|
|
||||||
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"}}}
|
|
||||||
}
|
|
||||||
self.pattern.path[11] = {
|
|
||||||
{target=4, actions={{action="left", event="target"}}}
|
|
||||||
}
|
|
||||||
self.pattern.path[12] = {
|
|
||||||
{target=6, actions={{action="right", event="target"}}}
|
|
||||||
}
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:fight() -- OK
|
|
||||||
if DEBUG_FN_NAME then print("fight") end
|
|
||||||
self:create_hot_points()
|
|
||||||
self:load_pattern_paths()
|
|
||||||
|
|
||||||
self.pattern.manual_target = self.pattern.node[6]
|
|
||||||
self.pattern.manual_path = {target=6, actions={{action="right",event="target"}}}
|
|
||||||
|
|
||||||
self.shot_target = abad
|
|
||||||
|
|
||||||
self.mood=self.moods.chase
|
|
||||||
self:pattern_movement()
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:reduce_timers()
|
|
||||||
if self.mood==self.moods.stop then return end
|
|
||||||
if DEBUG_FN_NAME then print("reduce_timers") end
|
|
||||||
|
|
||||||
for key, val in pairs(self.timers) do
|
|
||||||
self.timers[key] = val - 1
|
|
||||||
if (val-1)<0 then self.timers[key] = 0 end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:shot(actor)
|
|
||||||
if DEBUG_FN_NAME then print("shot") end
|
|
||||||
-- self.fight_mode = self.fight_modes["shot"]
|
|
||||||
-- self:reset_fight_mode_cooldown(1)
|
|
||||||
self:do_flip(abad)
|
|
||||||
self.flip_wait=100
|
|
||||||
-- print("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.shot_cooldown = 100
|
|
||||||
end
|
|
||||||
|
|
||||||
-- function imp:actualitzar_comportament()
|
|
||||||
-- if DEBUG_FN_NAME then print("actualitzar_comportament") end
|
|
||||||
-- self:reduce_cooldown()
|
|
||||||
-- if self.invencible_time<=0 then self.invencible=false end
|
|
||||||
-- -- if self.update==imp.state_jumping or self.update==imp.state_falling then
|
|
||||||
-- -- -- self:think()
|
|
||||||
-- -- -- self:move()
|
|
||||||
-- -- end
|
|
||||||
-- self:analyze_env()
|
|
||||||
-- if self.moure==imp.state_walking or self.update==imp.state_normal then
|
|
||||||
-- self:move()
|
|
||||||
-- end
|
|
||||||
-- self:controller_input()
|
|
||||||
-- end
|
|
||||||
|
|
||||||
require "imp_mood"
|
|
||||||
require "imp_action"
|
|
||||||
require "imp_target"
|
|
||||||
require "imp_movement"
|
|
||||||
require "imp_states"
|
|
||||||
require "imp_super"
|
|
||||||
@@ -560,7 +560,8 @@ if DEBUG_FN_NAME then print_dbg("") end
|
|||||||
-- Inicialització de fer el salt
|
-- Inicialització de fer el salt
|
||||||
jumpfwd = jumpfwd or false
|
jumpfwd = jumpfwd or false
|
||||||
self.jump_height = 0
|
self.jump_height = 0
|
||||||
self.step=0
|
-- self.step=0
|
||||||
|
self:_step(0,"jump")
|
||||||
self.jumpfwd=jumpfwd
|
self.jumpfwd=jumpfwd
|
||||||
self.moure = imp.state_jumping
|
self.moure = imp.state_jumping
|
||||||
end
|
end
|
||||||
@@ -568,7 +569,6 @@ end
|
|||||||
function imp:state_jumping()
|
function imp:state_jumping()
|
||||||
if self.mood==self.moods.stop then return self.mood end
|
if self.mood==self.moods.stop then return self.mood end
|
||||||
if DEBUG_FN_NAME then print_dbg("state_jumping") end
|
if DEBUG_FN_NAME then print_dbg("state_jumping") end
|
||||||
-- print_dbg(">>>>>>>>>> state_jumping")
|
|
||||||
-- ??
|
-- ??
|
||||||
self.wait=self.wait+1
|
self.wait=self.wait+1
|
||||||
self.wait=0
|
self.wait=0
|
||||||
@@ -581,7 +581,8 @@ if DEBUG_FN_NAME then print_dbg("state_jumping") end
|
|||||||
-- Canviar a mode caure
|
-- Canviar a mode caure
|
||||||
self.moure = imp.state_falling
|
self.moure = imp.state_falling
|
||||||
end
|
end
|
||||||
self.step=self.step+1
|
-- self.step=self.step+1
|
||||||
|
self:_step(self.step+1,"state_jumping")
|
||||||
|
|
||||||
-- cap endavant?
|
-- cap endavant?
|
||||||
if self.jumpfwd then self:advance() end
|
if self.jumpfwd then self:advance() end
|
||||||
@@ -680,7 +681,6 @@ end
|
|||||||
|
|
||||||
function imp:state_falling()
|
function imp:state_falling()
|
||||||
if DEBUG_FN_NAME then print_dbg("state_falling") end
|
if DEBUG_FN_NAME then print_dbg("state_falling") end
|
||||||
-- print_dbg(">>>>>>>>>> state_falling")
|
|
||||||
-- self.frame=30
|
-- self.frame=30
|
||||||
self.wait=self.wait+1
|
self.wait=self.wait+1
|
||||||
self.next_frame=imp.falling_next_frame
|
self.next_frame=imp.falling_next_frame
|
||||||
@@ -731,7 +731,6 @@ end
|
|||||||
function imp:state_walking()
|
function imp:state_walking()
|
||||||
if self.mood==self.moods.stop then return end
|
if self.mood==self.moods.stop then return end
|
||||||
if DEBUG_FN_NAME then print("state_walking") end
|
if DEBUG_FN_NAME then print("state_walking") end
|
||||||
-- print_dbg(">>>>>>>>>> state_walking")
|
|
||||||
|
|
||||||
-- Limitar la velocitat de moviment
|
-- Limitar la velocitat de moviment
|
||||||
self.wait=self.wait+1
|
self.wait=self.wait+1
|
||||||
@@ -756,10 +755,10 @@ end
|
|||||||
|
|
||||||
function imp:state_normal()
|
function imp:state_normal()
|
||||||
if DEBUG_FN_NAME then print_dbg("state_normal") end
|
if DEBUG_FN_NAME then print_dbg("state_normal") end
|
||||||
-- print_dbg(">>>>>>>>>> state_normal")
|
|
||||||
self.frame=28
|
self.frame=28
|
||||||
self.wait=0
|
self.wait=0
|
||||||
self.step=0
|
-- self.step=0
|
||||||
|
self:_step(0,"state_normal")
|
||||||
self.jumpfwd=false
|
self.jumpfwd=false
|
||||||
self.jump_height = 0
|
self.jump_height = 0
|
||||||
self.next_frame=imp.staying_next_frame
|
self.next_frame=imp.staying_next_frame
|
||||||
@@ -770,7 +769,8 @@ function imp:walking_next_frame()
|
|||||||
-- Selecció de frame
|
-- Selecció de frame
|
||||||
if self.wait>=6 then
|
if self.wait>=6 then
|
||||||
self.wait=0
|
self.wait=0
|
||||||
self.step=(self.step+1)%4
|
-- self.step=(self.step+1)%4
|
||||||
|
self:_step((self.step+1)%4,"walking_next_frame")
|
||||||
self.frame=self.anim[self.step+1]
|
self.frame=self.anim[self.step+1]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
100
data/imp3.lua
100
data/imp3.lua
@@ -57,7 +57,8 @@ function imp.new(_hab,_x,_y)
|
|||||||
super_fired = false,
|
super_fired = false,
|
||||||
can_warp = false,
|
can_warp = false,
|
||||||
invencible_time = 0,
|
invencible_time = 0,
|
||||||
death_time=40,
|
disappear_time=40,
|
||||||
|
disappearing = false,
|
||||||
--
|
--
|
||||||
moure = noop,
|
moure = noop,
|
||||||
draw=imp.draw,
|
draw=imp.draw,
|
||||||
@@ -86,9 +87,11 @@ function imp.new(_hab,_x,_y)
|
|||||||
super = imp.super,
|
super = imp.super,
|
||||||
super_movement = imp.super_movement,
|
super_movement = imp.super_movement,
|
||||||
hit = imp.hit,
|
hit = imp.hit,
|
||||||
|
warp_update = imp.warp_update,
|
||||||
-- debug
|
-- debug
|
||||||
_moure = imp._moure,
|
_moure = imp._moure,
|
||||||
_pause = false,
|
_pause = false,
|
||||||
|
_step = imp._step,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -96,8 +99,10 @@ function imp:draw() --OK
|
|||||||
self.pattern:draw()
|
self.pattern:draw()
|
||||||
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
|
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
|
||||||
|
|
||||||
|
if self.warping then
|
||||||
|
actor_warp_draw(self)
|
||||||
|
elseif self.moure==imp.state_super then
|
||||||
-- Modo super
|
-- Modo super
|
||||||
if self.moure==imp.state_super then
|
|
||||||
-- rotar paleta
|
-- rotar paleta
|
||||||
for col=13,15 do
|
for col=13,15 do
|
||||||
local newc = self.super_pal[col]
|
local newc = self.super_pal[col]
|
||||||
@@ -124,17 +129,18 @@ function imp:draw() --OK
|
|||||||
pal.subpal(5)
|
pal.subpal(5)
|
||||||
end
|
end
|
||||||
|
|
||||||
draw.rect(scr_x+self.bb.x,scr_y+self.bb.h, self.bb.w, 8,2)
|
-- draw.rect(scr_x+self.bb.x,scr_y+self.bb.h, self.bb.w, 8,2)
|
||||||
local wtx, wty = coords.room_to_world(hab1, tx1, ty1)
|
-- local wtx, wty = coords.room_to_world(hab1, tx1, ty1)
|
||||||
local scr_x, scr_y = viewp:screen_coords( wtx, wty )
|
-- local scr_x, scr_y = viewp:screen_coords( wtx, wty )
|
||||||
draw.rect(scr_x, scr_y, 16, 16, 15)
|
-- draw.rect(scr_x, scr_y, 16, 16, 15)
|
||||||
local wtx, wty = coords.room_to_world(hab2, tx2, ty2)
|
-- local wtx, wty = coords.room_to_world(hab2, tx2, ty2)
|
||||||
local scr_x, scr_y = viewp:screen_coords( wtx, wty )
|
-- local scr_x, scr_y = viewp:screen_coords( wtx, wty )
|
||||||
draw.rect(scr_x, scr_y, 16, 16, 13)
|
-- draw.rect(scr_x, scr_y, 16, 16, 13)
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:hit() -- OK
|
function imp:hit() -- OK
|
||||||
if not DEBUG_FN_NAME then print_dbg("hit") end
|
if self.energia <= 0 then return end
|
||||||
|
if DEBUG_FN_NAME then print_dbg("hit") end
|
||||||
if not self.invencible then
|
if not self.invencible then
|
||||||
self.energia = self.energia -1
|
self.energia = self.energia -1
|
||||||
if distancia(self, abad)<50 and self.invencible_time<=0 then
|
if distancia(self, abad)<50 and self.invencible_time<=0 then
|
||||||
@@ -148,53 +154,77 @@ if not DEBUG_FN_NAME then print_dbg("hit") end
|
|||||||
if self.energia <= 0 then
|
if self.energia <= 0 then
|
||||||
self.energia = 0
|
self.energia = 0
|
||||||
-- self.enabled = false
|
-- self.enabled = false
|
||||||
print("END BOSS")
|
|
||||||
self.update=imp.update_hit
|
|
||||||
if self.can_warp then self.warping=true end
|
if self.can_warp then self.warping=true end
|
||||||
self.shrink=1
|
self.shrink=1
|
||||||
self.angle=0
|
self.angle=0
|
||||||
self.dying=true
|
self.disappearing=true
|
||||||
-- calcular velocitat per al warp
|
-- calcular velocitat per al warp
|
||||||
local warp_time = self.death_time/3
|
local warp_time = self.disappear_time/3
|
||||||
self.d_angle = 720 / warp_time; -- 720 = 2 voltes
|
self.d_angle = 720 / warp_time; -- 720 = 2 voltes
|
||||||
self.d_shrink = self.shrink / warp_time
|
self.d_shrink = self.shrink / warp_time
|
||||||
|
|
||||||
|
self.update=imp.update_disappearing
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:update_hit()
|
function imp:_step( value, foo )
|
||||||
|
foo = foo or "anonymous"
|
||||||
|
-- print_dbg(foo)
|
||||||
|
self.step = value
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function imp:warp_update()
|
||||||
|
-- warp, wait, respawn
|
||||||
|
if self.warping then
|
||||||
|
if self.step<self.disappear_time then
|
||||||
|
self.shrink=self.shrink-self.d_shrink
|
||||||
|
self.angle=self.angle+self.d_angle
|
||||||
|
if self.angle>=360 then self.angle = self.angle % 360 end
|
||||||
|
if self.shrink<=0 then
|
||||||
|
-- Ha desaparegut
|
||||||
|
self.shrink=1
|
||||||
|
self.d_shrink=1
|
||||||
|
self.angle=0
|
||||||
|
self.d_angle=1
|
||||||
|
self.warping = false
|
||||||
|
self.frame = -1
|
||||||
|
-- self.can_warp = false
|
||||||
|
-- self.step = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self.can_warp = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function imp:update_disappearing()
|
||||||
|
-- print_dbg(">>>>>>>>>> update_hit")
|
||||||
if not self.enabled then return end
|
if not self.enabled then return end
|
||||||
-- Que pasa quan "mor"
|
-- Que pasa quan "mor"
|
||||||
local step_time = self.death_time
|
local step_time = self.disappear_time
|
||||||
if self.can_warp then
|
if self.can_warp then
|
||||||
step_time = self.death_time/3; -- warp, wait, appear
|
step_time = self.disappear_time/2; -- warp, wait
|
||||||
end
|
end
|
||||||
self.wait=self.wait+1
|
self.wait=self.wait+1
|
||||||
|
-- print(self.step)
|
||||||
if self.wait>=6 then
|
if self.wait>=6 then
|
||||||
self.wait=0
|
self.wait=0
|
||||||
self.step=self.step+1
|
-- self.step=self.step+1
|
||||||
|
self:_step(self.step+1,"update_hit")
|
||||||
|
|
||||||
if self.can_warp then
|
if self.can_warp then
|
||||||
actor_warp_update(self)
|
self:warp_update()
|
||||||
|
self.moure = self.noop
|
||||||
else
|
else
|
||||||
if self.step<self.death_time then
|
self.enabled = false
|
||||||
if self.step%2==0 then
|
print("END BOSS")
|
||||||
-- self.frame=21
|
stages.stage1_boss_finished()
|
||||||
self.frame=self.anim[#self.anim]
|
|
||||||
else
|
|
||||||
self.frame=-1
|
|
||||||
end
|
|
||||||
elseif self.step>=self.death_time then
|
|
||||||
-- self.frame=19
|
|
||||||
self.frame=self.anim[1]
|
|
||||||
self.step=0
|
|
||||||
self.wait=0
|
|
||||||
self.update=caco.update_normal
|
|
||||||
self.dying = false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:update_normal()
|
function imp:update_normal()
|
||||||
-- print("")
|
-- print("")
|
||||||
-- print("TARGET TIMER= "..self.timers.target)
|
-- print("TARGET TIMER= "..self.timers.target)
|
||||||
|
|||||||
@@ -1,193 +0,0 @@
|
|||||||
|
|
||||||
function imp:choose_action() -- antic imp:move
|
|
||||||
if self.mood==self.moods.stop then return self.mood end
|
|
||||||
if DEBUG_FN_NAME then print("choose_action "..self.mood) end
|
|
||||||
|
|
||||||
local next_action = self.actions.no_action
|
|
||||||
|
|
||||||
-- 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 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()
|
|
||||||
|
|
||||||
if self.analisis.target_reached and next_action=="super" then
|
|
||||||
-- print("Super READY!")
|
|
||||||
self.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
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:next_action()
|
|
||||||
local next_action = self.actions.no_action
|
|
||||||
|
|
||||||
-- Si el blanc està a tir
|
|
||||||
if self.timers.shot<=0 then
|
|
||||||
if h_collision(self, self.shot_target) then
|
|
||||||
next_action = self.actions.shot
|
|
||||||
end
|
|
||||||
end
|
|
||||||
print("next_action= "..next_action.." == "..self.actions.no_action)
|
|
||||||
if next_action==self.actions.no_action then
|
|
||||||
if self.move_type==self.move_types.free then
|
|
||||||
-- msg_print(10,20,"FREE",true)
|
|
||||||
next_action = self:free_next_action()
|
|
||||||
elseif self.move_type==self.move_types.pattern then
|
|
||||||
-- msg_print(10,20,"PATTERN "..self.action_event,true)
|
|
||||||
print("imp_action.lua -> next_action -> pattern")
|
|
||||||
next_action=self.pattern:next_action()
|
|
||||||
print("imp_action.lua -> next_action -> pattern => "..next_action)
|
|
||||||
elseif self.move_type==self.move_types.super then
|
|
||||||
-- msg_print(10,20,"SUPER "..self.action_event,true)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return next_action
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:free_next_action()
|
|
||||||
if DEBUG_FN_NAME then print("free_next_action") end
|
|
||||||
-- Moviment horitzontal
|
|
||||||
if self.target.x+self.target.bb.x>=self.x+self.bb.x then
|
|
||||||
action="right"
|
|
||||||
elseif self.target.x+self.target.bb.x<self.x+self.bb.x then
|
|
||||||
action="left"
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Els dos punts de baix pero un poc mes alt que el piso
|
|
||||||
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-4
|
|
||||||
-- Tiles on esta
|
|
||||||
local tile_type1, tile_code1= arc_check_tile(x1_check,y_check)
|
|
||||||
local tile_type2, tile_code2= arc_check_tile(x2_check,y_check)
|
|
||||||
|
|
||||||
-- debug
|
|
||||||
local scr_x1, scr_y = viewp:screen_coords( x1_check, y_check )
|
|
||||||
local scr_x2, scr_y = viewp:screen_coords( x2_check, y_check )
|
|
||||||
draw.rect(scr_x1,scr_y,scr_x2-scr_x1,8,2)
|
|
||||||
-- /debug
|
|
||||||
|
|
||||||
--Comprovar si está en target
|
|
||||||
if collision(self, self.target) then
|
|
||||||
self:reset_mood_timer()
|
|
||||||
|
|
||||||
-- Buscar quin es el target
|
|
||||||
local idx = 1
|
|
||||||
for i=1,#self.hot_points do
|
|
||||||
if self.target==self.hot_points[i] then
|
|
||||||
idx= i
|
|
||||||
-- print("TARGET ID= "..self.target.id.." HOT POINT IDX= "..i.." Reached")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Canviar a moviment per patro
|
|
||||||
self.path={next=idx, actions={}}
|
|
||||||
action = self:path_next_action()
|
|
||||||
-- elseif half_collision(self, self.target)
|
|
||||||
-- and tile_type1==tiletype.void
|
|
||||||
-- and tile_type2==tiletype.void then -- and (self.y>self.target.y or self.y<self.target.y) ) then -- afegir que no hi haja tile per a escalar
|
|
||||||
-- -- print("Next Target 2 "..tile_type1.." "..tile_code1)
|
|
||||||
-- elseif tile_type1~=tiletype.void
|
|
||||||
-- or tile_type2~=tiletype.void then
|
|
||||||
-- action="jump"
|
|
||||||
end
|
|
||||||
|
|
||||||
return action
|
|
||||||
end
|
|
||||||
|
|
||||||
-- function imp:pattern_next_action()
|
|
||||||
-- if DEBUG_FN_NAME then print("pattern_next_action") end
|
|
||||||
-- print("self.pattern_point= ".. self.pattern_point)
|
|
||||||
-- local pattern_event = self.pattern.actions[self.pattern_point].event
|
|
||||||
-- print("imp_action.lua -> pattern_next_action -> "..self.action_event.."~="..pattern_event)
|
|
||||||
-- -- Si no s'ha donat l'event mantindre el moviment
|
|
||||||
-- if self.action_event~=pattern_event then
|
|
||||||
-- action = self.actions[self.pattern.actions[self.pattern_point].action]
|
|
||||||
-- else
|
|
||||||
-- -- Si s'ha donat l'event avançar el punter del path
|
|
||||||
-- -- En el path
|
|
||||||
-- self.pattern_point = self.pattern_point + 1
|
|
||||||
-- -- Si no queden accions carregar el següent path
|
|
||||||
-- print(self.pattern_point..">#"..#self.pattern.actions)
|
|
||||||
-- if self.pattern_point>#self.pattern.actions then
|
|
||||||
-- self:pattern_get_next_path()
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- print("-self.pattern_point= ".. self.pattern_point)
|
|
||||||
-- action = self:pattern_action()
|
|
||||||
-- end
|
|
||||||
-- self.action_event = ""; -- Action_event processat
|
|
||||||
-- return action
|
|
||||||
-- end
|
|
||||||
|
|
||||||
function imp:pattern_next_action()
|
|
||||||
if DEBUG_FN_NAME then print("pattern_next_action") end
|
|
||||||
local pattern_event = self.pattern:event()
|
|
||||||
print("imp_action.lua -> pattern_next_action -> "..self.action_event.."~="..self.pattern:event())
|
|
||||||
-- Si no s'ha donat l'event mantindre el moviment
|
|
||||||
if self.action_event~=self.pattern:event() then
|
|
||||||
action = self.pattern:action()
|
|
||||||
else
|
|
||||||
-- Següent acció
|
|
||||||
local target0 = self.pattern:target()
|
|
||||||
action = self.pattern:next_action()
|
|
||||||
-- Comprovar si ha canviat el target al avançar d'acció
|
|
||||||
if target0~=self.pattern:target() then
|
|
||||||
self:reset_target_timer()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.action_event = ""; -- Action_event processat
|
|
||||||
return self.actions[action]
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:pattern_action()
|
|
||||||
if not DEBUG_FN_NAME then print("pattern_action") end
|
|
||||||
local idx = self.pattern_point
|
|
||||||
print(idx)
|
|
||||||
local pattern_action = self.pattern.actions[idx]
|
|
||||||
local curr_action = pattern_action.action
|
|
||||||
local next_action = self.actions[curr_action]
|
|
||||||
return next_action
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function imp:_moure( foo, name )
|
|
||||||
name = name or "anonymous"
|
|
||||||
print("_moure= "..name)
|
|
||||||
if not foo then print(name.." not found") end
|
|
||||||
self.moure = foo
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- function imp:path_next_action()
|
|
||||||
-- if not DEBUG_FN_NAME then print("path_next_action "..from) end
|
|
||||||
-- if #self.paths[self.path.target]>0 then
|
|
||||||
-- -- self:pattern_movement()
|
|
||||||
-- self:reset_target_timer()
|
|
||||||
-- self:next_target()
|
|
||||||
-- action = self:path_action()
|
|
||||||
-- else
|
|
||||||
-- action = self:pattern_recovery()
|
|
||||||
-- print("PNA Recovery "..action)
|
|
||||||
-- end
|
|
||||||
-- return action
|
|
||||||
-- end
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
function imp:choose_mood()
|
|
||||||
if self.mood==self.moods.stop then return end
|
|
||||||
if self.timers.mood<=0 then
|
|
||||||
self.mood=self.moods[math.random(2)+1] -- chase o avoid
|
|
||||||
self:reset_mood_timer()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:reset_mood_timer( value ) -- OK
|
|
||||||
if DEBUG_FN_NAME then print("reset_mood_timer") end
|
|
||||||
value = value or 150
|
|
||||||
self.timers.mood = value
|
|
||||||
return value
|
|
||||||
end
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
-------------------------------------------------------------------
|
|
||||||
-- // FREE MOVEMENT
|
|
||||||
|
|
||||||
function imp:free_movement() --OK
|
|
||||||
if DEBUG_FN_NAME then print("free_movement") end
|
|
||||||
self.move_type = self.move_types.free
|
|
||||||
print("Free")
|
|
||||||
end
|
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
-- // PATTERN MOVEMENT
|
|
||||||
|
|
||||||
function imp:pattern_movement() --OK
|
|
||||||
if DEBUG_FN_NAME then print("pattern_movement") end
|
|
||||||
self.movement_type = "pattern"
|
|
||||||
-- print("Pattern")
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:pattern_recovery() -- OK
|
|
||||||
-- print("Pattern recovery")
|
|
||||||
self:pattern_movement() -- Canviar a moviment per patró
|
|
||||||
self:path_reset() -- Borrar les instruccions pendents
|
|
||||||
|
|
||||||
-- Situar-se en el mapa respecte als punts de recuperació (els tres punts del pis)
|
|
||||||
local x_after_4 = false
|
|
||||||
local x_after_5 = false
|
|
||||||
local x_after_6 = false
|
|
||||||
local y_upper_4 = false
|
|
||||||
local y_upper_5 = false
|
|
||||||
local y_upper_6 = false
|
|
||||||
|
|
||||||
if self.hot_points[4].x<self.x then x_after_4 = true end
|
|
||||||
if self.hot_points[5].x<self.x then x_after_5 = true end
|
|
||||||
if self.hot_points[6].x<self.x then x_after_6 = true end
|
|
||||||
-- Comparar en el punt dels peus
|
|
||||||
if self.hot_points[4].y>self.y+self.h then y_upper_4 = true end
|
|
||||||
if self.hot_points[5].y>self.y+self.h then y_upper_5 = true end
|
|
||||||
if self.hot_points[6].y>self.y+self.h then y_upper_6 = true end
|
|
||||||
|
|
||||||
-- Seleccionar les instruccions segons la posicio
|
|
||||||
if not y_upper_5 then
|
|
||||||
-- target 5
|
|
||||||
self.target = self.hot_points[5]
|
|
||||||
if not x_after_5 then
|
|
||||||
-- right target
|
|
||||||
self.path = {next=5, actions={{action="right",event="target"}}}
|
|
||||||
else
|
|
||||||
-- left target
|
|
||||||
self.path = {next=5, actions={{action="left",event="target"}}}
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if x_after_5 then
|
|
||||||
--target 4
|
|
||||||
self.target = self.hot_points[4]
|
|
||||||
-- left target
|
|
||||||
self.path = {next=4, actions={{action="left",event="target"}}}
|
|
||||||
else
|
|
||||||
--target 6
|
|
||||||
self.target = self.hot_points[6]
|
|
||||||
-- right target
|
|
||||||
self.path = {next=6, actions={{action="right",event="target"}}}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Tornar l'acció a fer
|
|
||||||
return self.actions[self.path.actions[1].action]
|
|
||||||
end
|
|
||||||
|
|
||||||
-------------------------------
|
|
||||||
-- imp.controller_input()
|
|
||||||
--
|
|
||||||
-- Traduir a una entrada de pad
|
|
||||||
-------------------------------
|
|
||||||
function imp:controller_input()
|
|
||||||
if DEBUG_FN_NAME then print("controller_input") end
|
|
||||||
|
|
||||||
--To Do: JumpFWD
|
|
||||||
if 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.action == self.actions.jump then
|
|
||||||
self:do_jump()
|
|
||||||
elseif self.action == "jumpfwd" then
|
|
||||||
self:do_jump(true)
|
|
||||||
elseif self.action == self.actions.shot then
|
|
||||||
self:shot()
|
|
||||||
elseif self.action == self.actions.super then
|
|
||||||
self.moure=imp.state_super
|
|
||||||
end
|
|
||||||
self.action = self.actions.no_action
|
|
||||||
end
|
|
||||||
@@ -1,203 +0,0 @@
|
|||||||
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-walking)")
|
|
||||||
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
|
|
||||||
print("FALLING!")
|
|
||||||
-- 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
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
function imp:super_ready()
|
|
||||||
if not DEBUG_FN_NAME then print("super_ready()") end
|
|
||||||
if self.x<self.hot_points[3].x then
|
|
||||||
self.target = self.hot_points[3]
|
|
||||||
self.path = {next=3, actions= {{action="jumpfwd", event="land"},
|
|
||||||
{action="right" , event="target"},
|
|
||||||
{action="super" , event="super_ready"}}}
|
|
||||||
end
|
|
||||||
--if self.x<self.hot_points[3].x then
|
|
||||||
-- self.target = self.hot_points[11]
|
|
||||||
-- self.path = {next=11, actions= {{action="jumpfwd", event="land"},
|
|
||||||
-- {action="right" , event="target"},
|
|
||||||
-- {action="super" , event="super_ready"}}}
|
|
||||||
--else
|
|
||||||
-- self.target = self.hot_points[12]
|
|
||||||
-- self.path = {next=12, actions= {{action="jumpfwd", event="land"},
|
|
||||||
-- {action="left" , event="target"},
|
|
||||||
-- {action="super" , event="super_ready"}}}
|
|
||||||
--end
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:super()
|
|
||||||
if not DEBUG_FN_NAME then print("super()") end
|
|
||||||
self:super_movement()
|
|
||||||
-- self.fight_mode = self.fight_modes["super"]
|
|
||||||
self.invencible = true
|
|
||||||
self.update=self.state_super
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:state_super()
|
|
||||||
if DEBUG_FN_NAME then print("state_super") end
|
|
||||||
self.super_wait = self.super_wait -1
|
|
||||||
if self.zoom<1.75 and self.super_wait>100 then
|
|
||||||
if self.super_wait%4==0 then self.zoom=self.zoom+0.1 end
|
|
||||||
elseif not self.super_fired and self.zoom>=1.75 and self.super_wait>100 then
|
|
||||||
local x_ini = self.x+self.bb.x+self.bb.w+4
|
|
||||||
local hab, tx, ty, off_x, off_y = coords.world_to_tile(x_ini,self.y+(self.h/2))
|
|
||||||
fireball.init(hab, tx, ty, false, off_x, off_y, 2)
|
|
||||||
self.super_fired = true
|
|
||||||
elseif self.zoom>1 and self.super_wait<=100 then
|
|
||||||
if self.super_wait%4==0 then self.zoom=self.zoom-0.1 end
|
|
||||||
end
|
|
||||||
if self.super_wait == 0 then
|
|
||||||
self.update=imp.super_end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:super_end()
|
|
||||||
print("super_end()")
|
|
||||||
self.zoom = 1
|
|
||||||
self.super_wait = 200
|
|
||||||
-- self.super_cooldown=2000
|
|
||||||
self.super_cooldown=200
|
|
||||||
self:reset_fight_mode_cooldown()
|
|
||||||
self.invencible = false
|
|
||||||
self.super_fired = false
|
|
||||||
self:free_movement()
|
|
||||||
self.update=imp.state_normal
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:super_movement()
|
|
||||||
if DEBUG_FN_NAME then print("super_movement") end
|
|
||||||
self.movement_type = "super"
|
|
||||||
|
|
||||||
print("Super")
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:super_next_action()
|
|
||||||
print("Super Next Action")
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:super_next_target()
|
|
||||||
print("Super Next Target")
|
|
||||||
end
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
|
|
||||||
function imp:choose_target()
|
|
||||||
-- Si no te ganes de fer res, no moure
|
|
||||||
if self.mood==self.moods.stop then return end
|
|
||||||
-- S'ha acabat el temps per a arribar a un target
|
|
||||||
if self.timers.target <= 0 then
|
|
||||||
-- Canviar a moviment lliure
|
|
||||||
self:free_movement()
|
|
||||||
|
|
||||||
-- Reinicialitzar el patró de moviment i el cooldown
|
|
||||||
self:reset_mood_timer()
|
|
||||||
self:path_reset()
|
|
||||||
|
|
||||||
-- Seleccionar el següent target
|
|
||||||
self:next_target()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:next_target()
|
|
||||||
if self.move_type==self.move_types.free then
|
|
||||||
self:free_next_target()
|
|
||||||
elseif self.move_type==self.move_types.pattern then
|
|
||||||
self:pattern_next_target()
|
|
||||||
elseif self.move_type==self.move_types.super then
|
|
||||||
self:super_next_target()
|
|
||||||
end
|
|
||||||
self:reset_target_timer()
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:free_next_target() --OK
|
|
||||||
if DEBUG_FN_NAME then print("free_next_target") end
|
|
||||||
|
|
||||||
---- Abans se seleccionava un target aleatoriament ...
|
|
||||||
|
|
||||||
-- local new_point = math.random(#self.hot_points)
|
|
||||||
-- if self.target == self.hot_points[new_point] then
|
|
||||||
-- new_point = ((new_point+1)%#self.hot_points)+1
|
|
||||||
-- end
|
|
||||||
-- self.old_target = self.target
|
|
||||||
-- self.target=self.hot_points[new_point]
|
|
||||||
|
|
||||||
---- ... ara s'intenta tornar al moviment per patró
|
|
||||||
self:pattern_recovery()
|
|
||||||
end
|
|
||||||
|
|
||||||
function imp:pattern_next_target()
|
|
||||||
if not DEBUG_FN_NAME then print("pattern_next_target") end
|
|
||||||
local next_target = self.hot_points[self.pattern.target]
|
|
||||||
print(next_target.id)
|
|
||||||
self.target = next_target
|
|
||||||
end
|
|
||||||
@@ -89,7 +89,7 @@ function mini.init()
|
|||||||
surf.cls(16)
|
surf.cls(16)
|
||||||
local a = 1 | 2
|
local a = 1 | 2
|
||||||
print(a)
|
print(a)
|
||||||
flow:executar("game")
|
flow:executar("logo")
|
||||||
end
|
end
|
||||||
|
|
||||||
function mini.update()
|
function mini.update()
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ function pattern:noop()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function pattern:draw()
|
function pattern:draw()
|
||||||
|
if true then return end
|
||||||
local scr_x = 0
|
local scr_x = 0
|
||||||
local scr_y = 0
|
local scr_y = 0
|
||||||
local target = self:target()
|
local target = self:target()
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
stages = {}
|
stages = {}
|
||||||
|
|
||||||
stages.boss_ready = false
|
stages.boss_ready = false
|
||||||
|
stages.boss_finished = false
|
||||||
stages.boss_loaded = false
|
stages.boss_loaded = false
|
||||||
stages.boss_hot_points = {}
|
|
||||||
boss = nil
|
boss = nil
|
||||||
|
|
||||||
function stages.stage1_init()
|
function stages.stage1_init()
|
||||||
@@ -105,7 +105,7 @@ function stages.stage1_init()
|
|||||||
-- table.insert(actors,trigger.new(61,8,32,triggers.teleport_d))
|
-- table.insert(actors,trigger.new(61,8,32,triggers.teleport_d))
|
||||||
|
|
||||||
local abad_x, abad_y = coords.room_to_world ( 10, 4, 3 )
|
local abad_x, abad_y = coords.room_to_world ( 10, 4, 3 )
|
||||||
local abad_x, abad_y = coords.room_to_world ( 54, 8, 3 )
|
-- local abad_x, abad_y = coords.room_to_world ( 54, 8, 3 )
|
||||||
abad:move(abad_x, abad_y)
|
abad:move(abad_x, abad_y)
|
||||||
abad_make_safe( true )
|
abad_make_safe( true )
|
||||||
|
|
||||||
@@ -144,6 +144,7 @@ end
|
|||||||
|
|
||||||
function stages.stage1_boss_ready()
|
function stages.stage1_boss_ready()
|
||||||
stages.boss_ready = true
|
stages.boss_ready = true
|
||||||
|
stages.boss_finished = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function stages.stage1_boss()
|
function stages.stage1_boss()
|
||||||
@@ -159,6 +160,21 @@ function stages.stage1_boss()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function stages.stage1_boss_finished()
|
||||||
|
stages.boss_ready = true
|
||||||
|
stages.boss_finished = true
|
||||||
|
end
|
||||||
|
|
||||||
|
function stages.stage1_boss_end()
|
||||||
|
mapa_restore_backup()
|
||||||
|
set_actors_enabled_by_room(true, "boss", stage1_boss_mapa.r0.r, stage1_boss_mapa.r1.r)
|
||||||
|
remove_actor(boss)
|
||||||
|
stages.boss_ready = false
|
||||||
|
stages.boss_finished = false
|
||||||
|
stages.boss_loaded = false
|
||||||
|
viewp:free_move()
|
||||||
|
end
|
||||||
|
|
||||||
stage1_mapa={
|
stage1_mapa={
|
||||||
-- 1
|
-- 1
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ end
|
|||||||
function triggers:escena_lluita_imp()
|
function triggers:escena_lluita_imp()
|
||||||
set_actors_enabled_by_room(false, "boss", stage1_boss_mapa.r0.r, stage1_boss_mapa.r1.r)
|
set_actors_enabled_by_room(false, "boss", stage1_boss_mapa.r0.r, stage1_boss_mapa.r1.r)
|
||||||
viewp:fixed({l=8,r=44,u=0,d=0}, viewp.x, viewp.y-48)
|
viewp:fixed({l=8,r=44,u=0,d=0}, viewp.x, viewp.y-48)
|
||||||
-- start_scene(scenes.lluita_imp, nil, false)
|
start_scene(scenes.lluita_imp, nil, false)
|
||||||
remove_actor(self)
|
remove_actor(self)
|
||||||
stages.stage1_boss_ready()
|
stages.stage1_boss_ready()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ end
|
|||||||
|
|
||||||
function viewport:free_move()
|
function viewport:free_move()
|
||||||
self.range = nil
|
self.range = nil
|
||||||
|
if self.fixed_coord~=nil then print ("FIXED COORD= "..self.fixed_coord.x..", "..self.fixed_coord.y) end
|
||||||
self.smooth_adjust = self.fixed_coord
|
self.smooth_adjust = self.fixed_coord
|
||||||
self.fixed_coord = nil
|
self.fixed_coord = nil
|
||||||
end
|
end
|
||||||
@@ -75,33 +76,35 @@ function viewport:position(x, y)
|
|||||||
self.y = ny
|
self.y = ny
|
||||||
else
|
else
|
||||||
-- viewport lliure després de fixar-lo -> Ajustar suau
|
-- viewport lliure després de fixar-lo -> Ajustar suau
|
||||||
|
local speed_x = self.adjust_speed
|
||||||
|
local speed_y = self.adjust_speed
|
||||||
|
local sm_x = self.smooth_adjust.x
|
||||||
|
local sm_y = self.smooth_adjust.y
|
||||||
self.x = nx
|
self.x = nx
|
||||||
if self.smooth_adjust.x~=nil then
|
if sm_x~=nil then
|
||||||
if nx<self.smooth_adjust.x-self.adjust_speed then
|
if math.abs(nx-sm_x)<speed_x then
|
||||||
self.x=self.smooth_adjust.x-self.adjust_speed
|
sm_x = nil
|
||||||
self.smooth_adjust.x=self.smooth_adjust.x-self.adjust_speed
|
else
|
||||||
elseif nx>self.smooth_adjust.x+self.adjust_speed then
|
if nx<sm_x-speed_x then speed_x = -speed_x end
|
||||||
self.x=self.smooth_adjust.x+self.adjust_speed
|
self.x=sm_x+speed_x
|
||||||
self.smooth_adjust.x=self.smooth_adjust.x+self.adjust_speed
|
sm_x =sm_x+speed_x
|
||||||
elseif math.abs(nx-self.smooth_adjust.x)<self.adjust_speed then
|
|
||||||
self.smooth_adjust.x = nil
|
|
||||||
end
|
end
|
||||||
|
self.smooth_adjust.x = sm_x
|
||||||
end
|
end
|
||||||
|
|
||||||
self.y = ny
|
self.y = ny
|
||||||
if self.smooth_adjust.y~=nil then
|
if sm_y~=nil then
|
||||||
if ny<self.smooth_adjust.y-self.adjust_speed then
|
if math.abs(ny-sm_y)<speed_y then
|
||||||
self.y=self.smooth_adjust.y-self.adjust_speed
|
sm_y = nil
|
||||||
self.smooth_adjust.y=self.smooth_adjust.y-self.adjust_speed
|
else
|
||||||
elseif ny>self.smooth_adjust.y+self.adjust_speed then
|
if ny<sm_y-speed_y then speed_y = -speed_y end
|
||||||
self.y=self.smooth_adjust.y+self.adjust_speed
|
self.y=sm_y+speed_y
|
||||||
self.smooth_adjust.y=self.smooth_adjust.y-self.adjust_speed
|
sm_y =sm_y+speed_y
|
||||||
elseif math.abs(ny-self.smooth_adjust.y)<self.adjust_speed then
|
|
||||||
self.smooth_adjust.y = nil
|
|
||||||
end
|
end
|
||||||
|
self.smooth_adjust.y = sm_y
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.smooth_adjust.x == nil and self.smooth_adjust.y == nil then
|
if sm_x == nil and sm_y == nil then
|
||||||
self.smooth_adjust = nil
|
self.smooth_adjust = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user