void
AngryStone::activate()
{
- physic.vx = 0;
- physic.vy = 0;
- physic.gravity_enabled = true;
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
+ physic.enable_gravity(true);
sprite->set_action("idle");
}
(hit.normal.x == -attackDirection.x) && (hit.normal.y == attackDirection.y)) {
state = IDLE;
sprite->set_action("idle");
- physic.vx = 0;
- physic.vy = 0;
- physic.gravity_enabled = true;
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
+ physic.enable_gravity(true);
oldWallDirection.x = attackDirection.x;
oldWallDirection.y = attackDirection.y;
}
sprite->set_action("attacking");
timer.start(ATTACK_TIME);
state = ATTACKING;
- physic.gravity_enabled = false;
- physic.vx = SPEED * attackDirection.x;
- physic.vy = SPEED * attackDirection.y;
+ physic.enable_gravity(false);
+ physic.set_velocity_x(SPEED * attackDirection.x);
+ physic.set_velocity_y(SPEED * attackDirection.y);
oldWallDirection.x = 0;
oldWallDirection.y = 0;
}
timer.start(RECOVER_TIME);
state = RECOVERING;
sprite->set_action("idle");
- physic.gravity_enabled = true;
- physic.vx = 0;
- physic.vy = 0;
+ physic.enable_gravity(true);
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
}
}
if (timer.check()) {
state = IDLE;
sprite->set_action("idle");
- physic.gravity_enabled = true;
- physic.vx = 0;
- physic.vy = 0;
+ physic.enable_gravity(true);
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
}
}
void
BadGuy::collision_solid(const CollisionHit& hit)
{
- physic.vx = 0;
- physic.vy = 0;
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
update_on_ground_flag(hit);
}
BadGuy::kill_squished(GameObject& object)
{
sound_manager->play("sounds/squish.wav", get_pos());
- physic.gravity_enabled = true;
- physic.vx = 0;
- physic.vy = 0;
+ physic.enable_gravity(true);
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
set_state(STATE_SQUISHED);
set_group(COLGROUP_MOVING_ONLY_STATIC);
Player* player = dynamic_cast<Player*>(&object);
{
sound_manager->play("sounds/fall.wav", get_pos());
if (countMe) Sector::current()->get_level()->stats.badguys++;
- physic.vy = 0;
- physic.gravity_enabled = true;
+ physic.set_velocity_y(0);
+ physic.enable_gravity(true);
set_state(STATE_FALLING);
}
Bomb::collision_solid(const CollisionHit& hit)
{
if(hit.bottom)
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
HitResponse
void
BouncingSnowball::activate()
{
- physic.vx = (dir == LEFT ? -WALKSPEED : WALKSPEED);
+ physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
sprite->set_action(dir == LEFT ? "left" : "right");
}
{
if(hit.bottom) {
if(get_state() == STATE_ACTIVE) {
- physic.vy = JUMPSPEED;
+ physic.set_velocity_y(JUMPSPEED);
} else {
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
} else if(hit.top) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
if(hit.left || hit.right) { // left or right collision
dir = dir == LEFT ? RIGHT : LEFT;
sprite->set_action(dir == LEFT ? "left" : "right");
- physic.vx = -physic.vx;
+ physic.set_velocity_x(-physic.get_velocity_x());
}
}
Dart::Dart(const lisp::Lisp& reader)
: BadGuy(reader, "images/creatures/dart/dart.sprite"), parent(0)
{
- physic.gravity_enabled = false;
+ physic.enable_gravity(false);
countMe = false;
sound_manager->preload("sounds/darthit.wav");
sound_manager->preload("sounds/stomp.wav");
Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent = 0)
: BadGuy(pos, d, "images/creatures/dart/dart.sprite"), parent(parent)
{
- physic.gravity_enabled = false;
+ physic.enable_gravity(false);
countMe = false;
sound_manager->preload("sounds/darthit.wav");
sound_manager->preload("sounds/stomp.wav");
void
Dart::activate()
{
- physic.vx = (dir == LEFT ? -::SPEED : ::SPEED);
+ physic.set_velocity_x(dir == LEFT ? -::SPEED : ::SPEED);
sprite->set_action(dir == LEFT ? "flying-left" : "flying-right");
sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
Fish::Fish(const lisp::Lisp& reader)
: BadGuy(reader, "images/creatures/fish/fish.sprite", LAYER_TILES-1), stop_y(0)
{
- physic.gravity_enabled = true;
+ physic.enable_gravity(true);
}
Fish::Fish(const Vector& pos)
: BadGuy(pos, "images/creatures/fish/fish.sprite", LAYER_TILES-1), stop_y(0)
{
- physic.gravity_enabled = true;
+ physic.enable_gravity(true);
}
void
Fish::hit(const CollisionHit& hit)
{
if(hit.top) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
return CONTINUE;
void
Fish::collision_tile(uint32_t tile_attributes)
{
- if ((tile_attributes & Tile::WATER) && (physic.vy >= 0)) {
+ if ((tile_attributes & Tile::WATER) && (physic.get_velocity_y() >= 0)) {
// initialize stop position if uninitialized
if (stop_y == 0) stop_y = get_pos().y + get_bbox().get_height();
// set sprite
if(!frozen)
- sprite->set_action(physic.vy < 0 ? "normal" : "down");
+ sprite->set_action(physic.get_velocity_y() < 0 ? "normal" : "down");
// we can't afford flying out of the tilemap, 'cause the engine would remove us.
if ((get_pos().y - 31.8) < 0) // too high, let us fall
{
- physic.vy = 0;
- physic.gravity_enabled = true;
+ physic.set_velocity_y(0);
+ physic.enable_gravity(true);
}
}
{
waiting.start(FISH_WAIT_TIME);
set_group(COLGROUP_DISABLED);
- physic.gravity_enabled = false;
- physic.vy = 0;
+ physic.enable_gravity(false);
+ physic.set_velocity_y(0);
}
void
Fish::jump()
{
- physic.vy = FISH_JUMP_POWER;
- physic.gravity_enabled = true;
+ physic.set_velocity_y(FISH_JUMP_POWER);
+ physic.enable_gravity(true);
set_group(COLGROUP_MOVING);
}
Fish::freeze()
{
BadGuy::freeze();
- sprite->set_action(physic.vy < 0 ? "iced" : "iced-down");
+ sprite->set_action(physic.get_velocity_y() < 0 ? "iced" : "iced-down");
waiting.stop();
}
FlyingSnowBall::FlyingSnowBall(const lisp::Lisp& reader)
: BadGuy(reader, "images/creatures/flying_snowball/flying_snowball.sprite")
{
- physic.gravity_enabled = false;
+ physic.enable_gravity(false);
}
FlyingSnowBall::FlyingSnowBall(const Vector& pos)
: BadGuy(pos, "images/creatures/flying_snowball/flying_snowball.sprite")
{
- physic.gravity_enabled = false;
+ physic.enable_gravity(false);
}
void
{
sprite->set_action(dir == LEFT ? "left" : "right");
mode = FLY_UP;
- physic.vy = FLYSPEED;
+ physic.set_velocity_y(FLYSPEED);
timer.start(FLYTIME/2);
puff_timer.start(systemRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX));
}
FlyingSnowBall::collision_solid(const CollisionHit& hit)
{
if(hit.top || hit.bottom) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
}
if(timer.check()) {
if(mode == FLY_UP) {
mode = FLY_DOWN;
- physic.vy = -FLYSPEED;
+ physic.set_velocity_y(-FLYSPEED);
// stop puffing
puff_timer.stop();
} else if(mode == FLY_DOWN) {
mode = FLY_UP;
- physic.vy = FLYSPEED;
+ physic.set_velocity_y(FLYSPEED);
// roll a dice whether to start puffing
if (systemRandom.randf(0, 1) < PUFF_PROBABILITY) {
groundhit_pos_set = true;
}
- physic.vy = (frozen ? 0 : JUMPSPEED);
+ physic.set_velocity_y(frozen ? 0 : JUMPSPEED);
// TODO create a nice sound for this...
//sound_manager->play("sounds/skid.wav");
} else if(chit.top) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
return CONTINUE;
Jumpy::freeze()
{
BadGuy::freeze();
- physic.vy = std::max(0.0f, physic.vy);
+ physic.set_velocity_y(std::max(0.0f, physic.get_velocity_y()));
sprite->set_action(dir == LEFT ? "left-iced" : "right-iced");
}
{
reader.get("x", start_position.x);
sprite->set_action("falling");
- physic.gravity_enabled = false;
+ physic.enable_gravity(false);
}
void
void
Kugelblitz::activate()
{
- physic.vy = 300;
- physic.vx = -20; //fall a little to the left
+ physic.set_velocity_y(300);
+ physic.set_velocity_x(-20); //fall a little to the left
direction = 1;
dying = false;
}
groundhit_pos_set = true;
}
sprite->set_action("flying");
- physic.vy = 0;
+ physic.set_velocity_y(0);
//Set random initial speed and direction
direction = systemRandom.rand(2)? 1: -1;
int speed = (BASE_SPEED + (systemRandom.rand(RAND_SPEED))) * direction;
- physic.vx = speed;
+ physic.set_velocity_x(speed);
movement_timer.start(MOVETIME);
lifetime.start(LIFETIME);
} else if(hit.top) { // bumped on roof
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
return CONTINUE;
if (movement_timer.check()) {
if (direction == 1) direction = -1; else direction = 1;
int speed = (BASE_SPEED + (systemRandom.rand(RAND_SPEED))) * direction;
- physic.vx = speed;
+ physic.set_velocity_x(speed);
movement_timer.start(MOVETIME);
}
}
Mole::Mole(const lisp::Lisp& reader)
: BadGuy(reader, "images/creatures/mole/mole.sprite", LAYER_TILES-1), state(PRE_THROWING)
{
- physic.gravity_enabled = false;
+ physic.enable_gravity(false);
}
Mole::Mole(const Vector& pos)
: BadGuy(pos, "images/creatures/mole/mole.sprite", LAYER_TILES-1), state(PRE_THROWING)
{
- physic.gravity_enabled = false;
+ physic.enable_gravity(false);
}
void
MoleRock::MoleRock(const lisp::Lisp& reader)
: BadGuy(reader, "images/creatures/mole/mole_rock.sprite", LAYER_TILES - 2), parent(0), initial_velocity(Vector(0, -400))
{
- physic.gravity_enabled = true;
+ physic.enable_gravity(true);
countMe = false;
}
MoleRock::MoleRock(const Vector& pos, const Vector& velocity, const BadGuy* parent = 0)
: BadGuy(pos, LEFT, "images/creatures/mole/mole_rock.sprite", LAYER_TILES - 2), parent(parent), initial_velocity(velocity)
{
- physic.gravity_enabled = true;
+ physic.enable_gravity(true);
countMe = false;
}
void
MoleRock::activate()
{
- physic.vx = initial_velocity.x;
- physic.vy = initial_velocity.y;
+ physic.set_velocity(initial_velocity);
sprite->set_action("default");
}
update_on_ground_flag(hit);
if(hit.top || hit.bottom) { // floor or roof
- physic.vy = 0;
+ physic.set_velocity_y(0);
return;
}
if(hit.right && dir == RIGHT) {
dir = LEFT;
sound_manager->play("sounds/iceblock_bump.wav", get_pos());
- physic.vx = -KICKSPEED;
+ physic.set_velocity_x(-KICKSPEED);
} else if(hit.left && dir == LEFT) {
dir = RIGHT;
sound_manager->play("sounds/iceblock_bump.wav", get_pos());
- physic.vx = KICKSPEED;
+ physic.set_velocity_x(KICKSPEED);
}
sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
break;
}
case ICESTATE_FLAT:
- physic.vx = 0;
+ physic.set_velocity_x(0);
break;
case ICESTATE_GRABBED:
break;
break;
case ICESTATE_FLAT:
sound_manager->play("sounds/stomp.wav", get_pos());
- physic.vx = 0;
- physic.vy = 0;
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
flat_timer.start(4);
case ICESTATE_KICKED:
sound_manager->play("sounds/kick.wav", get_pos());
- physic.vx = (dir == LEFT ? -KICKSPEED : KICKSPEED);
+ physic.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED);
sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
// we should slide above 1 block holes now...
bbox.set_size(34, 31.8);
void
MrRocket::activate()
{
- physic.vx = (dir == LEFT ? -SPEED : SPEED);
- physic.gravity_enabled = false;
+ physic.set_velocity_x(dir == LEFT ? -SPEED : SPEED);
+ physic.enable_gravity(false);
sprite->set_action(dir == LEFT ? "left" : "right");
}
MrRocket::collision_solid(const CollisionHit& hit)
{
if(hit.top || hit.bottom) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
} else if(hit.left || hit.right) {
sprite->set_action(dir == LEFT ? "collision-left" : "collision-right");
- physic.vx = 0;
+ physic.set_velocity_x(0);
collision_timer.start(0.2, true);
}
}
dir = dir == LEFT ? RIGHT : LEFT;
state = PLANT_SLEEPING;
- physic.vx = 0;
+ physic.set_velocity_x(0);
sprite->set_action(dir == LEFT ? "sleeping-left" : "sleeping-right");
}
Plant::collision_solid(const CollisionHit& hit)
{
if(hit.top || hit.bottom) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
} else if(hit.left || hit.right) {
dir = dir == LEFT ? RIGHT : LEFT;
sprite->set_action(dir == LEFT ? "left" : "right");
- physic.vx = -physic.vx;
+ physic.set_velocity_x(-physic.get_velocity_x());
}
}
if(hit.left || hit.right) {
dir = dir == LEFT ? RIGHT : LEFT;
sprite->set_action(dir == LEFT ? "left" : "right");
- physic.vx = -physic.vx;
+ physic.set_velocity_x(-physic.get_velocity_x());
}
return CONTINUE;
if(timer.check()) {
// start walking
sprite->set_action(dir == LEFT ? "left" : "right");
- physic.vx = (dir == LEFT ? -WALKSPEED : WALKSPEED);
+ physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
state = PLANT_WALKING;
}
}
SkullyHop::set_state(SkullyHopState newState)
{
if (newState == STANDING) {
- physic.vx = 0;
- physic.vy = 0;
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
sprite->set_action(dir == LEFT ? "standing-left" : "standing-right");
float recover_time = systemRandom.randf(MIN_RECOVER_TIME,MAX_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());
}
return;
// check if we hit the floor while falling
- if(hit.bottom && physic.vy > 0 ) {
+ if(hit.bottom && physic.get_velocity_y() > 0 ) {
set_state(STANDING);
}
// check if we hit the roof while climbing
if(hit.top) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
// check if we hit left or right while moving in either direction
if(hit.left || hit.right) {
dir = dir == LEFT ? RIGHT : LEFT;
sprite->set_action(dir == LEFT ? "jumping-left" : "jumping-right");
- physic.vx = -0.25*physic.vx;
+ physic.set_velocity_x(-0.25*physic.get_velocity_x());
}
}
sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
sprite->set_fps(64);
- physic.vx = 0;
- physic.vy = 0;
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
flat_timer.start(4);
}
sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
sprite->set_fps(64);
- physic.vx = 0;
- physic.vy = 0;
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
// start a timer to delay addition of upward movement until we are (hopefully) out from under the player
kicked_delay_timer.start(0.05);
case STATE_KICKED_DELAY:
if (kicked_delay_timer.check()) {
- physic.vx = (dir == LEFT ? -KICKSPEED : KICKSPEED);
- physic.vy = KICKSPEED_Y;
+ physic.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED);
+ physic.set_velocity_y(KICKSPEED_Y);
state = STATE_KICKED;
}
BadGuy::active_update(elapsed_time);
break;
case STATE_KICKED:
- physic.vx = physic.vx * pow(0.99, elapsed_time/0.02);
- if (fabsf(physic.vx) < walk_speed) be_normal();
+ physic.set_velocity_x(physic.get_velocity_x() * pow(0.99, elapsed_time/0.02));
+ if (fabsf(physic.get_velocity_x()) < walk_speed) be_normal();
BadGuy::active_update(elapsed_time);
break;
break;
case STATE_FLAT:
if(hit.top || hit.bottom) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
if(hit.left || hit.right) {
}
break;
case STATE_KICKED_DELAY:
if(hit.top || hit.bottom) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
if(hit.left || hit.right) {
- physic.vy = 0;
+ physic.set_velocity_x(0);
}
break;
case STATE_KICKED:
if(hit.top || hit.bottom) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
if(hit.left || hit.right) {
sound_manager->play("sounds/iceblock_bump.wav", get_pos());
dir = (dir == LEFT) ? RIGHT : LEFT;
sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
- physic.vx = -physic.vx*0.75;
- if (fabsf(physic.vx) < walk_speed) be_normal();
+ physic.set_velocity_x(-physic.get_velocity_x()*0.75);
+ if (fabsf(physic.get_velocity_x()) < walk_speed) be_normal();
}
}
SpiderMite::SpiderMite(const lisp::Lisp& reader)
: BadGuy(reader, "images/creatures/spidermite/spidermite.sprite")
{
- physic.gravity_enabled = false;
+ physic.enable_gravity(false);
}
SpiderMite::SpiderMite(const Vector& pos)
: BadGuy(pos, "images/creatures/spidermite/spidermite.sprite")
{
- physic.gravity_enabled = false;
+ physic.enable_gravity(false);
}
void
{
sprite->set_action(dir == LEFT ? "left" : "right");
mode = FLY_UP;
- physic.vy = FLYSPEED;
+ physic.set_velocity_y(FLYSPEED);
timer.start(FLYTIME/2);
}
SpiderMite::collision_solid(const CollisionHit& hit)
{
if(hit.top || hit.bottom) { // hit floor or roof?
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
}
if(timer.check()) {
if(mode == FLY_UP) {
mode = FLY_DOWN;
- physic.vy = -FLYSPEED;
+ physic.set_velocity_y(-FLYSPEED);
} else if(mode == FLY_DOWN) {
mode = FLY_UP;
- physic.vy = FLYSPEED;
+ physic.set_velocity_y(FLYSPEED);
}
timer.start(FLYTIME);
}
SSpiky::activate()
{
state = SSPIKY_SLEEPING;
- physic.vx = 0;
+ physic.set_velocity_x(0);
sprite->set_action(dir == LEFT ? "sleeping-left" : "sleeping-right");
}
} else if(state == STALACTITE_SHAKING) {
if(timer.check()) {
state = STALACTITE_FALLING;
- physic.gravity_enabled = true;
+ physic.enable_gravity(true);
}
} else if(state == STALACTITE_FALLING || state == STALACTITE_SQUISHED) {
movement = physic.get_movement(elapsed_time);
if (hit.bottom) squish();
}
if(state == STALACTITE_SQUISHED) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
}
case STATE_INVINCIBLE:
sprite->set_action(dir == LEFT ? "dizzy-left" : "dizzy-right");
bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
- physic.vx = 0;
+ physic.set_velocity_x(0);
break;
case STATE_NORMAL:
WalkingBadguy::activate();
switch (mystate) {
case STATE_INVINCIBLE:
if(hit.top || hit.bottom) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
if(hit.left || hit.right) {
- physic.vx = 0;
+ physic.set_velocity_x(0);
}
break;
case STATE_NORMAL:
switch (mystate) {
case STATE_INVINCIBLE:
if(hit.top || hit.bottom) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
if(hit.left || hit.right) {
- physic.vx = 0;
+ physic.set_velocity_x(0);
}
return CONTINUE;
break;
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;
}
Totem::activate()
{
if (!carried_by) {
- physic.vx = (dir == LEFT ? -WALKSPEED : WALKSPEED);
+ physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
sprite->set_action(dir == LEFT ? "walking-left" : "walking-right");
return;
} else {
float dx = (p1.x - p2.x);
if (fabsf(dx - 128) > 2) continue;
- physic.vy = JUMP_ON_SPEED_Y;
+ physic.set_velocity_y(JUMP_ON_SPEED_Y);
p1.y -= 1;
this->set_pos(p1);
break;
// If we hit something from above or below: stop moving in this direction
if (hit.top || hit.bottom) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
// If we are hit from the direction we are facing: turn around
bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
- physic.vy = JUMP_OFF_SPEED_Y;
+ physic.set_velocity_y(JUMP_OFF_SPEED_Y);
}
void
pos.y -= sprite->get_current_hitbox_height();
set_pos(pos);
- physic.vx = base->physic.vx;
- physic.vy = base->physic.vy;
+ physic.set_velocity_x(base->physic.get_velocity_x());
+ physic.set_velocity_y(base->physic.get_velocity_y());
}
return;
sprite->set_action(dir == LEFT ? walk_left_action : walk_right_action);
bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
- physic.vx = (dir == LEFT ? -walk_speed : walk_speed);
+ physic.set_velocity_x(dir == LEFT ? -walk_speed : walk_speed);
}
void
update_on_ground_flag(hit);
if (hit.top) {
- if (physic.vy < 0) physic.vy = 0;
+ if (physic.get_velocity_y() < 0) physic.set_velocity_y(0);
}
if (hit.bottom) {
- if (physic.vy > 0) physic.vy = 0;
+ if (physic.get_velocity_y() > 0) physic.set_velocity_y(0);
}
if ((hit.left && (hit.slope_normal.y == 0) && (dir == LEFT)) || (hit.right && (hit.slope_normal.y == 0) && (dir == RIGHT))) {
return;
dir = dir == LEFT ? RIGHT : LEFT;
sprite->set_action(dir == LEFT ? walk_left_action : walk_right_action);
- physic.vx = -physic.vx;
+ physic.set_velocity_x(-physic.get_velocity_x());
}
void
WalkingBadguy::freeze()
{
BadGuy::freeze();
- physic.vx = 0;
+ physic.set_velocity_x(0);
}
void
float
WalkingBadguy::get_velocity_y() const
{
- return physic.vy;
+ return physic.get_velocity_y();
}
void
WalkingBadguy::set_velocity_y(float vy)
{
- physic.vy = vy;
+ physic.set_velocity_y(vy);
}
{
switch(state) {
case JUMP_DOWN:
- physic.vx = (dir==RIGHT?JUMP_DOWN_VX:-JUMP_DOWN_VX);
+ physic.set_velocity_x((dir==RIGHT)?+JUMP_DOWN_VX:-JUMP_DOWN_VX);
break;
case RUN:
- physic.vx = (dir==RIGHT?RUN_VX:-RUN_VX);
+ physic.set_velocity_x((dir==RIGHT)?+RUN_VX:-RUN_VX);
if (((dir == RIGHT) && (get_pos().x >= RIGHT_JUMP_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_JUMP_X))) jump_up();
break;
case JUMP_UP:
- physic.vx = (dir==RIGHT?JUMP_UP_VX:-JUMP_UP_VX);
+ physic.set_velocity_x((dir==RIGHT)?+JUMP_UP_VX:-JUMP_UP_VX);
if (((dir == RIGHT) && (get_pos().x >= RIGHT_STAND_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_STAND_X))) be_angry();
break;
case BE_ANGRY:
if(state_timer.check()) {
sound_manager->play("sounds/yeti_gna.wav");
- physic.vy = STOMP_VY;
+ physic.set_velocity_y(STOMP_VY);
sprite->set_action((dir==RIGHT)?"stomp-right":"stomp-left");
}
break;
Yeti::jump_down()
{
sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
- physic.vx = (dir==RIGHT?JUMP_DOWN_VX:-JUMP_DOWN_VX);
- physic.vy = JUMP_DOWN_VY;
+ physic.set_velocity_x((dir==RIGHT)?(+JUMP_DOWN_VX):(-JUMP_DOWN_VX));
+ physic.set_velocity_y(JUMP_DOWN_VY);
state = JUMP_DOWN;
}
Yeti::run()
{
sprite->set_action((dir==RIGHT)?"run-right":"run-left");
- physic.vx = (dir==RIGHT?RUN_VX:-RUN_VX);
- physic.vy = 0;
+ physic.set_velocity_x((dir==RIGHT)?(+RUN_VX):(-RUN_VX));
+ physic.set_velocity_y(0);
state = RUN;
}
Yeti::jump_up()
{
sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
- physic.vx = (dir==RIGHT?JUMP_UP_VX:-JUMP_UP_VX);
- physic.vy = JUMP_UP_VY;
+ physic.set_velocity_x((dir==RIGHT)?(+JUMP_UP_VX):(-JUMP_UP_VX));
+ physic.set_velocity_y(JUMP_UP_VY);
state = JUMP_UP;
}
dir = (dir==RIGHT)?LEFT:RIGHT;
sprite->set_action((dir==RIGHT)?"stand-right":"stand-left");
- physic.vx = 0;
- physic.vy = 0;
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
if (hit_points < INITIAL_HITPOINTS) summon_snowball();
stomp_count = 0;
state = BE_ANGRY;
if(hit_points <= 0) {
// We're dead
- physic.gravity_enabled = true;
- physic.vx = 0;
- physic.vy = 0;
+ physic.enable_gravity(true);
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
state = SQUISHED;
state_timer.start(SQUISH_TIME);
{
if(hit.top || hit.bottom) {
// hit floor or roof
- physic.vy = 0;
+ physic.set_velocity_y(0);
switch (state) {
case JUMP_DOWN:
run();
Zeekling::activate()
{
speed = systemRandom.rand(130, 171);
- physic.vx = (dir == LEFT ? -speed : speed);
- physic.gravity_enabled = false;
+ physic.set_velocity_x(dir == LEFT ? -speed : speed);
+ physic.enable_gravity(false);
sprite->set_action(dir == LEFT ? "left" : "right");
}
if (state == FLYING) {
dir = (dir == LEFT ? RIGHT : LEFT);
sprite->set_action(dir == LEFT ? "left" : "right");
- physic.vx = (dir == LEFT ? -speed : speed);
+ physic.set_velocity_x(dir == LEFT ? -speed : speed);
} else
if (state == DIVING) {
dir = (dir == LEFT ? RIGHT : LEFT);
state = FLYING;
sprite->set_action(dir == LEFT ? "left" : "right");
- physic.vx = (dir == LEFT ? -speed : speed);
- physic.vy = 0;
+ physic.set_velocity_x(dir == LEFT ? -speed : speed);
+ physic.set_velocity_y(0);
} else
if (state == CLIMBING) {
dir = (dir == LEFT ? RIGHT : LEFT);
sprite->set_action(dir == LEFT ? "left" : "right");
- physic.vx = (dir == LEFT ? -speed : speed);
+ physic.set_velocity_x(dir == LEFT ? -speed : speed);
} else {
assert(false);
}
void
Zeekling::onBumpVertical() {
if (state == FLYING) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
} else
if (state == DIVING) {
state = CLIMBING;
- physic.vy = -speed;
+ physic.set_velocity_y(-speed);
sprite->set_action(dir == LEFT ? "left" : "right");
} else
if (state == CLIMBING) {
state = FLYING;
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
}
if (state == FLYING) {
if (should_we_dive()) {
state = DIVING;
- physic.vy = 2*fabsf(physic.vx);
+ physic.set_velocity_y(2*fabsf(physic.get_velocity_x()));
sprite->set_action(dir == LEFT ? "diving-left" : "diving-right");
}
BadGuy::active_update(elapsed_time);
// stop climbing when we're back at initial height
if (get_pos().y <= start_position.y) {
state = FLYING;
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
BadGuy::active_update(elapsed_time);
return;
: life_count(3), type(type)
{
float speed = dir == RIGHT ? BULLET_XM : -BULLET_XM;
- physic.vx = speed + xm;
+ physic.set_velocity_x(speed + xm);
if(type == FIRE_BONUS) {
sprite.reset(sprite_manager->create("images/objects/bullets/firebullet.sprite"));
Bullet::collision_solid(const CollisionHit& hit)
{
if(hit.top || hit.bottom) {
- physic.vy = -physic.vy;
+ physic.set_velocity_y(-physic.get_velocity_y());
life_count--;
} else if(hit.left || hit.right) {
if(type == ICE_BONUS) {
- physic.vx = -physic.vx;
+ physic.set_velocity_x(-physic.get_velocity_x());
life_count--;
} else
remove_me();
float speed_x = delta_x / elapsed_time;
// limit our speed
- float maxv = 130 + (fabsf(player->physic.vx * 1.3));
+ float maxv = 130 + (fabsf(player->physic.get_velocity_x() * 1.3));
if(speed_x > maxv)
speed_x = maxv;
else if(speed_x < -maxv)
{
pos = start_position;
sprite = sprite_manager->create("images/objects/coin/coin.sprite");
- physic.vy = -800;
- physic.vx = vel_x;
+ physic.set_velocity_y(-800);
+ physic.set_velocity_x(vel_x);
}
FallingCoin::~FallingCoin()
GrowUp::GrowUp(Direction direction)
: MovingSprite(Vector(0,0), "images/powerups/egg/egg.sprite", LAYER_OBJECTS, COLGROUP_MOVING)
{
- physic.gravity_enabled = true;
- physic.vx = (direction == LEFT?-100:100);
+ physic.enable_gravity(true);
+ physic.set_velocity_x((direction == LEFT)?-100:100);
sound_manager->preload("sounds/grow.wav");
}
GrowUp::collision_solid(const CollisionHit& hit)
{
if(hit.top || hit.bottom)
- physic.vy = 0;
+ physic.set_velocity_y(0);
if(hit.left || hit.right)
- physic.vx = -physic.vx;
+ physic.set_velocity_x(-physic.get_velocity_x());
}
HitResponse
OneUp::OneUp(const Vector& pos, Direction direction)
: MovingSprite(pos, "images/powerups/1up/1up.sprite", LAYER_FLOATINGOBJECTS, COLGROUP_TOUCHABLE)
{
- physic.vx = ((direction == LEFT)?-100:100);
- physic.vy = -400;
+ physic.set_velocity((direction == LEFT)?-100:100, -400);
}
void
on_ground_flag = false;
grabbed_object = NULL;
- physic = Physic();
+ physic.reset();
}
void
// extend/shrink tux collision rectangle so that we fall through/walk over 1
// tile holes
- if(fabsf(physic.vx) > MAX_WALK_XM) {
+ if(fabsf(physic.get_velocity_x()) > MAX_WALK_XM) {
set_width(34);
} else {
set_width(31.8);
// on downward slopes, adjust vertical velocity so tux walks smoothly down
if (on_ground()) {
if(floor_normal.y != 0) {
- if ((floor_normal.x * physic.vx) >= 0) {
- physic.vy = 250;
+ if ((floor_normal.x * physic.get_velocity_x()) >= 0) {
+ physic.set_velocity_y(250);
}
}
}
if (backflipping) {
//prevent player from changing direction when backflipping
dir = (backflip_direction == 1) ? LEFT : RIGHT;
- if (backflip_timer.started()) physic.vx = 100 * backflip_direction;
+ if (backflip_timer.started()) physic.set_velocity_x(100 * backflip_direction);
}
// set fall mode...
void
Player::apply_friction()
{
- if ((on_ground()) && (fabs(physic.vx) < WALK_SPEED)) {
- physic.vx = 0;
- physic.ax = 0;
- } else if(physic.vx < 0) {
- physic.ax = WALK_ACCELERATION_X * 1.5;
+ if ((on_ground()) && (fabs(physic.get_velocity_x()) < WALK_SPEED)) {
+ physic.set_velocity_x(0);
+ physic.set_acceleration_x(0);
+ } else if(physic.get_velocity_x() < 0) {
+ physic.set_acceleration_x(WALK_ACCELERATION_X * 1.5);
} else {
- physic.ax = WALK_ACCELERATION_X * -1.5;
+ physic.set_acceleration_x(WALK_ACCELERATION_X * -1.5);
}
}
void
Player::handle_horizontal_input()
{
- float vx = physic.vx;
- float vy = physic.vy;
- float ax = physic.ax;
- float ay = physic.ay;
+ float vx = physic.get_velocity_x();
+ float vy = physic.get_velocity_y();
+ float ax = physic.get_acceleration_x();
+ float ay = physic.get_acceleration_y();
float dirsign = 0;
- if(!duck || physic.vy != 0) {
+ if(!duck || physic.get_velocity_y() != 0) {
if(controller->hold(Controller::LEFT) && !controller->hold(Controller::RIGHT)) {
old_dir = dir;
dir = LEFT;
}
}
- physic.vx = vx;
- physic.vy = vy;
- physic.ax = ax;
- physic.ay = ay;
+ physic.set_velocity(vx, vy);
+ physic.set_acceleration(ax, ay);
// we get slower when not pressing any keys
if(dirsign == 0) {
if (!is_big())
return;
- if (physic.vy != 0)
+ if (physic.get_velocity_y() != 0)
return;
if (!on_ground())
return;
if (!on_ground())
return;
- physic.vy = yspeed;
+ physic.set_velocity_y(yspeed);
//bbox.move(Vector(0, -1));
jumping = true;
on_ground_flag = false;
if(controller->pressed(Controller::JUMP) && (can_jump)) {
if (duck) {
// when running, only jump a little bit; else do a backflip
- if ((physic.vx != 0) || (controller->hold(Controller::LEFT)) || (controller->hold(Controller::RIGHT))) do_jump(-300); else do_backflip();
+ if ((physic.get_velocity_x() != 0) || (controller->hold(Controller::LEFT)) || (controller->hold(Controller::RIGHT))) do_jump(-300); else do_backflip();
} else {
// jump a bit higher if we are running; else do a normal jump
- if (fabs(physic.vx) > MAX_WALK_XM) do_jump(-580); else do_jump(-520);
+ if (fabs(physic.get_velocity_x()) > MAX_WALK_XM) do_jump(-580); else do_jump(-520);
}
}
// Let go of jump key
else if(!controller->hold(Controller::JUMP)) {
- if (!backflipping && jumping && physic.vy < 0) {
+ if (!backflipping && jumping && physic.get_velocity_y() < 0) {
jumping = false;
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
}
butt_jump = false;
// swimming
- physic.ay = 0;
+ physic.set_acceleration_y(0);
if (swimming) {
if (controller->hold(Controller::UP) || controller->hold(Controller::JUMP))
- physic.ay = -2000;
- physic.vy = physic.vy * 0.94;
+ physic.set_acceleration_y(-2000);
+ physic.set_velocity_y(physic.get_velocity_y() * 0.94);
}
}
if(Sector::current()->add_bullet(
get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2)
: Vector(32, bbox.get_height()/2)),
- physic.vx, dir))
+ physic.get_velocity_x(), dir))
shooting_timer.start(SHOOTING_TIME);
}
if (controller->hold(Controller::ACTION)) {
set_ghost_mode(false);
}
- physic.vx = vx;
- physic.vy = vy;
- physic.ax = 0;
- physic.ay = 0;
+ physic.set_velocity(vx, vy);
+ physic.set_acceleration(0, 0);
}
void
}
else
{
- if (fabsf(physic.vx) < 1.0f) // standing
+ if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
{
if(dir == LEFT)
tux_body->set_action("stand-left");
}
// Tux is holding something
- if ((grabbed_object != 0 && physic.vy == 0) ||
+ if ((grabbed_object != 0 && physic.get_velocity_y() == 0) ||
(shooting_timer.get_timeleft() > 0 && !shooting_timer.check()))
{
if (duck)
Player::collision_solid(const CollisionHit& hit)
{
if(hit.bottom) {
- if(physic.vy > 0)
- physic.vy = 0;
+ if(physic.get_velocity_y() > 0)
+ physic.set_velocity_y(0);
on_ground_flag = true;
floor_normal = hit.slope_normal;
} else if(hit.top) {
- if(physic.vy < 0)
- physic.vy = .2;
+ if(physic.get_velocity_y() < 0)
+ physic.set_velocity_y(.2);
}
if(hit.left || hit.right) {
- physic.vx = 0;
+ physic.set_velocity_x(0);
}
// crushed?
sound_manager->play("sounds/hurt.wav");
- physic.vx = 0;
+ physic.set_velocity_x(0);
if(!completely && is_big()) {
if(player_status->bonus == FIRE_BONUS
Vector(systemRandom.rand(5), systemRandom.rand(-32,18)),
systemRandom.rand(-100,100)));
}
- physic.gravity_enabled = true;
- physic.vx = 0;
- physic.vy = -700;
- physic.ax = 0;
- physic.ay = 0;
+ physic.enable_gravity(true);
+ physic.set_acceleration(0, 0);
+ physic.set_velocity(0, -700);
player_status->coins -= 25;
set_bonus(NO_BONUS, true);
dying = true;
duck = false;
last_ground_y = vector.y;
- physic = Physic();
+ physic.reset();
}
void
void
Player::add_velocity(const Vector& velocity)
{
- physic.vx += velocity.x;
- physic.vy += velocity.y;
+ physic.set_velocity(physic.get_velocity() + velocity);
}
void
Player::add_velocity(const Vector& velocity, const Vector& end_speed)
{
if (end_speed.x > 0)
- physic.vx = std::min(physic.vx + velocity.x, end_speed.x);
+ physic.set_velocity_x(std::min(physic.get_velocity_x() + velocity.x, end_speed.x));
if (end_speed.x < 0)
- physic.vx = std::max(physic.vx + velocity.x, end_speed.x);
+ physic.set_velocity_x(std::max(physic.get_velocity_x() + velocity.x, end_speed.x));
if (end_speed.y > 0)
- physic.vy = std::min(physic.vy + velocity.y, end_speed.y);
+ physic.set_velocity_y(std::min(physic.get_velocity_y() + velocity.y, end_speed.y));
if (end_speed.y < 0)
- physic.vy = std::max(physic.vy + velocity.y, end_speed.y);
+ physic.set_velocity_y(std::max(physic.get_velocity_y() + velocity.y, end_speed.y));
}
void
Player::bounce(BadGuy& )
{
if(controller->hold(Controller::JUMP))
- physic.vy = -520;
+ physic.set_velocity_y(-520);
else
- physic.vy = -300;
+ physic.set_velocity_y(-300);
}
//Scripting Functions Below
if (deactivated)
return;
deactivated = true;
- physic.vx = 0;
- physic.vy = 0;
- physic.ax = 0;
- physic.ay = 0;
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
+ physic.set_acceleration_x(0);
+ physic.set_acceleration_y(0);
}
void
void Player::walk(float speed)
{
- physic.vx = speed;
+ physic.set_velocity_x(speed);
}
void
if (enable) {
ghost_mode = true;
set_group(COLGROUP_DISABLED);
- physic.gravity_enabled = false;
+ physic.enable_gravity(false);
log_debug << "You feel lightheaded. Use movement controls to float around, press ACTION to scare badguys." << std::endl;
} else {
ghost_mode = false;
set_group(COLGROUP_MOVING);
- physic.gravity_enabled = true;
+ physic.enable_gravity(true);
log_debug << "You feel solid again." << std::endl;
}
}
lisp.get("script", script);
no_physics = false;
lisp.get("disable-physics", no_physics);
- physic.gravity_enabled = true;
+ physic.enable_gravity(true);
sound_manager->preload("sounds/grow.wav");
sound_manager->preload("sounds/fire-flower.wav");
}
PowerUp::collision_solid(const CollisionHit& hit)
{
if(hit.bottom) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
}
if(hit.right || hit.left) {
- physic.vx = -physic.vx;
+ physic.set_velocity_x(-physic.get_velocity_x());
}
}
{
Player* player = dynamic_cast<Player*>(&other);
if (!player) return FORCE_MOVE;
- float vy = player->physic.vy;
+ float vy = player->physic.get_velocity_y();
//player->add_velocity(Vector(0, -150));
- player->physic.vy = -150;
+ player->physic.set_velocity_y(-150);
if (state != OFF) return FORCE_MOVE;
if (!hit.top) return FORCE_MOVE;
if( grabbed )
return;
- if (on_ground) physic.vx = 0;
+ if (on_ground) physic.set_velocity_x(0);
movement = physic.get_movement(elapsed_time);
}
Rock::collision_solid(const CollisionHit& hit)
{
if(hit.top || hit.bottom)
- physic.vy = 0;
+ physic.set_velocity_y(0);
if(hit.left || hit.right)
- physic.vx = 0;
+ physic.set_velocity_x(0);
if(hit.crush)
- physic.vx = 0;
- physic.vy = 0;
+ physic.set_velocity(0, 0);
if(hit.bottom && !on_ground) {
sound_manager->play(ROCK_SOUND, get_pos());
Rock::collision(GameObject& other, const CollisionHit& hit)
{
if(!on_ground) {
- if(hit.bottom && physic.vy > 200) {
+ if(hit.bottom && physic.get_velocity_y() > 200) {
MovingObject* moving_object = dynamic_cast<MovingObject*> (&other);
if(moving_object) {
//Getting a rock on the head hurts. A lot.
set_group(COLGROUP_MOVING_STATIC);
on_ground = false;
if (last_movement.norm() > 1) {
- physic.vx = ((dir == RIGHT) ? 200 : -200);
- physic.vy = -200;
+ physic.set_velocity((dir == RIGHT) ? 200 : -200, -200);
} else {
- physic.vx = 0;
- physic.vy = 0;
+ physic.set_velocity(0, 0);
}
grabbed = false;
}
{
printf("SetPos: %f %f\n", x, y);
bbox.set_pos(Vector(x, y));
- physic = Physic();
+ physic.reset();
}
float
float
ScriptedObject::get_velocity_x()
{
- return physic.vx;
+ return physic.get_velocity_x();
}
float
ScriptedObject::get_velocity_y()
{
- return physic.vy;
+ return physic.get_velocity_y();
}
void
return;
if(new_vel_set) {
- physic.vx = new_vel.x;
- physic.vy = new_vel.y;
+ physic.set_velocity(new_vel.x, new_vel.y);
new_vel_set = false;
}
movement = physic.get_movement(elapsed_time);
return;
if(hit.bottom) {
- if(physic.vy > 0)
- physic.vy = 0;
+ if(physic.get_velocity_y() > 0)
+ physic.set_velocity_y(0);
} else if(hit.top) {
- physic.vy = .1;
+ physic.set_velocity_y(.1);
}
if(hit.left || hit.right) {
- physic.vx = 0;
+ physic.set_velocity_x(0);
}
}
} else if(hit) {
if(timer.check()) {
falling = true;
- physic.gravity_enabled = true;
+ physic.enable_gravity(true);
timer.stop();
} else if(!timer.started()) {
timer.start(FALLTIME);
Star::Star(const Vector& pos, Direction direction)
: MovingSprite(pos, "images/powerups/star/star.sprite", LAYER_OBJECTS, COLGROUP_MOVING)
{
- physic.vx = ((direction == LEFT) ? -SPEED : SPEED);
- physic.vy = INITIALJUMP;
+ physic.set_velocity((direction == LEFT) ? -SPEED : SPEED, INITIALJUMP);
}
void
Star::collision_solid(const CollisionHit& hit)
{
if(hit.bottom) {
- physic.vy = JUMPSPEED;
+ physic.set_velocity_y(JUMPSPEED);
} else if(hit.top) {
- physic.vy = 0;
+ physic.set_velocity_y(0);
} else if(hit.left || hit.right) {
- physic.vx = -physic.vx;
+ physic.set_velocity_x(-physic.get_velocity_x());
}
}
Player* player = dynamic_cast<Player*> (&other);
//Trampoline works for player
if(player) {
- float vy = player->physic.vy;
+ float vy = player->physic.get_velocity_y();
//player is falling down on trampoline
if(hit.top && vy >= 0) {
if(player->get_controller()->hold(Controller::JUMP)) {
} else {
vy = VY_INITIAL;
}
- player->physic.vy = vy;
+ player->physic.set_velocity_y(vy);
sound_manager->play(TRAMPOLINE_SOUND);
sprite->set_action("swinging", 1);
return FORCE_MOVE;
state = STATE_DISINTEGRATING;
sprite->set_action("disintegrating", 1);
set_group(COLGROUP_DISABLED);
- physic.gravity_enabled = true;
+ physic.enable_gravity(true);
}
break;
#include "physic.hpp"
Physic::Physic()
- : ax(0), ay(0), vx(0), vy(0), gravity_enabled(true), gravity(1000)
+ : ax(0), ay(0), vx(0), vy(0), gravity_enabled_flag(true), gravity(1000)
{
}
+Physic::~Physic()
+{
+}
+
+void
+Physic::reset()
+{
+ ax = ay = vx = vy = 0;
+ gravity_enabled_flag = true;
+}
+
+void
+Physic::set_velocity_x(float nvx)
+{
+ vx = nvx;
+}
+
+void
+Physic::set_velocity_y(float nvy)
+{
+ vy = nvy;
+}
+
+void
+Physic::set_velocity(float nvx, float nvy)
+{
+ vx = nvx;
+ vy = nvy;
+}
+
+void
+Physic::set_velocity(const Vector& vector)
+{
+ vx = vector.x;
+ vy = vector.y;
+}
+
+void Physic::inverse_velocity_x()
+{
+ vx = -vx;
+}
+
+void Physic::inverse_velocity_y()
+{
+ vy = -vy;
+}
+
+float
+Physic::get_velocity_x() const
+{
+ return vx;
+}
+
+float
+Physic::get_velocity_y() const
+{
+ return vy;
+}
+
+Vector
+Physic::get_velocity() const
+{
+ return Vector(vx, vy);
+}
+
+void
+Physic::set_acceleration_x(float nax)
+{
+ ax = nax;
+}
+
+void
+Physic::set_acceleration_y(float nay)
+{
+ ay = nay;
+}
+
+void
+Physic::set_acceleration(float nax, float nay)
+{
+ ax = nax;
+ ay = nay;
+}
+
+float
+Physic::get_acceleration_x() const
+{
+ return ax;
+}
+
+float
+Physic::get_acceleration_y() const
+{
+ return ay;
+}
+
+Vector
+Physic::get_acceleration() const
+{
+ return Vector(ax, ay);
+}
+
+void
+Physic::enable_gravity(bool enable_gravity)
+{
+ gravity_enabled_flag = enable_gravity;
+}
+
+bool
+Physic::gravity_enabled() const
+{
+ return gravity_enabled_flag;
+}
+
+void
+Physic::set_gravity(float gravity)
+{
+ this->gravity = gravity;
+}
+
+float
+Physic::get_gravity() const
+{
+ return gravity;
+}
+
Vector
Physic::get_movement(float elapsed_time)
{
- float grav = gravity_enabled ? gravity : 0;
+ float grav = gravity_enabled_flag ? gravity : 0;
Vector result(
vx * elapsed_time + ax * elapsed_time * elapsed_time,
{
public:
Physic();
+ ~Physic();
+
+ /// Resets all velocities and accelerations to 0.
+ void reset();
+
+ /// Sets velocity to a fixed value.
+ void set_velocity(float vx, float vy);
+ void set_velocity(const Vector& vector);
+
+ void set_velocity_x(float vx);
+ void set_velocity_y(float vy);
+
+ /// Velocities invertion.
+ void inverse_velocity_x();
+ void inverse_velocity_y();
+
+ Vector get_velocity() const;
+ float get_velocity_x() const;
+ float get_velocity_y() const;
+
+ /// Set acceleration.
+ /** Sets acceleration applied to the object. (Note that gravity is
+ * eventually added to the vertical acceleration)
+ */
+ void set_acceleration(float ax, float ay);
+
+ void set_acceleration_x(float ax);
+ void set_acceleration_y(float ay);
+
+ Vector get_acceleration() const;
+ float get_acceleration_x() const;
+ float get_acceleration_y() const;
+
+ /// Enables or disables handling of gravity.
+ void enable_gravity(bool gravity_enabled);
+ bool gravity_enabled() const;
+
+ /// Set gravity to apply to object when enabled
+ void set_gravity(float gravity);
+
+ /// Get gravity to apply to object when enabled
+ float get_gravity() const;
Vector get_movement(float elapsed_time);
+private:
/// horizontal and vertical acceleration
float ax, ay;
/// horizontal and vertical velocity
float vx, vy;
- /// should we respect gravity in our calculations?
- bool gravity_enabled;
+ /// should we respect gravity in out calculations?
+ bool gravity_enabled_flag;
/// current gravity to apply to object, if enabled
float gravity;
};
{
if (!validate_sector_player()) return;
::Player* tux = Sector::current()->player; // Scripting::Player != ::Player
- tux->physic.vx = tux->physic.vx*3;
+ tux->physic.set_velocity_x(tux->physic.get_velocity_x()*3);
}
void invincible()