00001 #include "CutScene.h" 00002 #include "Parser.h" 00003 #include "Command.h" 00004 00005 using namespace std; 00006 00007 CutScene::CutScene(List* info, int x, int y) 00008 :Object(info,x,y),_active(true),_keyTimer(21) 00009 { 00010 _type = CUTSCENE; 00011 load(info); 00012 } 00013 00014 CutScene::~CutScene() 00015 { 00016 while(!_scene.empty()) 00017 { 00018 delete _scene.front(); 00019 _scene.pop(); 00020 } 00021 } 00022 00023 void CutScene::load(List *info) 00024 { 00025 while(!info->empty()) { 00026 List *current = info->firstList(); 00027 00028 if(current->firstString() == "scene") 00029 _scene.push(new List(current->rest())); 00030 00031 info = info->rest(); 00032 } 00033 } 00034 00035 void CutScene::collide(Object *o) 00036 { 00037 if(o->getType() == PLAYER && _active) { 00038 runScene(); 00039 _active = false; 00040 } 00041 } 00042 00043 void CutScene::control() 00044 { 00045 Uint8 *keystates = SDL_GetKeyState( NULL ); 00046 00047 if(keystates[SDLK_SPACE] && _keyTimer > 20) { 00048 runScene(); 00049 _keyTimer = 0; 00050 } 00051 } 00052 00053 void CutScene::runScene() 00054 { 00055 if(_scene.empty()) { 00056 cerr << "Control still on " << _id << " after scene is over." << endl; 00057 return; 00058 } 00059 00060 /* 00061 queue<Command*> commands = _scene.front(); 00062 _scene.pop(); 00063 00064 while(!commands.empty()) { 00065 commands.front()->execute(); 00066 commands.pop(); 00067 } 00068 */ 00069 00070 List *commands = _scene.front(); 00071 00072 while(!commands->empty()) { 00073 Command::loadCommand(commands->firstList())->execute(); 00074 commands = commands->rest(); 00075 } 00076 00077 delete _scene.front(); 00078 _scene.pop(); 00079 }