Created
April 2, 2011 00:19
-
-
Save zaphire/899094 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Player::Update() | |
{ | |
Entity::Update(); | |
Vector2 lastPosition = position; | |
const float walkSpeed = 150; | |
const float runSpeed = 220; | |
const float maxFallSpeed = 50.0f; | |
const float gravity = 980.0f; | |
// fall, cap at maxFallSpeed | |
velocity.y += MIN(gravity * Monocle::deltaTime, maxFallSpeed); | |
position += velocity * Monocle::deltaTime; | |
float useSpeed = isWalking?walkSpeed:runSpeed; | |
const float turnThresh = 0.25f; | |
if (moveDir.x > turnThresh) | |
scale.x = 1; | |
else if (moveDir.x < -turnThresh) | |
scale.x = -1; | |
if (fabs(moveDir.x) < 0.5f) | |
{ | |
moveDir.x = 0; | |
} | |
position += moveDir * useSpeed * Monocle::deltaTime; | |
int y = 0; | |
int max = 16; | |
for (y = 0; y < max; y++) | |
{ | |
CollisionData collisionData; | |
if (Collide("Obstruction", &collisionData)) | |
{ | |
position.y = lastPosition.y; | |
velocity.y = 0; | |
} | |
else | |
{ | |
break; | |
} | |
position.y = lastPosition.y - y; | |
} | |
if (y == max) | |
{ | |
position = lastPosition; | |
} | |
moveDir = Vector2::zero; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment