C:/Documents and Settings/jegan/Desktop/projectX/CutScene.cpp

Go to the documentation of this file.
00001 #include "CutScene.h"
00002 #include "Parser.h"
00003 #include "Command.h"
00004 #include "CommandManager.h"
00005 
00006 using namespace std;
00007 
00008 CutScene::CutScene(List* info, int x, int y)
00009 :Object(info,x,y),_active(true),_keyTimer(0)
00010 {
00011 
00012         _type = CUTSCENE;
00013         _solid = false;
00014         load(info);
00015 }
00016 
00017 CutScene::~CutScene()
00018 {
00019         while(!_scene.empty())
00020         {
00021                 delete _scene.front();
00022                 _scene.pop();
00023         }
00024 }
00025 
00026 Object *CutScene::copy()
00027 {
00028         CutScene *copy = new CutScene(*this);
00029         copy->_scene.c.clear();
00030         for(size_t i = 0; i < _scene.c.size(); i++)
00031                 copy->_scene.c.push_back(new List(_scene.c[i]));
00032 
00033         return copy;
00034 }
00035 
00036 void CutScene::load(List *info)
00037 {
00038         while(!info->empty()) {
00039                 List *current = info->firstList();
00040 
00041                 if(current->firstString() == "scene"){
00042                         _scene.push(new List(current->rest()->rest()));
00043                         _waitTime.push(current->rest()->firstInt());
00044                 }
00045                         
00046 
00047                 info = info->rest();
00048         }
00049         _keyTimer = _waitTime.front()+1;
00050 }
00051 
00052 void CutScene::collide(Object *o)
00053 {
00054         if(o->getType() == PLAYER && _active)
00055                 activate();
00056 }
00057 
00058 void CutScene::activate()
00059 {
00060         CommandManager::instance()->flush();
00061         runScene();
00062         _keyTimer = 0;
00063         _active = false;
00064 }
00065 
00066 void CutScene::control()
00067 {
00068         Uint8 *keystates = SDL_GetKeyState( NULL );
00069 
00070         if(keystates[SDLK_SPACE] && _keyTimer > _waitTime.front()) {
00071                 _keyTimer = 0;
00072                 runScene();
00073         }
00074 }
00075 
00076 void CutScene::runScene()
00077 {
00078         if(_scene.empty()) {
00079                 cerr << "Control still on " << _id << " after scene is over." << endl;
00080                 return;
00081         }
00082 
00083         /*
00084         queue<Command*> commands = _scene.front();
00085         _scene.pop();
00086 
00087         while(!commands.empty()) {
00088                 commands.front()->execute();
00089                 commands.pop();
00090         }
00091         */
00092 
00093         List *commands = _scene.front();
00094 
00095         //int waitTime = 0;
00096         while(!commands->empty()) {
00097                 Command *command = Command::loadCommand(commands->firstList());
00098                 command->execute();
00099                 commands = commands->rest();
00100         }
00101 
00102         delete _scene.front();
00103         _scene.pop();
00104         _waitTime.pop();
00105 }

Generated on Fri May 5 00:20:18 2006 for ProjectX by  doxygen 1.4.6-NO