Initial frog behavior aiming implemented.

This commit is contained in:
2024-01-13 16:37:46 -06:00
parent 849244d407
commit 62a2119ab2
13 changed files with 138 additions and 22 deletions
@@ -564,6 +564,10 @@
</ClCompile>
<ClCompile Include="FallingDebris.h" />
<ClCompile Include="FireBolt.cpp" />
<ClCompile Include="Frog.cpp">
<SubType>
</SubType>
</ClCompile>
<ClCompile Include="FrogTongue.cpp">
<SubType>
</SubType>
@@ -716,6 +716,9 @@
<ClCompile Include="FrogTongue.cpp">
<Filter>Source Files\Bullet Types</Filter>
</ClCompile>
<ClCompile Include="Frog.cpp">
<Filter>Source Files\Monster Strategies</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint" />
+97
View File
@@ -0,0 +1,97 @@
#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 © 2023 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
#pragma endregion
#include "Monster.h"
#include "AdventuresInLestoria.h"
#include "MonsterStrategyHelpers.h"
#include "util.h"
INCLUDE_game
using A=Attribute;
void Monster::STRATEGY::FROG(Monster&m,float fElapsedTime,std::string strategy){
phase:
switch(m.I(A::PHASE)){
case 0:{ //Move towards phase.
float distToPlayer=geom2d::line<float>(m.GetPos(),game->GetPlayer()->GetPos()).length();
if(distToPlayer<24*ConfigInt("Range")/100.f){
m.I(A::PHASE)++;
m.F(A::LOCKON_WAITTIME)=ConfigFloat("Lockon Wait Time");
m.V(A::LOCKON_POS)=game->GetPlayer()->GetPos();
float dirToPlayer=util::angleTo(m.GetPos(),m.V(A::LOCKON_POS));
if(abs(dirToPlayer)<0.5f*PI){ //This sprite is supposed to be facing right (flipped)
m.facingDirection=RIGHT;
m.spriteRot=dirToPlayer;
}else{
m.facingDirection=LEFT;
if(dirToPlayer>0){
m.spriteRot=-PI+dirToPlayer;
}else{
m.spriteRot=PI+dirToPlayer;
}
}
goto phase;
}
float dirToPlayer=util::angleTo(m.GetPos(),m.target);
if(abs(dirToPlayer)<0.5f*PI){ //This sprite is supposed to be facing right (flipped)
m.facingDirection=RIGHT;
m.spriteRot=dirToPlayer;
}else{
m.facingDirection=LEFT;
if(dirToPlayer>0){
m.spriteRot=-PI+dirToPlayer;
}else{
m.spriteRot=PI+dirToPlayer;
}
}
RUN_TOWARDS(m,fElapsedTime,"Run Towards");
m.PerformJumpAnimation();
}break;
case 1:{
m.F(A::LOCKON_WAITTIME)=std::max(0.0f,m.F(A::LOCKON_WAITTIME)-fElapsedTime);
if(m.F(A::LOCKON_WAITTIME)==0.0f){
m.I(A::PHASE)=0;
}
m.PerformIdleAnimation();
}break;
default:{
ERR(std::format("Unhandled phase {} for {} strategy!",m.I(A::PHASE),strategy));
}
}
}
+1 -11
View File
@@ -264,7 +264,7 @@ void Monster::Draw(){
vf2d shadowScale=vf2d{8*GetSizeMult()/3.f,1}/std::max(1.f,GetZ()/24);
game->view.DrawDecal(GetPos()-vf2d{3,3}*shadowScale/2+vf2d{0,6*GetSizeMult()},GFX["circle.png"].Decal(),shadowScale,BLACK);
}
game->view.DrawPartialRotatedDecal(GetPos()-vf2d{0,GetZ()},GetFrame().GetSourceImage()->Decal(),0,GetFrame().GetSourceRect().size/2,GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,vf2d(GetSizeMult()*(GetFacingDirection()==RIGHT?-1:1),GetSizeMult()),GetBuffs(BuffType::SLOWDOWN).size()>0?Pixel{uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(128+127*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration)))}:WHITE);
game->view.DrawPartialRotatedDecal(GetPos()-vf2d{0,GetZ()},GetFrame().GetSourceImage()->Decal(),spriteRot,GetFrame().GetSourceRect().size/2,GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,vf2d(GetSizeMult()*(GetFacingDirection()==RIGHT?-1:1),GetSizeMult()),GetBuffs(BuffType::SLOWDOWN).size()>0?Pixel{uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(128+127*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration)))}:WHITE);
#pragma region Debug Pathfinding
#ifdef _DEBUG
@@ -506,16 +506,6 @@ void Monster::SetState(State::State newState){
state=newState;
}
void Monster::InitializeStrategies(){
STRATEGY_DATA.insert("Run Towards",Monster::STRATEGY::RUN_TOWARDS);
STRATEGY_DATA.insert("Shoot Afar",Monster::STRATEGY::SHOOT_AFAR);
STRATEGY_DATA.insert("Turret",Monster::STRATEGY::TURRET);
STRATEGY_DATA.insert("Slime King",Monster::STRATEGY::SLIMEKING);
STRATEGY_DATA.insert("Run Away",Monster::STRATEGY::RUN_AWAY);
STRATEGY_DATA.SetInitialized();
}
bool Monster::HasIframes(){
return iframe_timer>0;
}
+2
View File
@@ -202,6 +202,7 @@ private:
Pathfinding::sSpline path;
float pathIndex=0;
float lastHitTimer=0;
float spriteRot=0;
std::shared_ptr<DamageNumber>damageNumberPtr;
int phase=0;
bool diesNormally=true; //If set to false, the monster death is handled in a special way. Set it to true when it's time to die.
@@ -231,6 +232,7 @@ private:
static void TURRET(Monster&m,float fElapsedTime,std::string strategy);
static void SLIMEKING(Monster&m,float fElapsedTime,std::string strategy);
static void RUN_AWAY(Monster&m,float fElapsedTime,std::string strategy);
static void FROG(Monster&m,float fElapsedTime,std::string strategy);
};
};
@@ -76,4 +76,7 @@ enum class Attribute{
ITEM_QUANTITY,
LAST_INVENTORY_TYPE_OPENED,
NEXT_MENU, //Set to 0 for New Game, Set to 1 for Load Game Menu. This is used for the username checks
PHASE,
LOCKON_WAITTIME,
LOCKON_POS,
};
+11
View File
@@ -66,4 +66,15 @@ std::string Monster::STRATEGY::_GetString(Monster&m,std::string param,std::strin
void Monster::STRATEGY::RUN_STRATEGY(Monster&m,float fElapsedTime){
m.GetStrategy()(m,fElapsedTime,m.strategy);
}
void Monster::InitializeStrategies(){
STRATEGY_DATA.insert("Run Towards",Monster::STRATEGY::RUN_TOWARDS);
STRATEGY_DATA.insert("Shoot Afar",Monster::STRATEGY::SHOOT_AFAR);
STRATEGY_DATA.insert("Turret",Monster::STRATEGY::TURRET);
STRATEGY_DATA.insert("Slime King",Monster::STRATEGY::SLIMEKING);
STRATEGY_DATA.insert("Run Away",Monster::STRATEGY::RUN_AWAY);
STRATEGY_DATA.insert("Frog",Monster::STRATEGY::FROG);
STRATEGY_DATA.SetInitialized();
}
+1 -1
View File
@@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 1
#define VERSION_BUILD 5743
#define VERSION_BUILD 5750
#define stringify(a) stringify_(a)
#define stringify_(a) #a
Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

@@ -1075,7 +1075,7 @@
</object>
<object id="4" name="Green Slime" type="Monster" x="1052" y="4304">
<properties>
<property name="Type" propertytype="MonsterName" value="Green Slime"/>
<property name="Type" propertytype="MonsterName" value="Frog"/>
<property name="spawner" type="object" value="2"/>
</properties>
<point/>
@@ -167,4 +167,12 @@ MonsterStrategy
# If the player is farther than this distance, close in on them.
CloseInRange = 850
}
Frog
{
# How close the frog has to get to the player before beginning its attack.
Range = 350
# How long to wait after getting in range and locking on to the player, before firing tongue.
Lockon Wait Time = 1.5s
}
}
@@ -245,23 +245,21 @@ Monsters
}
Frog
{
Health = 110
Attack = 12
Health = 60
Attack = 15
CollisionDmg = 12
CollisionDmg = 15
MoveSpd = 120%
Size = 90%
MoveSpd = 70%
Size = 70%
XP = 14
XP = 8
Strategy = Run Towards
Strategy = Frog
#Size of each animation frame
SheetFrameSize = 24,24
# Tongue shoots from (9,13)
# Frame Count, Frame Speed (s), Frame Cycling (Repeat,OneShot,PingPong,Reverse)
IdleAnimation = 4, 0.13, PingPong
JumpAnimation = 10, 0.06, Repeat
Binary file not shown.