afegit player.md
This commit is contained in:
132
source/game/entities/player.md
Normal file
132
source/game/entities/player.md
Normal file
@@ -0,0 +1,132 @@
|
||||
handleInput()
|
||||
{
|
||||
if (checkAction(LEFT))
|
||||
{
|
||||
wannaGo::LEFT;
|
||||
}
|
||||
else if (checkAction(RIGHT))
|
||||
{
|
||||
wannaGo::RIGHT;
|
||||
}
|
||||
else
|
||||
{
|
||||
wannaGo::STAY;
|
||||
}
|
||||
|
||||
wannaJUMP = (checkAction(JUMP));
|
||||
}
|
||||
|
||||
move()
|
||||
{
|
||||
handleHorizontalMovement();
|
||||
handleVerticalMovement();
|
||||
}
|
||||
|
||||
handleHorizontalMovement()
|
||||
{
|
||||
if (State!=STANDING)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (automovement)
|
||||
{
|
||||
vx = FIXED_BY_ROOM;
|
||||
}
|
||||
else
|
||||
{
|
||||
vx = wannaGo::DIRECTION;
|
||||
}
|
||||
|
||||
moveAndCollide();
|
||||
|
||||
}
|
||||
|
||||
handleVerticalMovement()
|
||||
{
|
||||
if (State==STANDING)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (State==JUMPING)
|
||||
{
|
||||
applyGravity();
|
||||
}
|
||||
|
||||
moveAndCollide();
|
||||
|
||||
}
|
||||
|
||||
|
||||
handleConveyorBelts()
|
||||
{
|
||||
if (!automovement and isOnConveyorBelt and wannaGo::STAY)
|
||||
{
|
||||
automovement = true;
|
||||
}
|
||||
|
||||
if (automovement and !isOnConveyorBelt)
|
||||
{
|
||||
automovement = false;
|
||||
}
|
||||
}
|
||||
|
||||
handleShouldFall()
|
||||
{
|
||||
if (!isOnFloor and State::STANDING)
|
||||
{
|
||||
transitionToState(FALLING);
|
||||
}
|
||||
}
|
||||
|
||||
transitionToState(state)
|
||||
{
|
||||
prev = state_;
|
||||
state_ = state;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case STANDING:
|
||||
vy = 0;
|
||||
case JUMPING:
|
||||
if (prev==STANDING)
|
||||
{
|
||||
vy = -MAX_VY;
|
||||
last_ground_position = y;
|
||||
}
|
||||
case FALLING:
|
||||
last_ground_position = y;
|
||||
vy = MAX_VY;
|
||||
vx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
updateState()
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case STANDING:
|
||||
handleConveyorBelts();
|
||||
handleShouldFall();
|
||||
if (wannaJump)
|
||||
{
|
||||
transitionToState(JUMPING);
|
||||
}
|
||||
case JUMPING:
|
||||
automovement = false;
|
||||
playJumpingSound();
|
||||
handleEndJump();
|
||||
case FALLING:
|
||||
automovement = false;
|
||||
playFallingSound();
|
||||
}
|
||||
}
|
||||
|
||||
update()
|
||||
{
|
||||
hanldeInput();
|
||||
updateState();
|
||||
move();
|
||||
animate();
|
||||
}
|
||||
Reference in New Issue
Block a user