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. 19
      Crawler/Crawler.cpp
  2. 4
      Crawler/Crawler.h
  3. 2
      Crawler/Effect.cpp
  4. 5
      Crawler/Effect.h
  5. 24
      Crawler/Meteor.cpp
  6. 18
      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;
Crawler*game;
Key Crawler::KEY_ABILITY1=Q;
Key Crawler::KEY_ABILITY2=E;
Key Crawler::KEY_ABILITY3=R;
Key Crawler::KEY_ABILITY4=F;
Crawler::Crawler()
{
sAppName = "Crawler Concept";
@ -309,16 +314,11 @@ void Crawler::UpdateCamera(float fElapsedTime){
lastWorldShakeAdjust=std::max(0.f,lastWorldShakeAdjust-fElapsedTime);
if(worldShakeTime-fElapsedTime>0){
if(lastWorldShakeAdjust==0){
lastWorldShakeAdjust=util::random(0.04)+0.01;
worldShakeVel={util::random(200)+100,util::random(200)+100};
if(rand()%2==0){
lastWorldShakeAdjust=0.02;
worldShakeVel.x*=-1;
}
if(rand()%2==0){
worldShakeVel.y*=-1;
}
}
worldShake+=worldShakeVel*fElapsedTime;
worldShake=player->GetPos()+worldShakeVel*fElapsedTime;
} else {
camera.SetTarget(player->GetPos());
}
@ -568,7 +568,9 @@ void Crawler::RenderWorld(float fElapsedTime){
}
if(player->GetState()==State::PREP_CAST){
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
for(TileGroup&group:foregroundTileGroups){
@ -757,6 +759,7 @@ vf2d Crawler::GetWorldMousePos(){
}
void Crawler::SetupWorldShake(float duration){
worldShakeVel={750,-750};
worldShakeTime=duration;
worldShake=player->GetPos();
camera.SetTarget(worldShake);

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

@ -6,7 +6,7 @@ INCLUDE_ANIMATION_DATA
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(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]);
}

@ -19,15 +19,18 @@ struct Effect{
Animate2D::Frame GetFrame();
virtual void Draw();
bool OnUpperLevel();
protected:
float original_fadeoutTime;
private:
Animate2D::Animation<AnimationState>animation;
Animate2D::AnimationState internal_animState;
float original_fadeoutTime;
bool upperLevel=false;
};
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);
float startLifetime=0;
bool shakeField=false;
bool Update(float fElapsedTime)override;
void Draw()override;
};

@ -1,20 +1,38 @@
#include "Effect.h"
#include "DEFINES.h"
#include "Crawler.h"
#include "utils.h"
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)
: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){
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);
}
void Meteor::Draw(){
vf2d scale=vf2d{192,64}/3.f;
if(lifetime>0){
vf2d scale=vf2d{192,64}/3.f*(startLifetime+1-lifetime)*0.5;
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,BLACK);
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,6 +305,7 @@ void Player::Update(float fElapsedTime){
auto AllowedToCast=[&](Ability&ability){return !ability.precastInfo.precastTargetingRequired;};
auto CheckAndPerformAbility=[&](Ability&ability,HWButton key){
if(ability.name!="???"){
if(ability.cooldown==0&&GetMana()>=ability.manaCost){
if(key.bPressed||key.bReleased&&&ability==castPrepAbility&&GetState()==State::PREP_CAST){
if(AllowedToCast(ability)&&ability.action({})){
@ -319,11 +320,12 @@ void Player::Update(float fElapsedTime){
if(ability.cooldown==0&&GetMana()<ability.manaCost&&key.bPressed){
notEnoughManaDisplay={ability.name,1};
}
}
};
CheckAndPerformAbility(GetAbility1(),game->GetKey(SHIFT));
CheckAndPerformAbility(GetAbility2(),game->GetKey(SPACE));
CheckAndPerformAbility(GetAbility3(),game->GetKey(CTRL));
CheckAndPerformAbility(GetAbility4(),game->GetKey(R));
CheckAndPerformAbility(GetAbility1(),game->GetKey(Crawler::KEY_ABILITY1));
CheckAndPerformAbility(GetAbility2(),game->GetKey(Crawler::KEY_ABILITY2));
CheckAndPerformAbility(GetAbility3(),game->GetKey(Crawler::KEY_ABILITY3));
CheckAndPerformAbility(GetAbility4(),game->GetKey(Crawler::KEY_ABILITY4));
CheckAndPerformAbility(GetRightClickAbility(),game->GetMouse(1));
if(GetState()==State::PREP_CAST){
@ -332,13 +334,13 @@ void Player::Update(float fElapsedTime){
CheckAbilityKeyReleasedAndCastSpell(rightClickAbility,game->GetMouse(1))
else
CheckAbilityKeyReleasedAndCastSpell(ability,game->GetKey(SHIFT))
CheckAbilityKeyReleasedAndCastSpell(ability,game->GetKey(Crawler::KEY_ABILITY1))
else
CheckAbilityKeyReleasedAndCastSpell(ability2,game->GetKey(SPACE))
CheckAbilityKeyReleasedAndCastSpell(ability2,game->GetKey(Crawler::KEY_ABILITY2))
else
CheckAbilityKeyReleasedAndCastSpell(ability3,game->GetKey(CTRL))
CheckAbilityKeyReleasedAndCastSpell(ability3,game->GetKey(Crawler::KEY_ABILITY3))
else
CheckAbilityKeyReleasedAndCastSpell(ability4,game->GetKey(R))
CheckAbilityKeyReleasedAndCastSpell(ability4,game->GetKey(Crawler::KEY_ABILITY4))
}
switch(GetState()){

@ -121,7 +121,7 @@ void Wizard::InitializeClassAbilities(){
Wizard::ability3.action=
[&](vf2d pos={}){
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;
};
#pragma endregion

Loading…
Cancel
Save