From: Christoph Sommer Date: Sun, 3 Feb 2008 17:29:23 +0000 (+0000) Subject: Make Badguy activation dependent of Player position, not currently-visible screen X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=af906b173f5e7118644397ce35145e6b88f40be8;p=supertux.git Make Badguy activation dependent of Player position, not currently-visible screen SVN-Revision: 5310 --- diff --git a/src/badguy/angrystone.cpp b/src/badguy/angrystone.cpp index d6dd326fd..d44f9d8e7 100644 --- a/src/badguy/angrystone.cpp +++ b/src/badguy/angrystone.cpp @@ -31,6 +31,10 @@ static const float RECOVER_TIME = .5; AngryStone::AngryStone(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/angrystone/angrystone.sprite"), state(IDLE) { + physic.set_velocity_x(0); + physic.set_velocity_y(0); + physic.enable_gravity(true); + sprite->set_action("idle"); } void @@ -45,15 +49,6 @@ AngryStone::write(lisp::Writer& writer) } void -AngryStone::activate() -{ - physic.set_velocity_x(0); - physic.set_velocity_y(0); - physic.enable_gravity(true); - sprite->set_action("idle"); -} - -void AngryStone::collision_solid(const CollisionHit& hit) { // TODO diff --git a/src/badguy/angrystone.hpp b/src/badguy/angrystone.hpp index 73466af09..1a46e0c72 100644 --- a/src/badguy/angrystone.hpp +++ b/src/badguy/angrystone.hpp @@ -28,7 +28,6 @@ class AngryStone : public BadGuy public: AngryStone(const lisp::Lisp& reader); - void activate(); void write(lisp::Writer& writer); void collision_solid(const CollisionHit& hit); HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index cddb7ac0c..0e9347e78 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -17,7 +17,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include - #include "badguy.hpp" #include "object/camera.hpp" #include "object/tilemap.hpp" @@ -32,33 +31,38 @@ #include "random_generator.hpp" static const float SQUISH_TIME = 2; + static const float X_OFFSCREEN_DISTANCE = 1600; static const float Y_OFFSCREEN_DISTANCE = 1200; BadGuy::BadGuy(const Vector& pos, const std::string& sprite_name, int layer) - : MovingSprite(pos, sprite_name, layer, COLGROUP_DISABLED), countMe(true), + : MovingSprite(pos, sprite_name, layer, COLGROUP_DISABLED), countMe(true), is_initialized(false), dir(LEFT), start_dir(AUTO), frozen(false), ignited(false), - state(STATE_INIT), on_ground_flag(false) + state(STATE_INIT), on_ground_flag(false), colgroup_active(COLGROUP_MOVING) { start_position = bbox.p1; sound_manager->preload("sounds/squish.wav"); sound_manager->preload("sounds/fall.wav"); + + dir = (start_dir == AUTO) ? LEFT : start_dir; } BadGuy::BadGuy(const Vector& pos, Direction direction, const std::string& sprite_name, int layer) - : MovingSprite(pos, sprite_name, layer, COLGROUP_DISABLED), countMe(true), + : MovingSprite(pos, sprite_name, layer, COLGROUP_DISABLED), countMe(true), is_initialized(false), dir(direction), start_dir(direction), frozen(false), ignited(false), - state(STATE_INIT), on_ground_flag(false) + state(STATE_INIT), on_ground_flag(false), colgroup_active(COLGROUP_MOVING) { start_position = bbox.p1; sound_manager->preload("sounds/squish.wav"); sound_manager->preload("sounds/fall.wav"); + + dir = (start_dir == AUTO) ? LEFT : start_dir; } BadGuy::BadGuy(const lisp::Lisp& reader, const std::string& sprite_name, int layer) - : MovingSprite(reader, sprite_name, layer, COLGROUP_DISABLED), countMe(true), dir(LEFT), start_dir(AUTO), frozen(false), ignited(false), state(STATE_INIT), on_ground_flag(false) + : MovingSprite(reader, sprite_name, layer, COLGROUP_DISABLED), countMe(true), is_initialized(false), dir(LEFT), start_dir(AUTO), frozen(false), ignited(false), state(STATE_INIT), on_ground_flag(false), colgroup_active(COLGROUP_MOVING) { start_position = bbox.p1; @@ -71,6 +75,8 @@ BadGuy::BadGuy(const lisp::Lisp& reader, const std::string& sprite_name, int lay sound_manager->preload("sounds/squish.wav"); sound_manager->preload("sounds/fall.wav"); + + dir = (start_dir == AUTO) ? LEFT : start_dir; } void @@ -98,7 +104,7 @@ BadGuy::update(float elapsed_time) remove_me(); return; } - if(is_offscreen()) { + if ((state != STATE_INACTIVE) && is_offscreen()) { if (state == STATE_ACTIVE) deactivate(); set_state(STATE_INACTIVE); } @@ -147,6 +153,11 @@ BadGuy::str2dir( std::string dir_str ) } void +BadGuy::initialize() +{ +} + +void BadGuy::activate() { } @@ -371,8 +382,8 @@ BadGuy::set_state(State state) state_timer.start(SQUISH_TIME); break; case STATE_ACTIVE: - set_group(COLGROUP_MOVING); - bbox.set_pos(start_position); + set_group(colgroup_active); + //bbox.set_pos(start_position); break; case STATE_INACTIVE: // was the badguy dead anyway? @@ -392,79 +403,40 @@ BadGuy::set_state(State state) bool BadGuy::is_offscreen() { - float scroll_x = Sector::current()->camera->get_translation().x; - float scroll_y = Sector::current()->camera->get_translation().y; - - if(bbox.p2.x < scroll_x - X_OFFSCREEN_DISTANCE - || bbox.p1.x > scroll_x + X_OFFSCREEN_DISTANCE + SCREEN_WIDTH - || bbox.p2.y < scroll_y - Y_OFFSCREEN_DISTANCE - || bbox.p1.y > scroll_y + Y_OFFSCREEN_DISTANCE + SCREEN_HEIGHT) - return true; - - return false; + Player* player = get_nearest_player(); + if (!player) return false; + Vector dist = player->get_bbox().get_middle() - get_bbox().get_middle(); + if ((dist.x <= X_OFFSCREEN_DISTANCE+32) && (dist.y <= Y_OFFSCREEN_DISTANCE+32)) { + return false; + } + return true; } void BadGuy::try_activate() { - float scroll_x = Sector::current()->camera->get_translation().x; - float scroll_y = Sector::current()->camera->get_translation().y; - - /* Activate badguys if they're just around the screen to avoid - * the effect of having badguys suddenly popping up from nowhere. - */ - //Badguy left of screen - if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE && - start_position.x < scroll_x - bbox.get_width() && - start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && - start_position.y < scroll_y + SCREEN_HEIGHT + Y_OFFSCREEN_DISTANCE) { - if (start_dir != AUTO) dir = start_dir; else dir = RIGHT; - set_state(STATE_ACTIVE); - activate(); - //Badguy right of screen - } else if (start_position.x > scroll_x + SCREEN_WIDTH && - start_position.x < scroll_x + SCREEN_WIDTH + X_OFFSCREEN_DISTANCE && - start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && - start_position.y < scroll_y + SCREEN_HEIGHT + Y_OFFSCREEN_DISTANCE) { - if (start_dir != AUTO) dir = start_dir; else dir = LEFT; + // In SuperTux 0.1.x, Badguys were activated when Tux<->Badguy center distance was approx. <= ~668px + // This doesn't work for wide-screen monitors which give us a virt. res. of approx. 1066px x 600px + Player* player = get_nearest_player(); + if (!player) return; + Vector dist = player->get_bbox().get_middle() - get_bbox().get_middle(); + if ((fabsf(dist.x) <= X_OFFSCREEN_DISTANCE) && (fabsf(dist.y) <= Y_OFFSCREEN_DISTANCE)) { set_state(STATE_ACTIVE); - activate(); - //Badguy over or under screen - } else if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE && - start_position.x < scroll_x + SCREEN_WIDTH + X_OFFSCREEN_DISTANCE && - ((start_position.y > scroll_y + SCREEN_HEIGHT && - start_position.y < scroll_y + SCREEN_HEIGHT + Y_OFFSCREEN_DISTANCE) || - (start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && - start_position.y < scroll_y - bbox.get_height() ))) { - if (start_dir != AUTO) dir = start_dir; - else{ - // if nearest player is to our right, start facing right - Player* player = get_nearest_player(); - if (player && (player->get_bbox().p1.x > get_bbox().p2.x)) { - dir = RIGHT; - } else { - dir = LEFT; - } - } - set_state(STATE_ACTIVE); - activate(); - } else if(state == STATE_INIT - && start_position.x > scroll_x - X_OFFSCREEN_DISTANCE - && start_position.x < scroll_x + X_OFFSCREEN_DISTANCE + SCREEN_WIDTH - && start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE - && start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE + SCREEN_HEIGHT ) { - if (start_dir != AUTO) { - dir = start_dir; - } else { - // if nearest player is to our right, start facing right - Player* player = get_nearest_player(); - if (player && (player->get_bbox().p1.x > get_bbox().p2.x)) { - dir = RIGHT; - } else { - dir = LEFT; + if (!is_initialized) { + + // if starting direction was set to AUTO, this is our chance to re-orient the badguy + if (start_dir == AUTO) { + Player* player = get_nearest_player(); + if (player && (player->get_bbox().p1.x > get_bbox().p2.x)) { + dir = RIGHT; + } else { + dir = LEFT; + } } + + initialize(); + is_initialized = true; } - set_state(STATE_ACTIVE); activate(); } } @@ -541,7 +513,7 @@ BadGuy::freeze() void BadGuy::unfreeze() { - set_group(COLGROUP_MOVING); + set_group(colgroup_active); frozen = false; } @@ -579,3 +551,11 @@ BadGuy::is_ignited() const { return ignited; } + +void +BadGuy::set_colgroup_active(CollisionGroup group) +{ + this->colgroup_active = group; + if (state == STATE_ACTIVE) set_group(group); +} + diff --git a/src/badguy/badguy.hpp b/src/badguy/badguy.hpp index 31a5a2dae..2af09d213 100644 --- a/src/badguy/badguy.hpp +++ b/src/badguy/badguy.hpp @@ -162,6 +162,9 @@ protected: /** called each frame when the badguy is not activated. */ virtual void inactive_update(float elapsed_time); + bool is_initialized; /**< true if initialize() has already been called */ + /** called immediately before the first call to initialize */ + virtual void initialize(); /** * called when the badguy has been activated. (As a side effect the dir * variable might have been changed so that it faces towards the player. @@ -181,8 +184,6 @@ protected: */ Player* get_nearest_player(); - /// is the enemy activated - bool activated; /** * initial position of the enemy. Also the position where enemy respawns when * after being deactivated. @@ -238,6 +239,8 @@ protected: */ bool is_active(); + void set_colgroup_active(CollisionGroup group); /**< changes colgroup_active. Also calls set_group when badguy is in STATE_ACTIVE */ + private: void try_activate(); @@ -246,6 +249,7 @@ private: Timer state_timer; bool on_ground_flag; /**< true if we touched something solid from above and update_on_ground_flag was called last frame */ Vector floor_normal; /**< floor normal stored the last time when update_on_ground_flag was called and we touched something solid from above */ + CollisionGroup colgroup_active; /**< CollisionGroup the badguy should be in while active */ }; diff --git a/src/badguy/bouncing_snowball.cpp b/src/badguy/bouncing_snowball.cpp index f84561b74..ae9e91d1b 100644 --- a/src/badguy/bouncing_snowball.cpp +++ b/src/badguy/bouncing_snowball.cpp @@ -46,7 +46,7 @@ BouncingSnowball::write(lisp::Writer& writer) } void -BouncingSnowball::activate() +BouncingSnowball::initialize() { physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); diff --git a/src/badguy/bouncing_snowball.hpp b/src/badguy/bouncing_snowball.hpp index ed2c5cb16..933eb6508 100644 --- a/src/badguy/bouncing_snowball.hpp +++ b/src/badguy/bouncing_snowball.hpp @@ -28,7 +28,7 @@ public: BouncingSnowball(const lisp::Lisp& reader); BouncingSnowball(const Vector& pos, Direction d); - void activate(); + void initialize(); void write(lisp::Writer& writer); void collision_solid(const CollisionHit& hit); HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); diff --git a/src/badguy/dart.cpp b/src/badguy/dart.cpp index c5ad86eb7..9df6e8ce4 100644 --- a/src/badguy/dart.cpp +++ b/src/badguy/dart.cpp @@ -78,11 +78,15 @@ Dart::write(lisp::Writer& writer) } void -Dart::activate() +Dart::initialize() { physic.set_velocity_x(dir == LEFT ? -::SPEED : ::SPEED); sprite->set_action(dir == LEFT ? "flying-left" : "flying-right"); +} +void +Dart::activate() +{ sound_source.reset(sound_manager->create_sound_source(SOUNDFILE)); sound_source->set_position(get_pos()); sound_source->set_looping(true); diff --git a/src/badguy/dart.hpp b/src/badguy/dart.hpp index b8807e083..0fb6dc3ec 100644 --- a/src/badguy/dart.hpp +++ b/src/badguy/dart.hpp @@ -34,6 +34,7 @@ public: Dart(const Dart& dart); ~Dart(); + void initialize(); void activate(); void deactivate(); void write(lisp::Writer& writer); diff --git a/src/badguy/darttrap.cpp b/src/badguy/darttrap.cpp index be6cc1d01..41cc5858a 100644 --- a/src/badguy/darttrap.cpp +++ b/src/badguy/darttrap.cpp @@ -35,6 +35,9 @@ DartTrap::DartTrap(const lisp::Lisp& reader) countMe = false; sound_manager->preload("sounds/dartfire.wav"); if (start_dir == AUTO) log_warning << "Setting a DartTrap's direction to AUTO is no good idea" << std::endl; + state = IDLE; + set_colgroup_active(COLGROUP_DISABLED); + if (initial_delay == 0) initial_delay = 0.1f; } void @@ -50,13 +53,14 @@ DartTrap::write(lisp::Writer& writer) } void -DartTrap::activate() +DartTrap::initialize() { - state = IDLE; sprite->set_action(dir == LEFT ? "idle-left" : "idle-right"); - set_group(COLGROUP_DISABLED); +} - if (initial_delay == 0) initial_delay = 0.1f; +void +DartTrap::activate() +{ fire_timer.start(initial_delay); } diff --git a/src/badguy/darttrap.hpp b/src/badguy/darttrap.hpp index 1ba805938..da187668b 100644 --- a/src/badguy/darttrap.hpp +++ b/src/badguy/darttrap.hpp @@ -31,6 +31,7 @@ class DartTrap : public BadGuy public: DartTrap(const lisp::Lisp& reader); + void initialize(); void activate(); void write(lisp::Writer& writer); void active_update(float elapsed_time); diff --git a/src/badguy/dispenser.cpp b/src/badguy/dispenser.cpp index 613f06ec3..c603946e3 100644 --- a/src/badguy/dispenser.cpp +++ b/src/badguy/dispenser.cpp @@ -64,11 +64,6 @@ Dispenser::write(lisp::Writer& writer) void Dispenser::activate() { - if(frozen) - return; - if (badguy == "mrrocket") { - sprite->set_action(dir == LEFT ? "working-left" : "working-right"); - } dispense_timer.start(cycle, true); launch_badguy(); } diff --git a/src/badguy/fish.cpp b/src/badguy/fish.cpp index 803512096..93898d476 100644 --- a/src/badguy/fish.cpp +++ b/src/badguy/fish.cpp @@ -125,7 +125,7 @@ void Fish::start_waiting() { waiting.start(FISH_WAIT_TIME); - set_group(COLGROUP_DISABLED); + set_colgroup_active(COLGROUP_DISABLED); physic.enable_gravity(false); physic.set_velocity_y(0); } @@ -135,7 +135,7 @@ Fish::jump() { physic.set_velocity_y(FISH_JUMP_POWER); physic.enable_gravity(true); - set_group(COLGROUP_MOVING); + set_colgroup_active(COLGROUP_MOVING); } void diff --git a/src/badguy/flame.cpp b/src/badguy/flame.cpp index 7f8d3562e..8f035a7f4 100644 --- a/src/badguy/flame.cpp +++ b/src/badguy/flame.cpp @@ -33,6 +33,8 @@ Flame::Flame(const lisp::Lisp& reader) start_position.y + sin(angle) * radius)); countMe = false; sound_manager->preload(SOUNDFILE); + + set_colgroup_active(COLGROUP_TOUCHABLE); } void @@ -62,8 +64,6 @@ Flame::active_update(float elapsed_time) void Flame::activate() { - set_group(COLGROUP_TOUCHABLE); - sound_source.reset(sound_manager->create_sound_source(SOUNDFILE)); sound_source->set_position(get_pos()); sound_source->set_looping(true); diff --git a/src/badguy/flyingsnowball.cpp b/src/badguy/flyingsnowball.cpp index a0abf233a..9cc2363b8 100644 --- a/src/badguy/flyingsnowball.cpp +++ b/src/badguy/flyingsnowball.cpp @@ -58,12 +58,17 @@ FlyingSnowBall::write(lisp::Writer& writer) } void -FlyingSnowBall::activate() +FlyingSnowBall::initialize() { sprite->set_action(dir == LEFT ? "left" : "right"); mode = FLY_UP; physic.set_velocity_y(FLYSPEED); timer.start(FLYTIME/2); +} + +void +FlyingSnowBall::activate() +{ puff_timer.start(systemRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX)); } diff --git a/src/badguy/flyingsnowball.hpp b/src/badguy/flyingsnowball.hpp index 43e932494..7a00ddbce 100644 --- a/src/badguy/flyingsnowball.hpp +++ b/src/badguy/flyingsnowball.hpp @@ -28,6 +28,7 @@ public: FlyingSnowBall(const lisp::Lisp& reader); FlyingSnowBall(const Vector& pos); + void initialize(); void activate(); void write(lisp::Writer& writer); void active_update(float elapsed_time); diff --git a/src/badguy/ghosttree.cpp b/src/badguy/ghosttree.cpp index 973afa86b..61b5d5767 100644 --- a/src/badguy/ghosttree.cpp +++ b/src/badguy/ghosttree.cpp @@ -38,6 +38,7 @@ GhostTree::GhostTree(const lisp::Lisp& lisp) treecolor(0), suck_lantern(0) { glow_sprite.reset(sprite_manager->create("images/creatures/ghosttree/ghosttree-glow.sprite")); + set_colgroup_active(COLGROUP_TOUCHABLE); } GhostTree::~GhostTree() @@ -64,7 +65,6 @@ GhostTree::activate() willowisp_timer.start(1.0f, true); colorchange_timer.start(13, true); root_timer.start(5, true); - set_group(COLGROUP_TOUCHABLE); } void diff --git a/src/badguy/igel.cpp b/src/badguy/igel.cpp index b8450d226..60bb104bb 100644 --- a/src/badguy/igel.cpp +++ b/src/badguy/igel.cpp @@ -55,7 +55,7 @@ Igel::write(lisp::Writer& writer) void Igel::be_normal() { - activate(); + initialize(); } void diff --git a/src/badguy/kugelblitz.cpp b/src/badguy/kugelblitz.cpp index cbfdd9986..0022171de 100644 --- a/src/badguy/kugelblitz.cpp +++ b/src/badguy/kugelblitz.cpp @@ -52,7 +52,7 @@ Kugelblitz::write(lisp::Writer& writer) } void -Kugelblitz::activate() +Kugelblitz::initialize() { physic.set_velocity_y(300); physic.set_velocity_x(-20); //fall a little to the left diff --git a/src/badguy/kugelblitz.hpp b/src/badguy/kugelblitz.hpp index 5f327f29e..b16999769 100644 --- a/src/badguy/kugelblitz.hpp +++ b/src/badguy/kugelblitz.hpp @@ -29,7 +29,7 @@ class Kugelblitz : public BadGuy public: Kugelblitz(const lisp::Lisp& reader); - void activate(); + void initialize(); HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit); void collision_solid(const CollisionHit& hit); HitResponse collision_player(Player& player, const CollisionHit& hit); diff --git a/src/badguy/mole.cpp b/src/badguy/mole.cpp index 513274352..54dfe1710 100644 --- a/src/badguy/mole.cpp +++ b/src/badguy/mole.cpp @@ -138,27 +138,27 @@ Mole::set_state(MoleState new_state) switch (new_state) { case PRE_THROWING: sprite->set_action("idle"); - set_group(COLGROUP_DISABLED); + set_colgroup_active(COLGROUP_DISABLED); timer.start(IDLE_TIME); break; case THROWING: sprite->set_action("idle"); - set_group(COLGROUP_DISABLED); + set_colgroup_active(COLGROUP_DISABLED); timer.start(THROW_TIME); throw_timer.start(THROW_INTERVAL); break; case POST_THROWING: sprite->set_action("idle"); - set_group(COLGROUP_DISABLED); + set_colgroup_active(COLGROUP_DISABLED); timer.start(IDLE_TIME); break; case PEEKING: sprite->set_action("peeking", 1); - set_group(COLGROUP_STATIC); + set_colgroup_active(COLGROUP_STATIC); break; case DEAD: sprite->set_action("idle"); - set_group(COLGROUP_DISABLED); + set_colgroup_active(COLGROUP_DISABLED); break; } diff --git a/src/badguy/mole_rock.cpp b/src/badguy/mole_rock.cpp index c9252ff05..5de7914f8 100644 --- a/src/badguy/mole_rock.cpp +++ b/src/badguy/mole_rock.cpp @@ -65,7 +65,7 @@ MoleRock::write(lisp::Writer& writer) } void -MoleRock::activate() +MoleRock::initialize() { physic.set_velocity(initial_velocity); sprite->set_action("default"); diff --git a/src/badguy/mole_rock.hpp b/src/badguy/mole_rock.hpp index 42a7e05e4..f5bb95b64 100644 --- a/src/badguy/mole_rock.hpp +++ b/src/badguy/mole_rock.hpp @@ -34,7 +34,7 @@ public: MoleRock(const MoleRock& mole_rock); ~MoleRock(); - void activate(); + void initialize(); void deactivate(); void write(lisp::Writer& writer); diff --git a/src/badguy/mrbomb.cpp b/src/badguy/mrbomb.cpp index 93a58c2f2..cc74c01a4 100644 --- a/src/badguy/mrbomb.cpp +++ b/src/badguy/mrbomb.cpp @@ -115,7 +115,7 @@ MrBomb::grab(MovingObject&, const Vector& pos, Direction dir) movement = pos - get_pos(); this->dir = dir; sprite->set_action(dir == LEFT ? "iced-left" : "iced-right"); - set_group(COLGROUP_DISABLED); + set_colgroup_active(COLGROUP_DISABLED); grabbed = true; } @@ -123,7 +123,7 @@ void MrBomb::ungrab(MovingObject& , Direction dir) { this->dir = dir; - set_group(COLGROUP_MOVING); + set_colgroup_active(COLGROUP_MOVING); grabbed = false; } diff --git a/src/badguy/mriceblock.cpp b/src/badguy/mriceblock.cpp index 481bf088f..7cd8d863a 100644 --- a/src/badguy/mriceblock.cpp +++ b/src/badguy/mriceblock.cpp @@ -57,9 +57,9 @@ MrIceBlock::write(lisp::Writer& writer) } void -MrIceBlock::activate() +MrIceBlock::initialize() { - WalkingBadguy::activate(); + WalkingBadguy::initialize(); set_state(ICESTATE_NORMAL); } @@ -227,7 +227,7 @@ MrIceBlock::set_state(IceState state) switch(state) { case ICESTATE_NORMAL: - WalkingBadguy::activate(); + WalkingBadguy::initialize(); break; case ICESTATE_FLAT: if(dir == UP) { @@ -266,7 +266,7 @@ MrIceBlock::grab(MovingObject&, const Vector& pos, Direction dir) this->dir = dir; sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); set_state(ICESTATE_GRABBED); - set_group(COLGROUP_DISABLED); + set_colgroup_active(COLGROUP_DISABLED); } void @@ -274,7 +274,7 @@ MrIceBlock::ungrab(MovingObject& , Direction dir) { this->dir = dir; set_state(dir == UP ? ICESTATE_FLAT : ICESTATE_KICKED); - set_group(COLGROUP_MOVING); + set_colgroup_active(COLGROUP_MOVING); } bool diff --git a/src/badguy/mriceblock.hpp b/src/badguy/mriceblock.hpp index 9d6eb9774..ddf3847aa 100644 --- a/src/badguy/mriceblock.hpp +++ b/src/badguy/mriceblock.hpp @@ -29,7 +29,7 @@ public: MrIceBlock(const lisp::Lisp& reader); MrIceBlock(const Vector& pos, Direction d); - void activate(); + void initialize(); void write(lisp::Writer& writer); HitResponse collision(GameObject& object, const CollisionHit& hit); void collision_solid(const CollisionHit& hit); diff --git a/src/badguy/mrrocket.cpp b/src/badguy/mrrocket.cpp index 4ac7045a0..33c60201a 100644 --- a/src/badguy/mrrocket.cpp +++ b/src/badguy/mrrocket.cpp @@ -46,7 +46,7 @@ MrRocket::write(lisp::Writer& writer) } void -MrRocket::activate() +MrRocket::initialize() { physic.set_velocity_x(dir == LEFT ? -SPEED : SPEED); physic.enable_gravity(false); diff --git a/src/badguy/mrrocket.hpp b/src/badguy/mrrocket.hpp index 628df377d..4ff120945 100644 --- a/src/badguy/mrrocket.hpp +++ b/src/badguy/mrrocket.hpp @@ -29,7 +29,7 @@ public: MrRocket(const lisp::Lisp& reader); MrRocket(const Vector& pos, Direction d); - void activate(); + void initialize(); void active_update(float elapsed_time); void write(lisp::Writer& writer); void collision_solid(const CollisionHit& hit); diff --git a/src/badguy/plant.cpp b/src/badguy/plant.cpp index 5830d2b01..27db59bcd 100644 --- a/src/badguy/plant.cpp +++ b/src/badguy/plant.cpp @@ -42,7 +42,7 @@ Plant::write(lisp::Writer& writer) } void -Plant::activate() +Plant::initialize() { //FIXME: turns sspiky around for debugging dir = dir == LEFT ? RIGHT : LEFT; diff --git a/src/badguy/plant.hpp b/src/badguy/plant.hpp index 7216514e6..97aea8b67 100644 --- a/src/badguy/plant.hpp +++ b/src/badguy/plant.hpp @@ -27,7 +27,7 @@ class Plant : public BadGuy public: Plant(const lisp::Lisp& reader); - void activate(); + void initialize(); void write(lisp::Writer& writer); void collision_solid(const CollisionHit& hit); HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); diff --git a/src/badguy/root.cpp b/src/badguy/root.cpp index cad33cbc0..525468720 100644 --- a/src/badguy/root.cpp +++ b/src/badguy/root.cpp @@ -35,6 +35,7 @@ Root::Root(const Vector& pos) base_sprite->set_action("appearing", 1); base_sprite->set_animation_loops(1); // TODO: necessary because set_action ignores loops for default action physic.enable_gravity(false); + set_colgroup_active(COLGROUP_TOUCHABLE); } Root::~Root() @@ -42,12 +43,6 @@ Root::~Root() } void -Root::activate() -{ - set_group(COLGROUP_TOUCHABLE); -} - -void Root::deactivate() { remove_me(); diff --git a/src/badguy/root.hpp b/src/badguy/root.hpp index d693f232d..b3a302c0d 100644 --- a/src/badguy/root.hpp +++ b/src/badguy/root.hpp @@ -30,7 +30,6 @@ public: Root(const Vector& pos); ~Root(); - void activate(); void deactivate(); void active_update(float elapsed_time); virtual void draw(DrawingContext& context); diff --git a/src/badguy/skullyhop.cpp b/src/badguy/skullyhop.cpp index 76339f821..3c1fe3e21 100644 --- a/src/badguy/skullyhop.cpp +++ b/src/badguy/skullyhop.cpp @@ -52,7 +52,7 @@ SkullyHop::write(lisp::Writer& writer) } void -SkullyHop::activate() +SkullyHop::initialize() { // initial state is JUMPING, because we might start airborne state = JUMPING; diff --git a/src/badguy/skullyhop.hpp b/src/badguy/skullyhop.hpp index 02624b7c0..970ed93b8 100644 --- a/src/badguy/skullyhop.hpp +++ b/src/badguy/skullyhop.hpp @@ -32,7 +32,7 @@ public: SkullyHop(const lisp::Lisp& reader); SkullyHop(const Vector& pos, Direction d); - void activate(); + void initialize(); void write(lisp::Writer& writer); void collision_solid(const CollisionHit& hit); HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); diff --git a/src/badguy/snail.cpp b/src/badguy/snail.cpp index d68aad7f9..33d19155e 100644 --- a/src/badguy/snail.cpp +++ b/src/badguy/snail.cpp @@ -57,9 +57,9 @@ Snail::write(lisp::Writer& writer) } void -Snail::activate() +Snail::initialize() { - WalkingBadguy::activate(); + WalkingBadguy::initialize(); be_normal(); } @@ -69,7 +69,7 @@ Snail::be_normal() if (state == STATE_NORMAL) return; state = STATE_NORMAL; - WalkingBadguy::activate(); + WalkingBadguy::initialize(); } void diff --git a/src/badguy/snail.hpp b/src/badguy/snail.hpp index 642df55b2..0d31ca8c4 100644 --- a/src/badguy/snail.hpp +++ b/src/badguy/snail.hpp @@ -31,7 +31,7 @@ public: Snail(const lisp::Lisp& reader); Snail(const Vector& pos, Direction d); - void activate(); + void initialize(); void write(lisp::Writer& writer); void collision_solid(const CollisionHit& hit); HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); diff --git a/src/badguy/spidermite.cpp b/src/badguy/spidermite.cpp index 96a90a0ee..8ea7e74eb 100644 --- a/src/badguy/spidermite.cpp +++ b/src/badguy/spidermite.cpp @@ -49,7 +49,7 @@ SpiderMite::write(lisp::Writer& writer) } void -SpiderMite::activate() +SpiderMite::initialize() { sprite->set_action(dir == LEFT ? "left" : "right"); mode = FLY_UP; diff --git a/src/badguy/spidermite.hpp b/src/badguy/spidermite.hpp index ee36b5b20..1e17f0961 100644 --- a/src/badguy/spidermite.hpp +++ b/src/badguy/spidermite.hpp @@ -28,7 +28,7 @@ public: SpiderMite(const lisp::Lisp& reader); SpiderMite(const Vector& pos); - void activate(); + void initialize(); void write(lisp::Writer& writer); void active_update(float elapsed_time); void collision_solid(const CollisionHit& hit); diff --git a/src/badguy/sspiky.cpp b/src/badguy/sspiky.cpp index ad80b8de8..68ebaaa24 100644 --- a/src/badguy/sspiky.cpp +++ b/src/badguy/sspiky.cpp @@ -39,7 +39,7 @@ SSpiky::write(lisp::Writer& writer) } void -SSpiky::activate() +SSpiky::initialize() { state = SSPIKY_SLEEPING; physic.set_velocity_x(0); @@ -99,7 +99,7 @@ SSpiky::active_update(float elapsed_time) { if(sprite->animation_done()) { // start walking state = SSPIKY_WALKING; - WalkingBadguy::activate(); + WalkingBadguy::initialize(); } BadGuy::active_update(elapsed_time); diff --git a/src/badguy/sspiky.hpp b/src/badguy/sspiky.hpp index 8e346cdfe..b6a35ed84 100644 --- a/src/badguy/sspiky.hpp +++ b/src/badguy/sspiky.hpp @@ -27,7 +27,7 @@ class SSpiky : public WalkingBadguy public: SSpiky(const lisp::Lisp& reader); - void activate(); + void initialize(); void write(lisp::Writer& writer); void collision_solid(const CollisionHit& hit); HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); diff --git a/src/badguy/stalactite.cpp b/src/badguy/stalactite.cpp index 8bde2fbd3..8dc7f846f 100644 --- a/src/badguy/stalactite.cpp +++ b/src/badguy/stalactite.cpp @@ -72,7 +72,7 @@ void Stalactite::squish() { state = STALACTITE_SQUISHED; - set_group(COLGROUP_MOVING_ONLY_STATIC); + set_colgroup_active(COLGROUP_MOVING_ONLY_STATIC); sprite->set_action("squished"); if(!timer.started()) timer.start(SQUISH_TIME); diff --git a/src/badguy/stumpy.cpp b/src/badguy/stumpy.cpp index c53fe39d3..5f9b7aefd 100644 --- a/src/badguy/stumpy.cpp +++ b/src/badguy/stumpy.cpp @@ -55,7 +55,7 @@ Stumpy::write(lisp::Writer& writer) } void -Stumpy::activate() +Stumpy::initialize() { switch (mystate) { case STATE_INVINCIBLE: @@ -64,7 +64,7 @@ Stumpy::activate() physic.set_velocity_x(0); break; case STATE_NORMAL: - WalkingBadguy::activate(); + WalkingBadguy::initialize(); break; } } @@ -76,7 +76,7 @@ Stumpy::active_update(float elapsed_time) case STATE_INVINCIBLE: if (invincible_timer.check()) { mystate = STATE_NORMAL; - WalkingBadguy::activate(); + WalkingBadguy::initialize(); } BadGuy::active_update(elapsed_time); break; diff --git a/src/badguy/stumpy.hpp b/src/badguy/stumpy.hpp index 80117feb5..1559bfe7c 100644 --- a/src/badguy/stumpy.hpp +++ b/src/badguy/stumpy.hpp @@ -28,7 +28,7 @@ public: Stumpy(const lisp::Lisp& reader); Stumpy(const Vector& pos, Direction d); - void activate(); + void initialize(); void active_update(float elapsed_time); void write(lisp::Writer& writer); void collision_solid(const CollisionHit& hit); diff --git a/src/badguy/toad.cpp b/src/badguy/toad.cpp index 26da7e347..3df4901f2 100644 --- a/src/badguy/toad.cpp +++ b/src/badguy/toad.cpp @@ -51,7 +51,7 @@ Toad::write(lisp::Writer& writer) } void -Toad::activate() +Toad::initialize() { // initial state is JUMPING, because we might start airborne state = JUMPING; diff --git a/src/badguy/toad.hpp b/src/badguy/toad.hpp index 806716260..bbdc35f5e 100644 --- a/src/badguy/toad.hpp +++ b/src/badguy/toad.hpp @@ -32,7 +32,7 @@ public: Toad(const lisp::Lisp& reader); Toad(const Vector& pos, Direction d); - void activate(); + void initialize(); void write(lisp::Writer& writer); void collision_solid(const CollisionHit& hit); HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); diff --git a/src/badguy/totem.cpp b/src/badguy/totem.cpp index 139aa14df..cd4d975b4 100644 --- a/src/badguy/totem.cpp +++ b/src/badguy/totem.cpp @@ -74,7 +74,7 @@ Totem::write(lisp::Writer& writer) } void -Totem::activate() +Totem::initialize() { if (!carried_by) { physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); @@ -96,7 +96,7 @@ Totem::active_update(float elapsed_time) if (on_ground() && might_fall()) { dir = (dir == LEFT ? RIGHT : LEFT); - activate(); + initialize(); } Sector* s = Sector::current(); @@ -174,11 +174,11 @@ Totem::collision_solid(const CollisionHit& hit) // If we are hit from the direction we are facing: turn around if (hit.left && (dir == LEFT)) { dir = RIGHT; - activate(); + initialize(); } if (hit.right && (dir == RIGHT)) { dir = LEFT; - activate(); + initialize(); } } @@ -205,11 +205,11 @@ Totem::collision_badguy(BadGuy& badguy, const CollisionHit& hit) // If we are hit from the direction we are facing: turn around if(hit.left && (dir == LEFT)) { dir = RIGHT; - activate(); + initialize(); } if(hit.right && (dir == RIGHT)) { dir = LEFT; - activate(); + initialize(); } return CONTINUE; @@ -235,7 +235,7 @@ Totem::jump_on(Totem* target) target->carrying = this; this->carried_by = target; - this->activate(); + this->initialize(); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); sound_manager->play( LAND_ON_TOTEM_SOUND , get_pos()); @@ -255,7 +255,7 @@ Totem::jump_off() { this->carried_by = 0; - this->activate(); + this->initialize(); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); diff --git a/src/badguy/totem.hpp b/src/badguy/totem.hpp index 682fe456c..74022c50e 100644 --- a/src/badguy/totem.hpp +++ b/src/badguy/totem.hpp @@ -33,7 +33,7 @@ public: Totem(const Totem& totem); ~Totem(); - void activate(); + void initialize(); void active_update(float elapsed_time); void write(lisp::Writer& writer); void collision_solid(const CollisionHit& hit); diff --git a/src/badguy/treewillowisp.cpp b/src/badguy/treewillowisp.cpp index e1eb02721..4a0c06bce 100644 --- a/src/badguy/treewillowisp.cpp +++ b/src/badguy/treewillowisp.cpp @@ -38,6 +38,8 @@ TreeWillOWisp::TreeWillOWisp(GhostTree* tree, const Vector& pos, this->angle = 0; this->speed = speed; start_position = tree->get_pos() + treepos_delta; + + set_colgroup_active(COLGROUP_MOVING); } TreeWillOWisp::~TreeWillOWisp() @@ -53,8 +55,6 @@ TreeWillOWisp::activate() sound_source->set_gain(2.0); sound_source->set_reference_distance(32); sound_source->play(); - - set_group(COLGROUP_MOVING); } void @@ -62,7 +62,7 @@ TreeWillOWisp::vanish() { mystate = STATE_VANISHING; sprite->set_action("vanishing", 1); - set_group(COLGROUP_DISABLED); + set_colgroup_active(COLGROUP_DISABLED); } void diff --git a/src/badguy/walking_badguy.cpp b/src/badguy/walking_badguy.cpp index 3b8f7ab34..fe57032bf 100644 --- a/src/badguy/walking_badguy.cpp +++ b/src/badguy/walking_badguy.cpp @@ -46,7 +46,7 @@ WalkingBadguy::write(lisp::Writer& writer) } void -WalkingBadguy::activate() +WalkingBadguy::initialize() { if(frozen) return; @@ -129,7 +129,7 @@ void WalkingBadguy::unfreeze() { BadGuy::unfreeze(); - WalkingBadguy::activate(); + WalkingBadguy::initialize(); } diff --git a/src/badguy/walking_badguy.hpp b/src/badguy/walking_badguy.hpp index 3200cb708..f5a7eb627 100644 --- a/src/badguy/walking_badguy.hpp +++ b/src/badguy/walking_badguy.hpp @@ -34,7 +34,7 @@ public: WalkingBadguy(const Vector& pos, Direction direction, const std::string& sprite_name, const std::string& walk_left_action, const std::string& walk_right_action, int layer = LAYER_OBJECTS); WalkingBadguy(const lisp::Lisp& reader, const std::string& sprite_name, const std::string& walk_left_action, const std::string& walk_right_action, int layer = LAYER_OBJECTS); - void activate(); + void initialize(); void write(lisp::Writer& writer); void active_update(float elapsed_time); void collision_solid(const CollisionHit& hit); diff --git a/src/badguy/willowisp.cpp b/src/badguy/willowisp.cpp index bc70de8e3..b0fe7c62d 100644 --- a/src/badguy/willowisp.cpp +++ b/src/badguy/willowisp.cpp @@ -60,6 +60,8 @@ WillOWisp::WillOWisp(const lisp::Lisp& reader) countMe = false; sound_manager->preload(SOUNDFILE); sound_manager->preload("sounds/warp.wav"); + + sprite->set_action("idle"); } void @@ -136,8 +138,6 @@ WillOWisp::active_update(float elapsed_time) void WillOWisp::activate() { - sprite->set_action("idle"); - sound_source.reset(sound_manager->create_sound_source(SOUNDFILE)); sound_source->set_position(get_pos()); sound_source->set_looping(true); @@ -172,7 +172,7 @@ WillOWisp::vanish() { mystate = STATE_VANISHING; sprite->set_action("vanishing", 1); - set_group(COLGROUP_DISABLED); + set_colgroup_active(COLGROUP_DISABLED); } bool diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index 208555136..1c039068e 100644 --- a/src/badguy/yeti.cpp +++ b/src/badguy/yeti.cpp @@ -67,7 +67,7 @@ Yeti::~Yeti() } void -Yeti::activate() +Yeti::initialize() { dir = RIGHT; jump_down(); @@ -219,7 +219,7 @@ void Yeti::take_hit(Player& ) state = SQUISHED; state_timer.start(SQUISH_TIME); - set_group(COLGROUP_MOVING_ONLY_STATIC); + set_colgroup_active(COLGROUP_MOVING_ONLY_STATIC); sprite->set_action("dead"); if (countMe) Sector::current()->get_level()->stats.badguys++; diff --git a/src/badguy/yeti.hpp b/src/badguy/yeti.hpp index cfc6d055d..a3c996f25 100644 --- a/src/badguy/yeti.hpp +++ b/src/badguy/yeti.hpp @@ -33,7 +33,7 @@ public: void draw(DrawingContext& context); void write(lisp::Writer& writer); - void activate(); + void initialize(); void active_update(float elapsed_time); void collision_solid(const CollisionHit& hit); bool collision_squished(GameObject& object); diff --git a/src/badguy/zeekling.cpp b/src/badguy/zeekling.cpp index 0ea43d688..ffea907c0 100644 --- a/src/badguy/zeekling.cpp +++ b/src/badguy/zeekling.cpp @@ -29,12 +29,16 @@ Zeekling::Zeekling(const lisp::Lisp& reader) : 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) { state = FLYING; + speed = systemRandom.rand(130, 171); + physic.enable_gravity(false); } void @@ -49,11 +53,9 @@ Zeekling::write(lisp::Writer& writer) } void -Zeekling::activate() +Zeekling::initialize() { - speed = systemRandom.rand(130, 171); physic.set_velocity_x(dir == LEFT ? -speed : speed); - physic.enable_gravity(false); sprite->set_action(dir == LEFT ? "left" : "right"); } diff --git a/src/badguy/zeekling.hpp b/src/badguy/zeekling.hpp index 795827683..3979dd19e 100644 --- a/src/badguy/zeekling.hpp +++ b/src/badguy/zeekling.hpp @@ -30,7 +30,7 @@ public: Zeekling(const lisp::Lisp& reader); Zeekling(const Vector& pos, Direction d); - void activate(); + void initialize(); void write(lisp::Writer& writer); void collision_solid(const CollisionHit& hit); void active_update(float elapsed_time);