diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 8dd18b74..fac4e2df 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -29,6 +29,11 @@ std::vectorDAMAGENUMBER_LIST; std::vector>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){ - worldShakeVel.x*=-1; - } - if(rand()%2==0){ - worldShakeVel.y*=-1; - } + lastWorldShakeAdjust=0.02; + worldShakeVel.x*=-1; + 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); diff --git a/Crawler/Crawler.h b/Crawler/Crawler.h index 7bf0c2b9..3a79c183 100644 --- a/Crawler/Crawler.h +++ b/Crawler/Crawler.h @@ -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>foregroundEffects,backgroundEffects; std::mapMAP_DATA; diff --git a/Crawler/Effect.cpp b/Crawler/Effect.cpp index 17b8e57e..8a412e7b 100644 --- a/Crawler/Effect.cpp +++ b/Crawler/Effect.cpp @@ -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]); } diff --git a/Crawler/Effect.h b/Crawler/Effect.h index f8595402..dbbaeadc 100644 --- a/Crawler/Effect.h +++ b/Crawler/Effect.h @@ -19,15 +19,18 @@ struct Effect{ Animate2D::Frame GetFrame(); virtual void Draw(); bool OnUpperLevel(); +protected: + float original_fadeoutTime; private: Animate2D::Animationanimation; 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; }; \ No newline at end of file diff --git a/Crawler/Meteor.cpp b/Crawler/Meteor.cpp index f145e548..78b36514 100644 --- a/Crawler/Meteor.cpp +++ b/Crawler/Meteor.cpp @@ -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(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; - 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); + 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,{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)}); } \ No newline at end of file diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index 0b330f41..6e02b15c 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -305,25 +305,27 @@ void Player::Update(float fElapsedTime){ auto AllowedToCast=[&](Ability&ability){return !ability.precastInfo.precastTargetingRequired;}; auto CheckAndPerformAbility=[&](Ability&ability,HWButton key){ - if(ability.cooldown==0&&GetMana()>=ability.manaCost){ - if(key.bPressed||key.bReleased&&&ability==castPrepAbility&&GetState()==State::PREP_CAST){ - if(AllowedToCast(ability)&&ability.action({})){ - ability.cooldown=ability.COOLDOWN_TIME; - mana-=ability.manaCost; - }else - if(ability.precastInfo.precastTargetingRequired&&GetState()!=State::PREP_CAST){ - PrepareCast(ability); + 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({})){ + ability.cooldown=ability.COOLDOWN_TIME; + mana-=ability.manaCost; + }else + if(ability.precastInfo.precastTargetingRequired&&GetState()!=State::PREP_CAST){ + PrepareCast(ability); + } } + } else + if(ability.cooldown==0&&GetMana()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()){ diff --git a/Crawler/Wizard.cpp b/Crawler/Wizard.cpp index 19cb133f..b8882156 100644 --- a/Crawler/Wizard.cpp +++ b/Crawler/Wizard.cpp @@ -121,7 +121,7 @@ void Wizard::InitializeClassAbilities(){ Wizard::ability3.action= [&](vf2d pos={}){ CastSpell(Wizard::ability3); - game->AddEffect(std::make_unique(pos,3,AnimationState::METEOR,OnUpperLevel(),vf2d{1,1},2)); + game->AddEffect(std::make_unique(pos,3,AnimationState::METEOR,OnUpperLevel(),vf2d{1.75,1.75},2)); return true; }; #pragma endregion