-// $Id: toad.cpp 4192 2006-08-16 23:25:39Z sommer $
+// $Id$
//
// Toad - A jumping toad
// Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
}
void
-Toad::activate()
+Toad::initialize()
{
// initial state is JUMPING, because we might start airborne
state = JUMPING;
Toad::set_state(ToadState newState)
{
if (newState == IDLE) {
- physic.vx = 0;
- physic.vy = 0;
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(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.vx = (dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED);
- physic.vy = VERTICAL_SPEED;
+ physic.set_velocity_x(dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED);
+ physic.set_velocity_y(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.vx < 0) && hit.left) || ((physic.vx > 0) && hit.right)) {
+ if(((physic.get_velocity_x() < 0) && hit.left) || ((physic.get_velocity_x() > 0) && hit.right)) {
/*
dir = dir == LEFT ? RIGHT : LEFT;
if (state == JUMPING) {
sprite->set_action(dir == LEFT ? "idle-left" : "idle-right");
}
*/
- physic.vx = -0.25*physic.vx;
+ physic.set_velocity_x(-0.25*physic.get_velocity_x());
}
// check if we hit the floor while falling
// check if we hit the roof while climbing
if ((state == JUMPING) && hit.top) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
}
BadGuy::active_update(elapsed_time);
// change sprite when we are falling
- if ((state == JUMPING) && (physic.vy > 0)) {
+ if ((state == JUMPING) && (physic.get_velocity_y() > 0)) {
set_state(FALLING);
return;
}