|
|
|
@ -16,18 +16,59 @@ enum AnimationState{ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct Player{ |
|
|
|
|
private: |
|
|
|
|
int hp=100,maxhp=hp; |
|
|
|
|
int atk=10; |
|
|
|
|
vf2d pos; |
|
|
|
|
float moveSpd; |
|
|
|
|
float moveSpd=1.0f; |
|
|
|
|
float size=1.0f; |
|
|
|
|
float attack_range=1.5f; |
|
|
|
|
AnimationState animState=AnimationState::IDLE_S; |
|
|
|
|
private: |
|
|
|
|
Animate2D::Animation<AnimationState>animation; |
|
|
|
|
Animate2D::AnimationState internal_animState; |
|
|
|
|
Key lastReleasedMovementKey; |
|
|
|
|
public: |
|
|
|
|
Player(){}; |
|
|
|
|
Player(vf2d pos,float moveSpd): |
|
|
|
|
pos(pos),moveSpd(moveSpd){ |
|
|
|
|
Player(vf2d pos): |
|
|
|
|
pos(pos){ |
|
|
|
|
}; |
|
|
|
|
void SetX(float x){ |
|
|
|
|
pos.x=x; |
|
|
|
|
}; |
|
|
|
|
void SetY(float y){ |
|
|
|
|
pos.y=y; |
|
|
|
|
} |
|
|
|
|
void SetPos(vf2d pos){ |
|
|
|
|
this->pos=pos; |
|
|
|
|
} |
|
|
|
|
vf2d&GetPos(){ |
|
|
|
|
return pos; |
|
|
|
|
} |
|
|
|
|
float GetX(){ |
|
|
|
|
return pos.x; |
|
|
|
|
} |
|
|
|
|
float GetY(){ |
|
|
|
|
return pos.y; |
|
|
|
|
} |
|
|
|
|
int GetHealth(){ |
|
|
|
|
return hp; |
|
|
|
|
} |
|
|
|
|
int GetMaxHealth(){ |
|
|
|
|
return maxhp; |
|
|
|
|
} |
|
|
|
|
int GetAttack(){ |
|
|
|
|
return atk; |
|
|
|
|
} |
|
|
|
|
float GetMoveSpdMult(){ |
|
|
|
|
return moveSpd; |
|
|
|
|
} |
|
|
|
|
float GetSizeMult(){ |
|
|
|
|
return size; |
|
|
|
|
} |
|
|
|
|
float GetAttackRangeMult(){ |
|
|
|
|
return attack_range; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Update(float fElapsedTime){ |
|
|
|
|
animation.UpdateState(internal_animState,fElapsedTime); |
|
|
|
|
} |
|
|
|
@ -55,7 +96,7 @@ class Crawler : public olc::PixelGameEngine |
|
|
|
|
const vi2d WORLD_SIZE={64,8}; |
|
|
|
|
Camera2D camera; |
|
|
|
|
TileTransformedView view; |
|
|
|
|
Player player=Player{{},100}; |
|
|
|
|
Player player=Player{{}}; |
|
|
|
|
Renderable GFX_Pl_sheet; |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
@ -70,7 +111,7 @@ public: |
|
|
|
|
//Initialize Camera.
|
|
|
|
|
camera=Camera2D{WINDOW_SIZE}; |
|
|
|
|
camera.SetMode(olc::utils::Camera2D::Mode::LazyFollow); |
|
|
|
|
camera.SetTarget(player.pos); |
|
|
|
|
camera.SetTarget(player.GetPos()); |
|
|
|
|
camera.SetWorldBoundary({0,0},WORLD_SIZE*24); |
|
|
|
|
camera.EnableWorldBoundary(true); |
|
|
|
|
|
|
|
|
@ -118,7 +159,7 @@ public: |
|
|
|
|
player.AddAnimation(IDLE_W,pl_idle_w); |
|
|
|
|
view=TileTransformedView{GetScreenSize(),{1,1}}; |
|
|
|
|
|
|
|
|
|
player.pos={4*24,4*24}; |
|
|
|
|
player.SetPos({4*24,4*24}); |
|
|
|
|
player.UpdateAnimation(IDLE_S); |
|
|
|
|
|
|
|
|
|
std::cout<<MONSTER_DATA[SLIME_BLUE].GetHealth()<<std::endl; |
|
|
|
@ -138,19 +179,19 @@ public: |
|
|
|
|
void HandleUserInput(float fElapsedTime){ |
|
|
|
|
bool setIdleAnimation=true; |
|
|
|
|
if(GetKey(RIGHT).bHeld){ |
|
|
|
|
if(player.pos.x+12+fElapsedTime*player.moveSpd<WORLD_SIZE.x*24){ |
|
|
|
|
player.pos.x+=fElapsedTime*player.moveSpd; |
|
|
|
|
if(player.GetPos().x+12+fElapsedTime*100*player.GetMoveSpdMult()<WORLD_SIZE.x*24){ |
|
|
|
|
player.SetX(player.GetX()+fElapsedTime*100*player.GetMoveSpdMult()); |
|
|
|
|
} else { |
|
|
|
|
player.pos.x=WORLD_SIZE.x*24-12; |
|
|
|
|
player.SetX(WORLD_SIZE.x*24-12); |
|
|
|
|
} |
|
|
|
|
player.UpdateAnimation(WALK_E); |
|
|
|
|
setIdleAnimation=false; |
|
|
|
|
} |
|
|
|
|
if(GetKey(LEFT).bHeld){ |
|
|
|
|
if(player.pos.x-12+fElapsedTime*player.moveSpd>0){ |
|
|
|
|
player.pos.x-=fElapsedTime*player.moveSpd; |
|
|
|
|
if(player.GetPos().x-12+fElapsedTime*100*player.GetMoveSpdMult()>0){ |
|
|
|
|
player.SetX(player.GetX()-fElapsedTime*100*player.GetMoveSpdMult()); |
|
|
|
|
} else { |
|
|
|
|
player.pos.x=12; |
|
|
|
|
player.SetX(12); |
|
|
|
|
} |
|
|
|
|
if(setIdleAnimation){ |
|
|
|
|
player.UpdateAnimation(WALK_W); |
|
|
|
@ -158,10 +199,10 @@ public: |
|
|
|
|
setIdleAnimation=false; |
|
|
|
|
} |
|
|
|
|
if(GetKey(UP).bHeld){ |
|
|
|
|
if(player.pos.y-12+fElapsedTime*player.moveSpd>0){ |
|
|
|
|
player.pos.y-=fElapsedTime*player.moveSpd; |
|
|
|
|
if(player.GetPos().y-12+fElapsedTime*100*player.GetMoveSpdMult()>0){ |
|
|
|
|
player.SetY(player.GetY()-fElapsedTime*100*player.GetMoveSpdMult()); |
|
|
|
|
} else { |
|
|
|
|
player.pos.y=12; |
|
|
|
|
player.SetY(12); |
|
|
|
|
} |
|
|
|
|
if(setIdleAnimation){ |
|
|
|
|
player.UpdateAnimation(WALK_N); |
|
|
|
@ -169,10 +210,10 @@ public: |
|
|
|
|
setIdleAnimation=false; |
|
|
|
|
} |
|
|
|
|
if(GetKey(DOWN).bHeld){ |
|
|
|
|
if(player.pos.y+12+fElapsedTime*player.moveSpd<WORLD_SIZE.y*24){ |
|
|
|
|
player.pos.y+=fElapsedTime*player.moveSpd; |
|
|
|
|
if(player.GetPos().y+12+fElapsedTime*100*player.GetMoveSpdMult()<WORLD_SIZE.y*24){ |
|
|
|
|
player.SetY(player.GetY()+fElapsedTime*100*player.GetMoveSpdMult()); |
|
|
|
|
} else { |
|
|
|
|
player.pos.y=WORLD_SIZE.y*24-12; |
|
|
|
|
player.SetY(WORLD_SIZE.y*24-12); |
|
|
|
|
} |
|
|
|
|
if(setIdleAnimation){ |
|
|
|
|
player.UpdateAnimation(WALK_S); |
|
|
|
@ -262,7 +303,7 @@ public: |
|
|
|
|
view.DrawRect(vi2d{x,y}*24,{24,24},VERY_DARK_GREY); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
view.DrawPartialDecal(player.pos-vi2d{12,12},player.GetFrame().GetSourceImage()->Decal(),player.GetFrame().GetSourceRect().pos,player.GetFrame().GetSourceRect().size); |
|
|
|
|
view.DrawPartialDecal(player.GetPos()-vi2d{12,12},player.GetFrame().GetSourceImage()->Decal(),player.GetFrame().GetSourceRect().pos,player.GetFrame().GetSourceRect().size); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|