Bullets now have derived types.
This commit is contained in:
parent
5739ae9861
commit
1d396d3215
@ -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(){
|
||||
|
@ -19,12 +19,11 @@ struct Bullet{
|
||||
Animate2D::Animation<AnimationState>animation;
|
||||
Animate2D::AnimationState internal_animState;
|
||||
std::map<Monster*,bool>hitList;
|
||||
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();
|
||||
};
|
14
Crawler/BulletTypes.h
Normal file
14
Crawler/BulletTypes.h
Normal file
@ -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<MonsterSpawner>SPAWNER_LIST;
|
||||
std::vector<DamageNumber>DAMAGENUMBER_LIST;
|
||||
std::vector<Bullet>BULLET_LIST;
|
||||
std::vector<Bullet>PLAYER_BULLET_LIST;
|
||||
std::vector<std::unique_ptr<Bullet>>BULLET_LIST;
|
||||
std::vector<std::unique_ptr<Bullet>>PLAYER_BULLET_LIST;
|
||||
Crawler*game;
|
||||
|
||||
Crawler::Crawler()
|
||||
@ -591,64 +591,64 @@ void Crawler::UpdateEffects(float fElapsedTime){
|
||||
}
|
||||
}
|
||||
void Crawler::UpdateBullets(float fElapsedTime){
|
||||
for(std::vector<Bullet>::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<Bullet*>((*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.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);
|
||||
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<Bullet>::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<std::unique_ptr<Bullet>>::iterator it=PLAYER_BULLET_LIST.begin();it!=PLAYER_BULLET_LIST.end();++it){
|
||||
std::unique_ptr<Bullet>&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.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);
|
||||
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<Bullet>&b:BULLET_LIST){
|
||||
b->Draw();
|
||||
}
|
||||
for(Bullet&b:PLAYER_BULLET_LIST){
|
||||
b.Draw();
|
||||
for(std::unique_ptr<Bullet>&b:PLAYER_BULLET_LIST){
|
||||
b->Draw();
|
||||
}
|
||||
for(TileGroup&group:foregroundTileGroups){
|
||||
if(geom2d::overlaps(group.GetRange(),player.pos)){
|
||||
|
@ -161,11 +161,22 @@
|
||||
<Command>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File emscripten_build.ps1</Command>
|
||||
</PostBuildEvent>
|
||||
</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>
|
||||
<ClInclude Include="Ability.h" />
|
||||
<ClInclude Include="Animation.h" />
|
||||
<ClInclude Include="Buff.h" />
|
||||
<ClInclude Include="Bullet.h" />
|
||||
<ClInclude Include="BulletTypes.h" />
|
||||
<ClInclude Include="Class.h" />
|
||||
<ClInclude Include="Crawler.h" />
|
||||
<ClInclude Include="DamageNumber.h" />
|
||||
@ -193,6 +204,7 @@
|
||||
<ClCompile Include="Crawler.cpp" />
|
||||
<ClCompile Include="DamageNumber.cpp" />
|
||||
<ClCompile Include="Effect.cpp" />
|
||||
<ClCompile Include="EnergyBolt.cpp" />
|
||||
<ClCompile Include="Map.cpp" />
|
||||
<ClCompile Include="pixelGameEngine.cpp" />
|
||||
<ClCompile Include="Player.cpp" />
|
||||
|
@ -16,6 +16,9 @@
|
||||
<Filter Include="Documentation">
|
||||
<UniqueIdentifier>{50277c8c-92cf-4eef-81ed-3e70ff51ec56}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Bullet Types">
|
||||
<UniqueIdentifier>{715c64c5-956a-4ed3-9205-64110409fbeb}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="olcPixelGameEngine.h">
|
||||
@ -87,6 +90,9 @@
|
||||
<ClInclude Include="TSXParser.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="BulletTypes.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Player.cpp">
|
||||
@ -122,6 +128,9 @@
|
||||
<ClCompile Include="Map.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="EnergyBolt.cpp">
|
||||
<Filter>Source Files\Bullet Types</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="cpp.hint" />
|
||||
|
@ -5,7 +5,7 @@
|
||||
#define INCLUDE_DAMAGENUMBER_LIST extern std::vector<DamageNumber>DAMAGENUMBER_LIST;
|
||||
#define INCLUDE_game extern Crawler*game;
|
||||
#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_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;
|
17
Crawler/EnergyBolt.cpp
Normal file
17
Crawler/EnergyBolt.cpp
Normal file
@ -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 "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>(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());
|
||||
|
@ -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>(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>(Bullet(pos,bulletVel,30,GetAttack()*8,AnimationState::SONICSLASH,true,2.25,true)));
|
||||
game->SetupWorldShake(0.5);
|
||||
}break;
|
||||
case THIEF:{
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user