#include <config.h>
#include "kugelblitz.hpp"
-#include "sector.hpp"
#include "object/tilemap.hpp"
#include "tile.hpp"
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 {
}
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);
#include "badguy.hpp"
#include "timer.hpp"
+#include "object/electrifier.hpp"
class Kugelblitz : public BadGuy
{
bool dying;
Timer movement_timer;
Timer lifetime;
- Timer electrify_timer;
int direction;
};
--- /dev/null
+// 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& )
+{
+}
--- /dev/null
+// 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
+