mirror of
https://github.com/sigonasr2/hamster.git
synced 2026-10-16 09:13:34 -05:00
Add missing camera update call. Fix player flag being set on NPCs instead of the player. Add friction and movement.
This commit is contained in:
parent
cf7121701a
commit
7df7b5cbec
@ -59,10 +59,12 @@ Hamster::Hamster(const vf2d spawnPos,const std::string_view img,const PlayerCont
|
||||
void Hamster::UpdateHamsters(const float fElapsedTime){
|
||||
for(Hamster&h:HAMSTER_LIST){
|
||||
h.animations.UpdateState(h.internalAnimState,fElapsedTime);
|
||||
h.frictionEnabled=true;
|
||||
if(h.IsPlayerControlled){
|
||||
h.HandlePlayerControls();
|
||||
}
|
||||
h.TurnTowardsTargetDirection();
|
||||
h.MoveHamster();
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,9 +115,23 @@ void Hamster::HandlePlayerControls(){
|
||||
}
|
||||
if(aimingDir!=vf2d{}){
|
||||
targetRot=aimingDir.norm().polar().y;
|
||||
const vf2d currentVel{vel};
|
||||
vel=vf2d{std::min(maxSpd,currentVel.polar().x+(maxSpd*HamsterGame::Game().GetElapsedTime())/timeToMaxSpd),currentVel.polar().y}.cart();
|
||||
frictionEnabled=false;
|
||||
}
|
||||
}
|
||||
|
||||
void Hamster::TurnTowardsTargetDirection(){
|
||||
util::turn_towards_direction(rot,targetRot,turnSpd*HamsterGame::Game().GetElapsedTime());
|
||||
}
|
||||
|
||||
void Hamster::MoveHamster(){
|
||||
pos+=vel*HamsterGame::Game().GetElapsedTime();
|
||||
|
||||
#pragma region Handle Friction
|
||||
if(frictionEnabled){
|
||||
const vf2d currentVel{vel};
|
||||
vel=vf2d{std::max(0.f,currentVel.polar().x-friction*HamsterGame::Game().GetElapsedTime()),currentVel.polar().y}.cart();
|
||||
}
|
||||
#pragma endregion
|
||||
}
|
||||
@ -43,8 +43,8 @@ All rights reserved.
|
||||
|
||||
class Hamster{
|
||||
enum PlayerControlled{
|
||||
PLAYER_CONTROLLED,
|
||||
NPC,
|
||||
PLAYER_CONTROLLED=true,
|
||||
NPC=false,
|
||||
};
|
||||
|
||||
static std::vector<Hamster>HAMSTER_LIST;
|
||||
@ -60,6 +60,10 @@ class Hamster{
|
||||
float rot{};
|
||||
float targetRot{};
|
||||
float turnSpd{2.f*geom2d::pi};
|
||||
float maxSpd{128.f};
|
||||
float timeToMaxSpd{0.5f};
|
||||
float friction{400.f};
|
||||
bool frictionEnabled{false};
|
||||
std::string img;
|
||||
Animate2D::Animation<HamsterGame::AnimationState>animations;
|
||||
Animate2D::AnimationState internalAnimState;
|
||||
@ -75,4 +79,5 @@ public:
|
||||
const vf2d&GetPos()const;
|
||||
void HandlePlayerControls();
|
||||
void TurnTowardsTargetDirection();
|
||||
void MoveHamster();
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user