Toad::set_state(ToadState newState)
{
if (newState == IDLE) {
- physic.set_velocity_x(0);
- physic.set_velocity_y(0);
+ physic.vx = 0;
+ physic.vy = 0;
sprite->set_action(dir == LEFT ? "idle-left" : "idle-right");
recover_timer.start(RECOVER_TIME);
} else
if (newState == JUMPING) {
sprite->set_action(dir == LEFT ? "jumping-left" : "jumping-right");
- physic.set_velocity_x(dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED);
- physic.set_velocity_y(VERTICAL_SPEED);
+ physic.vx = (dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED);
+ physic.vy = VERTICAL_SPEED;
sound_manager->play( HOP_SOUND, get_pos());
} else
if (newState == FALLING) {
}
// check if we hit left or right while moving in either direction
- if(((physic.get_velocity_x() < 0) && hit.left) || ((physic.get_velocity_x() > 0) && hit.right)) {
+ if(((physic.vx < 0) && hit.left) || ((physic.vx > 0) && hit.right)) {
/*
dir = dir == LEFT ? RIGHT : LEFT;
if (state == JUMPING) {
sprite->set_action(dir == LEFT ? "idle-left" : "idle-right");
}
*/
- physic.set_velocity_x(-0.25*physic.get_velocity_x());
+ physic.vx = -0.25*physic.vx;
}
// check if we hit the floor while falling
// check if we hit the roof while climbing
if ((state == JUMPING) && hit.top) {
- physic.set_velocity_y(0);
+ physic.vy = 0;
}
}
BadGuy::active_update(elapsed_time);
// change sprite when we are falling
- if ((state == JUMPING) && (physic.get_velocity_y() > 0)) {
+ if ((state == JUMPING) && (physic.vy > 0)) {
set_state(FALLING);
return;
}