Implemented blocking. Made player abilities dynamic instead of fixed for class expansion preparation.
This commit is contained in:
+42
-8
@@ -3,6 +3,7 @@
|
||||
#include "olcUTIL_Camera2D.h"
|
||||
#include "DamageNumber.h"
|
||||
#include "Bullet.h"
|
||||
#include "Ability.h"
|
||||
#include "DEFINES.h"
|
||||
|
||||
//192x192
|
||||
@@ -35,6 +36,7 @@ bool Crawler::OnUserCreate(){
|
||||
GFX_Effect_GroundSlam_Back.Load("assets/ground-slam-attack-back.png");
|
||||
GFX_Effect_GroundSlam_Front.Load("assets/ground-slam-attack-front.png");
|
||||
GFX_Heart.Load("assets/heart.png");
|
||||
GFX_BLOCK_BUBBLE.Load("assets/block.png");
|
||||
|
||||
//Animations
|
||||
InitializeAnimations();
|
||||
@@ -221,9 +223,9 @@ bool Crawler::DownReleased(){
|
||||
|
||||
void Crawler::HandleUserInput(float fElapsedTime){
|
||||
bool setIdleAnimation=true;
|
||||
if(GetKey(SPACE).bPressed&&player.GetState()==State::NORMAL&&player.GetGroundSlamCooldown()==0){
|
||||
if(GetKey(SPACE).bPressed&&player.GetAbility2Cooldown()==0){
|
||||
player.Spin(Player::GROUND_SLAM_SPIN_TIME,14*PI);
|
||||
player.iframe_time=Player::GROUND_SLAM_SPIN_TIME;
|
||||
player.iframe_time=Player::GROUND_SLAM_SPIN_TIME+0.1;
|
||||
}
|
||||
if(player.GetVelocity()==vf2d{0,0}){
|
||||
if(RightHeld()){
|
||||
@@ -361,6 +363,10 @@ void Crawler::HandleUserInput(float fElapsedTime){
|
||||
}
|
||||
}
|
||||
|
||||
if(player.GetState()==State::BLOCK){
|
||||
setIdleAnimation=false;
|
||||
}
|
||||
|
||||
if(setIdleAnimation){
|
||||
switch(player.GetLastReleasedMovementKey()){
|
||||
case UP:{
|
||||
@@ -464,6 +470,9 @@ void Crawler::RenderWorld(float fElapsedTime){
|
||||
m.Draw();
|
||||
}
|
||||
view.DrawPartialRotatedDecal(player.GetPos()+vf2d{0,-player.GetZ()},player.GetFrame().GetSourceImage()->Decal(),player.GetSpinAngle(),{12,12},player.GetFrame().GetSourceRect().pos,player.GetFrame().GetSourceRect().size,vf2d(player.GetSizeMult(),player.GetSizeMult()));
|
||||
if(player.GetState()==State::BLOCK){
|
||||
view.DrawDecal(player.GetPos()-vf2d{12,12},GFX_BLOCK_BUBBLE.Decal());
|
||||
}
|
||||
for(Monster&m:monstersAfter){
|
||||
m.Draw();
|
||||
}
|
||||
@@ -497,12 +506,37 @@ Player&Crawler::GetPlayer(){
|
||||
}
|
||||
|
||||
void Crawler::RenderHud(){
|
||||
if(player.GetGroundSlamCooldown()>0){
|
||||
FillRectDecal({10,ScreenHeight()-22.f},{64,6},BLACK);
|
||||
FillRectDecal({11,ScreenHeight()-21.f},{62,4},DARK_GREY);
|
||||
GradientFillRectDecal({10,ScreenHeight()-22.f},{(player.GetGroundSlamCooldown()/Player::GROUND_SLAM_COOLDOWN)*64,6},VERY_DARK_RED,VERY_DARK_RED,DARK_RED,DARK_RED);
|
||||
DrawRotatedStringPropDecal(vf2d{8,ScreenHeight()-20.f}+vf2d{1,1},"G R O U N D S L A M",-PI/64,{0,0},BLACK,{0.4,0.4});
|
||||
DrawRotatedStringPropDecal({8,ScreenHeight()-20.f},"G R O U N D S L A M",-PI/64,{0,0},WHITE,{0.4,0.4});
|
||||
const std::function<std::string(std::string)>capitalize=[](std::string name)->std::string{
|
||||
std::string newName="";
|
||||
for(int i=0;i<name.length();i++){
|
||||
newName.append(1,name[i]>='a'?name[i]-32:name[i]);
|
||||
newName.append(1,' ');
|
||||
}
|
||||
return newName;
|
||||
};
|
||||
std::vector<Ability>cooldowns{
|
||||
player.rightClickAbility,
|
||||
player.ability1,
|
||||
player.ability2,
|
||||
player.ability3
|
||||
};
|
||||
std::vector<Ability>activeCooldowns;
|
||||
std::copy_if(cooldowns.begin(),cooldowns.end(),std::back_inserter(activeCooldowns),[](Ability a){
|
||||
return a.cooldown>0;
|
||||
});
|
||||
std::sort(activeCooldowns.begin(),activeCooldowns.end(),[](Ability&a1,Ability&a2){
|
||||
return a1.cooldown<a2.cooldown;
|
||||
});
|
||||
int offset=6*activeCooldowns.size();
|
||||
for(Ability&a:activeCooldowns){
|
||||
if(a.cooldown>0){
|
||||
FillRectDecal(vf2d{10,ScreenHeight()-22.f}-vf2d{0,float(offset)},{64,6},BLACK);
|
||||
FillRectDecal(vf2d{11,ScreenHeight()-21.f}-vf2d{0,float(offset)},{62,4},DARK_GREY);
|
||||
GradientFillRectDecal(vf2d{10,ScreenHeight()-22.f}-vf2d{0,float(offset)},{(a.cooldown/a.COOLDOWN_TIME)*64,6},a.barColor1,a.barColor1,a.barColor2,a.barColor2);
|
||||
DrawRotatedStringPropDecal(vf2d{8,ScreenHeight()-20.f}+vf2d{1,1}-vf2d{0,float(offset)},capitalize(a.name),-PI/64,{0,0},BLACK,{0.4,0.4});
|
||||
DrawRotatedStringPropDecal(vf2d{8,ScreenHeight()-20.f}-vf2d{0,float(offset)},capitalize(a.name),-PI/64,{0,0},WHITE,{0.4,0.4});
|
||||
}
|
||||
offset-=6;
|
||||
}
|
||||
DrawDecal({2,2},GFX_Heart.Decal());
|
||||
std::string text=player.GetHealth()>0?std::to_string(player.GetHealth()):"X";
|
||||
|
||||
Reference in New Issue
Block a user