MCPcopy Create free account
hub / github.com/atraczyk/2d-engine / update

Method update

engine/src/entity.cpp:500–810  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

498}
499
500void Player::update(WorldRect* pconstraints, TileMap* pcollisionmap,
501 TileMap* pfrontmap, std::vector<TileMap>* pdcollisionmaps,
502 Vector2 world_accel, int elapsedFrames, Camera* pcamera,
503 ScreenRect* pscreen)
504{
505 int pmovex = (!crouching || (crouching && (currentState == CS_JUMPING ||
506 currentState == CS_FALLING)))
507 ? toMove.x
508 : 0;
509 if (pmovex != 0)
510 {
511 if (pmovex == -1)
512 {
513 if (currentState != CS_JUMPING && currentState != CS_FALLING)
514 currentState = CS_MOVINGLEFT;
515 direction = -1;
516 }
517 else if (pmovex == 1)
518 {
519 if (currentState != CS_JUMPING && currentState != CS_FALLING)
520 currentState = CS_MOVINGRIGHT;
521 direction = 1;
522 }
523 if (!xycol && !ycol)
524 {
525 if (velocity.x * pmovex < 0)
526 velocity.x += X_AIR_MULTIPLIER * X_MDECELERATION * pmovex;
527 else
528 velocity.x += X_AIR_MULTIPLIER * X_ACCELERATION * pmovex;
529 }
530 else
531 {
532 if (velocity.x * pmovex < 0)
533 velocity.x += X_MDECELERATION * pmovex;
534 else if (!crouching)
535 velocity.x += X_ACCELERATION * pmovex;
536 }
537 }
538 else if (pmovex == 0 && currentState != CS_FALLING &&
539 currentState != CS_JUMPING)
540 {
541 if (velocity.x < 0.0f)
542 {
543 velocity.x += X_DECELERATION;
544 if (velocity.x > 0.0f)
545 velocity.x = 0.0f;
546 }
547 else if (velocity.x > 0.0f)
548 {
549 velocity.x -= X_DECELERATION;
550 if (velocity.x < 0.0f)
551 velocity.x = 0.0f;
552 }
553 }
554
555 if (swimming)
556 isRunning = false;
557

Callers

nothing calls this directly

Calls 6

EnemyClass · 0.85
Vector2Class · 0.85
PointClass · 0.85
PlaySfxMethod · 0.80
buttonDownMethod · 0.80
keyDownMethod · 0.80

Tested by

no test coverage detected