hatch door trigger files
authorStephen Groundwater <slacker@gluebox.com>
Thu, 31 Mar 2005 12:13:42 +0000 (12:13 +0000)
committerStephen Groundwater <slacker@gluebox.com>
Thu, 31 Mar 2005 12:13:42 +0000 (12:13 +0000)
SVN-Revision: 2306

src/trigger/hatch.cpp [new file with mode: 0644]
src/trigger/hatch.h [new file with mode: 0644]

diff --git a/src/trigger/hatch.cpp b/src/trigger/hatch.cpp
new file mode 100644 (file)
index 0000000..6019642
--- /dev/null
@@ -0,0 +1,100 @@
+//  $Id$
+//
+//  SuperTux -  A Jump'n Run
+//  Copyright (C) 2004 Matthias Braun <matze@braunis.de
+//
+//  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 <config.h>
+
+#include "hatch.h"
+#include "gameloop.h"
+#include "resources.h"
+#include "object_factory.h"
+#include "special/sprite.h"
+#include "special/sprite_manager.h"
+#include "video/drawing_context.h"
+#include "app/globals.h"
+#include "lisp/lisp.h"
+#include "lisp/writer.h"
+
+using namespace SuperTux;
+
+Hatch::Hatch(const lisp::Lisp& reader)
+{
+  reader.get("x", bbox.p1.x);
+  reader.get("y", bbox.p1.y);
+  bbox.set_size(64, 64);
+
+  reader.get("sector", target_sector);
+  reader.get("spawnpoint", target_spawnpoint);
+
+  sprite = sprite_manager->create("hatch");
+}
+
+Hatch::Hatch(int x, int y, std::string sector, std::string spawnpoint)
+{
+  bbox.set_pos(Vector(x, y));
+  bbox.set_size(64, 64);
+  target_sector = sector;
+  target_spawnpoint = spawnpoint;
+
+  sprite = sprite_manager->create("hatch");
+}
+
+Hatch::~Hatch()
+{
+  delete sprite;
+}
+
+void
+Hatch::write(lisp::Writer& writer)
+{
+  writer.start_list("hatch");
+
+  writer.write_float("x", bbox.p1.x);
+  writer.write_float("y", bbox.p1.y);
+  writer.write_float("width", bbox.get_width());
+  writer.write_float("height", bbox.get_height());
+  
+  writer.write_string("sector", target_sector);
+  writer.write_string("spawnpoint", target_spawnpoint);
+
+  writer.end_list("hatch");
+}
+
+void
+Hatch::action(float )
+{
+  //Check if hatch animation is complete
+  if(sprite->check_animation()) {
+    GameSession::current()->respawn(target_sector, target_spawnpoint);
+  }
+}
+
+void
+Hatch::draw(DrawingContext& context)
+{
+  sprite->draw(context, bbox.p1, LAYER_TILES);
+}
+
+void
+Hatch::event(Player& , EventType type)
+{
+  if(type == EVENT_ACTIVATE) {
+    sprite->set_action("open", 1);
+  }
+}
+
+IMPLEMENT_FACTORY(Hatch, "hatch");
diff --git a/src/trigger/hatch.h b/src/trigger/hatch.h
new file mode 100644 (file)
index 0000000..a759e1f
--- /dev/null
@@ -0,0 +1,49 @@
+//  $Id$
+//
+//  SuperTux -  A Jump'n Run
+//  Copyright (C) 2004 Matthias Braun <matze@braunis.de
+//
+//  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 SUPERTUX_HATCH_H
+#define SUPERTUX_HATCH_H
+
+#include <string>
+
+#include "video/surface.h"
+#include "special/sprite.h"
+#include "trigger_base.h"
+#include "serializable.h"
+#include "timer.h"
+
+class Hatch : public TriggerBase, public Serializable
+{
+public:
+  Hatch(const lisp::Lisp& reader);
+  Hatch(int x, int y, std::string sector, std::string spawnpoint);
+  virtual ~Hatch();
+
+  virtual void write(lisp::Writer& writer);
+  
+  virtual void action(float elapsed_time);
+  virtual void draw(DrawingContext& context);
+  virtual void event(Player& player, EventType type);
+
+private:
+  std::string target_sector;
+  std::string target_spawnpoint;
+  Sprite* sprite;
+};
+
+#endif