28 #ifndef GAME_PLAYER_MOVE_STATES_H 29 #define GAME_PLAYER_MOVE_STATES_H 37 iPlayerMoveState::iPlayerMoveState(
cPlayer *apPlayer,
cInit *apInit) {
41 mpGameConfig = mpInit->mpGameConfig;
42 mpHeadMove = mpPlayer->GetHeadMove();
45 mfForwardSpeed = 3.0f;
46 mfBackwardSpeed = 1.5f;
47 mfSidewaySpeed = 2.0f;
50 mfForwardDeacc = 12.0f;
52 mfSidewayDeacc = 12.0f;
57 mfMaxHeadMove = 0.05f;
58 mfMinHeadMove = -0.06f;
59 mfHeadMoveSpeed = 0.38f;
60 mfHeadMoveBackSpeed = 0.23f;
63 mfHeightAddSpeed = 1.5f;
73 void iPlayerMoveState::SetupBody() {
74 iCharacterBody *pCharBody = mpPlayer->GetCharacterBody();
75 float fMul = mpPlayer->GetSpeedMul() * mpPlayer->GetHealthSpeedMul();
77 pCharBody->SetMaxPositiveMoveSpeed(eCharDir_Forward, mfForwardSpeed * fMul);
78 pCharBody->SetMaxNegativeMoveSpeed(eCharDir_Forward, -mfBackwardSpeed * fMul);
80 pCharBody->SetMaxPositiveMoveSpeed(eCharDir_Right, mfSidewaySpeed * fMul);
81 pCharBody->SetMaxNegativeMoveSpeed(eCharDir_Right, -mfSidewaySpeed * fMul);
83 pCharBody->SetMoveAcc(eCharDir_Forward, mfForwardAcc);
84 pCharBody->SetMoveDeacc(eCharDir_Forward, mfForwardDeacc);
85 pCharBody->SetMoveAcc(eCharDir_Right, mfSidewayAcc);
86 pCharBody->SetMoveDeacc(eCharDir_Right, mfSidewayDeacc);
91 apPrevState->LeaveState(apPrevState);
92 apPrevState->mbActive =
false;
95 EnterState(apPrevState);
100 mpHeadMove->mfMaxHeadMove = mfMaxHeadMove;
101 mpHeadMove->mfMinHeadMove = mfMinHeadMove;
102 mpHeadMove->mfHeadMoveSpeed = mfHeadMoveSpeed;
103 mpHeadMove->mfHeadMoveBackSpeed = mfHeadMoveBackSpeed;
104 mpHeadMove->mfFootStepMul = mfFootStepMul;
107 void iPlayerMoveState::Start() {
108 if (mbActive ==
false) {
112 iCharacterBody *pCharBody = mpPlayer->GetCharacterBody();
113 float fMul = mpPlayer->GetSpeedMul();
115 pCharBody->SetMaxPositiveMoveSpeed(eCharDir_Forward, mfForwardSpeed * fMul);
116 pCharBody->SetMaxNegativeMoveSpeed(eCharDir_Forward, -mfBackwardSpeed * fMul);
118 pCharBody->SetMaxPositiveMoveSpeed(eCharDir_Right, mfSidewaySpeed * fMul);
119 pCharBody->SetMaxNegativeMoveSpeed(eCharDir_Right, -mfSidewaySpeed * fMul);
121 pCharBody->SetMoveAcc(eCharDir_Forward, mfForwardAcc);
122 pCharBody->SetMoveDeacc(eCharDir_Forward, mfForwardDeacc);
123 pCharBody->SetMoveAcc(eCharDir_Right, mfSidewayAcc);
124 pCharBody->SetMoveDeacc(eCharDir_Right, mfSidewayDeacc);
126 mpHeadMove->mfMaxHeadMove = mfMaxHeadMove;
127 mpHeadMove->mfMinHeadMove = mfMinHeadMove;
128 mpHeadMove->mfHeadMoveSpeed = mfHeadMoveSpeed;
129 mpHeadMove->mfHeadMoveBackSpeed = mfHeadMoveBackSpeed;
130 mpHeadMove->mfFootStepMul = mfFootStepMul;
136 void iPlayerMoveState::Stop() {
142 void iPlayerMoveState::Update(
float afTimeStep) {
144 float fPlayerHeightAdd = mpPlayer->GetHeightAdd();
145 if (fPlayerHeightAdd < mfHeightAdd) {
146 fPlayerHeightAdd += mfHeightAddSpeed * afTimeStep;
147 if (fPlayerHeightAdd > mfHeightAdd)
148 fPlayerHeightAdd = mfHeightAdd;
151 if (fPlayerHeightAdd > mfHeightAdd) {
152 fPlayerHeightAdd -= mfHeightAddSpeed * afTimeStep;
153 if (fPlayerHeightAdd < mfHeightAdd)
154 fPlayerHeightAdd = mfHeightAdd;
156 mpPlayer->SetHeightAdd(fPlayerHeightAdd);
158 OnUpdate(afTimeStep);
168 mfForwardSpeed = mpGameConfig->GetFloat(
"Movement_Walk",
"ForwardSpeed", 0);
169 mfBackwardSpeed = mpGameConfig->GetFloat(
"Movement_Walk",
"BackwardSpeed", 0);
170 mfSidewaySpeed = mpGameConfig->GetFloat(
"Movement_Walk",
"SidewaySpeed", 0);
172 mfForwardAcc = mpGameConfig->GetFloat(
"Movement_Walk",
"ForwardAcc", 0);
173 mfForwardDeacc = mpGameConfig->GetFloat(
"Movement_Walk",
"ForwardDeacc", 0);
174 mfSidewayAcc = mpGameConfig->GetFloat(
"Movement_Walk",
"SidewayAcc", 0);
175 mfSidewayDeacc = mpGameConfig->GetFloat(
"Movement_Walk",
"SidewayDeacc", 0);
178 mfMaxHeadMove = mpGameConfig->GetFloat(
"Movement_Walk",
"MaxHeadMove", 0);
179 mfMinHeadMove = mpGameConfig->GetFloat(
"Movement_Walk",
"MinHeadMove", 0);
180 mfHeadMoveSpeed = mpGameConfig->GetFloat(
"Movement_Walk",
"HeadMoveSpeed", 0);
181 mfHeadMoveBackSpeed = 0.23f;
184 mfFootStepMul = 1.0f;
188 mType = ePlayerMoveState_Walk;
199 mfForwardSpeed = mpGameConfig->GetFloat(
"Movement_Run",
"ForwardSpeed", 0);
200 mfBackwardSpeed = mpGameConfig->GetFloat(
"Movement_Run",
"BackwardSpeed", 0);
201 mfSidewaySpeed = mpGameConfig->GetFloat(
"Movement_Run",
"SidewaySpeed", 0);
203 mfForwardAcc = mpGameConfig->GetFloat(
"Movement_Run",
"ForwardAcc", 0);
204 mfForwardDeacc = mpGameConfig->GetFloat(
"Movement_Run",
"ForwardDeacc", 0);
205 mfSidewayAcc = mpGameConfig->GetFloat(
"Movement_Run",
"SidewayAcc", 0);
206 mfSidewayDeacc = mpGameConfig->GetFloat(
"Movement_Run",
"SidewayDeacc", 0);
209 mfMaxHeadMove = mpGameConfig->GetFloat(
"Movement_Run",
"MaxHeadMove", 0);
210 mfMinHeadMove = mpGameConfig->GetFloat(
"Movement_Run",
"MinHeadMove", 0);
211 mfHeadMoveSpeed = mpGameConfig->GetFloat(
"Movement_Run",
"HeadMoveSpeed", 0);
212 mfHeadMoveBackSpeed = 0.23f;
215 mfFootStepMul = 1.0f;
219 mType = ePlayerMoveState_Run;
230 mfForwardSpeed = 0.0f;
231 mfBackwardSpeed = 0.0f;
232 mfSidewaySpeed = 0.0f;
235 mfForwardDeacc = 6.0f;
237 mfSidewayDeacc = 6.0f;
240 mfMaxHeadMove = 0.03f;
241 mfMinHeadMove = -0.03f;
242 mfHeadMoveSpeed = 0.12f;
243 mfHeadMoveBackSpeed = 0.23f;
246 mfFootStepMul = 0.6f;
250 mType = ePlayerMoveState_Still;
255 mfHeightAdd = apPrevState->mfHeightAdd;
256 mfHeightAddSpeed = apPrevState->mfHeightAddSpeed;
272 float mfDefaultFowardSpeed;
273 float mfDefaultSidewaySpeed;
276 mfForwardSpeed = mpGameConfig->GetFloat(
"Movement_Jump",
"ForwardSpeed", 0);
277 mfDefaultFowardSpeed = mfForwardSpeed;
278 mfBackwardSpeed = mpGameConfig->GetFloat(
"Movement_Jump",
"BackwardSpeed", 0);
279 mfSidewaySpeed = mpGameConfig->GetFloat(
"Movement_Jump",
"SidewaySpeed", 0);
280 mfDefaultSidewaySpeed = mfSidewaySpeed;
282 mfForwardAcc = mpGameConfig->GetFloat(
"Movement_Jump",
"ForwardAcc", 0);
283 mfForwardDeacc = mpGameConfig->GetFloat(
"Movement_Jump",
"ForwardDeacc", 0);
284 mfSidewayAcc = mpGameConfig->GetFloat(
"Movement_Jump",
"SidewayAcc", 0);
285 mfSidewayDeacc = mpGameConfig->GetFloat(
"Movement_Jump",
"SidewayDeacc", 0);
288 mfMaxHeadMove = 0.00f;
289 mfMinHeadMove = 0.00f;
290 mfHeadMoveSpeed = 0.0f;
291 mfHeadMoveBackSpeed = 0.33f;
297 mfFootStepMul = 0.0f;
301 mfStartForce = mpInit->mpGameConfig->GetFloat(
"Player",
"JumpStartForce", 1);
303 mType = ePlayerMoveState_Jump;
307 iCharacterBody *pBody = mpPlayer->GetCharacterBody();
310 mPrevMoveState = apPrevState->mType;
312 mPrevMoveState = ePlayerMoveState_Walk;
314 float fForce = mfStartForce;
315 if (mPrevMoveState == ePlayerMoveState_Crouch) {
317 mfForwardSpeed = mfDefaultFowardSpeed * 0.6f;
318 mfSidewaySpeed = mfDefaultSidewaySpeed * 0.6f;
320 mfForwardSpeed = mfDefaultFowardSpeed;
321 mfSidewaySpeed = mfDefaultSidewaySpeed;
326 cVector3f vForward = pBody->GetMoveMatrix().GetForward() * -1.0f;
327 cVector3f vRight = pBody->GetMoveMatrix().GetRight();
329 vVel += vForward * pBody->GetMoveSpeed(eCharDir_Forward);
330 vVel += vRight * pBody->GetMoveSpeed(eCharDir_Right);
332 pBody->AddForceVelocity(vVel);
334 pBody->SetMoveSpeed(eCharDir_Forward, 0);
335 pBody->SetMoveSpeed(eCharDir_Right, 0);
338 pBody->AddForce(cVector3f(0, fForce * mpPlayer->GetDefaultMass(), 0));
340 mbFirstUpdate =
true;
343 if (mPrevMoveState == ePlayerMoveState_Still || mPrevMoveState == ePlayerMoveState_Walk) {
344 mfMaxForward = mpPlayer->GetMoveStateData(ePlayerMoveState_Walk)->mfForwardSpeed;
345 mfMaxSide = mpPlayer->GetMoveStateData(ePlayerMoveState_Walk)->mfSidewaySpeed;
347 mfMaxForward = apPrevState->mfForwardSpeed;
348 mfMaxSide = apPrevState->mfSidewaySpeed;
353 iCharacterBody *pBody = mpPlayer->GetCharacterBody();
355 pBody->AddForceVelocity(pBody->GetForceVelocity() * -0.7f);
358 void OnUpdate(
float afTimeStep) {
359 iCharacterBody *pBody = mpPlayer->GetCharacterBody();
362 mbFirstUpdate =
false;
367 cVector3f vForceVel = pBody->GetForceVelocity();
368 float fSpeed = vForceVel.Length();
370 if (fSpeed > mfMaxForward) {
373 float fForwardSpeed = pBody->GetMoveSpeed(eCharDir_Forward);
382 pBody->SetMoveSpeed(eCharDir_Forward, fForwardSpeed);
388 if (mpPlayer->GetJumpButtonDown() &&
389 mpPlayer->GetJumpCount() < mpPlayer->GetMaxJumpCount()) {
390 float fMul = 0.4f + 0.5f * (1 - mpPlayer->GetJumpCount() / mpPlayer->GetMaxJumpCount());
392 pBody->AddForce(cVector3f(0, -pBody->GetCustomGravity().y * pBody->GetMass() * fMul, 0));
393 }
else if (pBody->GetForceVelocity().y > 0) {
395 pBody->AddForce(cVector3f(0, -20.0f * pBody->GetMass(), 0));
399 if (pBody->IsOnGround() && pBody->GetForceVelocity().y == 0) {
400 mpPlayer->ChangeMoveState(mPrevMoveState);
401 }
else if (mpPlayer->GetLandedFromJump()) {
402 mpPlayer->SetLandedFromJump(
false);
403 mpPlayer->ChangeMoveState(mPrevMoveState);
417 mfForwardSpeed = mpGameConfig->GetFloat(
"Movement_Crouch",
"ForwardSpeed", 0);
418 mfBackwardSpeed = mpGameConfig->GetFloat(
"Movement_Crouch",
"BackwardSpeed", 0);
419 mfSidewaySpeed = mpGameConfig->GetFloat(
"Movement_Crouch",
"SidewaySpeed", 0);
421 mfForwardAcc = mpGameConfig->GetFloat(
"Movement_Crouch",
"ForwardAcc", 0);
422 mfForwardDeacc = mpGameConfig->GetFloat(
"Movement_Crouch",
"ForwardDeacc", 0);
423 mfSidewayAcc = mpGameConfig->GetFloat(
"Movement_Crouch",
"SidewayAcc", 0);
424 mfSidewayDeacc = mpGameConfig->GetFloat(
"Movement_Crouch",
"SidewayDeacc", 0);
427 mfMaxHeadMove = mpGameConfig->GetFloat(
"Movement_Crouch",
"MaxHeadMove", 0);
428 mfMinHeadMove = mpGameConfig->GetFloat(
"Movement_Crouch",
"MinHeadMove", 0);
429 mfHeadMoveSpeed = mpGameConfig->GetFloat(
"Movement_Crouch",
"HeadMoveSpeed", 0);
430 mfHeadMoveBackSpeed = 0.23f;
432 mfHeightAdd = -(mpPlayer->GetSize().y - mpPlayer->GetCrouchHeight());
433 mfHeightAddSpeed = 1.8f;
436 mfFootStepMul = 1.0f;
438 msStepType =
"sneak";
440 mType = ePlayerMoveState_Crouch;
444 iCharacterBody *pBody = mpPlayer->GetCharacterBody();
446 cVector3f vFeetPos = pBody->GetPosition() - cVector3f(0, pBody->GetShape()->GetSize().y / 2, 0);
447 pBody->SetActiveSize(1);
448 pBody->SetPosition(vFeetPos + cVector3f(0, pBody->GetShape()->GetSize().y / 2, 0));
453 iCharacterBody *pBody = mpPlayer->GetCharacterBody();
455 cVector3f vFeetPos = pBody->GetPosition() - cVector3f(0, pBody->GetShape()->GetSize().y / 2, 0);
456 pBody->SetActiveSize(0);
457 pBody->SetPosition(vFeetPos + cVector3f(0, pBody->GetShape()->GetSize().y / 2, 0));
461 cInit *pInit = mpPlayer->GetInit();
462 iPhysicsWorld *pWorld = pInit->mpGame->GetScene()->GetWorld3D()->GetPhysicsWorld();
464 pBody->SetPosition(pBody->GetPosition() + cVector3f(0, 0.005f, 0));
467 for (
int i = 0; i < 2; ++i) {
468 iCollideShape *pShape = pBody->GetExtraBody(i)->GetShape();
470 cVector3f vNewPos = pBody->GetPosition();
471 pWorld->CheckShapeWorldCollision(&vNewPos, pShape,
472 cMath::MatrixTranslate(pBody->GetPosition()),
473 pBody->GetBody(),
false,
true);
481 if (vNewPos != pBody->GetPosition()) {
482 pBody->SetPosition(pBody->GetPosition() - cVector3f(0, 0.005f, 0));
483 mpPlayer->ChangeMoveState(ePlayerMoveState_Crouch);
488 pBody->SetPosition(pBody->GetPosition() - cVector3f(0, 0.005f, 0));
491 void OnUpdate(
float afTimeStep) {
495 #endif // GAME_PLAYER_MOVE_STATES_H Definition: PlayerMoveStates.h:165
Definition: PlayerMoveStates.h:196
Definition: PlayerMoveStates.h:412
Definition: PlayerMoveStates.h:227
Definition: PlayerMoveStates.h:265