[WIP] Treballant en el jefe. Recuperar informació de l'entorn
This commit is contained in:
@@ -18,6 +18,17 @@ function half_collision(a, b)
|
|||||||
and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h))
|
and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function v_collision(a, b)
|
||||||
|
return ((a.x+a.bb.x+a.bb.w >= b.x+b.bb.x)
|
||||||
|
and (a.x+a.bb.x <= b.x+b.bb.x+b.bb.w) )
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function h_collision(a, b)
|
||||||
|
return ((a.y+a.bb.y+a.bb.h >= b.y+b.bb.y)
|
||||||
|
and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h))
|
||||||
|
end
|
||||||
|
|
||||||
function remove_actor(actor)
|
function remove_actor(actor)
|
||||||
for index, value in pairs(actors) do
|
for index, value in pairs(actors) do
|
||||||
if value == actor then
|
if value == actor then
|
||||||
|
|||||||
186
data/imp.lua
186
data/imp.lua
@@ -36,6 +36,7 @@ function imp.new(_hab, _x, _y)
|
|||||||
local world_x, world_y = coords.room_to_world(_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","shot"}
|
||||||
for i,v in ipairs(_fight_modes) do _fight_modes[v] = i end
|
for i,v in ipairs(_fight_modes) do _fight_modes[v] = i end
|
||||||
|
|
||||||
return { name="imp",
|
return { name="imp",
|
||||||
hab=_hab,
|
hab=_hab,
|
||||||
x=world_x, y=world_y,
|
x=world_x, y=world_y,
|
||||||
@@ -100,6 +101,8 @@ function imp.new(_hab, _x, _y)
|
|||||||
set_fight_mode=imp.set_fight_mode,
|
set_fight_mode=imp.set_fight_mode,
|
||||||
think=imp.think,
|
think=imp.think,
|
||||||
controller_input=imp.controller_input,
|
controller_input=imp.controller_input,
|
||||||
|
ia=imp.ia,
|
||||||
|
analyze_env=imp.analyze_env,
|
||||||
-- imp.enabled=false
|
-- imp.enabled=false
|
||||||
-- imp.counter=500
|
-- imp.counter=500
|
||||||
}
|
}
|
||||||
@@ -107,15 +110,23 @@ end
|
|||||||
|
|
||||||
function imp:fight()
|
function imp:fight()
|
||||||
print("FIGHTING MODE")
|
print("FIGHTING MODE")
|
||||||
table.insert(self.hot_points, point.new(54,5,4,12,8,"P1"))
|
-- table.insert(self.hot_points, point.new(54,5,4,12,8,"P1"))
|
||||||
table.insert(self.hot_points, point.new(44,5,3,12,8,"P2"))
|
-- table.insert(self.hot_points, point.new(44,5,3,12,8,"P2"))
|
||||||
table.insert(self.hot_points, point.new(55,7,4,12,8,"P3"))
|
-- table.insert(self.hot_points, point.new(55,7,4,12,8,"P3"))
|
||||||
table.insert(self.hot_points, point.new(45,7,3,12,8,"P4"))
|
-- table.insert(self.hot_points, point.new(45,7,3,12,8,"P4"))
|
||||||
table.insert(self.hot_points, point.new(44,12,5,12,8,"P5"))
|
-- table.insert(self.hot_points, point.new(44,12,5,12,8,"P5"))
|
||||||
table.insert(self.hot_points, point.new(54,12,4,12,8,"P6"))
|
-- table.insert(self.hot_points, point.new(54,12,4,12,8,"P6"))
|
||||||
|
|
||||||
|
table.insert(self.hot_points, point.new(54, 5, 4, 0, 0,"P1"))
|
||||||
|
table.insert(self.hot_points, point.new(44, 5, 3, 0, 0,"P2"))
|
||||||
|
table.insert(self.hot_points, point.new(55, 8, 4, 0, 0,"P3"))
|
||||||
|
table.insert(self.hot_points, point.new(45, 8, 3, 0, 0,"P4"))
|
||||||
|
table.insert(self.hot_points, point.new(44,12, 5, 0, 0,"P5"))
|
||||||
|
table.insert(self.hot_points, point.new(54,12, 4, 0, 0,"P6"))
|
||||||
table.insert(self.hot_points, abad);
|
table.insert(self.hot_points, abad);
|
||||||
self.mode="chase"
|
|
||||||
self.target = self.hot_points[3]
|
self.target = self.hot_points[3]
|
||||||
|
|
||||||
|
self.mode="chase"
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:draw()
|
function imp:draw()
|
||||||
@@ -149,9 +160,108 @@ function imp:do_jump ( jumpfwd )
|
|||||||
self.action=""
|
self.action=""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function imp:analyze_env()
|
||||||
|
|
||||||
|
-- Distancia fins els punts
|
||||||
|
local scr_x, scr_y = viewp:screen_coords(self.x, self.y)
|
||||||
|
-- for _, p in pairs(self.hot_points) do
|
||||||
|
-- local scr_x1, scr_y1 = viewp:screen_coords(p.x, p.y)
|
||||||
|
-- local color = 2
|
||||||
|
-- if self.target == p then color = 4 end
|
||||||
|
-- draw.line(scr_x, scr_y, scr_x1, scr_y1, color)
|
||||||
|
--
|
||||||
|
-- dx = (self.x-p.x)
|
||||||
|
-- dy = (self.y-p.y)
|
||||||
|
-- d = math.sqrt(dx*dx+dy*dy)
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- Distancia fins a l'abad
|
||||||
|
dx = (self.x-abad.x)
|
||||||
|
dy = (self.y-abad.y)
|
||||||
|
r = math.sqrt(dx*dx+dy*dy)
|
||||||
|
-- msg_print(10,20,r,true)
|
||||||
|
local can_chase_abad = false
|
||||||
|
if r<=100 then
|
||||||
|
-- draw.circ(scr_x+self.bb.w/2,scr_y+self.bb.h/2,r,2)
|
||||||
|
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)
|
||||||
|
local can_climb = false
|
||||||
|
if tile_type1~=tiletype.void or tile_type2~=tiletype.void then
|
||||||
|
can_climb = true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Abad a tir
|
||||||
|
local can_shot = false
|
||||||
|
if h_collision(self,abad) then can_shot=true end
|
||||||
|
|
||||||
|
-- Super preparat
|
||||||
|
local can_super = false
|
||||||
|
if self.super_cooldown<=0 then can_super=true end
|
||||||
|
|
||||||
|
-- Acces a la zona central
|
||||||
|
x1_check = self.x+self.bb.x
|
||||||
|
x2_check = self.x+self.bb.x+self.bb.w
|
||||||
|
y_check = self.y+self.bb.h
|
||||||
|
local 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
|
||||||
|
can_go_altar = true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Cau al següent moviment
|
||||||
|
local going_to_fall = false
|
||||||
|
local tile_type1, tile_code1= arc_check_tile(x1_check,y_check)
|
||||||
|
local tile_type2, tile_code2= arc_check_tile(x2_check,y_check)
|
||||||
|
if tile_type1==tiletype.void and tile_type2==tiletype.void then
|
||||||
|
going_to_fall = true
|
||||||
|
end
|
||||||
|
|
||||||
|
local target_reached = false
|
||||||
|
local target_aligned = false
|
||||||
|
if #self.target>0 then
|
||||||
|
-- Target reached
|
||||||
|
if collision(self, self.target) then target_reached=true end
|
||||||
|
|
||||||
|
-- Target aligned
|
||||||
|
if half_collision(self, self.target) then target_aligned=true end
|
||||||
|
end
|
||||||
|
-- if can_climb then print("Climb!") end
|
||||||
|
-- if can_shot then print("Shot!") end
|
||||||
|
-- if can_super then print("Super!") end
|
||||||
|
-- if can_go_altar then
|
||||||
|
-- -- msg_print(10,20,"Altar READY!", true)
|
||||||
|
-- print("Altar!")
|
||||||
|
-- end
|
||||||
|
-- msg_print(10,40,hab1..", "..tx1..", "..ty1, true)
|
||||||
|
-- msg_print(10,60,hab2..", "..tx2..", "..ty2, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
function imp:ia()
|
||||||
|
self:reduce_cooldown()
|
||||||
|
-- if self.update==imp.state_jumping or self.update==imp.state_falling then
|
||||||
|
-- -- self:set_fight_mode()
|
||||||
|
-- -- self:think()
|
||||||
|
-- end
|
||||||
|
self:analyze_env()
|
||||||
|
if self.update==imp.state_walking or self.update==imp.state_normal then
|
||||||
|
self:set_fight_mode()
|
||||||
|
self:think()
|
||||||
|
end
|
||||||
|
self:controller_input()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function imp:state_jumping()
|
function imp:state_jumping()
|
||||||
-- msg_print(0,0,"state_jumping",true)
|
-- msg_print(0,0,"state_jumping",true)
|
||||||
self:reduce_cooldown()
|
|
||||||
-- ??
|
-- ??
|
||||||
self.wait=self.wait+1
|
self.wait=self.wait+1
|
||||||
self.wait=0
|
self.wait=0
|
||||||
@@ -169,9 +279,7 @@ function imp:state_jumping()
|
|||||||
-- cap endavant?
|
-- cap endavant?
|
||||||
if self.jumpfwd then self:advance() end
|
if self.jumpfwd then self:advance() end
|
||||||
|
|
||||||
-- self:set_fight_mode()
|
self:ia()
|
||||||
-- self:think()
|
|
||||||
self:controller_input()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:jump()
|
function imp:jump()
|
||||||
@@ -221,8 +329,7 @@ function imp:jump()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function imp:state_walking()
|
function imp:state_walking()
|
||||||
msg_print(16,48,"state_walking",true)
|
-- msg_print(16,48,"state_walking",true)
|
||||||
self:reduce_cooldown()
|
|
||||||
|
|
||||||
-- Limitar la velocitat de moviment
|
-- Limitar la velocitat de moviment
|
||||||
self.wait=self.wait+1
|
self.wait=self.wait+1
|
||||||
@@ -248,22 +355,17 @@ msg_print(16,48,"state_walking",true)
|
|||||||
end
|
end
|
||||||
|
|
||||||
self:advance()
|
self:advance()
|
||||||
|
self:ia()
|
||||||
self:set_fight_mode()
|
|
||||||
self:think()
|
|
||||||
self:controller_input()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:state_falling()
|
function imp:state_falling()
|
||||||
msg_print(16,16,"state_falling",true)
|
-- msg_print(16,16,"state_falling",true)
|
||||||
self:reduce_cooldown()
|
|
||||||
|
|
||||||
self.frame=30
|
self.frame=30
|
||||||
self.wait=self.wait+1
|
self.wait=self.wait+1
|
||||||
|
|
||||||
-- Si toca terra canviar el mode
|
-- Si toca terra canviar el mode
|
||||||
if self:land() then
|
if self:land() then
|
||||||
print("landing")
|
|
||||||
self.update=imp.state_normal
|
self.update=imp.state_normal
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -275,14 +377,11 @@ msg_print(16,16,"state_falling",true)
|
|||||||
|
|
||||||
-- Caiguent cap endavant?
|
-- Caiguent cap endavant?
|
||||||
if self.jumpfwd then self:advance() end
|
if self.jumpfwd then self:advance() end
|
||||||
|
self:ia()
|
||||||
-- self:set_fight_mode()
|
|
||||||
-- self:think()
|
|
||||||
self:controller_input()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:land ()
|
function imp:land ()
|
||||||
msg_print(16,32,"land",true)
|
-- msg_print(16,32,"land",true)
|
||||||
-- Els dos punts de baix de l'abad
|
-- Els dos punts de baix de l'abad
|
||||||
local x1_check = self.x+self.bb.x
|
local x1_check = self.x+self.bb.x
|
||||||
local x2_check = self.x+self.bb.x+self.bb.w
|
local x2_check = self.x+self.bb.x+self.bb.w
|
||||||
@@ -341,27 +440,23 @@ end
|
|||||||
-- Controlador principal del personatge
|
-- Controlador principal del personatge
|
||||||
function imp:state_normal()
|
function imp:state_normal()
|
||||||
-- msg_print(0,0,"state_normal",true)
|
-- msg_print(0,0,"state_normal",true)
|
||||||
self:reduce_cooldown()
|
|
||||||
|
|
||||||
self.frame=28
|
self.frame=28
|
||||||
self.wait=0
|
self.wait=0
|
||||||
self.step=0
|
self.step=0
|
||||||
self.jumpfwd=false
|
self.jumpfwd=false
|
||||||
self.jump_height = 0
|
self.jump_height = 0
|
||||||
self:set_fight_mode()
|
self:ia()
|
||||||
self:think()
|
|
||||||
self:controller_input()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:chase()
|
-- function imp:chase()
|
||||||
self.mode = self.fight_modes["chase"]
|
-- self.mode = self.fight_modes["chase"]
|
||||||
self.mode_cooldown = 150+math.random(50)-1
|
-- self.mode_cooldown = 150+math.random(50)-1
|
||||||
end
|
-- end
|
||||||
|
|
||||||
function imp:away()
|
-- function imp:away()
|
||||||
self.mode = self.fight_modes["away"]
|
-- self.mode = self.fight_modes["away"]
|
||||||
self.mode_cooldown = 150+math.random(50)-1
|
-- self.mode_cooldown = 150+math.random(50)-1
|
||||||
end
|
-- end
|
||||||
|
|
||||||
function imp:state_super()
|
function imp:state_super()
|
||||||
self.mode = self.fight_modes["super"]
|
self.mode = self.fight_modes["super"]
|
||||||
@@ -416,7 +511,6 @@ end
|
|||||||
-- traduir a acció de pad
|
-- traduir a acció de pad
|
||||||
-------------------------------
|
-------------------------------
|
||||||
function imp:think( )
|
function imp:think( )
|
||||||
local scr_x, scr_y = viewp:screen_coords( self.x+self.bb.x, self.y )
|
|
||||||
-- local check_x =
|
-- local check_x =
|
||||||
-- local check_y =
|
-- local check_y =
|
||||||
local action = "stay"
|
local action = "stay"
|
||||||
@@ -432,19 +526,23 @@ function imp:think( )
|
|||||||
-- Els dos punts de baix de l'abad
|
-- Els dos punts de baix de l'abad
|
||||||
local x1_check = self.x+self.bb.x
|
local x1_check = self.x+self.bb.x
|
||||||
local x2_check = self.x+self.bb.x+self.bb.w
|
local x2_check = self.x+self.bb.x+self.bb.w
|
||||||
local y_check = self.y+self.bb.h-2
|
local y_check = self.y+self.bb.h-4
|
||||||
local tile_type1, tile_code1= arc_check_tile(x1_check,y_check)
|
local tile_type1, tile_code1= arc_check_tile(x1_check,y_check)
|
||||||
local tile_type2, tile_code2= arc_check_tile(x2_check,y_check)
|
local tile_type2, tile_code2= arc_check_tile(x2_check,y_check)
|
||||||
draw.rect(scr_x+self.bb.x,scr_y+self.bb.h-1,16,16,2)
|
|
||||||
|
local scr_x1, scr_y = viewp:screen_coords( x1_check, y_check )
|
||||||
|
local scr_x2, scr_y = viewp:screen_coords( x2_check, y_check )
|
||||||
|
draw.rect(scr_x1,scr_y,scr_x2-scr_x1,8,2)
|
||||||
if collision(self, self.target) then
|
if collision(self, self.target) then
|
||||||
print("Next target "..tile_type1.." "..tile_code1)
|
print("Next target "..tile_type1.." "..tile_code1)
|
||||||
|
print("Next target "..tile_type2.." "..tile_code2)
|
||||||
self.mode_cooldown = 0
|
self.mode_cooldown = 0
|
||||||
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.y) ) then -- afegir que no hi haja tile per a escalar
|
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.y) ) then -- afegir que no hi haja tile per a escalar
|
||||||
print("Next Target 2 "..tile_type1.." "..tile_code1)
|
print("Next Target 2 "..tile_type1.." "..tile_code1)
|
||||||
self.mode_cooldown = 0
|
-- self.mode_cooldown = 0
|
||||||
-- self:set_fight_mode()
|
-- self:set_fight_mode()
|
||||||
elseif tile_type1~=tiletype.void or tile_type2~=tiletype.void then
|
elseif tile_type1~=tiletype.void or tile_type2~=tiletype.void then
|
||||||
print("jump "..tile_type1..", "..tile_type2)
|
-- print("jump "..tile_type1..", "..tile_type2)
|
||||||
action="jump"
|
action="jump"
|
||||||
end
|
end
|
||||||
-- local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
|
-- local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
|
||||||
@@ -497,7 +595,7 @@ function imp:think( )
|
|||||||
-- end
|
-- end
|
||||||
|
|
||||||
self.action = action
|
self.action = action
|
||||||
print(self.action)
|
|
||||||
return action
|
return action
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ function point.new(_hab,_x,_y,_x_offset,_y_offset,_id)
|
|||||||
hab=_hab,
|
hab=_hab,
|
||||||
x=world_x+_x_offset,
|
x=world_x+_x_offset,
|
||||||
y=world_y+_y_offset,
|
y=world_y+_y_offset,
|
||||||
w=8,
|
w=16,
|
||||||
h=8,
|
h=16,
|
||||||
draw=point.draw,
|
draw=point.draw,
|
||||||
bb={x=0,y=0,w=1,h=1},
|
bb={x=4,y=0,w=8,h=16},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -21,8 +21,10 @@ function point:draw(fill)
|
|||||||
-- debug rect
|
-- debug rect
|
||||||
if not fill then
|
if not fill then
|
||||||
draw.rect(scr_x,scr_y,self.w,self.h,3)
|
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)
|
||||||
else
|
else
|
||||||
draw.rectf(scr_x,scr_y,self.w,self.h,3)
|
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)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user