From 1b812127e273dc8d7c8b9f6c77ce91ee8a5216c8 Mon Sep 17 00:00:00 2001 From: JailGamer Date: Wed, 15 Apr 2026 23:31:19 +0200 Subject: [PATCH] =?UTF-8?q?[WIP]=20Treballant=20en=20el=20jefe.=20La=20que?= =?UTF-8?q?=20s'est=C3=A0=20liant...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/game.lua | 2 +- data/imp2.lua | 11 +- data/imp3-functions.lua | 603 ++++++++++++++++++++++++++++++++++++++++ data/imp3.lua | 165 +++++++++++ data/imp_action.lua | 9 +- data/imp_movement.lua | 8 +- data/imp_states.lua | 54 ++-- data/imp_target.lua | 1 + data/pattern.lua | 29 +- 9 files changed, 834 insertions(+), 48 deletions(-) create mode 100644 data/imp3-functions.lua create mode 100644 data/imp3.lua diff --git a/data/game.lua b/data/game.lua index 0268f31..6bf5a4d 100644 --- a/data/game.lua +++ b/data/game.lua @@ -14,7 +14,7 @@ require "zombie" require "score" -- require "switches" require "trigger" -require "imp2" +require "imp3" require "fireball" require "bar_meter" diff --git a/data/imp2.lua b/data/imp2.lua index 4f87bda..9f3c210 100644 --- a/data/imp2.lua +++ b/data/imp2.lua @@ -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 diff --git a/data/imp3-functions.lua b/data/imp3-functions.lua new file mode 100644 index 0000000..0ddb371 --- /dev/null +++ b/data/imp3-functions.lua @@ -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_height0 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)=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" + 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" \ No newline at end of file diff --git a/data/imp_action.lua b/data/imp_action.lua index 0a83e83..9b1c28a 100644 --- a/data/imp_action.lua +++ b/data/imp_action.lua @@ -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 diff --git a/data/imp_movement.lua b/data/imp_movement.lua index 8fa7fb8..ea8acd7 100644 --- a/data/imp_movement.lua +++ b/data/imp_movement.lua @@ -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 \ No newline at end of file diff --git a/data/imp_states.lua b/data/imp_states.lua index 4bf6c83..4451985 100644 --- a/data/imp_states.lua +++ b/data/imp_states.lua @@ -42,12 +42,12 @@ if DEBUG_FN_NAME then print("jump") end 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 @@ -76,7 +76,7 @@ if DEBUG_FN_NAME then print("jump") end end end end - + -- Registrar el desplaçament self.jump_height = self.jump_height+1 end @@ -88,10 +88,10 @@ if not DEBUG_FN_NAME then print("state_walking") end -- 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 @@ -100,11 +100,11 @@ 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 - + self:advance() end @@ -114,19 +114,19 @@ if DEBUG_FN_NAME then print("state_falling") end 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 - + 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 @@ -138,24 +138,24 @@ if DEBUG_FN_NAME then print("land") end 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 + + -- 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 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 @@ -164,25 +164,25 @@ 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 + -- 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 + 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) "..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