From 9890da50f82d286c67e72feefcc423d1bc9076c3 Mon Sep 17 00:00:00 2001 From: Marek Moeckel Date: Sun, 18 Sep 2005 10:01:16 +0000 Subject: [PATCH] fixed kugelblitz, added electrifier object SVN-Revision: 2771 --- src/badguy/kugelblitz.cpp | 16 ++++------------ src/badguy/kugelblitz.hpp | 2 +- src/object/electrifier.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++ src/object/electrifier.hpp | 41 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 src/object/electrifier.cpp create mode 100644 src/object/electrifier.hpp 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 + -- 2.11.0