]> git.mxchange.org Git - quix0rs-blobwars.git/blobdiff - src/enemies.cpp
Added .gitignore to ignore certain files + fixed access rights on Makefile* as
[quix0rs-blobwars.git] / src / enemies.cpp
index 9c998c3e8532f4c67defbb4a4b9360a68e5c3c3a..944eab2d30bd5703bbe9b6cff3baa86a0efa8cdd 100644 (file)
@@ -1,5 +1,6 @@
 /*
-Copyright (C) 2004 Parallel Realities
+Copyright (C) 2004-2011 Parallel Realities
+Copyright (C) 2011-2015 Perpendicular Dimensions
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
@@ -56,7 +57,6 @@ Entity *getEnemy(const char *name)
 
 void addEnemy(const char *name, int x, int y, int flags)
 {
-       Entity *enemy = new Entity();
        Entity *defEnemy = getDefinedEnemy(name);
 
        if (defEnemy == NULL)
@@ -65,6 +65,7 @@ void addEnemy(const char *name, int x, int y, int flags)
                return;
        }
 
+       Entity *enemy = new Entity();
        enemy->setName(defEnemy->name);
        enemy->setSprites(defEnemy->sprite[0], defEnemy->sprite[1], defEnemy->sprite[2]);
        enemy->currentWeapon = defEnemy->currentWeapon;
@@ -421,7 +422,7 @@ void enemyBulletCollisions(Entity *bullet)
 
                                if (!(enemy->flags & ENT_EXPLODES))
                                {
-                                       audio.playSound(SND_HIT, CH_ANY);
+                                       audio.playSound(SND_HIT, CH_ANY, enemy->x);
                                        if (game.gore)
                                        {
                                                addBlood(enemy, bullet->dx / 4, Math::rrand(-6, -3), 1);
@@ -433,7 +434,7 @@ void enemyBulletCollisions(Entity *bullet)
                                }
                                else
                                {
-                                       audio.playSound(SND_CLANG, CH_ANY);
+                                       audio.playSound(SND_CLANG, CH_ANY, enemy->x);
                                        addColorParticles(bullet->x, bullet->y, Math::rrand(25, 75), -1);
                                }
 
@@ -469,11 +470,11 @@ void enemyBulletCollisions(Entity *bullet)
                                                        
                                                        if (enemy->flags & ENT_EXPLODES)
                                                        {
-                                                               audio.playSound(SND_ELECDEATH1 + Math::prand() % 3, CH_DEATH);
+                                                               audio.playSound(SND_ELECDEATH1 + Math::prand() % 3, CH_DEATH, enemy->x);
                                                        }
                                                        else if (game.gore)
                                                        {
-                                                               audio.playSound(SND_DEATH1 + Math::prand() % 3, CH_DEATH);
+                                                               audio.playSound(SND_DEATH1 + Math::prand() % 3, CH_DEATH, enemy->x);
                                                        }
                                                }
                                        }
@@ -493,11 +494,11 @@ void enemyBulletCollisions(Entity *bullet)
                                        
                                        if (enemy->flags & ENT_EXPLODES)
                                        {
-                                               audio.playSound(SND_ELECDEATH1 + Math::prand() % 3, CH_DEATH);
+                                               audio.playSound(SND_ELECDEATH1 + Math::prand() % 3, CH_DEATH, enemy->x);
                                        }
                                        else if (game.gore)
                                        {
-                                               audio.playSound(SND_DEATH1 + Math::prand() % 3, CH_DEATH);
+                                               audio.playSound(SND_DEATH1 + Math::prand() % 3, CH_DEATH, enemy->x);
                                        }
 
                                        if (bullet->owner == &player)
@@ -590,7 +591,7 @@ void gibEnemy(Entity *enemy)
                }
        }
        
-       (game.gore) ? audio.playSound(SND_SPLAT, CH_ANY) : audio.playSound(SND_POP, CH_ANY);
+       (game.gore) ? audio.playSound(SND_SPLAT, CH_ANY) : audio.playSound(SND_POP, CH_ANY, enemy->x);
 }
 
 void doEnemies()
@@ -738,7 +739,7 @@ void doEnemies()
                                        {
                                                if (game.gore)
                                                {
-                                                       audio.playSound(SND_DEATH1 + Math::prand() % 3, CH_DEATH);
+                                                       audio.playSound(SND_DEATH1 + Math::prand() % 3, CH_DEATH, enemy->x);
                                                }
                                        }
                                }
@@ -820,7 +821,7 @@ void loadEnemy(const char *token)
 {
        int enemy = -1;
 
-       for (int i = MAX_ENEMIES ; i > -1 ; i--)
+       for (int i = MAX_ENEMIES - 1; i >= 0; i--)
                if (strcmp(defEnemy[i].name, "") == 0)
                        enemy = i;
 
@@ -855,7 +856,7 @@ void loadDefEnemies()
 
        if (!engine.loadData("data/defEnemies"))
        {
-               graphics.showErrorAndExit("Couldn't load enemy definitions file (%s)", "data/defEnemies");
+               return graphics.showErrorAndExit("Couldn't load enemy definitions file (%s)", "data/defEnemies");
        }
 
        char *token = strtok((char*)engine.dataBuffer, "\n");