Hosting courtesy of Sourceforge

SourceForge Logo
Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

Powerup.cpp

Go to the documentation of this file.
00001 //
00002 //                                 Powerup.cpp
00003 //                             -------------------
00004 //    begin                : Thu Mar 7 2002
00005 //    copyright            : (C) 2002 by Rob Renaud
00006 //    email                : rrenaud@eden.rutgers.edu
00007 //
00008 //   This program is free software; you can redistribute it and/or modify
00009 //   it under the terms of the GNU General Public License as published by
00010 //   the Free Software Foundation; either version 2 of the License, or
00011 //   (at your option) any later version.
00012 //
00013 
00014 #include "Powerup.h"
00015 
00016 #include <cstdlib>
00017 #include "../Parse/ParseAction.h"
00018 
00019 using namespace Game;
00020 
00021 
00022 Powerup_impl::Powerup_impl(Graphics::DrawableAt* p) :
00023 pic(p)
00024 { }
00025 
00026 Powerup_impl::~Powerup_impl() {
00027         delete pic;
00028 }
00029 
00030 void Powerup_impl::drawAt(SDL_Surface* s, SDL_Rect* r) {
00031         pic->drawAt(s,r);
00032 }
00033 
00034 SpeedUp::SpeedUp() :
00035 Powerup_impl(new Graphics::SingleFrameImage("GameData/Powerup/SpeedUp.bmp", SDL_RLEACCEL | SDL_SRCCOLORKEY))
00036 { }
00037 
00038 void SpeedUp::effect(AbstractPlayer* p) {
00039         p->setSpeed(p->getSpeed() + 1);
00040 }
00041 
00042 IncreaseBombRadius::IncreaseBombRadius() :
00043 Powerup_impl(new Graphics::SingleFrameImage("GameData/Powerup/IncreaseBombRadius.bmp", SDL_RLEACCEL | SDL_SRCCOLORKEY))
00044 { }
00045 
00046 void IncreaseBombRadius::effect(AbstractPlayer* p) {
00047         p->setBombRadius(p->getBombRadius() + 1);
00048 }
00049 
00050 IncreaseBombCount::IncreaseBombCount() :
00051 Powerup_impl(new Graphics::SingleFrameImage("GameData/Powerup/IncreaseBombs.bmp", SDL_RLEACCEL | SDL_SRCCOLORKEY))
00052 { }
00053 
00054 void IncreaseBombCount::effect(AbstractPlayer* p) {
00055         p->increaseBombsLeft();
00056 }
00057 
00058 PowerupFactory::PowerupFactory() :
00059 incBombCountProb(Constants::PROB_BOMB_COUNT),
00060 incBombRadProb(Constants::PROB_BOMB_RAD),
00061 speedUpProb(Constants::PROB_SPEED_UP)
00062 { }
00063 
00064 Powerup* PowerupFactory::getPowerup() {
00065         float randFloat = (float) rand() / RAND_MAX; // should start in range [0,1]
00066         
00067         randFloat -= incBombCountProb;
00068         if (randFloat < 0) return new IncreaseBombCount;
00069 
00070         randFloat -= incBombRadProb;
00071         if (randFloat < 0) return new IncreaseBombRadius;
00072 
00073         randFloat -= speedUpProb;
00074         if (randFloat < 0) return new SpeedUp;
00075 
00076         return NULL;
00077 }
00078 
00079 Parse::Parser* PowerupFactory::makeParserToParseMe(std::istream& in) {
00080         Parse::SimpleParser *p = new Parse::SimpleParser(in);
00081         
00082         p->addAction("BombCount",       new Parse::StdRead<float>(incBombCountProb));
00083         p->addAction("BombRad",         new Parse::StdRead<float>(incBombRadProb));
00084         p->addAction("SpeedUp",         new Parse::StdRead<float>(speedUpProb));
00085 
00086         return p;
00087 }
00088 

Generated on Tue May 21 07:26:51 2002 for BomberLAN by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001