From af4ce38296b5c08e27b9cf7f23d68b1dda4f007d Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 26 Feb 2018 18:56:13 +0000 Subject: [PATCH] Added directional audio. --- src/combat/explosions.c | 2 +- src/combat/explosions.h | 2 +- src/combat/weapons.c | 16 ++++++------- src/combat/weapons.h | 3 ++- src/entities/blobs/teeka.c | 4 ++-- src/entities/blobs/teeka.h | 2 +- src/entities/boss/blobBoss.c | 14 ++++++------ src/entities/boss/blobBoss.h | 1 + src/entities/boss/eyeDroidCommander.c | 12 +++++----- src/entities/boss/eyeDroidCommander.h | 1 + src/entities/boss/tankCommander.c | 6 ++--- src/entities/boss/tankCommander.h | 1 + src/entities/bullets/bullet.c | 8 +++---- src/entities/bullets/bullet.h | 1 + src/entities/bullets/grenade.c | 2 +- src/entities/bullets/grenade.h | 1 + src/entities/bullets/laser.c | 4 ++-- src/entities/bullets/laser.h | 1 + src/entities/evilBlobs/evilBlob.c | 8 +++---- src/entities/evilBlobs/evilBlob.h | 1 + src/entities/eyeDroids/eyeDroid.c | 4 ++-- src/entities/eyeDroids/eyeDroid.h | 1 + src/entities/items/item.c | 2 +- src/entities/items/item.h | 1 + src/entities/structures/door.c | 6 ++--- src/entities/structures/door.h | 1 + src/entities/structures/pressurePlate.c | 2 +- src/entities/structures/pressurePlate.h | 1 + src/entities/structures/pushBlock.c | 2 +- src/entities/structures/pushBlock.h | 1 + src/entities/structures/teleporter.c | 2 +- src/entities/structures/teleporter.h | 1 + src/entities/traps/laserTrap.c | 2 +- src/entities/traps/laserTrap.h | 1 + src/entities/unit.c | 4 ++-- src/entities/unit.h | 1 + src/system/sound.c | 30 +++++++++++++++++++++++++ src/system/sound.h | 8 +++++++ src/test/atlasTest.c | 6 ++--- src/util/maths.c | 6 +++++ src/world/entities.c | 8 +++---- src/world/entities.h | 1 + src/world/world.c | 2 +- src/world/world.h | 1 + 44 files changed, 123 insertions(+), 61 deletions(-) diff --git a/src/combat/explosions.c b/src/combat/explosions.c index b7efb3d..15f001f 100644 --- a/src/combat/explosions.c +++ b/src/combat/explosions.c @@ -30,7 +30,7 @@ void addExplosion(float x, float y, int radius, Entity *owner) float power; int i; - playSound(SND_EXPLOSION, -1); + playBattleSound(SND_EXPLOSION, -1, x, y); /* assuming x and y were from the top left of the entity */ x += radius / 2; diff --git a/src/combat/explosions.h b/src/combat/explosions.h index 8b7ef4a..00524a7 100644 --- a/src/combat/explosions.h +++ b/src/combat/explosions.h @@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern int rrnd(int low, int high); extern void stunBob(void); extern void addExplosionParticles(float x, float y, float radius, int amount); -extern void playSound(int snd, int ch); +extern void playBattleSound(int snd, int ch, int x, int y); extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern int getDistance(int x1, int y1, int x2, int y2); extern void swapSelf(Entity *e); diff --git a/src/combat/weapons.c b/src/combat/weapons.c index daaf2de..4d5b25b 100644 --- a/src/combat/weapons.c +++ b/src/combat/weapons.c @@ -105,7 +105,7 @@ void fireAimedShot(Unit *owner) owner->reload = 15; - playSound(SND_PISTOL, owner->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_PISTOL, owner->uniqueId % MAX_SND_CHANNELS, owner->x, owner->y); } } @@ -121,7 +121,7 @@ void fireMachineGun(Unit *owner) bullet->sprite[1] = bulletSprite[1]; owner->reload = 8; - playSound(SND_MACHINE_GUN, owner->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_MACHINE_GUN, owner->uniqueId % MAX_SND_CHANNELS, owner->x, owner->y); } } @@ -139,7 +139,7 @@ void firePlasma(Unit *owner) owner->reload = owner->type == ET_BOB ? 4 : 8; - playSound(SND_PLASMA, owner->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_PLASMA, owner->uniqueId % MAX_SND_CHANNELS, owner->x, owner->y); } } @@ -166,7 +166,7 @@ void fireSpread(Unit *owner, int numberOfShots) owner->reload = 16; } - playSound(SND_SPREAD, owner->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_SPREAD, owner->uniqueId % MAX_SND_CHANNELS, owner->x, owner->y); } } @@ -188,7 +188,7 @@ void fireLaser(Unit *owner) owner->reload = owner->type == ET_BOB ? FPS / 2 : FPS; - playSound(SND_LASER, owner->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_LASER, owner->uniqueId % MAX_SND_CHANNELS, owner->x, owner->y); } } @@ -211,7 +211,7 @@ void fireGrenade(Unit *owner) owner->reload = FPS / 2; - playSound(SND_THROW, owner->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_THROW, owner->uniqueId % MAX_SND_CHANNELS, owner->x, owner->y); } } @@ -239,7 +239,7 @@ void fireShotgun(Unit *owner) owner->reload = 15; } - playSound(SND_SHOTGUN, owner->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_SHOTGUN, owner->uniqueId % MAX_SND_CHANNELS, owner->x, owner->y); } } @@ -262,7 +262,7 @@ void fireMissile(Unit *owner) owner->reload = FPS / 2; - playSound(SND_MISSILE, owner->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_MISSILE, owner->uniqueId % MAX_SND_CHANNELS, owner->x, owner->y); } } diff --git a/src/combat/weapons.h b/src/combat/weapons.h index d949a18..e6ef908 100644 --- a/src/combat/weapons.h +++ b/src/combat/weapons.h @@ -21,12 +21,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" extern Sprite *getSprite(char *name); -extern void playSound(int snd, int ch); +extern void playBattleSound(int snd, int ch, int x, int y); extern int rrnd(int low, int high); extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy); extern void initLaser(Bullet *b); extern void initGrenade(Bullet *b); extern void initMissile(Bullet *b); extern Bullet *createBaseBullet(Unit *owner); +extern void playSound(int snd, int ch); extern World world; diff --git a/src/entities/blobs/teeka.c b/src/entities/blobs/teeka.c index 026f738..85a95b3 100644 --- a/src/entities/blobs/teeka.c +++ b/src/entities/blobs/teeka.c @@ -119,7 +119,7 @@ static void lookForEnemies(void) { addTeleportStars(self); u->alive = ALIVE_DEAD; - playSound(SND_APPEAR, u->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_APPEAR, u->uniqueId % MAX_SND_CHANNELS, u->x, u->y); } else { @@ -175,7 +175,7 @@ static void attack(void) ((Unit*)self)->reload = 8; - playSound(SND_PISTOL, self->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_PISTOL, self->uniqueId % MAX_SND_CHANNELS, self->x, self->y); } void teekaExitMission(void) diff --git a/src/entities/blobs/teeka.h b/src/entities/blobs/teeka.h index 3fa67c7..800498b 100644 --- a/src/entities/blobs/teeka.h +++ b/src/entities/blobs/teeka.h @@ -28,7 +28,7 @@ extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy); extern int getDistance(int x1, int y1, int x2, int y2); extern int hasLineOfSight(Entity *src, Entity *dest); extern void addTeleportStars(Entity *e); -extern void playSound(int snd, int ch); +extern void playBattleSound(int snd, int ch, int x, int y); extern Entity *self; extern World world; diff --git a/src/entities/boss/blobBoss.c b/src/entities/boss/blobBoss.c index 565a11c..9644a1c 100644 --- a/src/entities/boss/blobBoss.c +++ b/src/entities/boss/blobBoss.c @@ -165,15 +165,15 @@ static void die1(void) switch (rand() % 3) { case 0: - playSound(SND_DEATH_1, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_DEATH_1, b->uniqueId % MAX_SND_CHANNELS, b->x, b->y); break; case 1: - playSound(SND_DEATH_2, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_DEATH_2, b->uniqueId % MAX_SND_CHANNELS, b->x, b->y); break; case 2: - playSound(SND_DEATH_3, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_DEATH_3, b->uniqueId % MAX_SND_CHANNELS, b->x, b->y); break; } @@ -327,7 +327,7 @@ static void attack(void) ((Boss*)self)->reload = 4; - playSound(SND_MACHINE_GUN, self->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_MACHINE_GUN, self->uniqueId % MAX_SND_CHANNELS, self->x, self->y); } } @@ -359,7 +359,7 @@ void reappear(void) addTeleportStars(self); - playSound(SND_APPEAR, -1); + playBattleSound(SND_APPEAR, -1, self->x, self->y); } static void applyDamage(int amount) @@ -384,7 +384,7 @@ static void teleport(void) self->flags |= EF_GONE; self->thinkTime = FPS * rrnd(3, 6); addTeleportStars(self); - playSound(SND_APPEAR, -1); + playBattleSound(SND_APPEAR, -1, self->x, self->y); } } @@ -400,7 +400,7 @@ static void die2(void) { addTeleportStars(self); - playSound(SND_APPEAR, -1); + playBattleSound(SND_APPEAR, -1, self->x, self->y); /* don't die! */ b->flags |= EF_GONE; diff --git a/src/entities/boss/blobBoss.h b/src/entities/boss/blobBoss.h index 923fed2..dc38eba 100644 --- a/src/entities/boss/blobBoss.h +++ b/src/entities/boss/blobBoss.h @@ -28,6 +28,7 @@ extern int isPlayingMusic(void); extern float limit(float i, float a, float b); extern double randF(void); extern void playSound(int snd, int ch); +extern void playBattleSound(int snd, int ch, int x, int y); extern Bullet *createBaseBullet(Unit *owner); extern Sprite *getSprite(char *name); extern int getDistance(int x1, int y1, int x2, int y2); diff --git a/src/entities/boss/eyeDroidCommander.c b/src/entities/boss/eyeDroidCommander.c index d4ea44a..0d7719f 100644 --- a/src/entities/boss/eyeDroidCommander.c +++ b/src/entities/boss/eyeDroidCommander.c @@ -292,7 +292,7 @@ static void attackPistol(void) b->reload = 4; - playSound(SND_MACHINE_GUN, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_MACHINE_GUN, b->uniqueId % MAX_SND_CHANNELS, self->x, self->y); } static void attackPlasma(void) @@ -317,7 +317,7 @@ static void attackPlasma(void) b->reload = 4; - playSound(SND_PLASMA, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_PLASMA, b->uniqueId % MAX_SND_CHANNELS, self->x, self->y); } static void attackMissile(void) @@ -341,7 +341,7 @@ static void attackMissile(void) b->reload = 15; - playSound(SND_MISSILE, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_MISSILE, b->uniqueId % MAX_SND_CHANNELS, self->x, self->y); } static void applyDamage(int amount) @@ -374,11 +374,11 @@ static void die(void) if (rand() % 2) { - playSound(SND_DROID_DIE_1, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_DROID_DIE_1, b->uniqueId % MAX_SND_CHANNELS, self->x, self->y); } else { - playSound(SND_DROID_DIE_2, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_DROID_DIE_2, b->uniqueId % MAX_SND_CHANNELS, self->x, self->y); } } @@ -392,7 +392,7 @@ static void die2() { addTeleportStars(self); - playSound(SND_APPEAR, -1); + playBattleSound(SND_APPEAR, -1, self->x, self->y); /* don't die! */ b->flags |= EF_GONE; diff --git a/src/entities/boss/eyeDroidCommander.h b/src/entities/boss/eyeDroidCommander.h index 5459bbc..64d7d56 100644 --- a/src/entities/boss/eyeDroidCommander.h +++ b/src/entities/boss/eyeDroidCommander.h @@ -38,6 +38,7 @@ extern void addExplosion(float x, float y, int radius, Entity *owner); extern void awardTrophy(char *id); extern void entityIdle(void); extern void initMissile(Bullet *b); +extern void playBattleSound(int snd, int ch, int x, int y); extern Entity *self; extern Game game; diff --git a/src/entities/boss/tankCommander.c b/src/entities/boss/tankCommander.c index fcaa486..8125996 100644 --- a/src/entities/boss/tankCommander.c +++ b/src/entities/boss/tankCommander.c @@ -264,7 +264,7 @@ static void attackPistol(void) b->reload = 4; - playSound(SND_MACHINE_GUN, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_MACHINE_GUN, b->uniqueId % MAX_SND_CHANNELS, b->x, b->y); } static void attackMissile(void) @@ -290,7 +290,7 @@ static void attackMissile(void) initMissile(missile); - playSound(SND_MISSILE, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_MISSILE, b->uniqueId % MAX_SND_CHANNELS, b->x, b->y); } static void die1(void) @@ -332,7 +332,7 @@ static void die2(void) addTeleportStars(self); addTeleportStars(tankTrack); - playSound(SND_APPEAR, -1); + playBattleSound(SND_APPEAR, -1, self->x, self->y); /* don't die! */ b->flags |= EF_GONE; diff --git a/src/entities/boss/tankCommander.h b/src/entities/boss/tankCommander.h index d559d7a..60a4ed2 100644 --- a/src/entities/boss/tankCommander.h +++ b/src/entities/boss/tankCommander.h @@ -38,6 +38,7 @@ extern Entity *initTankTrack(Boss *owner); extern void awardTrophy(char *id); extern void entityIdle(void); extern void initMissile(Bullet *b); +extern void playBattleSound(int snd, int ch, int x, int y); extern Entity *self; extern Game game; diff --git a/src/entities/bullets/bullet.c b/src/entities/bullets/bullet.c index 9ae32df..bfac54c 100644 --- a/src/entities/bullets/bullet.c +++ b/src/entities/bullets/bullet.c @@ -88,11 +88,11 @@ static void touch(Entity *other) if (rand() % 2) { - playSound(SND_RICO_1, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_RICO_1, b->uniqueId % MAX_SND_CHANNELS, b->x, b->y); } else { - playSound(SND_RICO_2, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_RICO_2, b->uniqueId % MAX_SND_CHANNELS, b->x, b->y); } } else if (other != b->owner && (!(other->flags & EF_IGNORE_BULLETS)) && b->owner->type != other->type) @@ -103,13 +103,13 @@ static void touch(Entity *other) if (other->flags & EF_EXPLODES) { - playSound(SND_METAL_HIT, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_METAL_HIT, b->uniqueId % MAX_SND_CHANNELS, b->x, b->y); addSparkParticles(b->x, b->y); } else { - playSound(SND_FLESH_HIT, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_FLESH_HIT, b->uniqueId % MAX_SND_CHANNELS, b->x, b->y); addSmallFleshChunk(b->x, b->y); } diff --git a/src/entities/bullets/bullet.h b/src/entities/bullets/bullet.h index ba46c61..7ecd54e 100644 --- a/src/entities/bullets/bullet.h +++ b/src/entities/bullets/bullet.h @@ -26,6 +26,7 @@ extern void addSmallFleshChunk(float x, float y); extern void addSparkParticles(float x, float y); extern Bullet *createBaseBullet(Unit *owner); extern void swapSelf(Entity *e); +extern void playBattleSound(int snd, int ch, int x, int y); extern Camera camera; extern Entity *self; diff --git a/src/entities/bullets/grenade.c b/src/entities/bullets/grenade.c index 530813d..ec351fa 100644 --- a/src/entities/bullets/grenade.c +++ b/src/entities/bullets/grenade.c @@ -106,7 +106,7 @@ static float bounce(float x) if (b->environment == ENV_AIR) { - playSound(SND_GRENADE_BOUNCE, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_GRENADE_BOUNCE, b->uniqueId % MAX_SND_CHANNELS, b->x, b->y); } return superBounce(x); diff --git a/src/entities/bullets/grenade.h b/src/entities/bullets/grenade.h index 9ea87fa..5b5ddf0 100644 --- a/src/entities/bullets/grenade.h +++ b/src/entities/bullets/grenade.h @@ -27,6 +27,7 @@ extern void addSparkParticles(float x, float y); extern void addExplosion(float x, float y, int radius, Entity *owner); extern void addScorchDecal(int x, int y); extern void swapSelf(Entity *e); +extern void playBattleSound(int snd, int ch, int x, int y); extern Entity *self; extern Game game; diff --git a/src/entities/bullets/laser.c b/src/entities/bullets/laser.c index 7242633..d35c91a 100644 --- a/src/entities/bullets/laser.c +++ b/src/entities/bullets/laser.c @@ -60,12 +60,12 @@ static void touch(Entity *other) if (other->flags & EF_EXPLODES) { addSparkParticles(b->x, b->y); - playSound(SND_METAL_HIT, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_METAL_HIT, b->uniqueId % MAX_SND_CHANNELS, b->x, b->y); } else { addSmallFleshChunk(b->x, b->y); - playSound(SND_FLESH_HIT, b->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_FLESH_HIT, b->uniqueId % MAX_SND_CHANNELS, b->x, b->y); } swapSelf(other); diff --git a/src/entities/bullets/laser.h b/src/entities/bullets/laser.h index 469b709..ed93cf9 100644 --- a/src/entities/bullets/laser.h +++ b/src/entities/bullets/laser.h @@ -27,6 +27,7 @@ extern void addSmallFleshChunk(float x, float y); extern void addSparkParticles(float x, float y); extern void stunBob(void); extern void swapSelf(Entity *e); +extern void playBattleSound(int snd, int ch, int x, int y); extern Entity *self; extern Game game; diff --git a/src/entities/evilBlobs/evilBlob.c b/src/entities/evilBlobs/evilBlob.c index a7d9b3a..2d0df58 100644 --- a/src/entities/evilBlobs/evilBlob.c +++ b/src/entities/evilBlobs/evilBlob.c @@ -94,7 +94,7 @@ static void die2(void) my = (int) (u->y / MAP_TILE_SIZE) + 1; addBloodDecal(mx, my); - playSound(SND_SPLAT, u->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_SPLAT, u->uniqueId % MAX_SND_CHANNELS, u->x, u->y); } } @@ -297,15 +297,15 @@ static void die(void) switch (rand() % 3) { case 0: - playSound(SND_DEATH_1, u->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_DEATH_1, u->uniqueId % MAX_SND_CHANNELS, u->x, u->y); break; case 1: - playSound(SND_DEATH_2, u->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_DEATH_2, u->uniqueId % MAX_SND_CHANNELS, u->x, u->y); break; case 2: - playSound(SND_DEATH_3, u->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_DEATH_3, u->uniqueId % MAX_SND_CHANNELS, u->x, u->y); break; } } diff --git a/src/entities/evilBlobs/evilBlob.h b/src/entities/evilBlobs/evilBlob.h index 6ffb99e..d7bbdff 100644 --- a/src/entities/evilBlobs/evilBlob.h +++ b/src/entities/evilBlobs/evilBlob.h @@ -34,6 +34,7 @@ extern void fireTriggers(char *name); extern void addRandomItems(int x, int y); extern int rrnd(int low, int high); extern Unit *createUnit(void); +extern void playBattleSound(int snd, int ch, int x, int y); extern Dev dev; extern Entity *self; diff --git a/src/entities/eyeDroids/eyeDroid.c b/src/entities/eyeDroids/eyeDroid.c index 6849d13..0e577ab 100644 --- a/src/entities/eyeDroids/eyeDroid.c +++ b/src/entities/eyeDroids/eyeDroid.c @@ -134,11 +134,11 @@ static void die(void) if (rand() % 2) { - playSound(SND_DROID_DIE_1, u->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_DROID_DIE_1, u->uniqueId % MAX_SND_CHANNELS, u->x, u->y); } else { - playSound(SND_DROID_DIE_2, u->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_DROID_DIE_2, u->uniqueId % MAX_SND_CHANNELS, u->x, u->y); } } diff --git a/src/entities/eyeDroids/eyeDroid.h b/src/entities/eyeDroids/eyeDroid.h index 03cf084..4e321fe 100644 --- a/src/entities/eyeDroids/eyeDroid.h +++ b/src/entities/eyeDroids/eyeDroid.h @@ -36,6 +36,7 @@ extern void throwDebris(float x, float y, int amount); extern void addSmokeParticles(float x, float y); extern void addScorchDecal(int x, int y); extern Unit *createUnit(void); +extern void playBattleSound(int snd, int ch, int x, int y); extern Dev dev; extern Entity *self; diff --git a/src/entities/items/item.c b/src/entities/items/item.c index 263e08b..ba9d877 100644 --- a/src/entities/items/item.c +++ b/src/entities/items/item.c @@ -222,7 +222,7 @@ static void changeEnvironment(void) i->x = i->startX; i->y = i->startY; addTeleportStars(self); - playSound(SND_APPEAR, -1); + playBattleSound(SND_APPEAR, -1, i->x, i->y); } } diff --git a/src/entities/items/item.h b/src/entities/items/item.h index f64c1fa..44fc1b8 100644 --- a/src/entities/items/item.h +++ b/src/entities/items/item.h @@ -28,6 +28,7 @@ extern void initEntity(Entity *e); extern Sprite *getSprite(char *name); extern int addItem(Item *i, int num); extern void updateObjective(char *targetName); +extern void playBattleSound(int snd, int ch, int x, int y); extern Entity *self; extern Game game; diff --git a/src/entities/structures/door.c b/src/entities/structures/door.c index 1e936b9..61fe764 100644 --- a/src/entities/structures/door.c +++ b/src/entities/structures/door.c @@ -166,7 +166,7 @@ static void tick(void) { s->isStatic = 1; - playSound(SND_DOOR_FINISH, s->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_DOOR_FINISH, s->uniqueId % MAX_SND_CHANNELS, s->x, s->y); } } @@ -208,7 +208,7 @@ static void touch(Entity *other) if (s->state != DOOR_OPEN) { - playSound(SND_DOOR_START, s->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_DOOR_START, s->uniqueId % MAX_SND_CHANNELS, s->x, s->y); } s->state = DOOR_OPEN; @@ -276,7 +276,7 @@ static void activate(int active) s->state = (s->state == DOOR_CLOSED) ? DOOR_OPEN : DOOR_CLOSED; - playSound(SND_DOOR_START, s->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_DOOR_START, s->uniqueId % MAX_SND_CHANNELS, s->x, s->y); if (active) { diff --git a/src/entities/structures/door.h b/src/entities/structures/door.h index 3010bbb..9c3e2c8 100644 --- a/src/entities/structures/door.h +++ b/src/entities/structures/door.h @@ -32,6 +32,7 @@ extern char *getLookupName(const char *prefix, long num); extern long lookup(const char *name); extern int isOnScreen(Entity *e); extern void observeActivation(Entity *e); +extern void playBattleSound(int snd, int ch, int x, int y); extern Entity *self; extern Dev dev; diff --git a/src/entities/structures/pressurePlate.c b/src/entities/structures/pressurePlate.c index 6718236..330ce68 100644 --- a/src/entities/structures/pressurePlate.c +++ b/src/entities/structures/pressurePlate.c @@ -101,7 +101,7 @@ static void touch(Entity *other) { activateEntities(s->targetNames, 1); - playSound(SND_PRESSURE_PLATE, s->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_PRESSURE_PLATE, s->uniqueId % MAX_SND_CHANNELS, s->x, s->y); } s->active = 1; diff --git a/src/entities/structures/pressurePlate.h b/src/entities/structures/pressurePlate.h index 0b1e5e3..c2858f6 100644 --- a/src/entities/structures/pressurePlate.h +++ b/src/entities/structures/pressurePlate.h @@ -25,5 +25,6 @@ extern Structure *createStructure(void); extern Sprite *getSprite(char *name); extern void activateEntities(char *names, int activate); extern void playSound(int snd, int ch); +extern void playBattleSound(int snd, int ch, int x, int y); extern Entity *self; diff --git a/src/entities/structures/pushBlock.c b/src/entities/structures/pushBlock.c index b4959a0..941870e 100644 --- a/src/entities/structures/pushBlock.c +++ b/src/entities/structures/pushBlock.c @@ -79,7 +79,7 @@ static void activate(int active) s->y = s->startY; s->dx = s->dy = 0; addTeleportStars(self); - playSound(SND_APPEAR, s->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_APPEAR, s->uniqueId % MAX_SND_CHANNELS, s->x, s->y); } } diff --git a/src/entities/structures/pushBlock.h b/src/entities/structures/pushBlock.h index f531c20..5c86748 100644 --- a/src/entities/structures/pushBlock.h +++ b/src/entities/structures/pushBlock.h @@ -26,5 +26,6 @@ extern void addTeleportStars(Entity *e); extern Structure *createStructure(void); extern Sprite *getSprite(char *name); extern int rrnd(int low, int high); +extern void playBattleSound(int snd, int ch, int x, int y); extern Entity *self; diff --git a/src/entities/structures/teleporter.c b/src/entities/structures/teleporter.c index 656686f..cfdcc06 100644 --- a/src/entities/structures/teleporter.c +++ b/src/entities/structures/teleporter.c @@ -99,7 +99,7 @@ static void touch(Entity *other) teleportEntity(other, tx, ty); - playSound(SND_TELEPORT, self->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_TELEPORT, self->uniqueId % MAX_SND_CHANNELS, self->x, self->y); } } diff --git a/src/entities/structures/teleporter.h b/src/entities/structures/teleporter.h index 9220a78..36f7cda 100644 --- a/src/entities/structures/teleporter.h +++ b/src/entities/structures/teleporter.h @@ -29,5 +29,6 @@ extern int isOnScreen(Entity *e); extern void setGameplayMessage(int type, char *format, ...); extern Structure *createStructure(void); extern Sprite *getSprite(char *name); +extern void playBattleSound(int snd, int ch, int x, int y); extern Entity *self; diff --git a/src/entities/traps/laserTrap.c b/src/entities/traps/laserTrap.c index d16f32b..dd9a688 100644 --- a/src/entities/traps/laserTrap.c +++ b/src/entities/traps/laserTrap.c @@ -138,7 +138,7 @@ static void touch(Entity *other) swapSelf(other); } - playSound(SND_FLESH_HIT, other->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_FLESH_HIT, other->uniqueId % MAX_SND_CHANNELS, other->x, other->y); } if (other == (Entity*)world.bob && world.bob->stunTimer == 0) diff --git a/src/entities/traps/laserTrap.h b/src/entities/traps/laserTrap.h index 6afb41a..94e74ed 100644 --- a/src/entities/traps/laserTrap.h +++ b/src/entities/traps/laserTrap.h @@ -32,6 +32,7 @@ extern void addSparkParticles(float x, float y); extern void addSmallFleshChunk(float x, float y); extern void swapSelf(Entity *e); extern void playSound(int snd, int ch); +extern void playBattleSound(int snd, int ch, int x, int y); extern Entity *self; extern World world; diff --git a/src/entities/unit.c b/src/entities/unit.c index da9a5f5..1e42a39 100644 --- a/src/entities/unit.c +++ b/src/entities/unit.c @@ -158,7 +158,7 @@ static void reappear(void) addTeleportStars(self); - playSound(SND_APPEAR, self->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_APPEAR, self->uniqueId % MAX_SND_CHANNELS, self->x, self->y); } else { @@ -192,7 +192,7 @@ static void applyDamage(int damage) u->flags |= EF_GONE; u->thinkTime = rrnd(FPS, FPS * 2); addTeleportStars(self); - playSound(SND_APPEAR, self->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_APPEAR, self->uniqueId % MAX_SND_CHANNELS, u->x, u->y); } } } diff --git a/src/entities/unit.h b/src/entities/unit.h index a356b7d..43b925e 100644 --- a/src/entities/unit.h +++ b/src/entities/unit.h @@ -35,6 +35,7 @@ extern void fireShotgun(Entity *e); extern void fireMissile(Entity *e); extern void addTeleportStars(Entity *e); extern void playSound(int snd, int ch); +extern void playBattleSound(int snd, int ch, int x, int y); extern Entity *self; extern World world; diff --git a/src/system/sound.c b/src/system/sound.c index 36473e1..6c1b4b1 100644 --- a/src/system/sound.c +++ b/src/system/sound.c @@ -76,6 +76,36 @@ void playSound(int snd, int ch) Mix_PlayChannel(ch, sounds[snd], 0); } +void playBattleSound(int snd, int channel, int x, int y) +{ + float distance, bearing, vol; + + distance = getDistance(world.bob->x, world.bob->y, x, y); + + if (distance <= MAX_BATTLE_SOUND_DISTANCE) + { + channel = Mix_PlayChannel(channel, sounds[snd], 0); + + if (channel != -1) + { + vol = 255; + vol /= MAX_BATTLE_SOUND_DISTANCE; + vol *= distance; + + if (distance >= MIN_BATTLE_SOUND_DISTANCE) + { + bearing = 360 - getAngle(x, y, world.bob->x, world.bob->y); + + Mix_SetPosition(channel, (Sint16)bearing, (Uint8)vol); + } + else + { + Mix_SetDistance(channel, vol); + } + } + } +} + int isPlayingMusic(void) { return Mix_PlayingMusic(); diff --git a/src/system/sound.h b/src/system/sound.h index ae05f71..7bd90bc 100644 --- a/src/system/sound.h +++ b/src/system/sound.h @@ -19,6 +19,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "../common.h" + #include "SDL2/SDL_mixer.h" +#define MIN_BATTLE_SOUND_DISTANCE MAP_TILE_SIZE * 2 +#define MAX_BATTLE_SOUND_DISTANCE (SCREEN_WIDTH * 2) + extern char *getFileLocation(char *filename); +extern int getDistance(int x1, int y1, int x2, int y2); +extern float getAngle(int x1, int y1, int x2, int y2); + +extern World world; diff --git a/src/test/atlasTest.c b/src/test/atlasTest.c index 8ffcda1..c5834f4 100644 --- a/src/test/atlasTest.c +++ b/src/test/atlasTest.c @@ -26,10 +26,10 @@ void initAtlasTest(void) dev.debug = 0; dev.cheatStatic = 0; - dev.cheatBlind = 1; + dev.cheatBlind = 0; dev.cheatNoEnemies = 0; dev.cheatKeys = 0; - dev.cheatPower = 0; + dev.cheatPower = 1; dev.cheatHealth = 0; dev.cheatLevels = 0; dev.takeScreenshots = 0; @@ -49,7 +49,7 @@ void initAtlasTest(void) break; case 1: - STRNCPY(game.worldId, "boss1", MAX_NAME_LENGTH); + STRNCPY(game.worldId, "beachFront2", MAX_NAME_LENGTH); initWorld(); break; diff --git a/src/util/maths.c b/src/util/maths.c index cdb4cd7..686e523 100644 --- a/src/util/maths.c +++ b/src/util/maths.c @@ -25,6 +25,12 @@ float mod(float n, float x) return fmod(fmod(n, x) + x, x); } +float getAngle(int x1, int y1, int x2, int y2) +{ + float angle = -90 + atan2(y1 - y2, x1 - x2) * (180 / PI); + return angle >= 0 ? angle : 360 + angle; +} + int rrnd(int low, int high) { return low + rand() % ((high - low) + 1); diff --git a/src/world/entities.c b/src/world/entities.c index 9e11c6d..8f0378e 100644 --- a/src/world/entities.c +++ b/src/world/entities.c @@ -842,7 +842,7 @@ static void compareEnvironments(void) switch (prevEnv) { case ENV_WATER: - playSound(SND_WATER_OUT, self->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_WATER_OUT, self->uniqueId % MAX_SND_CHANNELS, self->x, self->y); if ((self->environment == ENV_AIR) && (self->dy < 0)) { self->dy = JUMP_POWER; @@ -854,11 +854,11 @@ static void compareEnvironments(void) self->dy = 0.25f; if (self->environment == ENV_WATER) { - playSound(SND_WATER_IN, self->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_WATER_IN, self->uniqueId % MAX_SND_CHANNELS, self->x, self->y); } else { - playSound(SND_SLIME, self->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_SLIME, self->uniqueId % MAX_SND_CHANNELS, self->x, self->y); } break; @@ -963,7 +963,7 @@ static void handleTeleport(void) addTeleportStars(self); self->dx = self->dy = 0; self->environment = ENV_AIR; - playSound(SND_TELEPORT, self->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_TELEPORT, self->uniqueId % MAX_SND_CHANNELS, self->x, self->y); } } diff --git a/src/world/entities.h b/src/world/entities.h index 8e0531e..8fa4940 100644 --- a/src/world/entities.h +++ b/src/world/entities.h @@ -39,6 +39,7 @@ extern int isLiquid(int x, int y); extern int isSolid(int x, int y); extern void terminateJetpack(void); extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); +extern void playBattleSound(int snd, int ch, int x, int y); extern Dev dev; extern Entity *self; diff --git a/src/world/world.c b/src/world/world.c index 33db6fc..4172d6a 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -640,7 +640,7 @@ static void spawnEnemies(void) u->spawnedIn = 1; u->canCarryItem = 0; addTeleportStars((Entity*)u); - playSound(SND_APPEAR, u->uniqueId % MAX_SND_CHANNELS); + playBattleSound(SND_APPEAR, u->uniqueId % MAX_SND_CHANNELS, u->x, u->y); } } diff --git a/src/world/world.h b/src/world/world.h index e82b79b..3e425c7 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -111,6 +111,7 @@ extern void drawWidgetFrame(void); extern void retryMission(void); extern void returnToHub(void); extern void returnToTitle(void); +extern void playBattleSound(int snd, int ch, int x, int y); extern App app; extern Colors colors;