[Super-tux-commit] supertux/src/object infoblock.cpp,NONE,1.1 infoblock.h,NONE,1.1 block.cpp,1.9,1.1
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2005-03-30 12:01:11
|
Update of /cvsroot/super-tux/supertux/src/object In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1392/src/object Modified Files: block.cpp block.h invisible_block.cpp Added Files: infoblock.cpp infoblock.h Log Message: -Some cleanups in text scrolling code -Added the (temporary) bell graphics which I forgot yesterday -Implemented an infoblock object (the textbox isn't finished yet) and it also needs new graphics --- NEW FILE: infoblock.h --- #ifndef __INFOBLOCK_H__ #define __INFOBLOCK_H__ #include "block.h" class InfoBlock : public Block { public: InfoBlock(const lisp::Lisp& lisp); virtual ~InfoBlock(); protected: virtual void hit(Player& player); std::string message; }; #endif Index: block.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/block.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- block.cpp 25 Mar 2005 20:39:55 -0000 1.9 +++ block.cpp 30 Mar 2005 12:01:01 -0000 1.10 @@ -7,6 +7,7 @@ #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" @@ -22,13 +23,11 @@ static const float BOUNCY_BRICK_SPEED=90; static const float EPSILON = .0001; -Block::Block(const Vector& pos, Sprite* newsprite) +Block::Block(Sprite* newsprite) : sprite(newsprite), bouncing(false), bounce_dir(0), bounce_offset(0) { - bbox.set_pos(pos); bbox.set_size(32, 32.1); flags |= FLAG_SOLID; - original_y = pos.y; } Block::~Block() @@ -97,10 +96,49 @@ //--------------------------------------------------------------------------- -BonusBlock::BonusBlock(const Vector& pos, int newdata) - : Block(pos, sprite_manager->create("bonusblock")), data(newdata) +BonusBlock::BonusBlock(const Vector& pos, int data) + : Block(sprite_manager->create("bonusblock")) { + bbox.set_pos(pos); sprite->set_action("default"); + 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: + std::cerr << "Invalid box contents!\n"; + contents = CONTENT_COIN; + break; + } +} + +BonusBlock::BonusBlock(const lisp::Lisp& lisp) + : 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; + } else { + std::cerr << "Invalid box contents '" << contentstring << "'.\n"; + } + } } void @@ -119,13 +157,13 @@ Sector* sector = Sector::current(); Player& player = *(sector->player); - switch(data) { - case 1: // coin + switch(contents) { + case CONTENT_COIN: Sector::current()->add_object(new BouncyCoin(get_pos())); player.get_status().incCoins(); break; - case 2: // grow/fireflower + case CONTENT_FIREGROW: if(player.size == SMALL) { SpecialRiser* riser = new SpecialRiser( new GrowUp(get_pos() + Vector(0, -32))); @@ -138,7 +176,7 @@ SoundManager::get()->play_sound(IDToSound(SND_UPGRADE)); break; - case 5: // grow/iceflower + case CONTENT_ICEGROW: if(player.size == SMALL) { SpecialRiser* riser = new SpecialRiser( new GrowUp(get_pos() + Vector(0, -32))); @@ -151,11 +189,11 @@ SoundManager::get()->play_sound(IDToSound(SND_UPGRADE)); break; - case 3: // star + case CONTENT_STAR: sector->add_object(new Star(get_pos() + Vector(0, -32))); break; - case 4: // 1up + case CONTENT_1UP: sector->add_object(new OneUp(get_pos())); break; @@ -167,14 +205,15 @@ sprite->set_action("empty"); } -//IMPLEMENT_FACTORY(BonusBlock, "bonusblock") +IMPLEMENT_FACTORY(BonusBlock, "bonusblock") //--------------------------------------------------------------------------- Brick::Brick(const Vector& pos, int data) - : Block(pos, sprite_manager->create("brick")), breakable(false), + : Block(sprite_manager->create("brick")), breakable(false), coin_counter(0) { + bbox.set_pos(pos); if(data == 1) coin_counter = 5; else Index: invisible_block.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/invisible_block.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- invisible_block.cpp 20 Dec 2004 21:24:27 -0000 1.3 +++ invisible_block.cpp 30 Mar 2005 12:01:02 -0000 1.4 @@ -8,8 +8,9 @@ #include "object_factory.h" InvisibleBlock::InvisibleBlock(const Vector& pos) - : Block(pos, sprite_manager->create("invisibleblock")), visible(false) + : Block(sprite_manager->create("invisibleblock")), visible(false) { + bbox.set_pos(pos); flags &= ~FLAG_SOLID; } Index: block.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/block.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- block.h 30 Mar 2005 01:52:14 -0000 1.4 +++ block.h 30 Mar 2005 12:01:01 -0000 1.5 @@ -2,6 +2,7 @@ #define __BLOCK_H__ #include "special/moving_object.h" +#include "lisp/lisp.h" namespace SuperTux { class Sprite; @@ -13,7 +14,7 @@ class Block : public MovingObject { public: - Block(const Vector& pos, Sprite* sprite); + Block(Sprite* sprite = 0); ~Block(); virtual HitResponse collision(GameObject& other, const CollisionHit& hit); @@ -35,6 +36,7 @@ { public: BonusBlock(const Vector& pos, int data); + BonusBlock(const lisp::Lisp& lisp); void try_open(); @@ -42,7 +44,15 @@ virtual void hit(Player& player); private: - int data; + enum Contents { + CONTENT_COIN, + CONTENT_FIREGROW, + CONTENT_ICEGROW, + CONTENT_STAR, + CONTENT_1UP + }; + + Contents contents; }; class Brick : public Block --- NEW FILE: infoblock.cpp --- #include <config.h> #include "infoblock.h" #include "gameloop.h" #include "resources.h" #include "special/sprite_manager.h" #include "object_factory.h" #include "lisp/lisp.h" InfoBlock::InfoBlock(const lisp::Lisp& lisp) : Block(sprite_manager->create("bonusblock")) { Vector pos; lisp.get("x", pos.x); lisp.get("y", pos.y); bbox.set_pos(pos); if(!lisp.get("message", message)) { std::cerr << "No message in InfoBlock!\n"; } } InfoBlock::~InfoBlock() { } void InfoBlock::hit(Player& ) { GameSession::current()->display_info_box(message); start_bounce(); } IMPLEMENT_FACTORY(InfoBlock, "infoblock") |