[WIP] Treballant en el jefe. La que s'està liant...

This commit is contained in:
2026-04-15 23:31:19 +02:00
parent 0c9c31dca2
commit 1b812127e2
9 changed files with 834 additions and 48 deletions

View File

@@ -14,7 +14,7 @@ require "zombie"
require "score"
-- require "switches"
require "trigger"
require "imp2"
require "imp3"
require "fireball"
require "bar_meter"

View File

@@ -162,7 +162,7 @@ function imp.new(_hab,_x,_y)
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=150, shot=2500, super=20000, flip_wait=50}, --anterior *_cooldown
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
@@ -214,6 +214,7 @@ function imp.new(_hab,_x,_y)
shot = imp.shot,
advance=imp.advance,
jump=imp.jump,
reset_target_timer=imp.reset_target_timer,
_moure=imp._moure, -- temporal debug
}
@@ -289,16 +290,18 @@ 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_mood()
-- self:choose_target()
-- analisis
self:analyze_env()
-- decisio
self:choose_target()
self:choose_action()
-- moviment
@@ -461,7 +464,7 @@ end
function imp:reset_target_timer( value ) -- OK
if DEBUG_FN_NAME then print("reset_target_timer") end
value = value or 150
value = value or 250
self.timers.target = value
return value
end

603
data/imp3-functions.lua Normal file
View File

@@ -0,0 +1,603 @@
function imp:_moure( foo, name )
name = name or "anonymous"
if not foo then
print_dbg(name.." not found")
else
print_dbg(name)
end
self.moure = foo
end
function noop ()
end
-------------------------------
--
-------------------------------
function imp:reduce_timers()
if self.mood==self.moods.stop then return end
if DEBUG_FN_NAME then print_dbg("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:analyze_env() --OK
if self.mood==self.moods.stop then return end
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
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
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: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
-- 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
-------------------------------
-- imp.controller_input()
--
-- Traduir a una entrada de pad
-------------------------------
function imp:controller_input()
if DEBUG_FN_NAME then print_dbg("controller_input") 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 == "jumpfwd" then
self:do_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.action = self.actions.no_action
end
-------------------------------
--
-------------------------------
function imp:fight() -- OK
if DEBUG_FN_NAME then print_dbg("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: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
-------------------------------------------------------------------
-- // PATTERN MOVEMENT
function imp:pattern_movement() --OK
if DEBUG_FN_NAME then print_dbg("pattern_movement") end
self.movement_type = "pattern"
-- print("Pattern")
end
-------------------------------------------------------------------
-- // ACTION
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
end
-- Resta d'accions
if next_action==self.actions.no_action then
if self.move_type==self.move_types.free then
-- next_action = self:free_next_action()
elseif self.move_type==self.move_types.pattern then
if self.pattern:in_target(self) then
next_action=self.pattern:next_action()
print("TARGET => "..next_action)
else
next_action=self.pattern:action()
print("ON WAY => "..next_action)
end
elseif self.move_type==self.move_types.super then
--
end
end
-- next_action es text, traduir
return self.actions[next_action]
end
function imp:do_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=""
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
-- ??
self.wait=self.wait+1
self.wait=0
self.next_frame=imp.jumping_next_frame
-- 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_dbg("jump") end
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: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
-- 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
function imp:state_falling()
if DEBUG_FN_NAME then print_dbg("state_falling") end
-- msg_print(16,16,"state_falling",true)
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)")
return
end
print_dbg("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_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
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
if can_land then print_dbg ("LANDED") end
return can_land
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_normal()
if DEBUG_FN_NAME then print_dbg("state_normal") end
self.frame=28
self.wait=0
self.step=0
self.jumpfwd=false
self.jump_height = 0
self.next_frame=imp.staying_next_frame
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.pattern:target_node())
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
function imp:do_flip( actor )
actor = actor or self.pattern:target_node()
-- enllaçat a actor
if actor.x<self.x then self.flip=true else self.flip=false end
end

165
data/imp3.lua Normal file
View File

@@ -0,0 +1,165 @@
function print_dbg(...)
-- level = 2 → el llamador de imprimir_con_contexto
local info = debug.getinfo(2, "n")
local nombre = info.name or "<anónima>"
print("[" .. nombre .. "]", ...)
end
require "pattern"
imp = {}
DEBUG_FN_NAME = true
function imp.new(_hab,_x,_y)
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
return {
name="imp",
hab=_hab,
x=world_x, y=world_y,
w=32, h=32,
bb={x=8,y=0,w=16,h=32},
flip=true,
frame=28,
anim={28,29,28,30}, -- seqüencia de frames
wait=0,
step=0,
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
actions={no_action=0, up=1, down=2, left=4, right=8, jump=16, shot=32, super=64},
pattern= pattern.new(),
analisis = {}, -- memoria per a guardar el resultat de l'analisis
step_length=1,
energia=21,
max_energia=21,
jump_height=0,
max_jump_height=24,
vmove_space = 1,
falling = 0,
--
moure = noop,
draw=imp.draw,
update=imp.update_normal,
reduce_timers = imp.reduce_timers,
analyze_env = imp.analyze_env,
choose_action = imp.choose_action,
controller_input = imp.controller_input,
fight = imp.fight,
create_hot_points = imp.create_hot_points,
load_pattern_paths = imp.load_pattern_paths,
pattern_movement = imp.pattern_movement,
next_action = imp.next_action,
do_jump = imp.do_jump,
jump = imp.jump,
advance = imp.advance,
land = imp.land,
next_frame = imp.staying_next_frame,
do_flip = imp.do_flip,
_moure = imp._moure,
}
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_dbg("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
cpu_wait = 10
function imp:update_normal()
cpu_wait = cpu_wait -1
if cpu_wait<=0 then
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)
cpu_wait = 1
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
end
require "imp3-functions"

View File

@@ -2,6 +2,7 @@
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
@@ -49,7 +50,7 @@ print("next_action= "..next_action.." == "..self.actions.no_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()
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)
@@ -144,7 +145,12 @@ print("imp_action.lua -> pattern_next_action -> "..self.action_event.."~="..self
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]
@@ -165,6 +171,7 @@ 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

View File

@@ -74,8 +74,6 @@ end
function imp:controller_input()
if DEBUG_FN_NAME then print("controller_input") end
print(self.action)
--To Do: JumpFWD
if self.action == self.actions.right or self.action == self.actions.left then
self.movement = self.action
@@ -84,11 +82,11 @@ print(self.action)
elseif self.action == self.actions.jump then
self:do_jump()
elseif self.action == "jumpfwd" then
-- self:do_jump(true)
self:do_jump(true)
elseif self.action == self.actions.shot then
-- self:shot()
self:shot()
elseif self.action == self.actions.super then
-- self.moure=imp.state_super
self.moure=imp.state_super
end
self.action = self.actions.no_action
end

View File

@@ -100,8 +100,8 @@ 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, "state_falling (states)")
self.moure=imp.state_falling
self:_moure(imp.state_falling, "state_falling (states-walking)")
return
end
@@ -121,7 +121,7 @@ if DEBUG_FN_NAME then print("state_falling") end
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

View File

@@ -24,6 +24,7 @@ function imp: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

View File

@@ -25,18 +25,22 @@ end
-- ara aleatori
function pattern:origin()
print_dbg("")
return self.node[self.path_idx]
end
function pattern:origin_num ()
print_dbg("")
return self.path_idx
end
function pattern:set_path ( num )
print_dbg("")
self.path_idx = num
end
function pattern:get_path ( num )
print_dbg("")
return self.path[num]
end
@@ -46,12 +50,11 @@ end
-- return self.path[self.path_idx][target_idx].target
-- end
function pattern:target()
print("pattern:target 1")
if not empty_table(self.manual_path) then
print("pattern:target 2 a")
print_dbg("MANUAL => "..self.manual_path.target)
return self.manual_path.target
else
print("pattern:target 2 b")
print_dbg("PATH => "..self.path[self.path_idx][self.target_idx].target)
return self.path[self.path_idx][self.target_idx].target
end
end
@@ -61,6 +64,7 @@ end
-- return self.path[self.path_idx][target_idx].actions
-- end
function pattern:actions()
print_dbg("")
if not empty_table(self.manual_path) then
return self.manual_path.actions
else
@@ -74,14 +78,17 @@ end
-- end
function pattern:action()
if not empty_table(self.manual_path) then
print_dbg("MANUAL => "..self.manual_path.actions[self.action_idx].action)
return self.manual_path.actions[self.action_idx].action
else
print_dbg("PATH => "..self.path[self.path_idx][self.target_idx].actions[self.action_idx].action)
return self.path[self.path_idx][self.target_idx].actions[self.action_idx].action
end
end
-- [OK] Torna l'event actual
function pattern:event()
print_dbg("")
if not empty_table(self.manual_path) then
return self.manual_path.actions[self.action_idx].event
else
@@ -98,7 +105,7 @@ end
-- return pattern:action()
-- end
function pattern:next_action ( )
print("pattern:next_action 1")
print_dbg("")
local num_actions = 0
-- index a la següent acció
self.action_idx = self.action_idx+1
@@ -108,45 +115,47 @@ print("pattern:next_action 1")
else
num_actions = #self.path[self.path_idx][self.target_idx].actions
end
print("pattern:next_action 2")
if self.action_idx>num_actions then
-- avançar el target
self:next_target() -- pasar per paràmetre o no
end
print("pattern:next_action 3")
-- Tornar l'acció
return self:action()
end
-- [OK] Canvia al següent target segons el path o al que se li pase
function pattern:next_target( target )
print("pattern:next_target 1")
print_dbg("")
target = target or self:target()
print("pattern:next_target 2")
-- Si hi ha una entrada manual eliminar-la
if not empty_table(self.manual_path) then
self.manual_path = {}
self.manual_target = {}
end
print("pattern:next_target 3")
-- target id
self.path_idx = target
-- tindre en compte l'estrategia per a triar el següent target des del path actual per ara aleatori
self.target_idx = math.random(#self.path[self.path_idx])
self.action_idx = 1
print("pattern:next_target 4")
end
-- [OK] Torna el node del target actual
function pattern:target_node()
print_dbg(self.node[self:target()])
return self.node[self:target()]
end
-- Comprova si point ha arribat al target (Afegir precissio per si volem que estiga nomes tocar, dins o abans d'eixir?)
function pattern:in_target( area )
if collision( area, self:target_node() ) then
print_dbg("COLLISION")
else
print_dbg("-")
end
return collision( area, self:target_node() )
end
function pattern:recovery( point, target)
print_dbg("")
end