From: Christoph Sommer Date: Wed, 5 Jul 2006 23:34:08 +0000 (+0000) Subject: Fixed problems with Rockets and Cannons sometimes reversing direction on X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=7c2f8e23f9accd00bd9ee2319da8ab8aa341c7cf;p=supertux.git Fixed problems with Rockets and Cannons sometimes reversing direction on re-activation by making the start direction a property of Badguy SVN-Revision: 3910 --- diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 38d077b5b..755723b5f 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -34,7 +34,16 @@ 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), dir(LEFT), state(STATE_INIT) + : MovingSprite(pos, sprite_name, layer, COLGROUP_DISABLED), countMe(true), dir(LEFT), start_dir(AUTO), state(STATE_INIT) +{ + start_position = bbox.p1; + + sound_manager->preload("sounds/squish.wav"); + sound_manager->preload("sounds/fall.wav"); +} + +BadGuy::BadGuy(const Vector& pos, Direction direction, const std::string& sprite_name, int layer) + : MovingSprite(pos, sprite_name, layer, COLGROUP_DISABLED), countMe(true), dir(direction), start_dir(direction), state(STATE_INIT) { start_position = bbox.p1; @@ -43,10 +52,15 @@ BadGuy::BadGuy(const Vector& pos, const std::string& sprite_name, int layer) } BadGuy::BadGuy(const lisp::Lisp& reader, const std::string& sprite_name, int layer) - : MovingSprite(reader, sprite_name, layer, COLGROUP_DISABLED), countMe(true), dir(LEFT), state(STATE_INIT) + : MovingSprite(reader, sprite_name, layer, COLGROUP_DISABLED), countMe(true), dir(LEFT), start_dir(AUTO), state(STATE_INIT) { start_position = bbox.p1; + std::string dir_str = "auto"; + reader.get("direction", dir_str); + start_dir = str2dir( dir_str ); + dir = start_dir; + sound_manager->preload("sounds/squish.wav"); sound_manager->preload("sounds/fall.wav"); } @@ -105,8 +119,8 @@ BadGuy::update(float elapsed_time) Direction BadGuy::str2dir( std::string dir_str ) { - if( dir_str == "auto" || dir_str == "" ) - return dir; + if( dir_str == "auto" ) + return AUTO; if( dir_str == "left" ) return LEFT; if( dir_str == "right" ) @@ -322,7 +336,7 @@ BadGuy::try_activate() start_position.x < scroll_x - bbox.get_width() && start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) { - dir = RIGHT; + if (start_dir != AUTO) dir = start_dir; else dir = RIGHT; set_state(STATE_ACTIVE); activate(); //Badguy right of screen @@ -330,7 +344,7 @@ BadGuy::try_activate() start_position.x < scroll_x + SCREEN_WIDTH + X_OFFSCREEN_DISTANCE && start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) { - dir = LEFT; + if (start_dir != AUTO) dir = start_dir; else dir = LEFT; set_state(STATE_ACTIVE); activate(); //Badguy over or under screen @@ -340,7 +354,7 @@ BadGuy::try_activate() 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() ))) { - dir = start_position.x < scroll_x ? RIGHT : LEFT; + if (start_dir != AUTO) dir = start_dir; else dir = start_position.x < scroll_x ? RIGHT : LEFT; set_state(STATE_ACTIVE); activate(); } else if(state == STATE_INIT @@ -348,7 +362,7 @@ BadGuy::try_activate() && start_position.x < scroll_x + X_OFFSCREEN_DISTANCE && start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) { - dir = LEFT; + if (start_dir != AUTO) dir = start_dir; else dir = LEFT; set_state(STATE_ACTIVE); activate(); } diff --git a/src/badguy/badguy.hpp b/src/badguy/badguy.hpp index ebcee6970..0b8d8de16 100644 --- a/src/badguy/badguy.hpp +++ b/src/badguy/badguy.hpp @@ -42,6 +42,7 @@ class BadGuy : public MovingSprite, public Serializable { public: BadGuy(const Vector& pos, const std::string& sprite_name, int layer = LAYER_OBJECTS); + BadGuy(const Vector& pos, Direction direction, const std::string& sprite_name, int layer = LAYER_OBJECTS); BadGuy(const lisp::Lisp& reader, const std::string& sprite_name, int layer = LAYER_OBJECTS); /** Called when the badguy is drawn. The default implementation simply draws @@ -154,9 +155,17 @@ protected: Vector start_position; + /** + * The direction we currently face in + */ Direction dir; /** + * The direction we initially faced in + */ + Direction start_dir; + + /** * Get Direction from String. */ Direction str2dir( std::string dir_str ); diff --git a/src/badguy/bomb.cpp b/src/badguy/bomb.cpp index d7e4caa26..41351590d 100644 --- a/src/badguy/bomb.cpp +++ b/src/badguy/bomb.cpp @@ -24,10 +24,9 @@ #include "object/sprite_particle.hpp" Bomb::Bomb(const Vector& pos, Direction dir) - : BadGuy(pos, "images/creatures/mr_cherry/cherry.sprite") + : BadGuy(pos, dir, "images/creatures/mr_cherry/cherry.sprite") { state = STATE_TICKING; - this->dir = dir; set_action(dir == LEFT ? "ticking-left" : "ticking-right", 1); countMe = false; diff --git a/src/badguy/bouncing_snowball.cpp b/src/badguy/bouncing_snowball.cpp index 5fce3cf67..c0af31d9c 100644 --- a/src/badguy/bouncing_snowball.cpp +++ b/src/badguy/bouncing_snowball.cpp @@ -27,19 +27,11 @@ static const float WALKSPEED = 80; BouncingSnowball::BouncingSnowball(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/bouncing_snowball/bouncing_snowball.sprite") { - set_direction = false; - reader.get("direction", direction); - if( direction != "auto" && direction != ""){ - set_direction = true; - initial_direction = str2dir( direction ); - } } BouncingSnowball::BouncingSnowball(const Vector& pos, Direction d) - : BadGuy(pos, "images/creatures/bouncing_snowball/bouncing_snowball.sprite") + : BadGuy(pos, d, "images/creatures/bouncing_snowball/bouncing_snowball.sprite") { - set_direction = true; - initial_direction = d; } void @@ -47,7 +39,6 @@ BouncingSnowball::write(lisp::Writer& writer) { writer.start_list("bouncingsnowball"); - writer.write_string("direction", direction); writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); @@ -57,7 +48,6 @@ BouncingSnowball::write(lisp::Writer& writer) void BouncingSnowball::activate() { - if (set_direction) {dir = initial_direction;} 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 6ba417d60..1bcb8ab53 100644 --- a/src/badguy/bouncing_snowball.hpp +++ b/src/badguy/bouncing_snowball.hpp @@ -37,9 +37,6 @@ public: protected: bool collision_squished(Player& player); - bool set_direction; - Direction initial_direction; - std::string direction; }; #endif diff --git a/src/badguy/dart.cpp b/src/badguy/dart.cpp index 5e70e26da..cd251c820 100644 --- a/src/badguy/dart.cpp +++ b/src/badguy/dart.cpp @@ -29,7 +29,7 @@ namespace { static const std::string SOUNDFILE = "sounds/flame.wav"; Dart::Dart(const lisp::Lisp& reader) - : BadGuy(reader, "images/creatures/dart/dart.sprite"), set_direction(false), parent(0) + : BadGuy(reader, "images/creatures/dart/dart.sprite"), parent(0) { physic.enable_gravity(false); countMe = false; @@ -38,7 +38,7 @@ Dart::Dart(const lisp::Lisp& reader) } Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent = 0) - : BadGuy(pos, "images/creatures/dart/dart.sprite"), set_direction(true), initial_direction(d), parent(parent) + : BadGuy(pos, d, "images/creatures/dart/dart.sprite"), parent(parent) { physic.enable_gravity(false); countMe = false; @@ -47,7 +47,7 @@ Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent = 0) } Dart::Dart(const Dart& other) - : BadGuy(other), set_direction(other.set_direction), initial_direction(other.initial_direction), parent(other.parent) + : BadGuy(other), parent(other.parent) { sound_source.reset(sound_manager->create_sound_source(SOUNDFILE)); sound_manager->preload("sounds/darthit.wav"); @@ -79,8 +79,7 @@ Dart::write(lisp::Writer& writer) void Dart::activate() -{ - if (set_direction) dir = initial_direction; +{ physic.set_velocity_x(dir == LEFT ? -::SPEED : ::SPEED); sprite->set_action(dir == LEFT ? "flying-left" : "flying-right"); diff --git a/src/badguy/dart.hpp b/src/badguy/dart.hpp index 1c6a3d33d..670a0d6c0 100644 --- a/src/badguy/dart.hpp +++ b/src/badguy/dart.hpp @@ -49,8 +49,6 @@ public: virtual bool updatePointers(const GameObject* from_object, GameObject* to_object); protected: - bool set_direction; - Direction initial_direction; const BadGuy* parent; /**< collisions with this BadGuy will be ignored */ std::auto_ptr sound_source; /**< SoundSource for ambient sound */ }; diff --git a/src/badguy/darttrap.cpp b/src/badguy/darttrap.cpp index 6add15810..0cd62497a 100644 --- a/src/badguy/darttrap.cpp +++ b/src/badguy/darttrap.cpp @@ -27,12 +27,8 @@ namespace { } DartTrap::DartTrap(const lisp::Lisp& reader) - : BadGuy(reader, "images/creatures/darttrap/darttrap.sprite"), set_direction(true), initial_direction(LEFT), initial_delay(0), fire_delay(2), ammo(-1), state(IDLE) + : BadGuy(reader, "images/creatures/darttrap/darttrap.sprite"), initial_delay(0), fire_delay(2), ammo(-1), state(IDLE) { - reader.get("direction", direction); - if( direction != "auto" && direction != ""){ - initial_direction = str2dir( direction ); - } reader.get("initial-delay", initial_delay); reader.get("fire-delay", fire_delay); reader.get("ammo", ammo); @@ -44,7 +40,6 @@ void DartTrap::write(lisp::Writer& writer) { writer.start_list("darttrap"); - writer.write_string("direction", direction); writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); writer.write_float("initial-delay", initial_delay); @@ -56,7 +51,6 @@ DartTrap::write(lisp::Writer& writer) void DartTrap::activate() { - if (set_direction) dir = initial_direction; state = IDLE; sprite->set_action(dir == LEFT ? "idle-left" : "idle-right"); diff --git a/src/badguy/darttrap.hpp b/src/badguy/darttrap.hpp index 09ac5fdad..b891de432 100644 --- a/src/badguy/darttrap.hpp +++ b/src/badguy/darttrap.hpp @@ -46,15 +46,12 @@ protected: void load(); /**< load a shot */ void fire(); /**< fire a shot */ - bool set_direction; - Direction initial_direction; float initial_delay; /**< time to wait before firing first shot */ float fire_delay; /**< reload time */ int ammo; /**< ammo left (-1 means unlimited) */ State state; /**< current state */ Timer fire_timer; /**< time until new shot is fired */ - std::string direction; }; #endif diff --git a/src/badguy/dispenser.cpp b/src/badguy/dispenser.cpp index b06c18df1..1bcf021da 100644 --- a/src/badguy/dispenser.cpp +++ b/src/badguy/dispenser.cpp @@ -33,13 +33,6 @@ Dispenser::Dispenser(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/dispenser/dispenser.sprite") { - set_direction = false; - reader.get("direction", direction); - if( direction != "auto" && direction != ""){ - set_direction = true; - initial_direction = str2dir( direction ); - dir = str2dir( direction ); - } reader.get("cycle", cycle); reader.get("badguy", badguy); if (badguy == "mrrocket") { @@ -55,7 +48,6 @@ Dispenser::write(lisp::Writer& writer) { writer.start_list("dispenser"); - writer.write_string("direction", direction); writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); writer.write_float("cycle", cycle); @@ -95,9 +87,6 @@ Dispenser::active_update(float ) void Dispenser::launch_badguy() { - if( set_direction ){ - dir = initial_direction; - } //FIXME: Does is_offscreen() work right here? if (!is_offscreen()) { if (badguy == "snowball") diff --git a/src/badguy/dispenser.hpp b/src/badguy/dispenser.hpp index 2ba8ba219..f79e8e6d0 100644 --- a/src/badguy/dispenser.hpp +++ b/src/badguy/dispenser.hpp @@ -40,9 +40,6 @@ protected: float cycle; std::string badguy; Timer dispense_timer; - bool set_direction; - Direction initial_direction; - std::string direction; }; #endif diff --git a/src/badguy/igel.cpp b/src/badguy/igel.cpp index 78d067a24..f7d5e1daf 100644 --- a/src/badguy/igel.cpp +++ b/src/badguy/igel.cpp @@ -1,4 +1,4 @@ -// $Id: igel.cpp 3478 2006-04-30 23:14:15Z sommer $ +// $Id$ // // SuperTux - Badguy "Igel" // Copyright (C) 2006 Christoph Sommer @@ -33,14 +33,11 @@ namespace { Igel::Igel(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/igel/igel.sprite"), state(STATE_NORMAL) { - set_direction = false; } Igel::Igel(const Vector& pos, Direction d) - : BadGuy(pos, "images/creatures/igel/igel.sprite"), state(STATE_NORMAL) + : BadGuy(pos, d, "images/creatures/igel/igel.sprite"), state(STATE_NORMAL) { - set_direction = true; - initial_direction = d; } void @@ -57,8 +54,6 @@ Igel::write(lisp::Writer& writer) void Igel::activate() { - if (set_direction) {dir = initial_direction;} - be_normal(); } diff --git a/src/badguy/igel.hpp b/src/badguy/igel.hpp index bdb7b75e0..a824620df 100644 --- a/src/badguy/igel.hpp +++ b/src/badguy/igel.hpp @@ -1,4 +1,4 @@ -// $Id: igel.hpp 3452 2006-04-27 18:19:15Z sommer $ +// $Id$ // // SuperTux - Badguy "Igel" // Copyright (C) 2006 Christoph Sommer @@ -54,8 +54,6 @@ private: }; State state; Timer turn_recover_timer; /**< wait time until we will turn around again when shot at */ - bool set_direction; - Direction initial_direction; }; #endif diff --git a/src/badguy/mrbomb.cpp b/src/badguy/mrbomb.cpp index 0421edddd..80d4c5447 100644 --- a/src/badguy/mrbomb.cpp +++ b/src/badguy/mrbomb.cpp @@ -27,19 +27,11 @@ static const float WALKSPEED = 80; MrBomb::MrBomb(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/mr_cherry/mr_cherry.sprite") { - set_direction = false; - reader.get("direction", direction); - if( direction != "auto" && direction != ""){ - set_direction = true; - initial_direction = str2dir( direction ); - } } MrBomb::MrBomb(const Vector& pos, Direction d) - : BadGuy(pos, "images/creatures/mr_cherry/mr_cherry.sprite") + : BadGuy(pos, d, "images/creatures/mr_cherry/mr_cherry.sprite") { - set_direction = true; - initial_direction = d; } void @@ -47,7 +39,6 @@ MrBomb::write(lisp::Writer& writer) { writer.start_list("mrbomb"); - writer.write_string("direction", direction); writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); @@ -57,7 +48,6 @@ MrBomb::write(lisp::Writer& writer) void MrBomb::activate() { - if (set_direction) {dir = initial_direction;} physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); } diff --git a/src/badguy/mrbomb.hpp b/src/badguy/mrbomb.hpp index 4759f8be4..6e49d0b10 100644 --- a/src/badguy/mrbomb.hpp +++ b/src/badguy/mrbomb.hpp @@ -39,9 +39,6 @@ public: protected: bool collision_squished(Player& player); - bool set_direction; - Direction initial_direction; - std::string direction; }; #endif diff --git a/src/badguy/mriceblock.cpp b/src/badguy/mriceblock.cpp index ca0431a22..95fd17f3a 100644 --- a/src/badguy/mriceblock.cpp +++ b/src/badguy/mriceblock.cpp @@ -31,22 +31,14 @@ namespace { MrIceBlock::MrIceBlock(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/mr_iceblock/mr_iceblock.sprite"), ice_state(ICESTATE_NORMAL), squishcount(0) { - reader.get("direction", direction); - set_direction = false; - if( direction != "auto" && direction != ""){ - set_direction = true; - initial_direction = str2dir( direction ); - } sound_manager->preload("sounds/iceblock_bump.wav"); sound_manager->preload("sounds/stomp.wav"); sound_manager->preload("sounds/kick.wav"); } MrIceBlock::MrIceBlock(const Vector& pos, Direction d) - : BadGuy(pos, "images/creatures/mr_iceblock/mr_iceblock.sprite"), ice_state(ICESTATE_NORMAL), squishcount(0) + : BadGuy(pos, d, "images/creatures/mr_iceblock/mr_iceblock.sprite"), ice_state(ICESTATE_NORMAL), squishcount(0) { - set_direction = true; - initial_direction = d; sound_manager->preload("sounds/iceblock_bump.wav"); sound_manager->preload("sounds/stomp.wav"); sound_manager->preload("sounds/kick.wav"); @@ -57,7 +49,6 @@ MrIceBlock::write(lisp::Writer& writer) { writer.start_list("mriceblock"); - writer.write_string("direction", direction); writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); @@ -67,10 +58,6 @@ MrIceBlock::write(lisp::Writer& writer) void MrIceBlock::activate() { - if (set_direction) { - dir = initial_direction; - } - physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); set_state(ICESTATE_NORMAL); diff --git a/src/badguy/mriceblock.hpp b/src/badguy/mriceblock.hpp index ca6c59d85..ea5506560 100644 --- a/src/badguy/mriceblock.hpp +++ b/src/badguy/mriceblock.hpp @@ -59,9 +59,6 @@ private: IceState ice_state; Timer flat_timer; int squishcount; - bool set_direction; - Direction initial_direction; - std::string direction; }; #endif diff --git a/src/badguy/mrrocket.cpp b/src/badguy/mrrocket.cpp index cbe72b5c4..cfa4faf50 100644 --- a/src/badguy/mrrocket.cpp +++ b/src/badguy/mrrocket.cpp @@ -26,14 +26,11 @@ static const float SPEED = 200; MrRocket::MrRocket(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/mr_rocket/mr_rocket.sprite") { - set_direction = false; } MrRocket::MrRocket(const Vector& pos, Direction d) - : BadGuy(pos, "images/creatures/mr_rocket/mr_rocket.sprite") + : BadGuy(pos, d, "images/creatures/mr_rocket/mr_rocket.sprite") { - set_direction = true; - initial_direction = d; } void @@ -50,7 +47,6 @@ MrRocket::write(lisp::Writer& writer) void MrRocket::activate() { - if (set_direction) {dir = initial_direction;} physic.set_velocity_x(dir == LEFT ? -SPEED : SPEED); physic.enable_gravity(false); sprite->set_action(dir == LEFT ? "left" : "right"); diff --git a/src/badguy/mrrocket.hpp b/src/badguy/mrrocket.hpp index 5cb37b77d..f756d020a 100644 --- a/src/badguy/mrrocket.hpp +++ b/src/badguy/mrrocket.hpp @@ -39,8 +39,6 @@ public: protected: bool collision_squished(Player& player); - bool set_direction; - Direction initial_direction; Timer collision_timer; }; diff --git a/src/badguy/mrtree.cpp b/src/badguy/mrtree.cpp index 40ed3563b..14062c2a2 100644 --- a/src/badguy/mrtree.cpp +++ b/src/badguy/mrtree.cpp @@ -36,13 +36,6 @@ static const float POISONIVY_Y_OFFSET = 24; MrTree::MrTree(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/mr_tree/mr_tree.sprite"), mystate(STATE_BIG) { - reader.get("direction", direction); - set_direction = false; - if( direction != "auto" && direction != ""){ - set_direction = true; - initial_direction = str2dir( direction ); - dir = str2dir( direction ); - } sprite->set_action(dir == LEFT ? "large-left" : "large-right"); sound_manager->preload("sounds/mr_tree.ogg"); sound_manager->preload("sounds/mr_treehit.ogg"); @@ -53,7 +46,6 @@ MrTree::write(lisp::Writer& writer) { writer.start_list("mrtree"); - writer.write_string("direction", direction); writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); @@ -63,9 +55,6 @@ MrTree::write(lisp::Writer& writer) void MrTree::activate() { - if( set_direction ){ - dir = initial_direction; - } if (mystate == STATE_BIG) { physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "large-left" : "large-right"); @@ -189,7 +178,6 @@ MrTree::collision_solid(GameObject& , const CollisionHit& hit) physic.set_velocity_y(0); } else { dir = dir == LEFT ? RIGHT : LEFT; - set_direction = false; activate(); } @@ -201,7 +189,6 @@ MrTree::collision_badguy(BadGuy& , const CollisionHit& hit) { if(fabsf(hit.normal.x) > .8) { // left or right hit dir = dir == LEFT ? RIGHT : LEFT; - set_direction = false; activate(); } diff --git a/src/badguy/mrtree.hpp b/src/badguy/mrtree.hpp index 9795a6d6b..652a00e6b 100644 --- a/src/badguy/mrtree.hpp +++ b/src/badguy/mrtree.hpp @@ -44,9 +44,6 @@ protected: Timer invincible_timer; bool collision_squished(Player& player); - std::string direction; - bool set_direction; - Direction initial_direction; }; #endif diff --git a/src/badguy/poisonivy.cpp b/src/badguy/poisonivy.cpp index dfcfa3d64..ae118276c 100644 --- a/src/badguy/poisonivy.cpp +++ b/src/badguy/poisonivy.cpp @@ -28,19 +28,11 @@ static const float WALKSPEED = 80; PoisonIvy::PoisonIvy(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/poison_ivy/poison_ivy.sprite") { - set_direction = false; - reader.get("direction", direction); - if( direction != "auto" && direction != ""){ - set_direction = true; - initial_direction = str2dir( direction ); - } } PoisonIvy::PoisonIvy(const Vector& pos, Direction d) - : BadGuy(pos, "images/creatures/poison_ivy/poison_ivy.sprite") + : BadGuy(pos, d, "images/creatures/poison_ivy/poison_ivy.sprite") { - set_direction = true; - initial_direction = d; } void @@ -48,7 +40,6 @@ PoisonIvy::write(lisp::Writer& writer) { writer.start_list("poisonivy"); - writer.write_string("direction", direction); writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); @@ -58,7 +49,6 @@ PoisonIvy::write(lisp::Writer& writer) void PoisonIvy::activate() { - if (set_direction) {dir = initial_direction;} physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); } diff --git a/src/badguy/poisonivy.hpp b/src/badguy/poisonivy.hpp index 6ee178d8f..09b6af643 100644 --- a/src/badguy/poisonivy.hpp +++ b/src/badguy/poisonivy.hpp @@ -37,9 +37,6 @@ public: protected: bool collision_squished(Player& player); - bool set_direction; - Direction initial_direction; - std::string direction; }; #endif diff --git a/src/badguy/rocketexplosion.cpp b/src/badguy/rocketexplosion.cpp index dcc612014..a1497ee93 100644 --- a/src/badguy/rocketexplosion.cpp +++ b/src/badguy/rocketexplosion.cpp @@ -24,9 +24,8 @@ static const float EXPLOSIONTIME = 1; RocketExplosion::RocketExplosion(const Vector& pos, Direction dir) - : BadGuy(pos, "images/creatures/mr_rocket/explosion.sprite") + : BadGuy(pos, dir, "images/creatures/mr_rocket/explosion.sprite") { - this->dir = dir; countMe = false; explode(); } diff --git a/src/badguy/skullyhop.cpp b/src/badguy/skullyhop.cpp index fb12d7519..a5ba2caf0 100644 --- a/src/badguy/skullyhop.cpp +++ b/src/badguy/skullyhop.cpp @@ -32,14 +32,11 @@ namespace { SkullyHop::SkullyHop(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/skullyhop/skullyhop.sprite") { - has_initial_direction = false; } SkullyHop::SkullyHop(const Vector& pos, Direction d) - : BadGuy(pos, "images/creatures/skullyhop/skullyhop.sprite") + : BadGuy(pos, d, "images/creatures/skullyhop/skullyhop.sprite") { - has_initial_direction = true; - initial_direction = d; } void @@ -54,8 +51,6 @@ SkullyHop::write(lisp::Writer& writer) void SkullyHop::activate() { - if (has_initial_direction) dir = initial_direction; - // initial state is JUMPING, because we might start airborne state = JUMPING; sprite->set_action(dir == LEFT ? "jumping-left" : "jumping-right"); diff --git a/src/badguy/skullyhop.hpp b/src/badguy/skullyhop.hpp index b3acd8611..c12962c62 100644 --- a/src/badguy/skullyhop.hpp +++ b/src/badguy/skullyhop.hpp @@ -48,9 +48,6 @@ protected: JUMPING }; - bool has_initial_direction; - Direction initial_direction; - Timer recover_timer; SkullyHopState state; diff --git a/src/badguy/snail.cpp b/src/badguy/snail.cpp index d53e91456..6f1e1e94c 100644 --- a/src/badguy/snail.cpp +++ b/src/badguy/snail.cpp @@ -32,22 +32,14 @@ namespace { Snail::Snail(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/snail/snail.sprite"), state(STATE_NORMAL), squishcount(0) { - reader.get("direction", direction); - set_direction = false; - if( direction != "auto" && direction != ""){ - set_direction = true; - initial_direction = str2dir( direction ); - } sound_manager->preload("sounds/iceblock_bump.wav"); sound_manager->preload("sounds/stomp.wav"); sound_manager->preload("sounds/kick.wav"); } Snail::Snail(const Vector& pos, Direction d) - : BadGuy(pos, "images/creatures/snail/snail.sprite"), state(STATE_NORMAL), squishcount(0) + : BadGuy(pos, d, "images/creatures/snail/snail.sprite"), state(STATE_NORMAL), squishcount(0) { - set_direction = true; - initial_direction = d; sound_manager->preload("sounds/iceblock_bump.wav"); sound_manager->preload("sounds/stomp.wav"); sound_manager->preload("sounds/kick.wav"); @@ -58,7 +50,6 @@ Snail::write(lisp::Writer& writer) { writer.start_list("snail"); - writer.write_string("direction", direction); writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); @@ -68,8 +59,6 @@ Snail::write(lisp::Writer& writer) void Snail::activate() { - if (set_direction) {dir = initial_direction;} - be_normal(); } diff --git a/src/badguy/snail.hpp b/src/badguy/snail.hpp index 50e230179..5d259f002 100644 --- a/src/badguy/snail.hpp +++ b/src/badguy/snail.hpp @@ -57,9 +57,6 @@ private: Timer flat_timer; /**< wait time until flipping right-side-up again */ Timer kicked_delay_timer; /**< wait time until switching from STATE_KICKED_DELAY to STATE_KICKED */ int squishcount; - bool set_direction; - Direction initial_direction; - std::string direction; }; #endif diff --git a/src/badguy/snowball.cpp b/src/badguy/snowball.cpp index 22dce8e8f..889578e3e 100644 --- a/src/badguy/snowball.cpp +++ b/src/badguy/snowball.cpp @@ -26,19 +26,11 @@ static const float WALKSPEED = 80; SnowBall::SnowBall(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/snowball/snowball.sprite") { - set_direction = false; - reader.get("direction", direction); - if( direction != "auto" && direction != ""){ - set_direction = true; - initial_direction = str2dir( direction ); - } } SnowBall::SnowBall(const Vector& pos, Direction d) - : BadGuy(pos, "images/creatures/snowball/snowball.sprite") + : BadGuy(pos, d, "images/creatures/snowball/snowball.sprite") { - set_direction = true; - initial_direction = d; } void @@ -46,7 +38,6 @@ SnowBall::write(lisp::Writer& writer) { writer.start_list("snowball"); - writer.write_string("direction", direction); writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); /* @@ -60,7 +51,6 @@ SnowBall::write(lisp::Writer& writer) void SnowBall::activate() { - if (set_direction) {dir = initial_direction;} physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); } diff --git a/src/badguy/snowball.hpp b/src/badguy/snowball.hpp index eab2c069b..49bfa9f94 100644 --- a/src/badguy/snowball.hpp +++ b/src/badguy/snowball.hpp @@ -37,9 +37,6 @@ public: protected: bool collision_squished(Player& player); - bool set_direction; - Direction initial_direction; - std::string direction; }; #endif diff --git a/src/badguy/spiky.cpp b/src/badguy/spiky.cpp index cf498c3c7..fbe27eee8 100644 --- a/src/badguy/spiky.cpp +++ b/src/badguy/spiky.cpp @@ -26,12 +26,6 @@ static const float WALKSPEED = 80; Spiky::Spiky(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/spiky/spiky.sprite") { - reader.get("direction", direction); - set_direction = false; - if( direction != "auto" && direction != ""){ - set_direction = true; - initial_direction = str2dir( direction ); - } } void @@ -39,7 +33,6 @@ Spiky::write(lisp::Writer& writer) { writer.start_list("spiky"); - writer.write_string("direction", direction); writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); @@ -49,9 +42,6 @@ Spiky::write(lisp::Writer& writer) void Spiky::activate() { - if( set_direction ){ - dir = initial_direction; - } physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); } diff --git a/src/badguy/spiky.hpp b/src/badguy/spiky.hpp index 75d2f5f26..fd86096d3 100644 --- a/src/badguy/spiky.hpp +++ b/src/badguy/spiky.hpp @@ -36,9 +36,6 @@ public: virtual Spiky* clone() const { return new Spiky(*this); } private: - bool set_direction; - Direction initial_direction; - std::string direction; }; #endif diff --git a/src/badguy/sspiky.cpp b/src/badguy/sspiky.cpp index a70d2f7be..3379c0b94 100644 --- a/src/badguy/sspiky.cpp +++ b/src/badguy/sspiky.cpp @@ -27,12 +27,6 @@ static const float WAKE_TIME = .5; SSpiky::SSpiky(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/spiky/sleepingspiky.sprite"), state(SSPIKY_SLEEPING) { - set_direction = false; - reader.get("direction", direction); - if( direction != "auto" && direction != ""){ - set_direction = true; - initial_direction = str2dir( direction ); - } } void @@ -40,7 +34,6 @@ SSpiky::write(lisp::Writer& writer) { writer.start_list("sspiky"); - writer.write_string("direction", direction); writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); @@ -50,9 +43,6 @@ SSpiky::write(lisp::Writer& writer) void SSpiky::activate() { - if( set_direction ){ - dir = initial_direction; - } state = SSPIKY_SLEEPING; physic.set_velocity_x(0); sprite->set_action(dir == LEFT ? "sleeping-left" : "sleeping-right"); diff --git a/src/badguy/sspiky.hpp b/src/badguy/sspiky.hpp index aa6c7958d..bb7741930 100644 --- a/src/badguy/sspiky.hpp +++ b/src/badguy/sspiky.hpp @@ -44,9 +44,6 @@ protected: SSPIKY_WALKING }; SSpikyState state; - std::string direction; - bool set_direction; - Direction initial_direction; }; #endif diff --git a/src/badguy/zeekling.cpp b/src/badguy/zeekling.cpp index 479643a7d..3d3a539e0 100644 --- a/src/badguy/zeekling.cpp +++ b/src/badguy/zeekling.cpp @@ -28,20 +28,12 @@ Zeekling::Zeekling(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/zeekling/zeekling.sprite") { - set_direction = false; - reader.get("direction", direction); - if( direction != "auto" && direction != ""){ - set_direction = true; - initial_direction = str2dir( direction ); - } state = FLYING; } Zeekling::Zeekling(const Vector& pos, Direction d) - : BadGuy(pos, "images/creatures/zeekling/zeekling.sprite") + : BadGuy(pos, d, "images/creatures/zeekling/zeekling.sprite") { - set_direction = true; - initial_direction = d; state = FLYING; } @@ -50,7 +42,6 @@ Zeekling::write(lisp::Writer& writer) { writer.start_list("zeekling"); - writer.write_string("direction", direction); writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); @@ -61,7 +52,6 @@ void Zeekling::activate() { speed = systemRandom.rand(130, 171); - if (set_direction) {dir = initial_direction;} 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 0b3532e0b..fd6b5191a 100644 --- a/src/badguy/zeekling.hpp +++ b/src/badguy/zeekling.hpp @@ -39,8 +39,6 @@ public: protected: bool collision_squished(Player& player); - bool set_direction; - Direction initial_direction; float speed; Timer diveRecoverTimer; @@ -56,7 +54,6 @@ private: bool should_we_dive(); void onBumpHorizontal(); void onBumpVertical(); - std::string direction; }; #endif diff --git a/src/direction.hpp b/src/direction.hpp index a0a07719a..c7bb2e1bc 100644 --- a/src/direction.hpp +++ b/src/direction.hpp @@ -20,6 +20,6 @@ #ifndef SUPERTUX_DIRECTION_H #define SUPERTUX_DIRECTION_H -enum Direction { LEFT = 0, RIGHT = 1 }; +enum Direction { AUTO, LEFT, RIGHT }; #endif