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.
139 lines
5.2 KiB
139 lines
5.2 KiB
#pragma region License
|
|
/*
|
|
License (OLC-3)
|
|
~~~~~~~~~~~~~~~
|
|
|
|
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
are permitted provided that the following conditions are met:
|
|
|
|
1. Redistributions or derivations of source code must retain the above copyright
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions or derivative works in binary form must reproduce the above
|
|
copyright notice. This list of conditions and the following disclaimer must be
|
|
reproduced in the documentation and/or other materials provided with the distribution.
|
|
|
|
3. Neither the name of the copyright holder nor the names of its contributors may
|
|
be used to endorse or promote products derived from this software without specific
|
|
prior written permission.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
|
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
SUCH DAMAGE.
|
|
|
|
Portions of this software are copyright © 2024 The FreeType
|
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
|
All rights reserved.
|
|
*/
|
|
#pragma endregion
|
|
|
|
#include "MonsterStrategyHelpers.h"
|
|
#include "util.h"
|
|
#include "AdventuresInLestoria.h"
|
|
#include "SoundEffect.h"
|
|
#include "BulletTypes.h"
|
|
|
|
using A=Attribute;
|
|
|
|
INCLUDE_game
|
|
|
|
void Monster::STRATEGY::SANDWORM(Monster&m,float fElapsedTime,std::string strategy){
|
|
enum PhaseName{
|
|
INITIALIZE,
|
|
UNDERGROUND,
|
|
SURFACING,
|
|
ATTACK,
|
|
SHOOTING,
|
|
BURROWING,
|
|
};
|
|
|
|
m.F(A::ATTACK_COOLDOWN)-=fElapsedTime;
|
|
m.F(A::SUCTION_TIMER)-=fElapsedTime;
|
|
const float distToPlayer{util::distance(game->GetPlayer()->GetPos(),m.GetPos())};
|
|
if(m.F(A::SUCTION_TIMER)>0.f&&distToPlayer<=ConfigPixels("Suction Radius")){
|
|
game->GetPlayer()->AddVelocity(util::pointTo(game->GetPlayer()->GetPos(),m.GetPos())*100.f*ConfigFloat("Suction Pull Amount")/100.f);
|
|
}
|
|
|
|
const auto AcquireNewUndergroundTarget=[&](){
|
|
const float randomRange=util::random_range(0,ConfigPixels("Burrow Target Range"));
|
|
m.target=game->GetPlayer()->GetPos()+vf2d{randomRange,util::random(2*PI)}.cart();
|
|
};
|
|
|
|
switch(PHASE()){
|
|
case INITIALIZE:{
|
|
SETPHASE(UNDERGROUND);
|
|
AcquireNewUndergroundTarget();
|
|
}break;
|
|
case UNDERGROUND:{
|
|
m.SetCollisionRadius(0.f);
|
|
RUN_TOWARDS(m,fElapsedTime,"Run Towards");
|
|
m.PerformAnimation("SWIM",m.GetFacingDirection());
|
|
if(m.ReachedTargetPos()){
|
|
m.PerformAnimation("EMERGE",game->GetPlayer()->GetPos());
|
|
m.F(A::RECOVERY_TIME)=m.GetCurrentAnimation().GetTotalAnimationDuration();
|
|
game->AddEffect(std::make_unique<Effect>(m.GetPos(),ConfigInt("Suction Duration"),"sand_suction.png",m.OnUpperLevel(),0.25f,0.25f,ConfigFloat("Suction Animation Size")/300.f*vf2d{1.f,1.f},vf2d{},WHITE,util::random(),-PI/8),true);
|
|
SETPHASE(SURFACING);
|
|
m.F(A::SUCTION_TIMER)=ConfigFloat("Suction Duration")+0.25f;
|
|
}
|
|
}break;
|
|
case SURFACING:{
|
|
m.F(A::RECOVERY_TIME)-=fElapsedTime;
|
|
if(m.F(A::RECOVERY_TIME)<=0.f){
|
|
SETPHASE(ATTACK);
|
|
m.PerformAnimation("IDLE",game->GetPlayer()->GetPos());
|
|
m.SetCollisionRadius(m.GetOriginalCollisionRadius());
|
|
m.I(A::ATTACK_COUNT)=ConfigInt("Max Attack Count");
|
|
}
|
|
}break;
|
|
case ATTACK:{
|
|
if(m.I(A::ATTACK_COUNT)<=0||distToPlayer>=ConfigPixels("Max Attack Range")){
|
|
m.SetCollisionRadius(0.f);
|
|
m.PerformAnimation("BURROW");
|
|
m.F(A::CASTING_TIMER)=m.GetCurrentAnimation().GetTotalAnimationDuration();
|
|
SETPHASE(BURROWING);
|
|
break;
|
|
}
|
|
if(m.F(A::ATTACK_COOLDOWN)<=0.f){
|
|
m.PerformAnimation("SAND ATTACK",game->GetPlayer()->GetPos());
|
|
m.F(A::CASTING_TIMER)=ConfigFloat("Shoot Delay");
|
|
m.F(A::SHOOT_ANIMATION_TIME)=m.GetCurrentAnimation().GetTotalAnimationDuration();
|
|
m.B(A::BULLET_HAS_BEEN_SHOT)=false;
|
|
SETPHASE(SHOOTING);
|
|
}
|
|
}break;
|
|
case SHOOTING:{
|
|
const auto ShootBullet=[&](){
|
|
m.B(A::BULLET_HAS_BEEN_SHOT)=true;
|
|
m.I(A::ATTACK_COUNT)--;
|
|
CreateBullet(Bullet)(m.GetPos(),vf2d{ConfigPixels("Bullet Speed"),util::angleTo(m.GetPos(),game->GetPlayer()->GetPos())}.cart(),ConfigFloat("Bullet Radius"),m.GetAttack(),m.OnUpperLevel(),false,ConfigPixel("Bullet Color"),ConfigFloat("Bullet Radius")*vf2d{1.f,1.f}/2.f)EndBullet;
|
|
};
|
|
|
|
m.F(A::CASTING_TIMER)-=fElapsedTime;
|
|
m.F(A::SHOOT_ANIMATION_TIME)-=fElapsedTime;
|
|
if(m.F(A::CASTING_TIMER)<=0.f&&!m.B(A::BULLET_HAS_BEEN_SHOT)){
|
|
ShootBullet();
|
|
}
|
|
if(m.F(A::SHOOT_ANIMATION_TIME)<=0.f){
|
|
if(!m.B(A::BULLET_HAS_BEEN_SHOT))ShootBullet();
|
|
m.PerformAnimation("IDLE",game->GetPlayer()->GetPos());
|
|
SETPHASE(ATTACK);
|
|
}
|
|
}break;
|
|
case BURROWING:{
|
|
m.F(A::CASTING_TIMER)-=fElapsedTime;
|
|
if(m.F(A::CASTING_TIMER)<=0.f){
|
|
AcquireNewUndergroundTarget();
|
|
SETPHASE(UNDERGROUND);
|
|
}
|
|
}break;
|
|
}
|
|
} |