From: Mathnerd314 Date: Mon, 18 Jan 2010 00:15:08 +0000 (+0000) Subject: Doors can run scripts now. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=2e04de67d9232d7649d1332608295b59eb9529a1;p=supertux.git Doors can run scripts now. SVN-Revision: 6257 --- diff --git a/data/levels/test/doortest.stl b/data/levels/test/doortest.stl new file mode 100644 index 000000000..8d1bb5723 --- /dev/null +++ b/data/levels/test/doortest.stl @@ -0,0 +1,65 @@ +(supertux-level + (version 2) + (name (_ "Door Test")) + (author "Mathnerd314") + (sector + (name "main") + (music "music/chipdisko.ogg") + (ambient-light 1 1 1) + (background + (speed 0.5) + (image "images/background/arctis.jpg") + ) + (camera + (mode "normal") + ) + (door + (x 288) + (y 448) + (script "ghost()") + ) + (door + (x 384) + (y 448) + (sector "main") + (spawnpoint "test") + ) + (spawnpoint + (name "main") + (x 100) + (y 100) + ) + (spawnpoint + (name "test") + (x 500) + (y 100) + ) + (tilemap + (solid #t) + (z-pos 0) + (width 27) + (height 19) + (tiles + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 0 0 0 0 0 0 + 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 15 0 0 0 0 0 0 + 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 12 0 0 0 0 0 0 + ) + ) + ) +) diff --git a/src/trigger/door.cpp b/src/trigger/door.cpp index c1418d89d..56060d46d 100644 --- a/src/trigger/door.cpp +++ b/src/trigger/door.cpp @@ -19,6 +19,7 @@ #include "sprite/sprite_manager.hpp" #include "supertux/game_session.hpp" #include "supertux/object_factory.hpp" +#include "supertux/sector.hpp" #include "trigger/door.hpp" #include "util/reader.hpp" @@ -34,6 +35,8 @@ Door::Door(const Reader& reader) : reader.get("sector", target_sector); reader.get("spawnpoint", target_spawnpoint); + reader.get("script", script); + sprite = sprite_manager->create("images/objects/door/door.sprite"); sprite->set_action("closed"); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); @@ -136,7 +139,14 @@ Door::collision(GameObject& other, const CollisionHit& hit) if (player) { state = CLOSING; sprite->set_action("closing", 1); - GameSession::current()->respawn(target_sector, target_spawnpoint); + if(script != "") { + std::istringstream stream(script); + Sector::current()->run_script(stream, "Door"); + } + + if(target_sector != "") { + GameSession::current()->respawn(target_sector, target_spawnpoint); + } } } break; diff --git a/src/trigger/door.hpp b/src/trigger/door.hpp index 41e1a14f2..0fefb7e07 100644 --- a/src/trigger/door.hpp +++ b/src/trigger/door.hpp @@ -46,6 +46,7 @@ private: DoorState state; /**< current state of the door */ std::string target_sector; /**< target sector to teleport to */ std::string target_spawnpoint; /**< target spawnpoint to teleport to */ + std::string script; SpritePtr sprite; /**< "door" sprite to render */ Timer stay_open_timer; /**< time until door will close again */ };