From: Marek Moeckel Date: Sun, 18 Sep 2005 10:01:16 +0000 (+0000) Subject: fixed kugelblitz, added electrifier object X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9890da50f82d286c67e72feefcc423d1bc9076c3;p=supertux.git fixed kugelblitz, added electrifier object SVN-Revision: 2771 --- diff --git a/src/badguy/kugelblitz.cpp b/src/badguy/kugelblitz.cpp index be289ffce..94be05864 100644 --- a/src/badguy/kugelblitz.cpp +++ b/src/badguy/kugelblitz.cpp @@ -20,7 +20,6 @@ #include #include "kugelblitz.hpp" -#include "sector.hpp" #include "object/tilemap.hpp" #include "tile.hpp" @@ -125,12 +124,7 @@ Kugelblitz::hit(const CollisionHit& chit) void Kugelblitz::active_update(float elapsed_time) { - if (electrify_timer.check()) { - Sector::current()->solids->change_all(1421,75); - Sector::current()->solids->change_all(1422,76); - explode(); - } - else if (lifetime.check()) { + if (lifetime.check()) { explode(); } else { @@ -144,11 +138,9 @@ Kugelblitz::active_update(float elapsed_time) } if (Sector::current()->solids->get_tile_at(get_pos())->getAttributes() == 16) { //HIT WATER - Sector::current()->solids->change_all(75,1421); - Sector::current()->solids->change_all(76,1422); - physic.set_velocity_x(0); - physic.set_velocity_y(0); - electrify_timer.start(1); + Sector::current()->add_object(new Electrifier(75,1421,1.5)); + Sector::current()->add_object(new Electrifier(76,1422,1.5)); + explode(); } } BadGuy::active_update(elapsed_time); diff --git a/src/badguy/kugelblitz.hpp b/src/badguy/kugelblitz.hpp index 5e591207b..302a5e5a5 100644 --- a/src/badguy/kugelblitz.hpp +++ b/src/badguy/kugelblitz.hpp @@ -22,6 +22,7 @@ #include "badguy.hpp" #include "timer.hpp" +#include "object/electrifier.hpp" class Kugelblitz : public BadGuy { @@ -45,7 +46,6 @@ private: bool dying; Timer movement_timer; Timer lifetime; - Timer electrify_timer; int direction; }; diff --git a/src/object/electrifier.cpp b/src/object/electrifier.cpp new file mode 100644 index 000000000..6ab6e0ca8 --- /dev/null +++ b/src/object/electrifier.cpp @@ -0,0 +1,47 @@ +// SuperTux +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +#include "electrifier.hpp" +#include "sector.hpp" +#include "object/tilemap.hpp" +#include "tile.hpp" + + +Electrifier::Electrifier(uint32_t oldtile, uint32_t newtile, float seconds) +{ + duration.start(seconds); + change_from = oldtile; + change_to = newtile; + Sector::current()->solids->change_all(change_from,change_to); +} + +Electrifier::~Electrifier() { + remove_me(); +} + +void +Electrifier::update(float ) +{ + if (duration.check()) { + Sector::current()->solids->change_all(change_to,change_from); + remove_me(); + } +} + +void +Electrifier::draw(DrawingContext& ) +{ +} diff --git a/src/object/electrifier.hpp b/src/object/electrifier.hpp new file mode 100644 index 000000000..cc6a7a005 --- /dev/null +++ b/src/object/electrifier.hpp @@ -0,0 +1,41 @@ +// SuperTux +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. + +#ifndef __ELECTRIFIER_H__ +#define __ELECTRIFIER_H__ + +#include "game_object.hpp" +#include "timer.hpp" + +//Changes all tiles with the given ID to a new one for a given amount of time, then removes itself +//Used by the Kugelblitz to electrify water - can be used for other effects, too +class Electrifier : public GameObject +{ +public: + Electrifier(uint32_t oldtile, uint32_t newtile, float seconds); + ~Electrifier(); +protected: + virtual void update(float time); + virtual void draw(DrawingContext& context); +private: + uint32_t change_from; + uint32_t change_to; + Timer duration; +}; + +#endif +