# 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 <EFBFBD> 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"
using A = Attribute ;
void Monster : : STRATEGY : : BREAKING_PILLAR ( Monster & m , float fElapsedTime , std : : string strategy ) {
enum Phase {
INITIALIZE ,
RUN ,
} ;
if ( m . GetHealthRatio ( ) > = ConfigFloat ( " Break Phase 1 HP % Threshold " ) / 100.f ) {
m . animation . ModifyDisplaySprite ( m . internal_animState , ConfigString ( " Unbroken Animation Name " ) ) ;
} else
if ( m . GetHealthRatio ( ) > = ConfigFloat ( " Break Phase 2 HP % Threshold " ) / 100.f ) {
m . animation . ModifyDisplaySprite ( m . internal_animState , ConfigString ( " Break Phase 1 Animation Name " ) ) ;
} else m . animation . ModifyDisplaySprite ( m . internal_animState , ConfigString ( " Break Phase 2 Animation Name " ) ) ;
switch ( m . phase ) {
case INITIALIZE : {
m . F ( A : : BREAK_TIME ) = ConfigFloat ( " Break Time " ) ;
m . F ( A : : SHAKE_TIMER ) = 0.2f ;
m . phase = RUN ;
m . SetStrategyDeathFunction ( [ & ] ( GameEvent & deathEvent , Monster & m , const std : : string & strategy ) {
m . lifetime = 0.01f ;
m . B ( A : : MARKED_DEAD ) = true ;
const float bulletAngRandomOffset { util : : random ( PI / 2 ) } ;
for ( int i = 0 ; i < ConfigInt ( " Death Ring Bullet Count " ) ; i + + ) {
const float bulletAngle = ( ( 2 * PI ) / ConfigInt ( " Death Ring Bullet Count " ) ) * i + bulletAngRandomOffset ;
CreateBullet ( Bullet ) ( m . GetPos ( ) , vf2d { ConfigFloat ( " Death Ring Bullet Speed " ) , bulletAngle } . cart ( ) , ConfigFloat ( " Death Ring Bullet Size " ) , ConfigInt ( " Death Ring Bullet Damage " ) , m . OnUpperLevel ( ) , false , ConfigPixel ( " Death Ring Bullet Color " ) , vf2d { ConfigFloat ( " Death Ring Bullet Size " ) / 3 , ConfigFloat ( " Death Ring Bullet Size " ) / 3 } ) EndBullet ;
}
return false ;
} ) ;
} break ;
case RUN : {
m . F ( A : : BREAK_TIME ) - = fElapsedTime ;
if ( m . F ( A : : BREAK_TIME ) < = 2.f ) {
if ( m . F ( A : : BREAK_TIME ) < = 0.f ) {
m . _DealTrueDamage ( m . GetHealth ( ) ) ; //Kill the pillar, making it crumble.
break ;
}
m . F ( A : : SHAKE_TIMER ) - = fElapsedTime ;
if ( m . F ( A : : SHAKE_TIMER ) < = 0.f ) {
m . F ( A : : SHAKE_TIMER ) + = 0.2f ;
if ( m . B ( A : : SHAKE_DIR ) ) m . SetX ( m . GetPos ( ) . x - 2 ) ;
else m . SetX ( m . GetPos ( ) . x + 2 ) ;
m . B ( A : : SHAKE_DIR ) = ! m . B ( A : : SHAKE_DIR ) ;
SoundEffect : : PlaySFX ( " Pillar Shake " , m . GetPos ( ) ) ;
}
}
} break ;
}
}