Bullets now have derived types.

pull/28/head
sigonasr2 1 year ago
parent 22729c3928
commit 1a441914ca
  1. 7
      Crawler/Bullet.cpp
  2. 3
      Crawler/Bullet.h
  3. 14
      Crawler/BulletTypes.h
  4. 56
      Crawler/Crawler.cpp
  5. 12
      Crawler/Crawler.vcxproj
  6. 9
      Crawler/Crawler.vcxproj.filters
  7. 4
      Crawler/DEFINES.h
  8. 17
      Crawler/EnergyBolt.cpp
  9. 3
      Crawler/Monster.cpp
  10. 5
      Crawler/Player.cpp
  11. 2
      Crawler/Version.h

@ -19,13 +19,6 @@ Animate2D::Frame Bullet::GetFrame(){
} }
void Bullet::Update(float fElapsedTime){ void Bullet::Update(float fElapsedTime){
if(animated){
lastParticleSpawn=std::max(0.f,lastParticleSpawn-fElapsedTime);
if(lastParticleSpawn==0&&animation.GetFrame(internal_animState).GetSourceImage()==&game->GFX_EnergyBolt){
lastParticleSpawn=0.03;
game->AddEffect(Effect(pos,float(rand()%500)/500,AnimationState::ENERGY_PARTICLE,float(rand()%1000)/500,0.5,{float(rand()%60)-30,float(rand()%60)-30}));
}
}
} }
void Bullet::Draw(){ void Bullet::Draw(){

@ -19,12 +19,11 @@ struct Bullet{
Animate2D::Animation<AnimationState>animation; Animate2D::Animation<AnimationState>animation;
Animate2D::AnimationState internal_animState; Animate2D::AnimationState internal_animState;
std::map<Monster*,bool>hitList; std::map<Monster*,bool>hitList;
float lastParticleSpawn=0;
Bullet(vf2d pos,vf2d vel,float radius,int damage,Pixel col=WHITE); Bullet(vf2d pos,vf2d vel,float radius,int damage,Pixel col=WHITE);
//Initializes a bullet with an animation. //Initializes a bullet with an animation.
Bullet(vf2d pos,vf2d vel,float radius,int damage,AnimationState animation,bool hitsMultiple=false,float lifetime=INFINITE,bool rotatesWithAngle=false,Pixel col=WHITE); Bullet(vf2d pos,vf2d vel,float radius,int damage,AnimationState animation,bool hitsMultiple=false,float lifetime=INFINITE,bool rotatesWithAngle=false,Pixel col=WHITE);
public: public:
void Update(float fElapsedTime); virtual void Update(float fElapsedTime);
Animate2D::Frame GetFrame(); Animate2D::Frame GetFrame();
void Draw(); void Draw();
}; };

@ -0,0 +1,14 @@
#pragma once
#include "Bullet.h"
struct GenericBullet:public Bullet{
GenericBullet(vf2d pos,vf2d vel,float radius,int damage,Pixel col=WHITE);
GenericBullet(vf2d pos,vf2d vel,float radius,int damage,AnimationState animation,bool hitsMultiple=false,float lifetime=INFINITE,bool rotatesWithAngle=false,Pixel col=WHITE);
void Update(float fElapsedTime)override;
};
struct EnergyBolt:public Bullet{
float lastParticleSpawn=0;
EnergyBolt(vf2d pos,vf2d vel,float radius,int damage,Pixel col=WHITE);
void Update(float fElapsedTime)override;
};

@ -17,8 +17,8 @@ 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<DamageNumber>DAMAGENUMBER_LIST;
std::vector<Bullet>BULLET_LIST; std::vector<std::unique_ptr<Bullet>>BULLET_LIST;
std::vector<Bullet>PLAYER_BULLET_LIST; std::vector<std::unique_ptr<Bullet>>PLAYER_BULLET_LIST;
Crawler*game; Crawler*game;
Crawler::Crawler() Crawler::Crawler()
@ -591,64 +591,64 @@ void Crawler::UpdateEffects(float fElapsedTime){
} }
} }
void Crawler::UpdateBullets(float fElapsedTime){ void Crawler::UpdateBullets(float fElapsedTime){
for(std::vector<Bullet>::iterator it=BULLET_LIST.begin();it!=BULLET_LIST.end();++it){ for(auto it=BULLET_LIST.begin();it!=BULLET_LIST.end();++it){
Bullet&b=*it; Bullet*b=dynamic_cast<Bullet*>((*it).get());
b.Update(fElapsedTime); b->Update(fElapsedTime);
b.pos+=b.vel*fElapsedTime; b->pos+=b->vel*fElapsedTime;
if(geom2d::overlaps(geom2d::circle(player.GetPos(),12*player.GetSizeMult()/2),geom2d::circle(b.pos,b.radius))){ if(geom2d::overlaps(geom2d::circle(player.GetPos(),12*player.GetSizeMult()/2),geom2d::circle(b->pos,b->radius))){
if(player.Hurt(b.damage)){ if(player.Hurt(b->damage)){
it=BULLET_LIST.erase(it); it=BULLET_LIST.erase(it);
if(it==BULLET_LIST.end()){ if(it==BULLET_LIST.end()){
break; break;
} }
} }
} }
if(b.pos.x<view.GetWorldTL().x||b.pos.x>view.GetWorldBR().x||b.pos.y<view.GetWorldTL().y||b.pos.y>view.GetWorldBR().y){ if(b->pos.x<view.GetWorldTL().x||b->pos.x>view.GetWorldBR().x||b->pos.y<view.GetWorldTL().y||b->pos.y>view.GetWorldBR().y){
it=BULLET_LIST.erase(it); it=BULLET_LIST.erase(it);
if(it==BULLET_LIST.end()){ if(it==BULLET_LIST.end()){
break; break;
} }
} }
b.lifetime-=fElapsedTime; b->lifetime-=fElapsedTime;
if(b.lifetime<=0){ if(b->lifetime<=0){
it=BULLET_LIST.erase(it); it=BULLET_LIST.erase(it);
if(it==BULLET_LIST.end()){ if(it==BULLET_LIST.end()){
break; break;
} }
} }
b.animation.UpdateState(b.internal_animState,fElapsedTime); b->animation.UpdateState(b->internal_animState,fElapsedTime);
} }
for(std::vector<Bullet>::iterator it=PLAYER_BULLET_LIST.begin();it!=PLAYER_BULLET_LIST.end();++it){ for(std::vector<std::unique_ptr<Bullet>>::iterator it=PLAYER_BULLET_LIST.begin();it!=PLAYER_BULLET_LIST.end();++it){
Bullet&b=*it; std::unique_ptr<Bullet>&b=*it;
b.Update(fElapsedTime); b->Update(fElapsedTime);
b.pos+=b.vel*fElapsedTime; b->pos+=b->vel*fElapsedTime;
for(Monster&m:MONSTER_LIST){ for(Monster&m:MONSTER_LIST){
if(geom2d::overlaps(geom2d::circle(m.GetPos(),12*m.GetSizeMult()),geom2d::circle(b.pos,b.radius))){ if(geom2d::overlaps(geom2d::circle(m.GetPos(),12*m.GetSizeMult()),geom2d::circle(b->pos,b->radius))){
if(b.hitList.find(&m)==b.hitList.end()&&m.Hurt(b.damage)){ if(b->hitList.find(&m)==b->hitList.end()&&m.Hurt(b->damage)){
if(!b.hitsMultiple){ if(!b->hitsMultiple){
it=PLAYER_BULLET_LIST.erase(it); it=PLAYER_BULLET_LIST.erase(it);
if(it==PLAYER_BULLET_LIST.end()){ if(it==PLAYER_BULLET_LIST.end()){
goto outsidePlayerBulletLoop; goto outsidePlayerBulletLoop;
} }
} }
b.hitList[&m]=true; b->hitList[&m]=true;
} }
} }
} }
if(b.pos.x<view.GetWorldTL().x||b.pos.x>view.GetWorldBR().x||b.pos.y<view.GetWorldTL().y||b.pos.y>view.GetWorldBR().y){ if(b->pos.x<view.GetWorldTL().x||b->pos.x>view.GetWorldBR().x||b->pos.y<view.GetWorldTL().y||b->pos.y>view.GetWorldBR().y){
it=PLAYER_BULLET_LIST.erase(it); it=PLAYER_BULLET_LIST.erase(it);
if(it==PLAYER_BULLET_LIST.end()){ if(it==PLAYER_BULLET_LIST.end()){
break; break;
} }
} }
b.lifetime-=fElapsedTime; b->lifetime-=fElapsedTime;
if(b.lifetime<=0){ if(b->lifetime<=0){
it=PLAYER_BULLET_LIST.erase(it); it=PLAYER_BULLET_LIST.erase(it);
if(it==PLAYER_BULLET_LIST.end()){ if(it==PLAYER_BULLET_LIST.end()){
break; break;
} }
} }
b.animation.UpdateState(b.internal_animState,fElapsedTime); b->animation.UpdateState(b->internal_animState,fElapsedTime);
} }
outsidePlayerBulletLoop: outsidePlayerBulletLoop:
int a; int a;
@ -715,11 +715,11 @@ void Crawler::RenderWorld(float fElapsedTime){
for(Effect&e:foregroundEffects){ for(Effect&e:foregroundEffects){
e.Draw(); e.Draw();
} }
for(Bullet&b:BULLET_LIST){ for(std::unique_ptr<Bullet>&b:BULLET_LIST){
b.Draw(); b->Draw();
} }
for(Bullet&b:PLAYER_BULLET_LIST){ for(std::unique_ptr<Bullet>&b:PLAYER_BULLET_LIST){
b.Draw(); b->Draw();
} }
for(TileGroup&group:foregroundTileGroups){ for(TileGroup&group:foregroundTileGroups){
if(geom2d::overlaps(group.GetRange(),player.pos)){ if(geom2d::overlaps(group.GetRange(),player.pos)){

@ -161,11 +161,22 @@
<Command>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File emscripten_build.ps1</Command> <Command>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File emscripten_build.ps1</Command>
</PostBuildEvent> </PostBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Emscripten|Win32'">
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Emscripten|x64'">
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Ability.h" /> <ClInclude Include="Ability.h" />
<ClInclude Include="Animation.h" /> <ClInclude Include="Animation.h" />
<ClInclude Include="Buff.h" /> <ClInclude Include="Buff.h" />
<ClInclude Include="Bullet.h" /> <ClInclude Include="Bullet.h" />
<ClInclude Include="BulletTypes.h" />
<ClInclude Include="Class.h" /> <ClInclude Include="Class.h" />
<ClInclude Include="Crawler.h" /> <ClInclude Include="Crawler.h" />
<ClInclude Include="DamageNumber.h" /> <ClInclude Include="DamageNumber.h" />
@ -193,6 +204,7 @@
<ClCompile Include="Crawler.cpp" /> <ClCompile Include="Crawler.cpp" />
<ClCompile Include="DamageNumber.cpp" /> <ClCompile Include="DamageNumber.cpp" />
<ClCompile Include="Effect.cpp" /> <ClCompile Include="Effect.cpp" />
<ClCompile Include="EnergyBolt.cpp" />
<ClCompile Include="Map.cpp" /> <ClCompile Include="Map.cpp" />
<ClCompile Include="pixelGameEngine.cpp" /> <ClCompile Include="pixelGameEngine.cpp" />
<ClCompile Include="Player.cpp" /> <ClCompile Include="Player.cpp" />

@ -16,6 +16,9 @@
<Filter Include="Documentation"> <Filter Include="Documentation">
<UniqueIdentifier>{50277c8c-92cf-4eef-81ed-3e70ff51ec56}</UniqueIdentifier> <UniqueIdentifier>{50277c8c-92cf-4eef-81ed-3e70ff51ec56}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Source Files\Bullet Types">
<UniqueIdentifier>{715c64c5-956a-4ed3-9205-64110409fbeb}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="olcPixelGameEngine.h"> <ClInclude Include="olcPixelGameEngine.h">
@ -87,6 +90,9 @@
<ClInclude Include="TSXParser.h"> <ClInclude Include="TSXParser.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="BulletTypes.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Player.cpp"> <ClCompile Include="Player.cpp">
@ -122,6 +128,9 @@
<ClCompile Include="Map.cpp"> <ClCompile Include="Map.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="EnergyBolt.cpp">
<Filter>Source Files\Bullet Types</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="cpp.hint" /> <None Include="cpp.hint" />

@ -5,7 +5,7 @@
#define INCLUDE_DAMAGENUMBER_LIST extern std::vector<DamageNumber>DAMAGENUMBER_LIST; #define INCLUDE_DAMAGENUMBER_LIST extern std::vector<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<Bullet>BULLET_LIST; #define INCLUDE_BULLET_LIST extern std::vector<std::unique_ptr<Bullet>>BULLET_LIST;
#define INCLUDE_CLASS_DATA extern std::map<Class,ClassData>CLASS_DATA; #define INCLUDE_CLASS_DATA extern std::map<Class,ClassData>CLASS_DATA;
#define INCLUDE_PLAYER_BULLET_LIST extern std::vector<Bullet>PLAYER_BULLET_LIST; #define INCLUDE_PLAYER_BULLET_LIST extern std::vector<std::unique_ptr<Bullet>>PLAYER_BULLET_LIST;
#define INCLUDE_PARTICLE_LIST extern std::vector<Particle>PARTICLE_LIST; #define INCLUDE_PARTICLE_LIST extern std::vector<Particle>PARTICLE_LIST;

@ -0,0 +1,17 @@
#include "BulletTypes.h"
#include "Effect.h"
#include "Crawler.h"
#include "DEFINES.h"
INCLUDE_game
EnergyBolt::EnergyBolt(vf2d pos,vf2d vel,float radius,int damage,Pixel col)
:Bullet(pos,vel,radius,damage,AnimationState::ENERGY_BOLT,false,INFINITE,true,col){}
void EnergyBolt::Update(float fElapsedTime){
lastParticleSpawn=std::max(0.f,lastParticleSpawn-fElapsedTime);
if(lastParticleSpawn==0&&animation.GetFrame(internal_animState).GetSourceImage()==&game->GFX_EnergyBolt){
lastParticleSpawn=0.03;
game->AddEffect(Effect(pos,float(rand()%500)/500,AnimationState::ENERGY_PARTICLE,float(rand()%1000)/500,0.5,{float(rand()%60)-30,float(rand()%60)-30}));
}
}

@ -2,6 +2,7 @@
#include "DamageNumber.h" #include "DamageNumber.h"
#include "Crawler.h" #include "Crawler.h"
#include "Bullet.h" #include "Bullet.h"
#include "BulletTypes.h"
#include "DEFINES.h" #include "DEFINES.h"
INCLUDE_ANIMATION_DATA INCLUDE_ANIMATION_DATA
@ -206,7 +207,7 @@ bool Monster::Update(float fElapsedTime){
queueShotTimer-=fElapsedTime; queueShotTimer-=fElapsedTime;
if(queueShotTimer<0){ if(queueShotTimer<0){
queueShotTimer=0; queueShotTimer=0;
BULLET_LIST.push_back(Bullet(pos+vf2d{0,-4},geom2d::line(pos+vf2d{0,-4},game->GetPlayer().GetPos()).vector().norm()*24*3.f,2,GetAttack(),{75/2,162/2,225/2})); BULLET_LIST.push_back(std::make_unique<Bullet>(Bullet(pos+vf2d{0,-4},geom2d::line(pos+vf2d{0,-4},game->GetPlayer().GetPos()).vector().norm()*24*3.f,2,GetAttack(),{75/2,162/2,225/2})));
} }
} }
geom2d::line line(pos,game->GetPlayer().GetPos()); geom2d::line line(pos,game->GetPlayer().GetPos());

@ -3,6 +3,7 @@
#include "Crawler.h" #include "Crawler.h"
#include "DamageNumber.h" #include "DamageNumber.h"
#include "Bullet.h" #include "Bullet.h"
#include "BulletTypes.h"
#include "DEFINES.h" #include "DEFINES.h"
INCLUDE_MONSTER_DATA INCLUDE_MONSTER_DATA
@ -327,7 +328,7 @@ void Player::Update(float fElapsedTime){
case WIZARD: { case WIZARD: {
attack_cooldown_timer=MAGIC_ATTACK_COOLDOWN; attack_cooldown_timer=MAGIC_ATTACK_COOLDOWN;
float angleToCursor=atan2(game->GetWorldMousePos().y-pos.y,game->GetWorldMousePos().x-pos.x); float angleToCursor=atan2(game->GetWorldMousePos().y-pos.y,game->GetWorldMousePos().x-pos.x);
PLAYER_BULLET_LIST.push_back(Bullet(pos,{cos(angleToCursor)*200,sin(angleToCursor)*200},12,GetAttack(),AnimationState::ENERGY_BOLT,false,INFINITE,true)); PLAYER_BULLET_LIST.push_back(std::make_unique<EnergyBolt>(EnergyBolt(pos,{cos(angleToCursor)*200,sin(angleToCursor)*200},12,GetAttack())));
}break; }break;
case WITCH: { case WITCH: {
}break; }break;
@ -413,7 +414,7 @@ void Player::Update(float fElapsedTime){
UpdateAnimation(AnimationState::WARRIOR_SWINGSONICSWORD_S); UpdateAnimation(AnimationState::WARRIOR_SWINGSONICSWORD_S);
}break; }break;
} }
PLAYER_BULLET_LIST.push_back(Bullet(pos,bulletVel,30,GetAttack()*8,AnimationState::SONICSLASH,true,2.25,true)); PLAYER_BULLET_LIST.push_back(std::make_unique<Bullet>(Bullet(pos,bulletVel,30,GetAttack()*8,AnimationState::SONICSLASH,true,2.25,true)));
game->SetupWorldShake(0.5); game->SetupWorldShake(0.5);
}break; }break;
case THIEF:{ case THIEF:{

@ -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 316 #define VERSION_BUILD 347
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

Loading…
Cancel
Save