function print_dbg(...) -- level = 2 → el llamador de imprimir_con_contexto local info = debug.getinfo(2, "n") local nombre = info.name or "" 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"