diff --git a/data/imp.lua b/data/imp.lua index fd0ec61..6caa129 100644 --- a/data/imp.lua +++ b/data/imp.lua @@ -38,67 +38,75 @@ function imp.new(_hab, _x, _y) jump_height=0, jump_in_half_block=0, jump_in_half_block_used = false, - max_shoot_cooldown=24, + -- 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, - fight_modes=_fight_modes, - mode="stop", - mode_cooldown=500, - super_cooldown=2000, - shot_cooldown=500, - action="", - movement="", - movement_type="", + -- scene_intro=false, + -- scene_object=false, enabled=true, disable_reason="", can_warp=false, - fight=imp.fight, - draw=imp.draw, - hit=imp.hit, - hot_points={}, - target={}, - old_target={}, - path={}, - paths={}, - action_event="", - path_curr_action=1, - analisis={}, + -- 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?) + mode="stop", -- mode de lluita actiu + mode_cooldown=500, -- cicles fins al canvi de mode + super_cooldown=2000, -- cicles fins a Super actiu + shot_cooldown=500, -- 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, -- direccio=imp.direccio, + draw=imp.draw, + hit=imp.hit, do_jump=imp.do_jump, jump=imp.jump, state_jumping=imp.state_jumping, - chase=imp.chase, - away=imp.away, - move=imp.move, - super=imp.super, - shot=imp.shot, - do_flip=imp.do_flip, update=imp.state_normal, land=imp.land, - mode_controller=imp.mode_controller, advance=imp.advance, - reduce_cooldown=imp.reduce_cooldown, - think=imp.think, - move=imp.move, - controller_input=imp.controller_input, - ia=imp.ia, - analyze_env=imp.analyze_env, - next_pattern_action=imp.next_pattern_action, - pattern_action=imp.pattern_action, - reset_mode_cooldown=imp.reset_mode_cooldown, - free_movement=imp.free_movement, - free_move=imp.free_move, - reset_pattern_movement=imp.reset_pattern_movement, - pattern_move=imp.pattern_move, - next_pattern_target=imp.next_pattern_target, - next_free_target=imp.next_free_target, - old_action="-" + -- 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.state_super, -- Entra en mode 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_mode_cooldown=imp.reset_mode_cooldown, -- Asignar un valor a 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 + + 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 + + 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 } @@ -234,6 +242,7 @@ if DEBUG_FN_NAME then print("fight") end self.paths[11] = {} self.mode="chase" + self:pattern_movement() end function imp:draw() @@ -297,7 +306,7 @@ if DEBUG_FN_NAME then print("state_jumping") end -- cap endavant? if self.jumpfwd then self:advance() end - self:ia() + self:actualitzar_comportament() end function imp:jump() @@ -375,7 +384,7 @@ if DEBUG_FN_NAME then print("state_walking") end end self:advance() - self:ia() + self:actualitzar_comportament() end function imp:state_falling() @@ -398,7 +407,7 @@ if DEBUG_FN_NAME then print("state_falling") end -- Caiguent cap endavant? if self.jumpfwd then self:advance() end - self:ia() + self:actualitzar_comportament() end function imp:land () @@ -470,7 +479,7 @@ if DEBUG_FN_NAME then print("state_normal") end self.step=0 self.jumpfwd=false self.jump_height = 0 - self:ia() + self:actualitzar_comportament() end function imp:state_super() @@ -510,14 +519,14 @@ if DEBUG_FN_NAME then print("reset_mode_cooldown") end return value end -function imp:reset_pattern_movement() -if DEBUG_FN_NAME then print("reset_pattern_movement") end +function imp:path_reset() +if DEBUG_FN_NAME then print("path_reset") end self.path={} self.path_curr_action=1; end -function imp:pattern_action() -if DEBUG_FN_NAME then print("pattern_action") end +function imp:path_action() +if DEBUG_FN_NAME then print("path_action") end local action = self.path.actions[self.path_curr_action].action -- print("PATTERN"); -- print(" TARGET= "..self.path.next) @@ -525,8 +534,15 @@ if DEBUG_FN_NAME then print("pattern_action") end return action end -function imp:pattern_move() -if DEBUG_FN_NAME then print("pattern_move") end +function imp:pattern_movement() +if DEBUG_FN_NAME then print("pattern_movement") end + self.movement_type = "pattern" + + print("Pattern") +end + +function imp:pattern_next_action() +if DEBUG_FN_NAME then print("pattern_next_action") end local path_event = self.path.actions[self.path_curr_action].event -- print(" PATH_EVENT= "..path_event) -- print(" ACTION_EV = "..self.action_event) @@ -540,11 +556,11 @@ if DEBUG_FN_NAME then print("pattern_move") end -- En el path self.path_curr_action = self.path_curr_action + 1 -- print(" CURR_ACC= "..self.path_curr_action) - action = self:pattern_action() + action = self:path_action() -- print(" ACTION 1= "..action) else -- Path acabat, anar al següent - action = self:next_pattern_action() + action = self:path_next_action() -- print(" ACTION 2= "..action) end end @@ -552,8 +568,8 @@ if DEBUG_FN_NAME then print("pattern_move") end return action end -function imp:next_pattern_target(from) -if DEBUG_FN_NAME then print("next_pattern_target") end +function imp:pattern_next_target(from) +if DEBUG_FN_NAME then print("pattern_next_target") end -- obtindre uno dels possibles camins des del punt "from" (en el que està) local next_path_idx = math.random(#self.paths[from]) @@ -562,19 +578,19 @@ if DEBUG_FN_NAME then print("next_pattern_target") end self.target = self.hot_points[self.path.next] end -function imp:next_pattern_action( from ) +function imp:path_next_action( from ) from = from or self.path.next -if DEBUG_FN_NAME then print("next_pattern_action "..from) end +if DEBUG_FN_NAME then print("path_next_action "..from) end if #self.paths[from]>0 then - self.movement_type = "pattern" + self:pattern_movement() self:reset_mode_cooldown() -- Activar següent target - self:next_pattern_target(from) - action = self:pattern_action() + self:next_target(from) + action = self:path_action() -- self.action_event="" else self:free_movement() - action = self:free_move() + action = self:next_action() end return action end @@ -586,8 +602,8 @@ if DEBUG_FN_NAME then print("free_movement") end print("Free") end -function imp:free_move() -if DEBUG_FN_NAME then print("free_move") 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" @@ -623,7 +639,7 @@ if DEBUG_FN_NAME then print("free_move") end end -- Canviar a moviment per patro - action = self:next_pattern_action(idx) + action = self:path_next_action(idx) -- 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.id) end - + self:do_flip(abad) + + if self.analisis.going_to_fall then self.action_event="prefall" end + if self.analisis.target_reached then self.action_event="target" end + + action = self:next_action() + + if self.old_action~=action then + self.old_action=action + -- print(self.old_action) + end + + self.action = action + self.action_event = "" + + return action --if imp.wait==6 then -- imp.wait=0 @@ -962,5 +979,5 @@ if DEBUG_FN_NAME then print("think") end -- end -- end -- - --end + --end end