Add Spinning attack animation

pull/28/head
sigonasr2 1 year ago
parent 306473ff9a
commit c680d52431
  1. 9
      Crawler/Crawler.cpp
  2. 2
      Crawler/Crawler.vcxproj
  3. 6
      Crawler/Crawler.vcxproj.filters
  4. 53
      Crawler/Player.cpp
  5. 10
      Crawler/Player.h
  6. 6
      Crawler/State.h
  7. 4
      Crawler/olcPixelGameEngine.h
  8. 6711
      Crawler/pixelGameEngine.h

@ -115,11 +115,8 @@ void Crawler::InitializeAnimations(){
void Crawler::HandleUserInput(float fElapsedTime){
bool setIdleAnimation=true;
if(GetKey(PGUP).bHeld){
player.SetZ(player.GetZ()+5*fElapsedTime);
}
if(GetKey(PGDN).bHeld){
player.SetZ(std::max(0.f,player.GetZ()-5*fElapsedTime));
if(GetKey(SPACE).bPressed){
player.Spin(Player::GROUND_SLAM_SPIN_TIME,14*PI);
}
if(GetKey(RIGHT).bHeld){
if(player.GetPos().x+12+fElapsedTime*100*player.GetMoveSpdMult()<WORLD_SIZE.x*24){
@ -262,7 +259,7 @@ void Crawler::RenderWorld(float fElapsedTime){
for(Monster&m:monstersBefore){
view.DrawPartialDecal(m.GetPos()-vf2d{12,12}*m.GetSizeMult(),m.GetFrame().GetSourceImage()->Decal(),m.GetFrame().GetSourceRect().pos,m.GetFrame().GetSourceRect().size,vf2d(m.GetSizeMult(),m.GetSizeMult()));
}
view.DrawPartialDecal(player.GetPos()-vf2d{12,12}*player.GetSizeMult()+vf2d{0,-player.GetZ()},player.GetFrame().GetSourceImage()->Decal(),player.GetFrame().GetSourceRect().pos,player.GetFrame().GetSourceRect().size,vf2d(player.GetSizeMult(),player.GetSizeMult()));
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()));
for(Monster&m:monstersAfter){
view.DrawPartialDecal(m.GetPos()-vf2d{12,12}*m.GetSizeMult(),m.GetFrame().GetSourceImage()->Decal(),m.GetFrame().GetSourceRect().pos,m.GetFrame().GetSourceRect().size,vf2d(m.GetSizeMult(),m.GetSizeMult()));
}

@ -139,10 +139,12 @@
<ClInclude Include="olcUTIL_Camera2D.h" />
<ClInclude Include="olcUTIL_Geometry2D.h" />
<ClInclude Include="Player.h" />
<ClInclude Include="State.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Crawler.cpp" />
<ClCompile Include="DamageNumber.cpp" />
<ClCompile Include="pixelGameEngine.cpp" />
<ClCompile Include="Player.cpp" />
<ClCompile Include="Monster.cpp" />
<ClCompile Include="MonsterData.cpp" />

@ -45,6 +45,9 @@
<ClInclude Include="DamageNumber.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="State.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Player.cpp">
@ -62,5 +65,8 @@
<ClCompile Include="DamageNumber.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pixelGameEngine.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

@ -11,6 +11,8 @@ extern std::vector<MonsterSpawner>SPAWNER_LIST;
extern std::vector<DamageNumber>DAMAGENUMBER_LIST;
extern Crawler*game;
const float Player::GROUND_SLAM_SPIN_TIME=0.6f;
Player::Player(){
}
@ -74,8 +76,52 @@ float Player::GetAttackRangeMult(){
return attack_range;
}
float Player::GetSpinAngle(){
return spin_angle;
}
State Player::GetState(){
return state;
}
void Player::Update(float fElapsedTime){
attack_cooldown_timer=std::max(0.f,attack_cooldown_timer-fElapsedTime);
switch(state){
case SPIN:{
switch(lastReleasedMovementKey){
case UP:{
if(lastAnimationFlip==0){
lastAnimationFlip=0.03;
lastReleasedMovementKey=DOWN;
animation.ChangeState(internal_animState,AnimationState::WALK_S);
}
}break;
case DOWN:{
if(lastAnimationFlip==0){
lastAnimationFlip=0.03;
lastReleasedMovementKey=UP;
animation.ChangeState(internal_animState,AnimationState::WALK_N);
}
}break;
}
if(lastReleasedMovementKey==DOWN||lastReleasedMovementKey==RIGHT){
spin_angle-=spin_spd*fElapsedTime;
} else {
spin_angle+=spin_spd*fElapsedTime;
}
if(spin_attack_timer>0){
z=50*sin(3.3*(GROUND_SLAM_SPIN_TIME-spin_attack_timer)/GROUND_SLAM_SPIN_TIME);
spin_attack_timer=std::max(0.f,spin_attack_timer-fElapsedTime);
} else {
state=NORMAL;
spin_angle=0;
z=0;
}
}break;
default:{
//Update animations normally.
}
}
animation.UpdateState(internal_animState,fElapsedTime);
if(attack_cooldown_timer==0&&game->GetMouse(0).bHeld){
bool attack=false;
@ -123,4 +169,11 @@ void Player::Moved(){
spawner.SetTriggered(true);
}
}
}
void Player::Spin(float duration,float spinSpd){
state=State::SPIN;
spin_attack_timer=duration;
spin_spd=spinSpd;
spin_angle=0;
}

@ -2,6 +2,7 @@
#include "olcUTIL_Animate2D.h"
#include "Animation.h"
#include "Monster.h"
#include "State.h"
struct Player{
private:
@ -14,12 +15,18 @@ private:
float attack_range=1.5f;
const float ATTACK_COOLDOWN=0.75f;
float attack_cooldown_timer=0;
float spin_attack_timer=0;
float spin_spd=0;
float spin_angle=0;
float lastAnimationFlip=0;
State state;
Animate2D::Animation<AnimationState>animation;
Animate2D::AnimationState internal_animState;
Key lastReleasedMovementKey;
public:
Player();
Player(vf2d pos);
const static float GROUND_SLAM_SPIN_TIME;
void SetX(float x);
void SetY(float y);
void SetZ(float z);
@ -34,9 +41,12 @@ public:
float GetMoveSpdMult();
float GetSizeMult();
float GetAttackRangeMult();
float GetSpinAngle();
State GetState();
void Hurt(int damage);
void Spin(float duration,float spinSpd);
void Update(float fElapsedTime);
void AddAnimation(AnimationState state);
void UpdateAnimation(AnimationState animState);

@ -0,0 +1,6 @@
#pragma once
enum State{
NORMAL,
SPIN
};

@ -6694,4 +6694,6 @@ namespace olc
// | END OF OLC_PGE_APPLICATION |
// O------------------------------------------------------------------------------O
using namespace olc;
using namespace olc;
#define PI 3.14159

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save