From d4ef8ba55196f97d347e74633486a495f17756a5 Mon Sep 17 00:00:00 2001 From: JailGamer Date: Sat, 11 Apr 2026 02:32:55 +0200 Subject: [PATCH] [WIP] Treballant en el jefe. Pattern mode funcionant --- data/imp.lua | 902 ++++++++++++++++++++++++++----------------------- data/point.lua | 4 +- 2 files changed, 487 insertions(+), 419 deletions(-) diff --git a/data/imp.lua b/data/imp.lua index 570712f..3dc6f0e 100644 --- a/data/imp.lua +++ b/data/imp.lua @@ -1,28 +1,9 @@ cxr2 = arcade_config.character_per_row_base2 --- 4, 3 - --- imp={hab=75, --- x=24, --- y=24, --- w=32, --- h=32, --- flip=true, --- enabled=false, --- counter=500, --- frame=28, --- wait=0, --- step=0, --- anim={28,29,28,30}, --- bb={x=4,y=0,w=16,h=32}, --- scene_intro=false, --- scene_object=false, --- fight_modes={"chase","away","super","shot"}, --- mode="stop", --- mode_cooldown=100} - imp = {} +local DEBUG_FN_NAME = false + function imp.reset() imp.hit=imp.hit imp.update=imp.update @@ -101,154 +82,81 @@ function imp.new(_hab, _x, _y) update=imp.state_normal, land=imp.land, mode_controller=imp.mode_controller, - --movement=imp.movement, advance=imp.advance, reduce_cooldown=imp.reduce_cooldown, - set_fight_mode=imp.set_fight_mode, think=imp.think, + move=imp.move, controller_input=imp.controller_input, ia=imp.ia, analyze_env=imp.analyze_env, - next_pattern_movement=imp.next_pattern_movement, + 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 + 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="-" -- imp.enabled=false -- imp.counter=500 } end -function imp:reset_mode_cooldown( value ) - value = value or 500 - self.mode_cooldown = value - return value -end - -function imp:reset_pattern_movement() - self.path={} - self.path_curr_action=1; -end - -function imp:next_pattern_movement( from ) - self.movement_type = "pattern" - self:reset_mode_cooldown() - from = from or self.path.next - -- obtindre uno dels possibles camins des del punt "from" - local next_path_idx = math.random(#self.paths[from]) - -- Activar següent target - local next_path = self.paths[from][next_path_idx] - self.target = self.hot_points[next_path.next] - - print("TARGET ID= "..self.target.id.." HOT POINT= "..next_path.next) - self.path = next_path - self.path_curr_action = 1 - action = self.path.actions[1].action - self.action_event="" - return action -end - -function imp:free_move() - -- 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.xself.target.y or self.y0 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 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 + + -- representació del moviment + -- 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 + + -- 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.update=imp.state_falling + return + end + + self:advance() + self:ia() +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.update=imp.state_normal + return + end + + -- 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 + self:ia() +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(0,0,"advance",true) + local step_length=self.step_length; --lo que avança el imp cada pas + local limit=tiletype.block + + if self.update~=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=="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)0 then + self.movement_type = "pattern" + self:reset_mode_cooldown() + -- Activar següent target + self:next_pattern_target(from) + action = self:pattern_action() + -- self.action_event="" + else + self:free_movement() + action = self:free_move() + end + return action +end + +function imp:free_movement() +if DEBUG_FN_NAME then print("free_movement") end + self.movement_type = "free" + + print("Free") +end + +function imp:free_move() +if DEBUG_FN_NAME then print("free_move") 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.xself.target.y or self.y0 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() --- msg_print(16,48,"state_walking",true) - - -- Limitar la velocitat de moviment - self.wait=self.wait+1 - - -- representació del moviment - -- 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 - - -- 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.update=imp.state_falling - return - end - - self:advance() - self:ia() -end - -function imp:state_falling() --- 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.update=imp.state_normal - self.action_event = "land" - return - end - - -- 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 - self:ia() -end - -function imp:land () --- 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 - end - - return can_land -end - -function imp:advance() --- msg_print(0,0,"advance",true) - local step_length=self.step_length; --lo que avança el imp cada pas - local limit=tiletype.block - - if self.update~=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 - if self.movement=="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)0 then self.mode=self.fight_modes["shot"] end - -- if self.mode==self.fight_modes["shot"] and self.shot_cooldown>0 then self.mode=self.fight_modes["chase"] end self.mode=self.fight_modes["chase"] - -- print("cambiar modo => "..self.fight_modes[self.mode]) - -- if self.movement_type == "free" then - 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] - print("Next random target => "..self.target.id) - -- else - --if self.action_event=="target" then - -- print(self.old_target.id) - --end - -- end + -- Seleccionar el següent target aleatoriament + self:next_free_target() + + print("Next random target => "..self.target.id) end - -- -- if self.mode==last_mode then self.mode=((last_mode+1)%#self.fight_modes)+1 end - -- elseif self.mode_cooldown == 0 then - -- if self.shot_cooldown<=0 then self.mode=self.fight_modes["shot"] end; - -- end self:do_flip(abad) - -- self:movement(abad) --if imp.wait==6 then -- imp.wait=0 @@ -867,12 +944,3 @@ function imp:set_fight_mode() -- --end end - -function imp:collision() - -- comprovar colisio en l'abad - if viewp:inside(self.x, self.y, self.w, self.h) then - if collision(abad,self) then - abad_hurt(1) - end - end -end diff --git a/data/point.lua b/data/point.lua index 4c18eee..6c5e638 100644 --- a/data/point.lua +++ b/data/point.lua @@ -21,10 +21,10 @@ function point:draw(fill) -- debug rect if not fill then draw.rect(scr_x,scr_y,self.w,self.h,3) - draw.rect(scr_x+self.bb.x,scr_y,self.bb.w,self.h,2) + -- draw.rect(scr_x+self.bb.x,scr_y,self.bb.w,self.h,2) else draw.rectf(scr_x,scr_y,self.w,self.h,3) - draw.rectf(scr_x+self.bb.x,scr_y,self.bb.w,self.h,2) + -- draw.rectf(scr_x+self.bb.x,scr_y,self.bb.w,self.h,2) end end