Meteor Effect particles and impact code completed

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
pull/28/head
Nic0Nic0Nii 1 year ago
parent 50a73a53e7
commit eb5bb15918
  1. 23
      Crawler/Crawler.cpp
  2. 4
      Crawler/Crawler.h
  3. 2
      Crawler/Effect.cpp
  4. 5
      Crawler/Effect.h
  5. 26
      Crawler/Meteor.cpp
  6. 40
      Crawler/Player.cpp
  7. 2
      Crawler/Wizard.cpp

@ -29,6 +29,11 @@ std::vector<DamageNumber>DAMAGENUMBER_LIST;
std::vector<std::unique_ptr<Bullet>>BULLET_LIST; std::vector<std::unique_ptr<Bullet>>BULLET_LIST;
Crawler*game; Crawler*game;
Key Crawler::KEY_ABILITY1=Q;
Key Crawler::KEY_ABILITY2=E;
Key Crawler::KEY_ABILITY3=R;
Key Crawler::KEY_ABILITY4=F;
Crawler::Crawler() Crawler::Crawler()
{ {
sAppName = "Crawler Concept"; sAppName = "Crawler Concept";
@ -309,16 +314,11 @@ void Crawler::UpdateCamera(float fElapsedTime){
lastWorldShakeAdjust=std::max(0.f,lastWorldShakeAdjust-fElapsedTime); lastWorldShakeAdjust=std::max(0.f,lastWorldShakeAdjust-fElapsedTime);
if(worldShakeTime-fElapsedTime>0){ if(worldShakeTime-fElapsedTime>0){
if(lastWorldShakeAdjust==0){ if(lastWorldShakeAdjust==0){
lastWorldShakeAdjust=util::random(0.04)+0.01; lastWorldShakeAdjust=0.02;
worldShakeVel={util::random(200)+100,util::random(200)+100}; worldShakeVel.x*=-1;
if(rand()%2==0){ worldShakeVel.y*=-1;
worldShakeVel.x*=-1;
}
if(rand()%2==0){
worldShakeVel.y*=-1;
}
} }
worldShake+=worldShakeVel*fElapsedTime; worldShake=player->GetPos()+worldShakeVel*fElapsedTime;
} else { } else {
camera.SetTarget(player->GetPos()); camera.SetTarget(player->GetPos());
} }
@ -568,7 +568,9 @@ void Crawler::RenderWorld(float fElapsedTime){
} }
if(player->GetState()==State::PREP_CAST){ if(player->GetState()==State::PREP_CAST){
float precastSize=GetPlayer()->castPrepAbility->precastInfo.size; float precastSize=GetPlayer()->castPrepAbility->precastInfo.size;
view.DrawDecal(GetWorldMousePos()-vf2d{precastSize/4.5f,precastSize/4.5f},GFX_Circle.Decal(),{precastSize/3,precastSize/3},{255,0,0,192}); vf2d scale=vf2d{precastSize,precastSize}/3.f;
vf2d centerPoint=GetWorldMousePos()-vf2d{game->GFX_Circle.Sprite()->width*scale.x/2,game->GFX_Circle.Sprite()->height*scale.y/2};
view.DrawDecal(centerPoint,GFX_Circle.Decal(),scale,{255,0,0,96});
} }
#pragma region Foreground Rendering #pragma region Foreground Rendering
for(TileGroup&group:foregroundTileGroups){ for(TileGroup&group:foregroundTileGroups){
@ -757,6 +759,7 @@ vf2d Crawler::GetWorldMousePos(){
} }
void Crawler::SetupWorldShake(float duration){ void Crawler::SetupWorldShake(float duration){
worldShakeVel={750,-750};
worldShakeTime=duration; worldShakeTime=duration;
worldShake=player->GetPos(); worldShake=player->GetPos();
camera.SetTarget(worldShake); camera.SetTarget(worldShake);

@ -31,6 +31,10 @@ class Crawler : public olc::PixelGameEngine
public: public:
Renderable GFX_BulletCircle,GFX_BulletCircleOutline,GFX_EnergyBolt,GFX_Circle; Renderable GFX_BulletCircle,GFX_BulletCircleOutline,GFX_EnergyBolt,GFX_Circle;
Pathfinding pathfinder; Pathfinding pathfinder;
static Key KEY_ABILITY1;
static Key KEY_ABILITY2;
static Key KEY_ABILITY3;
static Key KEY_ABILITY4;
private: private:
std::vector<std::unique_ptr<Effect>>foregroundEffects,backgroundEffects; std::vector<std::unique_ptr<Effect>>foregroundEffects,backgroundEffects;
std::map<MapName,Map>MAP_DATA; std::map<MapName,Map>MAP_DATA;

@ -6,7 +6,7 @@ INCLUDE_ANIMATION_DATA
INCLUDE_game INCLUDE_game
Effect::Effect(vf2d pos,float lifetime,AnimationState animation,bool upperLevel,float size,float fadeout,vf2d spd,Pixel col,float rotation,float rotationSpd,bool additiveBlending) Effect::Effect(vf2d pos,float lifetime,AnimationState animation,bool upperLevel,float size,float fadeout,vf2d spd,Pixel col,float rotation,float rotationSpd,bool additiveBlending)
:Effect::Effect(pos,lifetime,animation,upperLevel,{size,size},fadeout,spd,col,rotation,rotationSpd,additiveBlending){ :Effect::Effect(pos,lifetime,animation,upperLevel,vf2d{size,size},fadeout,spd,col,rotation,rotationSpd,additiveBlending){
this->animation.AddState(animation,ANIMATION_DATA[animation]); this->animation.AddState(animation,ANIMATION_DATA[animation]);
} }

@ -19,15 +19,18 @@ struct Effect{
Animate2D::Frame GetFrame(); Animate2D::Frame GetFrame();
virtual void Draw(); virtual void Draw();
bool OnUpperLevel(); bool OnUpperLevel();
protected:
float original_fadeoutTime;
private: private:
Animate2D::Animation<AnimationState>animation; Animate2D::Animation<AnimationState>animation;
Animate2D::AnimationState internal_animState; Animate2D::AnimationState internal_animState;
float original_fadeoutTime;
bool upperLevel=false; bool upperLevel=false;
}; };
struct Meteor:Effect{ struct Meteor:Effect{
Meteor(vf2d pos,float lifetime,AnimationState animation,bool upperLevel,vf2d size={1,1},float fadeout=0.0f,vf2d spd={},Pixel col=WHITE,float rotation=0,float rotationSpd=0,bool additiveBlending=false); Meteor(vf2d pos,float lifetime,AnimationState animation,bool upperLevel,vf2d size={1,1},float fadeout=0.0f,vf2d spd={},Pixel col=WHITE,float rotation=0,float rotationSpd=0,bool additiveBlending=false);
float startLifetime=0;
bool shakeField=false;
bool Update(float fElapsedTime)override; bool Update(float fElapsedTime)override;
void Draw()override; void Draw()override;
}; };

@ -1,20 +1,38 @@
#include "Effect.h" #include "Effect.h"
#include "DEFINES.h" #include "DEFINES.h"
#include "Crawler.h" #include "Crawler.h"
#include "utils.h"
INCLUDE_game INCLUDE_game
Meteor::Meteor(vf2d pos, float lifetime, AnimationState animation, bool upperLevel, vf2d size, float fadeout, vf2d spd, Pixel col, float rotation, float rotationSpd, bool additiveBlending) Meteor::Meteor(vf2d pos, float lifetime, AnimationState animation, bool upperLevel, vf2d size, float fadeout, vf2d spd, Pixel col, float rotation, float rotationSpd, bool additiveBlending)
:Effect(pos,lifetime,animation,upperLevel,size,fadeout,spd,col,rotation,rotationSpd,additiveBlending){ :Effect(pos,lifetime,animation,upperLevel,size,fadeout,spd,col,rotation,rotationSpd,additiveBlending),startLifetime(lifetime){
} }
bool Meteor::Update(float fElapsedTime){ bool Meteor::Update(float fElapsedTime){
if(lifetime<=0&&!shakeField){
shakeField=true;
game->SetupWorldShake(2);
for(int i=0;i<360;i++){
float randomAngle=2*PI;
float randomRange=192*size.x*(1-util::random(0.25))*(1-util::random(0.25));
float randomColorTint=util::random(128);
game->AddEffect(std::make_unique<Effect>(pos+vf2d{cos(randomAngle),sin(randomAngle)}*randomRange,0,AnimationState::DOT_PARTICLE,OnUpperLevel(),vf2d{util::random(2),util::random(3)},util::random(3)+1,vf2d{util::random(4)-2,-util::random(4)},Pixel{255,uint8_t(randomColorTint),uint8_t(randomColorTint),uint8_t(util::random(128)+128)},0,0,true));
}
}
return Effect::Update(fElapsedTime); return Effect::Update(fElapsedTime);
} }
void Meteor::Draw(){ void Meteor::Draw(){
vf2d scale=vf2d{192,64}/3.f; if(lifetime>0){
vf2d centerPoint=pos-vf2d{game->GFX_Circle.Sprite()->width*scale.x/2,game->GFX_Circle.Sprite()->height*scale.y/2}; vf2d scale=vf2d{192,64}/3.f*(startLifetime+1-lifetime)*0.5;
game->view.DrawDecal(centerPoint,game->GFX_Circle.Decal(),scale,BLACK); vf2d centerPoint=pos-vf2d{game->GFX_Circle.Sprite()->width*scale.x/2,game->GFX_Circle.Sprite()->height*scale.y/2};
game->view.DrawDecal(centerPoint,game->GFX_Circle.Decal(),scale,{0,0,0,192});
}
vf2d meteorOffset=pos+vf2d{lifetime,-lifetime}*320-vf2d{0,GetFrame().GetSourceRect().size.y/2.f};
if(lifetime<=0){
meteorOffset=pos-vf2d{0,GetFrame().GetSourceRect().size.y/2.f};
}
game->view.DrawPartialRotatedDecal(meteorOffset,GetFrame().GetSourceImage()->Decal(),rotation,GetFrame().GetSourceRect().size/2,GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,size,{col.r,col.g,col.b,uint8_t(fadeout/original_fadeoutTime*255)});
} }

@ -305,25 +305,27 @@ void Player::Update(float fElapsedTime){
auto AllowedToCast=[&](Ability&ability){return !ability.precastInfo.precastTargetingRequired;}; auto AllowedToCast=[&](Ability&ability){return !ability.precastInfo.precastTargetingRequired;};
auto CheckAndPerformAbility=[&](Ability&ability,HWButton key){ auto CheckAndPerformAbility=[&](Ability&ability,HWButton key){
if(ability.cooldown==0&&GetMana()>=ability.manaCost){ if(ability.name!="???"){
if(key.bPressed||key.bReleased&&&ability==castPrepAbility&&GetState()==State::PREP_CAST){ if(ability.cooldown==0&&GetMana()>=ability.manaCost){
if(AllowedToCast(ability)&&ability.action({})){ if(key.bPressed||key.bReleased&&&ability==castPrepAbility&&GetState()==State::PREP_CAST){
ability.cooldown=ability.COOLDOWN_TIME; if(AllowedToCast(ability)&&ability.action({})){
mana-=ability.manaCost; ability.cooldown=ability.COOLDOWN_TIME;
}else mana-=ability.manaCost;
if(ability.precastInfo.precastTargetingRequired&&GetState()!=State::PREP_CAST){ }else
PrepareCast(ability); if(ability.precastInfo.precastTargetingRequired&&GetState()!=State::PREP_CAST){
PrepareCast(ability);
}
} }
} else
if(ability.cooldown==0&&GetMana()<ability.manaCost&&key.bPressed){
notEnoughManaDisplay={ability.name,1};
} }
} else
if(ability.cooldown==0&&GetMana()<ability.manaCost&&key.bPressed){
notEnoughManaDisplay={ability.name,1};
} }
}; };
CheckAndPerformAbility(GetAbility1(),game->GetKey(SHIFT)); CheckAndPerformAbility(GetAbility1(),game->GetKey(Crawler::KEY_ABILITY1));
CheckAndPerformAbility(GetAbility2(),game->GetKey(SPACE)); CheckAndPerformAbility(GetAbility2(),game->GetKey(Crawler::KEY_ABILITY2));
CheckAndPerformAbility(GetAbility3(),game->GetKey(CTRL)); CheckAndPerformAbility(GetAbility3(),game->GetKey(Crawler::KEY_ABILITY3));
CheckAndPerformAbility(GetAbility4(),game->GetKey(R)); CheckAndPerformAbility(GetAbility4(),game->GetKey(Crawler::KEY_ABILITY4));
CheckAndPerformAbility(GetRightClickAbility(),game->GetMouse(1)); CheckAndPerformAbility(GetRightClickAbility(),game->GetMouse(1));
if(GetState()==State::PREP_CAST){ if(GetState()==State::PREP_CAST){
@ -332,13 +334,13 @@ void Player::Update(float fElapsedTime){
CheckAbilityKeyReleasedAndCastSpell(rightClickAbility,game->GetMouse(1)) CheckAbilityKeyReleasedAndCastSpell(rightClickAbility,game->GetMouse(1))
else else
CheckAbilityKeyReleasedAndCastSpell(ability,game->GetKey(SHIFT)) CheckAbilityKeyReleasedAndCastSpell(ability,game->GetKey(Crawler::KEY_ABILITY1))
else else
CheckAbilityKeyReleasedAndCastSpell(ability2,game->GetKey(SPACE)) CheckAbilityKeyReleasedAndCastSpell(ability2,game->GetKey(Crawler::KEY_ABILITY2))
else else
CheckAbilityKeyReleasedAndCastSpell(ability3,game->GetKey(CTRL)) CheckAbilityKeyReleasedAndCastSpell(ability3,game->GetKey(Crawler::KEY_ABILITY3))
else else
CheckAbilityKeyReleasedAndCastSpell(ability4,game->GetKey(R)) CheckAbilityKeyReleasedAndCastSpell(ability4,game->GetKey(Crawler::KEY_ABILITY4))
} }
switch(GetState()){ switch(GetState()){

@ -121,7 +121,7 @@ void Wizard::InitializeClassAbilities(){
Wizard::ability3.action= Wizard::ability3.action=
[&](vf2d pos={}){ [&](vf2d pos={}){
CastSpell(Wizard::ability3); CastSpell(Wizard::ability3);
game->AddEffect(std::make_unique<Meteor>(pos,3,AnimationState::METEOR,OnUpperLevel(),vf2d{1,1},2)); game->AddEffect(std::make_unique<Meteor>(pos,3,AnimationState::METEOR,OnUpperLevel(),vf2d{1.75,1.75},2));
return true; return true;
}; };
#pragma endregion #pragma endregion

Loading…
Cancel
Save