+ bbox.set_pos(pos);
+ sprite->set_action("normal");
+ switch(data) {
+ case 1: contents = CONTENT_COIN; break;
+ case 2: contents = CONTENT_FIREGROW; break;
+ case 3: contents = CONTENT_STAR; break;
+ case 4: contents = CONTENT_1UP; break;
+ case 5: contents = CONTENT_ICEGROW; break;
+ default:
+ log_warning << "Invalid box contents" << std::endl;
+ contents = CONTENT_COIN;
+ break;
+ }
+}
+
+BonusBlock::BonusBlock(const lisp::Lisp& lisp)
+ : Block(sprite_manager->create("images/objects/bonus_block/bonusblock.sprite"))
+{
+ Vector pos;
+
+ contents = CONTENT_COIN;
+ 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 {
+ log_warning << "Invalid box contents '" << contentstring << "'" << std::endl;
+ }
+ } else {
+ 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 {
+ log_warning << "Invalid element '" << token << "' in bonusblock" << std::endl;
+ }
+ }
+ }
+
+ 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;