Switch to smart pointer implementation for damage numbers to handle damage combo'ing quick attack displays.

pull/28/head
sigonasr2 1 year ago
parent 9585baf5c6
commit a0916cfe9b
  1. 23
      Crawler/Crawler.cpp
  2. 2
      Crawler/DEFINES.h
  3. 1
      Crawler/DamageNumber.h
  4. 11
      Crawler/Monster.cpp
  5. 3
      Crawler/Monster.h
  6. 11
      Crawler/Player.cpp
  7. 3
      Crawler/Player.h
  8. 2
      Crawler/Version.h
  9. 2
      Crawler/assets/Campaigns/1_1.tmx

@ -25,7 +25,7 @@ const vi2d WINDOW_SIZE={24*15,24*10};
std::map<AnimationState,Animate2D::FrameSequence>ANIMATION_DATA; std::map<AnimationState,Animate2D::FrameSequence>ANIMATION_DATA;
std::vector<Monster>MONSTER_LIST; std::vector<Monster>MONSTER_LIST;
std::vector<MonsterSpawner>SPAWNER_LIST; std::vector<MonsterSpawner>SPAWNER_LIST;
std::vector<DamageNumber>DAMAGENUMBER_LIST; std::vector<std::shared_ptr<DamageNumber>>DAMAGENUMBER_LIST;
std::vector<std::unique_ptr<Bullet>>BULLET_LIST; std::vector<std::unique_ptr<Bullet>>BULLET_LIST;
Crawler*game; Crawler*game;
@ -699,21 +699,26 @@ void Crawler::RenderWorld(float fElapsedTime){
} }
} }
#pragma endregion #pragma endregion
for(std::vector<DamageNumber>::iterator it=DAMAGENUMBER_LIST.begin();it!=DAMAGENUMBER_LIST.end();++it){ for(std::vector<std::shared_ptr<DamageNumber>>::iterator it=DAMAGENUMBER_LIST.begin();it!=DAMAGENUMBER_LIST.end();++it){
DamageNumber&dn=*it; DamageNumber*dn=(*it).get();
dn.lifeTime+=fElapsedTime; if(dn->pauseTime>0){
if(dn.lifeTime>1){ dn->pauseTime-=fElapsedTime;
} else{
dn->lifeTime+=fElapsedTime;
if(dn->lifeTime>1){
it=DAMAGENUMBER_LIST.erase(it); it=DAMAGENUMBER_LIST.erase(it);
if(it==DAMAGENUMBER_LIST.end()){ if(it==DAMAGENUMBER_LIST.end()){
break; break;
} }
} else { } else {
if(dn.lifeTime<DamageNumber::MOVE_UP_TIME){ if(dn->lifeTime<DamageNumber::MOVE_UP_TIME){
dn.pos.y-=20*fElapsedTime; dn->pos.y-=20*fElapsedTime;
}
} }
std::string text=std::to_string(dn.damage);
view.DrawStringPropDecal(dn.pos-GetTextSizeProp(text)/2,text,DARK_RED);
} }
std::string text=std::to_string(dn->damage);
view.DrawStringPropDecal(dn->pos-GetTextSizeProp(text)/2,text,DARK_RED);
} }
} }

@ -2,7 +2,7 @@
#define INCLUDE_ANIMATION_DATA extern std::map<AnimationState,Animate2D::FrameSequence>ANIMATION_DATA; #define INCLUDE_ANIMATION_DATA extern std::map<AnimationState,Animate2D::FrameSequence>ANIMATION_DATA;
#define INCLUDE_MONSTER_LIST extern std::vector<Monster>MONSTER_LIST; #define INCLUDE_MONSTER_LIST extern std::vector<Monster>MONSTER_LIST;
#define INCLUDE_SPAWNER_LIST extern std::vector<MonsterSpawner>SPAWNER_LIST; #define INCLUDE_SPAWNER_LIST extern std::vector<MonsterSpawner>SPAWNER_LIST;
#define INCLUDE_DAMAGENUMBER_LIST extern std::vector<DamageNumber>DAMAGENUMBER_LIST; #define INCLUDE_DAMAGENUMBER_LIST extern std::vector<std::shared_ptr<DamageNumber>>DAMAGENUMBER_LIST;
#define INCLUDE_game extern Crawler*game; #define INCLUDE_game extern Crawler*game;
#define INCLUDE_MONSTER_DATA extern std::map<MonsterName,MonsterData>MONSTER_DATA; #define INCLUDE_MONSTER_DATA extern std::map<MonsterName,MonsterData>MONSTER_DATA;
#define INCLUDE_BULLET_LIST extern std::vector<std::unique_ptr<Bullet>>BULLET_LIST; #define INCLUDE_BULLET_LIST extern std::vector<std::unique_ptr<Bullet>>BULLET_LIST;

@ -5,6 +5,7 @@ struct DamageNumber{
vf2d pos; vf2d pos;
int damage; int damage;
float lifeTime=0; float lifeTime=0;
float pauseTime=0;
const static float MOVE_UP_TIME; const static float MOVE_UP_TIME;
DamageNumber(); DamageNumber();
DamageNumber(vf2d pos,int damage); DamageNumber(vf2d pos,int damage);

@ -98,6 +98,7 @@ bool Monster::SetY(float y){
return false; return false;
} }
bool Monster::Update(float fElapsedTime){ bool Monster::Update(float fElapsedTime){
lastHitTimer=std::max(0.f,lastHitTimer-fElapsedTime);
if(IsAlive()){ if(IsAlive()){
for(std::vector<Buff>::iterator it=buffList.begin();it!=buffList.end();++it){ for(std::vector<Buff>::iterator it=buffList.begin();it!=buffList.end();++it){
Buff&b=*it; Buff&b=*it;
@ -334,7 +335,15 @@ bool Monster::Hurt(int damage,bool onUpperLevel){
mod_dmg-=damage*b.intensity; mod_dmg-=damage*b.intensity;
} }
hp=std::max(0,hp-int(mod_dmg)); hp=std::max(0,hp-int(mod_dmg));
DAMAGENUMBER_LIST.push_back(DamageNumber(pos,int(mod_dmg))); if(lastHitTimer>0){
damageNumberPtr.get()->damage+=int(mod_dmg);
damageNumberPtr.get()->pauseTime=0.4;
} else {
DAMAGENUMBER_LIST.push_back(std::make_shared<DamageNumber>(pos,int(mod_dmg)));
std::shared_ptr<DamageNumber>numb=*(DAMAGENUMBER_LIST.end()-1);
damageNumberPtr=numb;
}
lastHitTimer=0.05;
if(hp<=0){ if(hp<=0){
animation.ChangeState(internal_animState,GetDeathAnimationName()); animation.ChangeState(internal_animState,GetDeathAnimationName());
} }

@ -4,6 +4,7 @@
#include "State.h" #include "State.h"
#include "Buff.h" #include "Buff.h"
#include "olcUTIL_Animate2D.h" #include "olcUTIL_Animate2D.h"
#include "DamageNumber.h"
struct Player; struct Player;
@ -85,6 +86,8 @@ struct Monster{
vf2d pathTarget={}; vf2d pathTarget={};
std::vector<vf2d>path; std::vector<vf2d>path;
int pathIndex=0; int pathIndex=0;
float lastHitTimer=0;
std::shared_ptr<DamageNumber>damageNumberPtr;
protected: protected:
public: public:
Monster()=delete; Monster()=delete;

@ -162,6 +162,7 @@ void Player::Update(float fElapsedTime){
iframe_time=std::max(0.f,iframe_time-fElapsedTime); iframe_time=std::max(0.f,iframe_time-fElapsedTime);
notEnoughManaDisplay.second=std::max(0.f,notEnoughManaDisplay.second-fElapsedTime); notEnoughManaDisplay.second=std::max(0.f,notEnoughManaDisplay.second-fElapsedTime);
notificationDisplay.second=std::max(0.f,notificationDisplay.second-fElapsedTime); notificationDisplay.second=std::max(0.f,notificationDisplay.second-fElapsedTime);
lastHitTimer=std::max(0.f,lastHitTimer-fElapsedTime);
manaTickTimer-=fElapsedTime; manaTickTimer-=fElapsedTime;
if(castInfo.castTimer>0){ if(castInfo.castTimer>0){
castInfo.castTimer-=fElapsedTime; castInfo.castTimer-=fElapsedTime;
@ -471,7 +472,15 @@ bool Player::Hurt(int damage,bool onUpperLevel){
mod_dmg-=damage*b.intensity; mod_dmg-=damage*b.intensity;
} }
hp=std::max(0,hp-int(mod_dmg)); hp=std::max(0,hp-int(mod_dmg));
DAMAGENUMBER_LIST.push_back(DamageNumber(pos,int(mod_dmg))); if(lastHitTimer>0){
damageNumberPtr.get()->damage+=int(mod_dmg);
damageNumberPtr.get()->pauseTime=0.4;
} else {
DAMAGENUMBER_LIST.push_back(std::make_shared<DamageNumber>(pos,int(mod_dmg)));
std::shared_ptr<DamageNumber>numb=*(DAMAGENUMBER_LIST.end()-1);
damageNumberPtr=numb;
}
lastHitTimer=0.05;
return true; return true;
} }

@ -7,6 +7,7 @@
#include "Class.h" #include "Class.h"
#include "Buff.h" #include "Buff.h"
#include "Pathfinding.h" #include "Pathfinding.h"
#include "DamageNumber.h"
struct CastInfo{ struct CastInfo{
std::string name; std::string name;
@ -48,6 +49,8 @@ struct Player{
std::vector<Buff>buffList; std::vector<Buff>buffList;
CastInfo castInfo={"",0}; CastInfo castInfo={"",0};
vf2d movementVelocity={};//This tells us if the player is moving (mostly controlled by user input) since their velocity is not used for regular movement. vf2d movementVelocity={};//This tells us if the player is moving (mostly controlled by user input) since their velocity is not used for regular movement.
float lastHitTimer=0; //When this is greater than zero, if we get hit again it adds to our displayed combo number.
std::shared_ptr<DamageNumber>damageNumberPtr;
protected: protected:
const float ATTACK_COOLDOWN=0.35f; const float ATTACK_COOLDOWN=0.35f;
const float MAGIC_ATTACK_COOLDOWN=0.85f; const float MAGIC_ATTACK_COOLDOWN=0.85f;

@ -2,7 +2,7 @@
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 0 #define VERSION_PATCH 0
#define VERSION_BUILD 847 #define VERSION_BUILD 854
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.1" orientation="orthogonal" renderorder="right-down" width="192" height="203" tilewidth="24" tileheight="24" infinite="0" nextlayerid="8" nextobjectid="156"> <map version="1.10" tiledversion="1.10.1" orientation="orthogonal" renderorder="right-down" width="192" height="203" tilewidth="24" tileheight="24" infinite="0" nextlayerid="8" nextobjectid="158">
<tileset firstgid="1" source="../maps/grass_tiles_24x24.tsx"/> <tileset firstgid="1" source="../maps/grass_tiles_24x24.tsx"/>
<tileset firstgid="784" source="../maps/grass_tiles_modded.tsx"/> <tileset firstgid="784" source="../maps/grass_tiles_modded.tsx"/>
<layer id="5" name="Collision Layer" width="192" height="203"> <layer id="5" name="Collision Layer" width="192" height="203">

Loading…
Cancel
Save