+// $Id$
+//
+// SuperTux
+// Copyright (C) 2005 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 "block.h"
-#include "resources.h"
-#include "player.h"
-#include "sector.h"
-#include "special/sprite.h"
-#include "special/sprite_manager.h"
-#include "video/drawing_context.h"
-#include "lisp/lisp.h"
-#include "gameobjs.h"
-#include "specialriser.h"
-#include "growup.h"
-#include "flower.h"
-#include "oneup.h"
-#include "star.h"
-#include "player_status.h"
-#include "badguy/badguy.h"
-#include "coin.h"
-#include "object_factory.h"
+#include "block.hpp"
+
+#include <stdexcept>
+
+#include "resources.hpp"
+#include "player.hpp"
+#include "sector.hpp"
+#include "sprite/sprite.hpp"
+#include "sprite/sprite_manager.hpp"
+#include "video/drawing_context.hpp"
+#include "lisp/lisp.hpp"
+#include "gameobjs.hpp"
+#include "specialriser.hpp"
+#include "growup.hpp"
+#include "flower.hpp"
+#include "oneup.hpp"
+#include "star.hpp"
+#include "player_status.hpp"
+#include "badguy/badguy.hpp"
+#include "coin.hpp"
+#include "object_factory.hpp"
+#include "lisp/list_iterator.hpp"
+#include "object_factory.hpp"
static const float BOUNCY_BRICK_MAX_OFFSET=8;
static const float BOUNCY_BRICK_SPEED=90;
}
void
-Block::action(float elapsed_time)
+Block::update(float elapsed_time)
{
if(!bouncing)
return;
//---------------------------------------------------------------------------
BonusBlock::BonusBlock(const Vector& pos, int data)
- : Block(sprite_manager->create("bonusblock"))
+ : Block(sprite_manager->create("bonusblock")), object(0)
{
bbox.set_pos(pos);
sprite->set_action("normal");
: Block(sprite_manager->create("bonusblock"))
{
Vector pos;
- lisp.get("x", pos.x);
- lisp.get("y", pos.y);
- bbox.set_pos(pos);
- std::string contentstring;
contents = CONTENT_COIN;
- if(lisp.get("contents", contentstring)) {
- if(contentstring == "coin") {
- contents = CONTENT_COIN;
- } else if(contentstring == "firegrow") {
- contents = CONTENT_FIREGROW;
- } else if(contentstring == "icegrow") {
- contents = CONTENT_ICEGROW;
- } else if(contentstring == "star") {
- contents = CONTENT_STAR;
- } else if(contentstring == "1up") {
- contents = CONTENT_1UP;
+ lisp::ListIterator iter(&lisp);
+ while(iter.next()) {
+ const std::string& token = iter.item();
+ if(token == "x") {
+ iter.value()->get(pos.x);
+ } else if(token == "y") {
+ iter.value()->get(pos.y);
+ } else if(token == "contents") {
+ std::string contentstring;
+ iter.value()->get(contentstring);
+ if(contentstring == "coin") {
+ contents = CONTENT_COIN;
+ } else if(contentstring == "firegrow") {
+ contents = CONTENT_FIREGROW;
+ } else if(contentstring == "icegrow") {
+ contents = CONTENT_ICEGROW;
+ } else if(contentstring == "star") {
+ contents = CONTENT_STAR;
+ } else if(contentstring == "1up") {
+ contents = CONTENT_1UP;
+ } else if(contentstring == "custom") {
+ contents = CONTENT_CUSTOM;
+ } else {
+ std::cerr << "Invalid box contents '" << contentstring << "'.\n";
+ }
} else {
- std::cerr << "Invalid box contents '" << contentstring << "'.\n";
- }
+ if(contents == CONTENT_CUSTOM) {
+ GameObject* game_object = create_object(token, *(iter.lisp()));
+ object = dynamic_cast<MovingObject*> (game_object);
+ if(object == 0)
+ throw std::runtime_error(
+ "Only MovingObjects are allowed inside BonusBlocks");
+ } else {
+ std::cerr << "Invalid element '" << token << "' in bonusblock.\n";
+ }
+ }
}
+
+ if(contents == CONTENT_CUSTOM && object == 0)
+ throw std::runtime_error("Need to specify content object for custom block");
+
+ bbox.set_pos(pos);
+}
+
+BonusBlock::~BonusBlock()
+{
+ delete object;
}
void
BonusBlock::try_open()
{
if(sprite->get_action_name() == "empty") {
- SoundManager::get()->play_sound(IDToSound(SND_BRICK));
+ sound_manager->play("sounds/brick.wav");
return;
}
case CONTENT_FIREGROW:
if(player.get_status()->bonus == NO_BONUS) {
- SpecialRiser* riser = new SpecialRiser(
- new GrowUp(get_pos() + Vector(0, -32)));
+ SpecialRiser* riser = new SpecialRiser(get_pos(), new GrowUp());
sector->add_object(riser);
} else {
SpecialRiser* riser = new SpecialRiser(
- new Flower(get_pos() + Vector(0, -32), Flower::FIREFLOWER));
+ get_pos(), new Flower(Flower::FIREFLOWER));
sector->add_object(riser);
}
- SoundManager::get()->play_sound(IDToSound(SND_UPGRADE));
+ sound_manager->play("sounds/upgrade.wav");
break;
case CONTENT_ICEGROW:
if(player.get_status()->bonus == NO_BONUS) {
- SpecialRiser* riser = new SpecialRiser(
- new GrowUp(get_pos() + Vector(0, -32)));
+ SpecialRiser* riser = new SpecialRiser(get_pos(), new GrowUp());
sector->add_object(riser);
} else {
- SpecialRiser* riser = new SpecialRiser(
- new Flower(get_pos() + Vector(0, -32), Flower::ICEFLOWER));
+ SpecialRiser* riser = new SpecialRiser(
+ get_pos(), new Flower(Flower::ICEFLOWER));
sector->add_object(riser);
}
- SoundManager::get()->play_sound(IDToSound(SND_UPGRADE));
+ sound_manager->play("sounds/upgrade.wav");
break;
case CONTENT_STAR:
sector->add_object(new OneUp(get_pos()));
break;
- default:
- assert(false);
+ case CONTENT_CUSTOM:
+ SpecialRiser* riser = new SpecialRiser(get_pos(), object);
+ object = 0;
+ sector->add_object(riser);
+ sound_manager->play("sounds/upgrade.wav");
+ break;
+
+ //default:
+ //assert(false);
}
start_bounce();
sprite->set_action("empty");
}
-IMPLEMENT_FACTORY(BonusBlock, "bonusblock")
+IMPLEMENT_FACTORY(BonusBlock, "bonusblock");
//---------------------------------------------------------------------------
if(sprite->get_action_name() == "empty")
return;
- SoundManager::get()->play_sound(IDToSound(SND_BRICK));
+ sound_manager->play("sounds/brick.wav");
Sector* sector = Sector::current();
Player& player = *(sector->player);
if(coin_counter > 0) {
}
}
-//IMPLEMENT_FACTORY(Brick, "brick")
+//IMPLEMENT_FACTORY(Brick, "brick");
+