Ajuste leve na velocidade permitindo movimentos mais sutis
[Projeto-PCG.git] / enemymanager.cpp
blobba960f8446dc5f30592b12ab94500acc71f3a3fd
1 #include <algorithm>
3 #include "enemymanager.h"
4 #include "enemy.h"
5 #include "game.h"
7 static int regenemy (lua_State *L) {
8 lua_settable(L, LUA_REGISTRYINDEX);
11 EnemyManager::EnemyManager(Game* g) {
12 game = g;
13 lstate = NULL;
16 void EnemyManager::loadEnemies() {
17 std::set<Enemy*>::iterator it;
18 for (it = enemies.begin();it != enemies.end(); it++) {
19 (*it)->die();
21 enemies.clear();
22 if (lstate != NULL)
23 lua_close(lstate);
24 lstate = newState();
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++) {
33 (*it)->desenha();
37 void EnemyManager::move() {
38 std::set<Enemy*>::iterator it;
39 for (it = enemies.begin();it != enemies.end(); it++) {
40 (*it)->move();
44 void EnemyManager::animate() {
45 std::set<Enemy*>::iterator it;
46 for (it = enemies.begin();it != enemies.end(); it++) {
47 (*it)->animate();
51 void EnemyManager::think() {
52 std::set<Enemy*>::iterator it;
53 for (it = enemies.begin();it != enemies.end(); it++) {
54 (*it)->think();
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);
68 lua_pop(lstate,2);
69 Enemy* ret = new Enemy(game);
70 enemies.insert(ret);
71 game->gravityManager->subscribe(ret);
72 game->collisionManager->subscribe(ret);
73 ret->equip(game->weaponManager->getWeapon(weaponname));
74 return ret;
77 bool enemyAlive(Enemy* e) {
78 return !e->dead;
81 bool EnemyManager::hasEnemies() {
82 if (enemies.empty())
83 return false;
84 return count_if(enemies.begin(), enemies.end(), enemyAlive) > 0;