diff --git a/Crawler/Bullet.cpp b/Crawler/Bullet.cpp index b6367e2a..70848b26 100644 --- a/Crawler/Bullet.cpp +++ b/Crawler/Bullet.cpp @@ -19,13 +19,6 @@ Animate2D::Frame Bullet::GetFrame(){ } 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(){ diff --git a/Crawler/Bullet.h b/Crawler/Bullet.h index a85cb292..67b2f128 100644 --- a/Crawler/Bullet.h +++ b/Crawler/Bullet.h @@ -19,12 +19,11 @@ struct Bullet{ Animate2D::Animationanimation; Animate2D::AnimationState internal_animState; std::maphitList; - float lastParticleSpawn=0; Bullet(vf2d pos,vf2d vel,float radius,int damage,Pixel col=WHITE); //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); public: - void Update(float fElapsedTime); + virtual void Update(float fElapsedTime); Animate2D::Frame GetFrame(); void Draw(); }; \ No newline at end of file diff --git a/Crawler/BulletTypes.h b/Crawler/BulletTypes.h new file mode 100644 index 00000000..542efa8c --- /dev/null +++ b/Crawler/BulletTypes.h @@ -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; +}; \ No newline at end of file diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 840317d9..7d93ee12 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -17,8 +17,8 @@ std::mapANIMATION_DATA; std::vectorMONSTER_LIST; std::vectorSPAWNER_LIST; std::vectorDAMAGENUMBER_LIST; -std::vectorBULLET_LIST; -std::vectorPLAYER_BULLET_LIST; +std::vector>BULLET_LIST; +std::vector>PLAYER_BULLET_LIST; Crawler*game; Crawler::Crawler() @@ -591,64 +591,64 @@ void Crawler::UpdateEffects(float fElapsedTime){ } } void Crawler::UpdateBullets(float fElapsedTime){ - for(std::vector::iterator it=BULLET_LIST.begin();it!=BULLET_LIST.end();++it){ - Bullet&b=*it; - b.Update(fElapsedTime); - b.pos+=b.vel*fElapsedTime; - if(geom2d::overlaps(geom2d::circle(player.GetPos(),12*player.GetSizeMult()/2),geom2d::circle(b.pos,b.radius))){ - if(player.Hurt(b.damage)){ + for(auto it=BULLET_LIST.begin();it!=BULLET_LIST.end();++it){ + Bullet*b=dynamic_cast((*it).get()); + b->Update(fElapsedTime); + b->pos+=b->vel*fElapsedTime; + if(geom2d::overlaps(geom2d::circle(player.GetPos(),12*player.GetSizeMult()/2),geom2d::circle(b->pos,b->radius))){ + if(player.Hurt(b->damage)){ it=BULLET_LIST.erase(it); if(it==BULLET_LIST.end()){ break; } } } - if(b.pos.xview.GetWorldBR().x||b.pos.yview.GetWorldBR().y){ + if(b->pos.xpos.x>view.GetWorldBR().x||b->pos.ypos.y>view.GetWorldBR().y){ it=BULLET_LIST.erase(it); if(it==BULLET_LIST.end()){ break; } } - b.lifetime-=fElapsedTime; - if(b.lifetime<=0){ + b->lifetime-=fElapsedTime; + if(b->lifetime<=0){ it=BULLET_LIST.erase(it); if(it==BULLET_LIST.end()){ break; } } - b.animation.UpdateState(b.internal_animState,fElapsedTime); + b->animation.UpdateState(b->internal_animState,fElapsedTime); } - for(std::vector::iterator it=PLAYER_BULLET_LIST.begin();it!=PLAYER_BULLET_LIST.end();++it){ - Bullet&b=*it; - b.Update(fElapsedTime); - b.pos+=b.vel*fElapsedTime; + for(std::vector>::iterator it=PLAYER_BULLET_LIST.begin();it!=PLAYER_BULLET_LIST.end();++it){ + std::unique_ptr&b=*it; + b->Update(fElapsedTime); + b->pos+=b->vel*fElapsedTime; for(Monster&m:MONSTER_LIST){ - 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.hitsMultiple){ + 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->hitsMultiple){ it=PLAYER_BULLET_LIST.erase(it); if(it==PLAYER_BULLET_LIST.end()){ goto outsidePlayerBulletLoop; } } - b.hitList[&m]=true; + b->hitList[&m]=true; } } } - if(b.pos.xview.GetWorldBR().x||b.pos.yview.GetWorldBR().y){ + if(b->pos.xpos.x>view.GetWorldBR().x||b->pos.ypos.y>view.GetWorldBR().y){ it=PLAYER_BULLET_LIST.erase(it); if(it==PLAYER_BULLET_LIST.end()){ break; } } - b.lifetime-=fElapsedTime; - if(b.lifetime<=0){ + b->lifetime-=fElapsedTime; + if(b->lifetime<=0){ it=PLAYER_BULLET_LIST.erase(it); if(it==PLAYER_BULLET_LIST.end()){ break; } } - b.animation.UpdateState(b.internal_animState,fElapsedTime); + b->animation.UpdateState(b->internal_animState,fElapsedTime); } outsidePlayerBulletLoop: int a; @@ -715,11 +715,11 @@ void Crawler::RenderWorld(float fElapsedTime){ for(Effect&e:foregroundEffects){ e.Draw(); } - for(Bullet&b:BULLET_LIST){ - b.Draw(); + for(std::unique_ptr&b:BULLET_LIST){ + b->Draw(); } - for(Bullet&b:PLAYER_BULLET_LIST){ - b.Draw(); + for(std::unique_ptr&b:PLAYER_BULLET_LIST){ + b->Draw(); } for(TileGroup&group:foregroundTileGroups){ if(geom2d::overlaps(group.GetRange(),player.pos)){ diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index 4544f812..597fb224 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -161,11 +161,22 @@ powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File emscripten_build.ps1 + + + Console + + + + + Console + + + @@ -193,6 +204,7 @@ + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index dc5d3b2e..fee87315 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -16,6 +16,9 @@ {50277c8c-92cf-4eef-81ed-3e70ff51ec56} + + {715c64c5-956a-4ed3-9205-64110409fbeb} + @@ -87,6 +90,9 @@ Header Files + + Header Files + @@ -122,6 +128,9 @@ Source Files + + Source Files\Bullet Types + diff --git a/Crawler/DEFINES.h b/Crawler/DEFINES.h index 1de04f5a..851118dd 100644 --- a/Crawler/DEFINES.h +++ b/Crawler/DEFINES.h @@ -5,7 +5,7 @@ #define INCLUDE_DAMAGENUMBER_LIST extern std::vectorDAMAGENUMBER_LIST; #define INCLUDE_game extern Crawler*game; #define INCLUDE_MONSTER_DATA extern std::mapMONSTER_DATA; -#define INCLUDE_BULLET_LIST extern std::vectorBULLET_LIST; +#define INCLUDE_BULLET_LIST extern std::vector>BULLET_LIST; #define INCLUDE_CLASS_DATA extern std::mapCLASS_DATA; -#define INCLUDE_PLAYER_BULLET_LIST extern std::vectorPLAYER_BULLET_LIST; +#define INCLUDE_PLAYER_BULLET_LIST extern std::vector>PLAYER_BULLET_LIST; #define INCLUDE_PARTICLE_LIST extern std::vectorPARTICLE_LIST; \ No newline at end of file diff --git a/Crawler/EnergyBolt.cpp b/Crawler/EnergyBolt.cpp new file mode 100644 index 00000000..19af65da --- /dev/null +++ b/Crawler/EnergyBolt.cpp @@ -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})); + } +} \ No newline at end of file diff --git a/Crawler/Monster.cpp b/Crawler/Monster.cpp index bdcc4aed..d5662717 100644 --- a/Crawler/Monster.cpp +++ b/Crawler/Monster.cpp @@ -2,6 +2,7 @@ #include "DamageNumber.h" #include "Crawler.h" #include "Bullet.h" +#include "BulletTypes.h" #include "DEFINES.h" INCLUDE_ANIMATION_DATA @@ -206,7 +207,7 @@ bool Monster::Update(float fElapsedTime){ queueShotTimer-=fElapsedTime; if(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(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()); diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index 2fb1de93..7852852c 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -3,6 +3,7 @@ #include "Crawler.h" #include "DamageNumber.h" #include "Bullet.h" +#include "BulletTypes.h" #include "DEFINES.h" INCLUDE_MONSTER_DATA @@ -327,7 +328,7 @@ void Player::Update(float fElapsedTime){ case WIZARD: { attack_cooldown_timer=MAGIC_ATTACK_COOLDOWN; 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(pos,{cos(angleToCursor)*200,sin(angleToCursor)*200},12,GetAttack()))); }break; case WITCH: { }break; @@ -413,7 +414,7 @@ void Player::Update(float fElapsedTime){ UpdateAnimation(AnimationState::WARRIOR_SWINGSONICSWORD_S); }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(pos,bulletVel,30,GetAttack()*8,AnimationState::SONICSLASH,true,2.25,true))); game->SetupWorldShake(0.5); }break; case THIEF:{ diff --git a/Crawler/Version.h b/Crawler/Version.h index e6f83963..98e0410a 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 316 +#define VERSION_BUILD 347 #define stringify(a) stringify_(a) #define stringify_(a) #a