00001 #include "Enemy.h" 00002 #include "Command.h" 00003 #include "CommandManager.h" 00004 #include "List.h" 00005 #include "Level.h" 00006 00007 #include <iostream> 00008 00009 using namespace std; 00010 00011 Enemy::Enemy(List *enemyInfo, int x, int y) 00012 :Person(enemyInfo, x, y) 00013 { 00014 _type = ENEMY; 00015 00016 load(enemyInfo); 00017 } 00018 00019 void Enemy::load(List *enemyInfo) 00020 { 00021 while(!enemyInfo->empty()) 00022 { 00023 List * current = enemyInfo->firstList(); 00024 00025 if(current->firstString() == "brain") 00026 { 00027 string braintype = current->rest()->firstString(); 00028 00029 if(braintype == "jump") 00030 _brain = JUMP; 00031 00032 else if(braintype == "followshootahead") 00033 _brain = FOLLOWSHOOTAHEAD; 00034 00035 else if(braintype == "followshoot") 00036 _brain = FOLLOWSHOOT; 00037 00038 else if(braintype == "sitandshoot") 00039 _brain = SITANDSHOOT; 00040 } 00041 00042 enemyInfo = enemyInfo->rest(); 00043 } 00044 } 00045 00046 void Enemy::update() 00047 { 00048 Person::update(); 00049 if( _brain == FOLLOWSHOOTAHEAD) 00050 { 00051 FollowPlayerCommand(this).execute(); 00052 //FIXME MAJK NUMBER 00053 ShootInRangeCommand(this, 1000).execute(); 00054 } 00055 00056 else if( _brain == JUMP) 00057 // JumpCommand(this, _xDirection).execute(); 00058 ; 00059 else if( _brain == FOLLOWSHOOT) 00060 { 00061 FollowPlayerInRangeCommand(this, 200).execute(); 00062 AimCommand(this).execute(); 00063 ShootInRangeCommand(this, 400).execute(); 00064 } 00065 else if(_brain == SITANDSHOOT) 00066 { 00067 AimCommand(this).execute(); 00068 ShootInRangeCommand(this, 400).execute(); 00069 } 00070 } 00071 00072 void Enemy::die() 00073 { 00074 Person::die(); 00075 Level::instance()->addScore(10); 00076 }