00001 #include "EventPoint.h"
00002 #include "CommandManager.h"
00003 #include "List.h"
00004 #include "Parser.h"
00005 #include "Sprite.h"
00006 #include <iostream>
00007
00008 using namespace std;
00009
00010 EventPoint::EventPoint(List* info, int x, int y)
00011 :Object(info,x,y),_active(true),_collideEvent(false),_hasSprite(false),_collideList(NULL)
00012 {
00013 _collidable = true;
00014 _solid = false;
00015 _type = EVENTPOINT;
00016
00017
00018
00019
00020
00021 load(info);
00022 }
00023
00024 EventPoint::~EventPoint()
00025 {
00026 delete _collideList;
00027 }
00028
00029 Object *EventPoint::copy()
00030 {
00031 EventPoint* copy = new EventPoint(*this);
00032 copy->_collideList = new List(_collideList);
00033 return copy;
00034 }
00035
00036 void EventPoint::load(List *info, bool fromConstructor)
00037 {
00038 if(!fromConstructor)
00039 Object::load(info,fromConstructor);
00040
00041 while(!info->empty()) {
00042 List *current = info->firstList();
00043
00044 if(current->firstString() == "collideScript") {
00045 if(current->rest()->first()->atomic()) {
00046 string collideFile = current->rest()->firstString();
00047 _collideList = Parser::parse(collideFile);
00048 }
00049 else {
00050 _collideList = new List(current->rest()->firstList());
00051 }
00052 _collideEvent = true;
00053 }
00054 else if(current->firstString() == "sprite") {
00055 _sprite = Sprite::loadSprite(current->rest()->firstString());
00056 _hasSprite = true;
00057 _box.h = _sprite->height();
00058 _box.w = _sprite->width();
00059 }
00060 else if(current->firstString() == "replace") {
00061 findAndReplace(current->rest()->firstString(), current->rest()->rest()->firstString());
00062 }
00063
00064 info = info->rest();
00065 }
00066
00067 }
00068
00069 void EventPoint::collide(Object *o)
00070 {
00071 if(o->getType() == PLAYER && _active && _collideEvent) {
00072 CommandManager::instance()->startPlaying(_collideList);
00073 _active = false;
00074 }
00075 }
00076
00077 void EventPoint::findAndReplace(std::string find, std::string replace)
00078 {
00079 if(_collideEvent) {
00080 _collideList->findAndReplace(find,replace);
00081 }
00082 }
00083
00084 void EventPoint::draw()
00085 {
00086 if(_hasSprite && _active)
00087 _sprite->draw(_box.x,_box.y);
00088 }