-- Enemy A.I.
local GuardId = "Guard01"
local Guard = getObject("Characters[" .. GuardId .. "]")
local Obstacle = 0
local RecognitionSpeed = 2
--if dymphna's outfit has changed
if Dymphna.CurrentOutfit ~= Dymphna.Outfits["dymA_default"] then
RecognitionSpeed = 1
end
--
local Distanz =
math.sqrt(
math.pow(Guard.Position.x-Dymphna.Position.x,2)
+
math.pow(Guard.Position.y-Dymphna.Position.y,2)
)
--RecognitionSpeed = RecognitionSpeed/Distanz
math.randomseed( os.time() + 1 )
local AI_Dest_X = math.floor(math.random(320))
math.randomseed( os.time() + 2 )
local AI_Dest_Y = math.floor(math.random(200))
--graphics.addDrawFunc("debugDest()", 0)
function Rect(_x1,_y1,_x2,_y2)
return {
{x=_x1,y=_y1},
{x=_x2,y=_y1},
{x=_x2,y=_y2},
{x=_x1,y=_y2}
}
end
function CheckRect(_x1,_y1,_x2,_y2)
for i=0, 1, 0.1 do
if isPointInsidePolygon( {x=lerp(Guard.Position.x,Dymphna.Position.x,i),y=lerp(Guard.Position.y-16,Dymphna.Position.y-13,i)}, Rect(_x1,_y1,_x2,_y2) ) then
Obstacle = Obstacle + 1
end
end
end
CheckRect(123, 66,196,138)
CheckRect( 0, 0,106, 59)
CheckRect(214, 0,320, 59)
CheckRect( 28, 89,106,126)
CheckRect(214, 89,292,126)
CheckRect( 0,156,105,200)
CheckRect(214,156,320,200)
CheckRect( 0,168,150,200)
CheckRect(169,168,320,200)
--if isPointInsidePolygon({x=30,y=80},game.GameCurrentScene.WaySystems.BurhCorridorWaysystem.Border) then
Guard:setValue(VCharacterTint, 0xffffff)
graphics.addDrawFunc("draw()", 0)
if Obstacle == 0 then
--Guard:setValue(VCharacterState,2)
Guard:setValue(VCharacterDestination, Guard.Position)
if Distanz <; ImmediateRecognitionAt then
Guard.Values.Recognition.Int = 100
end
if Values.Recognition.Int == 0 then
startSound(
"vispath:sound/guard01.wav",
{flags=1,volume=GuardVolume}
)
end
Guard.Values.AI_UpdateTime.Int = 50
alignChar(GuardId, "")
if Guard.Values.Recognition.Int <; 100 then
Guard.Values.Recognition.Int = Guard.Values.Recognition.Int + RecognitionSpeed
else
Guard.Values.Alarm.Int = 1
graphics.removeDrawFunc("draw()")
startSound(
"vispath:sound/guard02.wav",
{flags=1,volume=GuardVolume}
)
end
function draw()
-- "Recognized"-Line
graphics.drawLine(
Guard.Position.x,
Guard.Position.y -16,
lerp(
Guard.Position.x,
Dymphna.Position.x,
Guard.Values.Recognition.Int/100
),
lerp(
Guard.Position.y -16,
Dymphna.Position.y -13,
Guard.Values.Recognition.Int/100
),
RecognizeLineColor,
RecognizeLineAlpha
)
-- "Noticed"-Line
graphics.drawLine(
lerp(
Guard.Position.x,
Dymphna.Position.x,
Guard.Values.Recognition.Int/100
),
lerp(
Guard.Position.y -16,
Dymphna.Position.y -13,
Guard.Values.Recognition.Int/100
),
Dymphna.Position.x,
Dymphna.Position.y -13,
NoticeLineColor,
NoticeLineAlpha
)
end
else
--DEBUG: Visualize next Destination
function debugDest()
graphics.drawLine(
Guard.Position.x,
Guard.Position.y,
AI_Dest_X,
AI_Dest_Y,
"0x8800ff",
0.5
)
end
Guard.Values.AI_UpdateTime.Int = 500
Guard.Values.Recognition.Int = 0
graphics.removeDrawFunc("draw()")
--CharacterState scheint broken zu sein.
--if Guard.State == 2 then
if Guard.Position.x == Guard.Destination.x then
--
Guard:setValue(
VCharacterDestination,
{x=AI_Dest_X,y=AI_Dest_Y}
)
--
end
end