- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# C:/Documents and Settings/jegan/Desktop/projectX/Door.cpp

Go to the documentation of this file.

    00001 #include "Door.h"
    00002 #include "List.h"
    00003
    00004 Door::Door(List* info, int x, int y)
    00005 :Object(info,x,y),_open(false),_locked(true)
    00006 {
    00007         _type = DOOR;
    00008         load(info);
    00009 }
    00010
    00011 void Door::load(List *info, bool fromConstructor)
    00012 {
    00013         if(!fromConstructor)
    00014                 Object::load(info,fromConstructor);
    00015
    00016         while(!info->empty()) {
    00017                 List *current = info->firstList();
    00018
    00019                 if(current->firstString() == "openSprite") {
    00020                         _openSprite = Sprite::loadSprite(current->rest()->firstString());
    00021                 }
    00022                 else if(current->firstString() == "closedSprite") {
    00023                         _closedSprite = Sprite::loadSprite(current->rest()->firstString());
    00024                 }
    00025                 else if(current->firstString() == "unlocked")
    00026                         _locked = false;
    00027                 else if(current->firstString() == "locked")
    00028                         _locked = true;
    00029                 else if(current->firstString() == "open")
    00030                         _open = true;
    00031
    00032                 info = info->rest();
    00033         }
    00034
    00035         setOpen(_open);
    00036 }
    00037
    00038 Object *Door::copy()
    00039 {
    00040         return new Door(*this);
    00041 }
    00042
    00043 void Door::collide( Object* o )
    00044 {
    00045         if((o->getType() == PLAYER || o->getType() == ENEMY) && !_locked ) {
    00046                 _open = true;
    00047                 _collidable = false;
    00048         }
    00049 }
    00050
    00051 void Door::draw()
    00052 {
    00053         if(_open)
    00054                 _openSprite->draw(_box.x,_box.y);
    00055         else
    00056                 _closedSprite->draw(_box.x,_box.y);
    00057
    00058 }
    00059
    00060 void Door::setOpen(bool open)
    00061 {
    00062         _open = open;
    00063
    00064         if(_open) {
    00065                 _box.h = _openSprite->height();
    00066                 _box.w = _openSprite->width();
    00067                 _collidable = false;
    00068         }
    00069         else {
    00070                 _box.h = _closedSprite->height();
    00071                 _box.w = _closedSprite->width();
    00072                 _collidable = true;
    00073         }
    00074 }