The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'!
https://forums.lestoria.net
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.5 KiB
95 lines
2.5 KiB
#include "Monster.h"
|
|
#include "DEFINES.h"
|
|
#include "Crawler.h"
|
|
|
|
INCLUDE_BULLET_LIST
|
|
INCLUDE_game
|
|
|
|
void Monster::STRATEGY::SHOOT_AFAR(Monster&m,float fElapsedTime){
|
|
m.targetAcquireTimer=std::max(0.f,m.targetAcquireTimer-fElapsedTime);
|
|
m.attackCooldownTimer=std::max(0.f,m.attackCooldownTimer-fElapsedTime);
|
|
if(m.queueShotTimer>0){
|
|
m.queueShotTimer-=fElapsedTime;
|
|
if(m.queueShotTimer<0){
|
|
m.queueShotTimer=0;
|
|
{
|
|
BULLET_LIST.push_back(std::make_unique<Bullet>(Bullet(m.pos + vf2d{ 0,-4 }, geom2d::line(m.pos + vf2d{ 0,-4 }, game->GetPlayer()->GetPos()).vector().norm() * 24 * 3.f, 2, m.GetAttack(),m.upperLevel,false, { 75 / 2,162 / 2,225 / 2 })));
|
|
}
|
|
}
|
|
}
|
|
geom2d::line line(m.pos,game->GetPlayer()->GetPos());
|
|
if(m.targetAcquireTimer==0&&m.queueShotTimer==0){
|
|
m.targetAcquireTimer=1;
|
|
if(line.length()<24*6){
|
|
m.target=line.upoint(-1.2);
|
|
if(m.canMove){
|
|
m.SetState(MOVE_AWAY);
|
|
} else {
|
|
m.SetState(NORMAL);
|
|
}
|
|
} else
|
|
if(line.length()>24*7){
|
|
m.target=line.upoint(1.2);
|
|
m.SetState(MOVE_TOWARDS);
|
|
} else {
|
|
m.SetState(NORMAL);
|
|
}
|
|
}
|
|
m.canMove=true;
|
|
geom2d::line moveTowardsLine=geom2d::line(m.pos,m.target);
|
|
bool pathfindingDecision=false;
|
|
switch(m.state){
|
|
case MOVE_TOWARDS:{
|
|
if(moveTowardsLine.length()>1){
|
|
vf2d newPos=m.pos+moveTowardsLine.vector().norm()*100*fElapsedTime*m.GetMoveSpdMult();
|
|
bool movedX=m.SetX(newPos.x);
|
|
bool movedY=m.SetY(newPos.y);
|
|
pathfindingDecision=movedX|movedY;
|
|
m.canMove=movedX&&movedY;
|
|
}
|
|
if(!pathfindingDecision){
|
|
m.StartPathfinding(2.5);
|
|
}else
|
|
if(line.length()<=24*7){
|
|
m.SetState(NORMAL);
|
|
}
|
|
if(moveTowardsLine.vector().x>0){
|
|
m.facingDirection=RIGHT;
|
|
} else {
|
|
m.facingDirection=LEFT;
|
|
}
|
|
m.PerformJumpAnimation();
|
|
}break;
|
|
case MOVE_AWAY:{
|
|
if(moveTowardsLine.length()>1){
|
|
vf2d newPos=m.pos+moveTowardsLine.vector().norm()*100*fElapsedTime*m.GetMoveSpdMult();
|
|
bool movedX=m.SetX(newPos.x);
|
|
bool movedY=m.SetY(newPos.y);
|
|
pathfindingDecision=movedX|movedY;
|
|
m.canMove=movedX&&movedY;
|
|
}
|
|
if(!pathfindingDecision){
|
|
m.StartPathfinding(2.5);
|
|
}else
|
|
if(line.length()>=24*6){
|
|
m.SetState(NORMAL);
|
|
}
|
|
if(moveTowardsLine.vector().x>0){
|
|
m.facingDirection=RIGHT;
|
|
} else {
|
|
m.facingDirection=LEFT;
|
|
}
|
|
m.PerformJumpAnimation();
|
|
}break;
|
|
case PATH_AROUND:{
|
|
m.PathAroundBehavior(fElapsedTime);
|
|
}break;
|
|
default:{
|
|
if(m.attackCooldownTimer==0){
|
|
m.attackCooldownTimer=1;
|
|
m.queueShotTimer=0.7;
|
|
m.PerformShootAnimation();
|
|
}
|
|
}
|
|
}
|
|
} |