//
// Zeekling - flyer that swoops down when she spots the player
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
-// Copyright (C) 2006 Christoph Sommer <supertux@2006.expires.deltadevelopment.de>
+// Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
#include "random_generator.hpp"
Zeekling::Zeekling(const lisp::Lisp& reader)
- : BadGuy(reader, "images/creatures/zeekling/zeekling.sprite"), last_player(0)
+ : BadGuy(reader, "images/creatures/zeekling/zeekling.sprite"), last_player(0)
{
state = FLYING;
+ speed = systemRandom.rand(130, 171);
+ physic.enable_gravity(false);
}
Zeekling::Zeekling(const Vector& pos, Direction d)
- : BadGuy(pos, d, "images/creatures/zeekling/zeekling.sprite"), last_player(0)
+ : BadGuy(pos, d, "images/creatures/zeekling/zeekling.sprite"), last_player(0)
{
state = FLYING;
+ speed = systemRandom.rand(130, 171);
+ physic.enable_gravity(false);
}
void
}
void
-Zeekling::activate()
+Zeekling::initialize()
{
- speed = systemRandom.rand(130, 171);
- physic.vx = (dir == LEFT ? -speed : speed);
- physic.gravity_enabled = false;
+ physic.set_velocity_x(dir == LEFT ? -speed : speed);
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;