diff --git a/data/bar_meter.lua b/data/bar_meter.lua index 99f73d9..edb4c53 100644 --- a/data/bar_meter.lua +++ b/data/bar_meter.lua @@ -1,6 +1,9 @@ bar_meter={} -function bar_meter.new(scr_x, scr_y, width, height, _value, _max_value, _actor) +function bar_meter.new(scr_x, scr_y, width, height, _value, _max_value, _actor, _color_ok, _color_warn, _color_danger) + _color_ok = _color_ok or 10; -- verd + _color_warn = _color_warn or 8; -- groc + _color_danger = _color_danger or 3; -- roig return { x = scr_x, y = scr_y, @@ -10,6 +13,9 @@ function bar_meter.new(scr_x, scr_y, width, height, _value, _max_value, _actor) max_value = _max_value, draw=bar_meter.draw, actor=_actor, + color_ok = _color_ok, + color_warn = _color_warn, + color_danger = _color_danger, } end @@ -37,25 +43,29 @@ function bar_meter:draw() if self.value>self.max_value/2 then -- 50% - color = 10; -- verd + color = self.color_ok elseif self.value>self.max_value/3 then -- 33% - color = 8; -- groc + color = self.color_warn else - color = 3; -- roig + color = self.color_danger end - local segment_w = math.floor((w-2)/self.max_value) - local full_width = w-2 - local curr_width = math.floor((w-2)*(self.value/self.max_value)) + local lifebar_w = w-3 + local segment_w = lifebar_w/self.max_value + local life_w = math.floor(lifebar_w*(self.value/self.max_value)) + -- if self.value==self.max_value then curr_width=curr_width-2 end if self.value>0 then - -- -- fons negre - -- draw.rectf( x+2, y+2, w-4, h-4, 2 ); -- barra de vida - draw.rectf( x+2, y+2, curr_width-1, h-3, color ); + draw.rectf( x+2, y+2, life_w, h-3, color ); -- segments - for n_segment=1,self.max_value-1 do - draw.vline( x+2+segment_w*n_segment, y+2, y+h-2, 16) + for n_segment=1,self.value-1 do + x_segment = math.floor((x+2)+segment_w*n_segment) + -- if n_segment==self.max_value then + -- x_segment=x+w-2 + -- end + draw.vline( x_segment, y+2, y+h-2, 16) end + -- draw.vline( x+2+segment_w*n_segment, y+2, y+h-2, 16) end end \ No newline at end of file diff --git a/data/imp.lua b/data/imp.lua index 8f39da8..21768e3 100644 --- a/data/imp.lua +++ b/data/imp.lua @@ -15,7 +15,7 @@ end function imp.new(_hab, _x, _y) local world_x, world_y = coords.room_to_world(_hab,_x,_y) - _fight_modes={"chase","away","super","shot"} + _fight_modes={"chase","away","super","end_super","shot"} for i,v in ipairs(_fight_modes) do _fight_modes[v] = i end return { name="imp", @@ -56,7 +56,8 @@ function imp.new(_hab, _x, _y) fight_modes=_fight_modes, -- mode de lluita (Llevar?) fight_mode="stop", -- mode de lluita actiu fight_mode_cooldown=1500, -- cicles fins al canvi de mode - super_cooldown=2000, -- cicles fins a Super actiu + -- super_cooldown=2000, -- cicles fins a Super actiu + super_cooldown=100, -- 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 @@ -83,7 +84,8 @@ function imp.new(_hab, _x, _y) -- 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 + super=imp.super, -- Activa el mode super poder + state_super=imp.state_super, -- Entra en estat super poder shot=imp.shot, -- Dispara do_flip=imp.do_flip, -- Orienta a l'imp cap a l'actor -- mode_controller=imp.mode_controller, @@ -107,6 +109,11 @@ function imp.new(_hab, _x, _y) 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 + super_ready=imp.super_ready, + super_movement=imp.super_movement, + super_next_action=imp.super_next_action, + super_next_target=imp.super_next_target, + 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 @@ -120,6 +127,7 @@ if DEBUG_FN_NAME then print("fight") end self.hot_points[1] = point.new(44, 5, 1, 0, 8,"P1") self.hot_points[2] = point.new(45, 8, 1, 0, 8,"P2") self.hot_points[3] = point.new(44,12, 5, 8, 0,"P3") + self.hot_points["altar"] = self.hot_points[3] self.hot_points[4] = point.new(54, 5, 4, -8, 0,"P4") self.hot_points[5] = point.new(54,12, 4, 8, 0,"P5") self.hot_points[6] = point.new(55, 8, 4, 8, 0,"P6") @@ -194,9 +202,9 @@ if DEBUG_FN_NAME then print("fight") end } self.paths[4] = { {next=1, actions={{action="jump" , event="target"}}}, - {next=5, actions={{action="right", event="target"}}}, - {next=6, actions={{action="right", event="target"}}}, - {next=8, actions={{action="jump" , event="target"}}}, + --{next=5, actions={{action="right", event="target"}}}, + --{next=6, actions={{action="right", event="target"}}}, + --{next=8, actions={{action="jump" , event="target"}}}, } self.paths[5] = { {next=4, actions={{action="left" , event="target"}}}, @@ -204,9 +212,9 @@ if DEBUG_FN_NAME then print("fight") end } self.paths[6] = { {next=2, actions={{action="jump", event="target"}}}, - --{next=5, actions={{action="left", event="target"}}}, - --{next=7, actions={{action="jump", event="target"}}}, - --{next=4, actions={{action="left", event="target"}}} + {next=5, actions={{action="left", event="target"}}}, + {next=7, actions={{action="jump", event="target"}}}, + {next=4, actions={{action="left", event="target"}}} } self.paths[7] = { {next=5, actions={{action="left" , event="prefall"}, @@ -250,9 +258,15 @@ end function imp:draw() local scr_x, scr_y = viewp:screen_coords( self.x, self.y ) + if self.invencible then + pal.subpal(5,15) + 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) + draw.rect(scr_x+self.bb.x,scr_y+self.bb.y,self.bb.w,self.bb.h,3) - + if #self.hot_points>0 then for _, p in pairs(self.hot_points) do if self.target==p then @@ -275,6 +289,19 @@ end function imp:hit() if DEBUG_FN_NAME then print("hit") end + if not self.invencible then + self.energia = self.energia -1 + --if self:distancia(abad)<100 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") + end end function imp:do_jump ( jumpfwd ) @@ -485,11 +512,44 @@ if DEBUG_FN_NAME then print("state_normal") end self:actualitzar_comportament() end +function imp:super_ready() + self.target = self.hot_points["altar"] + if self.x0 then self:pattern_movement() self:reset_fight_mode_cooldown() @@ -611,10 +672,26 @@ if DEBUG_FN_NAME then print("path_next_action "..from) end -- self:free_movement() -- action = self:next_action() action = self:pattern_recovery() + print("PNA Recovery "..action) end return action end +function imp:super_movement() +if DEBUG_FN_NAME then print("super_movement") end + self.movement_type = "super" + + print("Super") +end + +function imp:super_next_action() + print("Super Next Action") +end + +function imp:super_next_target() + print("Super Next Target") +end + function imp:free_movement() if DEBUG_FN_NAME then print("free_movement") end self.movement_type = "free" @@ -623,6 +700,7 @@ if DEBUG_FN_NAME then print("free_movement") end end function imp:pattern_recovery() +print("Pattern recovery") self:pattern_movement() self:path_reset() local x_after_4 = false @@ -650,12 +728,14 @@ function imp:pattern_recovery() self.path = {next=5, actions={{action="left",event="target"}}} end else + print("OVER 5") if x_after_5 then --target 4 self.target = self.hot_points[4] -- left target self.path = {next=4, actions={{action="left",event="target"}}} else + print("BEFORE 5") --target 6 self.target = self.hot_points[6] -- right target @@ -770,7 +850,7 @@ if DEBUG_FN_NAME then print("analyze_env") end self.analisis.can_super = false if self.super_cooldown<=0 then self.analisis.can_super=true end - -- Acces a la zona central + -- 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 @@ -779,7 +859,7 @@ if DEBUG_FN_NAME then print("analyze_env") end 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 - self.analisis.can_go_altar = true + if self.analisis.can_super then self.analisis.can_go_altar = true end end -- Cau al següent moviment @@ -949,19 +1029,24 @@ function imp:next_action() if self.movement_type=="free" then msg_print(10,20,"FREE",true) action = self:free_next_action() - else + elseif self.movement_type=="pattern" then msg_print(10,20,"PATTERN "..self.action_event,true) action=self:pattern_next_action() + elseif self.movement_type=="super" then + msg_print(10,20,"SUPER "..self.action_event,true) end end + return action end function imp:next_target(from) if self.movement_type=="free" then self:free_next_target() - else + elseif self.movement_type=="pattern" then self:pattern_next_target( from ) + elseif self.movement_type=="super" then + self:super_next_target() end -- seleccionar mode d'acció @@ -982,9 +1067,9 @@ end ------------------------------- function imp:move( ) if DEBUG_FN_NAME then print("move "..self.fight_mode) end - local action = "stay" + local next_action = "stay" - if self.fight_mode=="stop" then return action end + if self.fight_mode=="stop" then return next_action end -- S'ha acabat el temps per a arribar a un target if self.fight_mode_cooldown <= 0 then @@ -1014,17 +1099,27 @@ if DEBUG_FN_NAME then print("move "..self.fight_mode) 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 +-- if self.action_event~="" then print("Action Event => "..self.action_event) end + next_action = self:next_action() - action = self:next_action() - - if self.old_action~=action then - self.old_action=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 = action - - return action + self.action = next_action + + return next_action --if imp.wait==6 then -- imp.wait=0 diff --git a/data/score.lua b/data/score.lua index 8ec3997..8df8143 100644 --- a/data/score.lua +++ b/data/score.lua @@ -1,4 +1,6 @@ -score={} +score={ + bar_meter = nil +} local gorro_img_x = 10*16 -- col local gorro_img_y = 11*16 -- row @@ -76,11 +78,11 @@ function score.create() surf.cls(0) score.avatar() - + score.bar_meter=bar_meter.new(0,2,51,10,1,1,abad) -- score.border() -- score.jailgames() - score.life_meter() + -- score.life_meter() surf.target(0) end @@ -90,7 +92,8 @@ function score.draw() surf.target(score.surf) surf.cls(0) score.avatar() - score.life_meter() + -- score.life_meter() + score.bar_meter:draw() surf.target(0) surf.source(score.surf) diff --git a/data/stage1.lua b/data/stage1.lua index cd6f7af..57dc52b 100644 --- a/data/stage1.lua +++ b/data/stage1.lua @@ -29,7 +29,7 @@ function stages.stage1_init() boss = imp.new(55,4,3) table.insert( actors, boss ) - boss_meter = bar_meter.new(64,176,128,8,1,1,boss) + boss_meter = bar_meter.new(20,12,128,10,1,1,boss,5) --batman