3 #include "enemymanager.h"
7 static int regenemy (lua_State
*L
) {
8 lua_settable(L
, LUA_REGISTRYINDEX
);
11 EnemyManager::EnemyManager(Game
* g
) {
16 void EnemyManager::loadEnemies() {
17 std::set
<Enemy
*>::iterator it
;
18 for (it
= enemies
.begin();it
!= enemies
.end(); it
++) {
25 registerFunction(lstate
,"regenemy",regenemy
);
26 doLuaFile(lstate
,"enemymanager.lua");
27 doLuaFile(lstate
,"enemies.lua");
30 void EnemyManager::desenha() {
31 std::set
<Enemy
*>::iterator it
;
32 for (it
= enemies
.begin();it
!= enemies
.end(); it
++) {
37 void EnemyManager::move() {
38 std::set
<Enemy
*>::iterator it
;
39 for (it
= enemies
.begin();it
!= enemies
.end(); it
++) {
44 void EnemyManager::animate() {
45 std::set
<Enemy
*>::iterator it
;
46 for (it
= enemies
.begin();it
!= enemies
.end(); it
++) {
51 void EnemyManager::think() {
52 std::set
<Enemy
*>::iterator it
;
53 for (it
= enemies
.begin();it
!= enemies
.end(); it
++) {
58 void EnemyManager::remove(Enemy
* enemy
) {
59 enemies
.erase(enemies
.find(enemy
));
62 Enemy
* EnemyManager::createEnemy(std::string name
) {
63 lua_pushstring(lstate
,name
.c_str());
64 lua_gettable(lstate
, LUA_REGISTRYINDEX
);
65 if (lua_pcall(lstate
,0,2,0) != 0) /* do the call */
66 printf("error: %s", lua_tostring(lstate
, -1));
67 std::string weaponname
= lua_tostring(lstate
, 1);
69 Enemy
* ret
= new Enemy(game
);
71 game
->gravityManager
->subscribe(ret
);
72 game
->collisionManager
->subscribe(ret
);
73 ret
->equip(game
->weaponManager
->getWeapon(weaponname
));
77 bool enemyAlive(Enemy
* e
) {
81 bool EnemyManager::hasEnemies() {
84 return count_if(enemies
.begin(), enemies
.end(), enemyAlive
) > 0;