Added directional audio.

This commit is contained in:
Steve 2018-02-26 18:56:13 +00:00
parent a729bfe7ee
commit af4ce38296
44 changed files with 123 additions and 61 deletions

View File

@ -30,7 +30,7 @@ void addExplosion(float x, float y, int radius, Entity *owner)
float power; float power;
int i; int i;
playSound(SND_EXPLOSION, -1); playBattleSound(SND_EXPLOSION, -1, x, y);
/* assuming x and y were from the top left of the entity */ /* assuming x and y were from the top left of the entity */
x += radius / 2; x += radius / 2;

View File

@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern int rrnd(int low, int high); extern int rrnd(int low, int high);
extern void stunBob(void); extern void stunBob(void);
extern void addExplosionParticles(float x, float y, float radius, int amount); 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 Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
extern int getDistance(int x1, int y1, int x2, int y2); extern int getDistance(int x1, int y1, int x2, int y2);
extern void swapSelf(Entity *e); extern void swapSelf(Entity *e);

View File

@ -105,7 +105,7 @@ void fireAimedShot(Unit *owner)
owner->reload = 15; 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]; bullet->sprite[1] = bulletSprite[1];
owner->reload = 8; 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; 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; 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; 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; 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; 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; owner->reload = FPS / 2;
playSound(SND_MISSILE, owner->uniqueId % MAX_SND_CHANNELS); playBattleSound(SND_MISSILE, owner->uniqueId % MAX_SND_CHANNELS, owner->x, owner->y);
} }
} }

View File

@ -21,12 +21,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../common.h" #include "../common.h"
extern Sprite *getSprite(char *name); 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 int rrnd(int low, int high);
extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy); extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy);
extern void initLaser(Bullet *b); extern void initLaser(Bullet *b);
extern void initGrenade(Bullet *b); extern void initGrenade(Bullet *b);
extern void initMissile(Bullet *b); extern void initMissile(Bullet *b);
extern Bullet *createBaseBullet(Unit *owner); extern Bullet *createBaseBullet(Unit *owner);
extern void playSound(int snd, int ch);
extern World world; extern World world;

View File

@ -119,7 +119,7 @@ static void lookForEnemies(void)
{ {
addTeleportStars(self); addTeleportStars(self);
u->alive = ALIVE_DEAD; 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 else
{ {
@ -175,7 +175,7 @@ static void attack(void)
((Unit*)self)->reload = 8; ((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) void teekaExitMission(void)

View File

@ -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 getDistance(int x1, int y1, int x2, int y2);
extern int hasLineOfSight(Entity *src, Entity *dest); extern int hasLineOfSight(Entity *src, Entity *dest);
extern void addTeleportStars(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 Entity *self;
extern World world; extern World world;

View File

@ -165,15 +165,15 @@ static void die1(void)
switch (rand() % 3) switch (rand() % 3)
{ {
case 0: 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; break;
case 1: 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; break;
case 2: 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; break;
} }
@ -327,7 +327,7 @@ static void attack(void)
((Boss*)self)->reload = 4; ((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); addTeleportStars(self);
playSound(SND_APPEAR, -1); playBattleSound(SND_APPEAR, -1, self->x, self->y);
} }
static void applyDamage(int amount) static void applyDamage(int amount)
@ -384,7 +384,7 @@ static void teleport(void)
self->flags |= EF_GONE; self->flags |= EF_GONE;
self->thinkTime = FPS * rrnd(3, 6); self->thinkTime = FPS * rrnd(3, 6);
addTeleportStars(self); addTeleportStars(self);
playSound(SND_APPEAR, -1); playBattleSound(SND_APPEAR, -1, self->x, self->y);
} }
} }
@ -400,7 +400,7 @@ static void die2(void)
{ {
addTeleportStars(self); addTeleportStars(self);
playSound(SND_APPEAR, -1); playBattleSound(SND_APPEAR, -1, self->x, self->y);
/* don't die! */ /* don't die! */
b->flags |= EF_GONE; b->flags |= EF_GONE;

View File

@ -28,6 +28,7 @@ extern int isPlayingMusic(void);
extern float limit(float i, float a, float b); extern float limit(float i, float a, float b);
extern double randF(void); extern double randF(void);
extern void playSound(int snd, int ch); extern void playSound(int snd, int ch);
extern void playBattleSound(int snd, int ch, int x, int y);
extern Bullet *createBaseBullet(Unit *owner); extern Bullet *createBaseBullet(Unit *owner);
extern Sprite *getSprite(char *name); extern Sprite *getSprite(char *name);
extern int getDistance(int x1, int y1, int x2, int y2); extern int getDistance(int x1, int y1, int x2, int y2);

View File

@ -292,7 +292,7 @@ static void attackPistol(void)
b->reload = 4; 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) static void attackPlasma(void)
@ -317,7 +317,7 @@ static void attackPlasma(void)
b->reload = 4; 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) static void attackMissile(void)
@ -341,7 +341,7 @@ static void attackMissile(void)
b->reload = 15; 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) static void applyDamage(int amount)
@ -374,11 +374,11 @@ static void die(void)
if (rand() % 2) 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 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); addTeleportStars(self);
playSound(SND_APPEAR, -1); playBattleSound(SND_APPEAR, -1, self->x, self->y);
/* don't die! */ /* don't die! */
b->flags |= EF_GONE; b->flags |= EF_GONE;

View File

@ -38,6 +38,7 @@ extern void addExplosion(float x, float y, int radius, Entity *owner);
extern void awardTrophy(char *id); extern void awardTrophy(char *id);
extern void entityIdle(void); extern void entityIdle(void);
extern void initMissile(Bullet *b); extern void initMissile(Bullet *b);
extern void playBattleSound(int snd, int ch, int x, int y);
extern Entity *self; extern Entity *self;
extern Game game; extern Game game;

View File

@ -264,7 +264,7 @@ static void attackPistol(void)
b->reload = 4; 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) static void attackMissile(void)
@ -290,7 +290,7 @@ static void attackMissile(void)
initMissile(missile); 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) static void die1(void)
@ -332,7 +332,7 @@ static void die2(void)
addTeleportStars(self); addTeleportStars(self);
addTeleportStars(tankTrack); addTeleportStars(tankTrack);
playSound(SND_APPEAR, -1); playBattleSound(SND_APPEAR, -1, self->x, self->y);
/* don't die! */ /* don't die! */
b->flags |= EF_GONE; b->flags |= EF_GONE;

View File

@ -38,6 +38,7 @@ extern Entity *initTankTrack(Boss *owner);
extern void awardTrophy(char *id); extern void awardTrophy(char *id);
extern void entityIdle(void); extern void entityIdle(void);
extern void initMissile(Bullet *b); extern void initMissile(Bullet *b);
extern void playBattleSound(int snd, int ch, int x, int y);
extern Entity *self; extern Entity *self;
extern Game game; extern Game game;

View File

@ -88,11 +88,11 @@ static void touch(Entity *other)
if (rand() % 2) 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 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) 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) 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); addSparkParticles(b->x, b->y);
} }
else 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); addSmallFleshChunk(b->x, b->y);
} }

View File

@ -26,6 +26,7 @@ extern void addSmallFleshChunk(float x, float y);
extern void addSparkParticles(float x, float y); extern void addSparkParticles(float x, float y);
extern Bullet *createBaseBullet(Unit *owner); extern Bullet *createBaseBullet(Unit *owner);
extern void swapSelf(Entity *e); extern void swapSelf(Entity *e);
extern void playBattleSound(int snd, int ch, int x, int y);
extern Camera camera; extern Camera camera;
extern Entity *self; extern Entity *self;

View File

@ -106,7 +106,7 @@ static float bounce(float x)
if (b->environment == ENV_AIR) 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); return superBounce(x);

View File

@ -27,6 +27,7 @@ extern void addSparkParticles(float x, float y);
extern void addExplosion(float x, float y, int radius, Entity *owner); extern void addExplosion(float x, float y, int radius, Entity *owner);
extern void addScorchDecal(int x, int y); extern void addScorchDecal(int x, int y);
extern void swapSelf(Entity *e); extern void swapSelf(Entity *e);
extern void playBattleSound(int snd, int ch, int x, int y);
extern Entity *self; extern Entity *self;
extern Game game; extern Game game;

View File

@ -60,12 +60,12 @@ static void touch(Entity *other)
if (other->flags & EF_EXPLODES) if (other->flags & EF_EXPLODES)
{ {
addSparkParticles(b->x, b->y); 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 else
{ {
addSmallFleshChunk(b->x, b->y); 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); swapSelf(other);

View File

@ -27,6 +27,7 @@ extern void addSmallFleshChunk(float x, float y);
extern void addSparkParticles(float x, float y); extern void addSparkParticles(float x, float y);
extern void stunBob(void); extern void stunBob(void);
extern void swapSelf(Entity *e); extern void swapSelf(Entity *e);
extern void playBattleSound(int snd, int ch, int x, int y);
extern Entity *self; extern Entity *self;
extern Game game; extern Game game;

View File

@ -94,7 +94,7 @@ static void die2(void)
my = (int) (u->y / MAP_TILE_SIZE) + 1; my = (int) (u->y / MAP_TILE_SIZE) + 1;
addBloodDecal(mx, my); 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) switch (rand() % 3)
{ {
case 0: 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; break;
case 1: 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; break;
case 2: 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; break;
} }
} }

View File

@ -34,6 +34,7 @@ extern void fireTriggers(char *name);
extern void addRandomItems(int x, int y); extern void addRandomItems(int x, int y);
extern int rrnd(int low, int high); extern int rrnd(int low, int high);
extern Unit *createUnit(void); extern Unit *createUnit(void);
extern void playBattleSound(int snd, int ch, int x, int y);
extern Dev dev; extern Dev dev;
extern Entity *self; extern Entity *self;

View File

@ -134,11 +134,11 @@ static void die(void)
if (rand() % 2) 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 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);
} }
} }

View File

@ -36,6 +36,7 @@ extern void throwDebris(float x, float y, int amount);
extern void addSmokeParticles(float x, float y); extern void addSmokeParticles(float x, float y);
extern void addScorchDecal(int x, int y); extern void addScorchDecal(int x, int y);
extern Unit *createUnit(void); extern Unit *createUnit(void);
extern void playBattleSound(int snd, int ch, int x, int y);
extern Dev dev; extern Dev dev;
extern Entity *self; extern Entity *self;

View File

@ -222,7 +222,7 @@ static void changeEnvironment(void)
i->x = i->startX; i->x = i->startX;
i->y = i->startY; i->y = i->startY;
addTeleportStars(self); addTeleportStars(self);
playSound(SND_APPEAR, -1); playBattleSound(SND_APPEAR, -1, i->x, i->y);
} }
} }

View File

@ -28,6 +28,7 @@ extern void initEntity(Entity *e);
extern Sprite *getSprite(char *name); extern Sprite *getSprite(char *name);
extern int addItem(Item *i, int num); extern int addItem(Item *i, int num);
extern void updateObjective(char *targetName); extern void updateObjective(char *targetName);
extern void playBattleSound(int snd, int ch, int x, int y);
extern Entity *self; extern Entity *self;
extern Game game; extern Game game;

View File

@ -166,7 +166,7 @@ static void tick(void)
{ {
s->isStatic = 1; 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) 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; s->state = DOOR_OPEN;
@ -276,7 +276,7 @@ static void activate(int active)
s->state = (s->state == DOOR_CLOSED) ? DOOR_OPEN : DOOR_CLOSED; 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) if (active)
{ {

View File

@ -32,6 +32,7 @@ extern char *getLookupName(const char *prefix, long num);
extern long lookup(const char *name); extern long lookup(const char *name);
extern int isOnScreen(Entity *e); extern int isOnScreen(Entity *e);
extern void observeActivation(Entity *e); extern void observeActivation(Entity *e);
extern void playBattleSound(int snd, int ch, int x, int y);
extern Entity *self; extern Entity *self;
extern Dev dev; extern Dev dev;

View File

@ -101,7 +101,7 @@ static void touch(Entity *other)
{ {
activateEntities(s->targetNames, 1); 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; s->active = 1;

View File

@ -25,5 +25,6 @@ extern Structure *createStructure(void);
extern Sprite *getSprite(char *name); extern Sprite *getSprite(char *name);
extern void activateEntities(char *names, int activate); extern void activateEntities(char *names, int activate);
extern void playSound(int snd, int ch); extern void playSound(int snd, int ch);
extern void playBattleSound(int snd, int ch, int x, int y);
extern Entity *self; extern Entity *self;

View File

@ -79,7 +79,7 @@ static void activate(int active)
s->y = s->startY; s->y = s->startY;
s->dx = s->dy = 0; s->dx = s->dy = 0;
addTeleportStars(self); addTeleportStars(self);
playSound(SND_APPEAR, s->uniqueId % MAX_SND_CHANNELS); playBattleSound(SND_APPEAR, s->uniqueId % MAX_SND_CHANNELS, s->x, s->y);
} }
} }

View File

@ -26,5 +26,6 @@ extern void addTeleportStars(Entity *e);
extern Structure *createStructure(void); extern Structure *createStructure(void);
extern Sprite *getSprite(char *name); extern Sprite *getSprite(char *name);
extern int rrnd(int low, int high); extern int rrnd(int low, int high);
extern void playBattleSound(int snd, int ch, int x, int y);
extern Entity *self; extern Entity *self;

View File

@ -99,7 +99,7 @@ static void touch(Entity *other)
teleportEntity(other, tx, ty); teleportEntity(other, tx, ty);
playSound(SND_TELEPORT, self->uniqueId % MAX_SND_CHANNELS); playBattleSound(SND_TELEPORT, self->uniqueId % MAX_SND_CHANNELS, self->x, self->y);
} }
} }

View File

@ -29,5 +29,6 @@ extern int isOnScreen(Entity *e);
extern void setGameplayMessage(int type, char *format, ...); extern void setGameplayMessage(int type, char *format, ...);
extern Structure *createStructure(void); extern Structure *createStructure(void);
extern Sprite *getSprite(char *name); extern Sprite *getSprite(char *name);
extern void playBattleSound(int snd, int ch, int x, int y);
extern Entity *self; extern Entity *self;

View File

@ -138,7 +138,7 @@ static void touch(Entity *other)
swapSelf(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) if (other == (Entity*)world.bob && world.bob->stunTimer == 0)

View File

@ -32,6 +32,7 @@ extern void addSparkParticles(float x, float y);
extern void addSmallFleshChunk(float x, float y); extern void addSmallFleshChunk(float x, float y);
extern void swapSelf(Entity *e); extern void swapSelf(Entity *e);
extern void playSound(int snd, int ch); extern void playSound(int snd, int ch);
extern void playBattleSound(int snd, int ch, int x, int y);
extern Entity *self; extern Entity *self;
extern World world; extern World world;

View File

@ -158,7 +158,7 @@ static void reappear(void)
addTeleportStars(self); addTeleportStars(self);
playSound(SND_APPEAR, self->uniqueId % MAX_SND_CHANNELS); playBattleSound(SND_APPEAR, self->uniqueId % MAX_SND_CHANNELS, self->x, self->y);
} }
else else
{ {
@ -192,7 +192,7 @@ static void applyDamage(int damage)
u->flags |= EF_GONE; u->flags |= EF_GONE;
u->thinkTime = rrnd(FPS, FPS * 2); u->thinkTime = rrnd(FPS, FPS * 2);
addTeleportStars(self); addTeleportStars(self);
playSound(SND_APPEAR, self->uniqueId % MAX_SND_CHANNELS); playBattleSound(SND_APPEAR, self->uniqueId % MAX_SND_CHANNELS, u->x, u->y);
} }
} }
} }

View File

@ -35,6 +35,7 @@ extern void fireShotgun(Entity *e);
extern void fireMissile(Entity *e); extern void fireMissile(Entity *e);
extern void addTeleportStars(Entity *e); extern void addTeleportStars(Entity *e);
extern void playSound(int snd, int ch); extern void playSound(int snd, int ch);
extern void playBattleSound(int snd, int ch, int x, int y);
extern Entity *self; extern Entity *self;
extern World world; extern World world;

View File

@ -76,6 +76,36 @@ void playSound(int snd, int ch)
Mix_PlayChannel(ch, sounds[snd], 0); 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) int isPlayingMusic(void)
{ {
return Mix_PlayingMusic(); return Mix_PlayingMusic();

View File

@ -19,6 +19,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "../common.h" #include "../common.h"
#include "SDL2/SDL_mixer.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 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;

View File

@ -26,10 +26,10 @@ void initAtlasTest(void)
dev.debug = 0; dev.debug = 0;
dev.cheatStatic = 0; dev.cheatStatic = 0;
dev.cheatBlind = 1; dev.cheatBlind = 0;
dev.cheatNoEnemies = 0; dev.cheatNoEnemies = 0;
dev.cheatKeys = 0; dev.cheatKeys = 0;
dev.cheatPower = 0; dev.cheatPower = 1;
dev.cheatHealth = 0; dev.cheatHealth = 0;
dev.cheatLevels = 0; dev.cheatLevels = 0;
dev.takeScreenshots = 0; dev.takeScreenshots = 0;
@ -49,7 +49,7 @@ void initAtlasTest(void)
break; break;
case 1: case 1:
STRNCPY(game.worldId, "boss1", MAX_NAME_LENGTH); STRNCPY(game.worldId, "beachFront2", MAX_NAME_LENGTH);
initWorld(); initWorld();
break; break;

View File

@ -25,6 +25,12 @@ float mod(float n, float x)
return fmod(fmod(n, x) + x, 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) int rrnd(int low, int high)
{ {
return low + rand() % ((high - low) + 1); return low + rand() % ((high - low) + 1);

View File

@ -842,7 +842,7 @@ static void compareEnvironments(void)
switch (prevEnv) switch (prevEnv)
{ {
case ENV_WATER: 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)) if ((self->environment == ENV_AIR) && (self->dy < 0))
{ {
self->dy = JUMP_POWER; self->dy = JUMP_POWER;
@ -854,11 +854,11 @@ static void compareEnvironments(void)
self->dy = 0.25f; self->dy = 0.25f;
if (self->environment == ENV_WATER) 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 else
{ {
playSound(SND_SLIME, self->uniqueId % MAX_SND_CHANNELS); playBattleSound(SND_SLIME, self->uniqueId % MAX_SND_CHANNELS, self->x, self->y);
} }
break; break;
@ -963,7 +963,7 @@ static void handleTeleport(void)
addTeleportStars(self); addTeleportStars(self);
self->dx = self->dy = 0; self->dx = self->dy = 0;
self->environment = ENV_AIR; self->environment = ENV_AIR;
playSound(SND_TELEPORT, self->uniqueId % MAX_SND_CHANNELS); playBattleSound(SND_TELEPORT, self->uniqueId % MAX_SND_CHANNELS, self->x, self->y);
} }
} }

View File

@ -39,6 +39,7 @@ extern int isLiquid(int x, int y);
extern int isSolid(int x, int y); extern int isSolid(int x, int y);
extern void terminateJetpack(void); extern void terminateJetpack(void);
extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); 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 Dev dev;
extern Entity *self; extern Entity *self;

View File

@ -640,7 +640,7 @@ static void spawnEnemies(void)
u->spawnedIn = 1; u->spawnedIn = 1;
u->canCarryItem = 0; u->canCarryItem = 0;
addTeleportStars((Entity*)u); addTeleportStars((Entity*)u);
playSound(SND_APPEAR, u->uniqueId % MAX_SND_CHANNELS); playBattleSound(SND_APPEAR, u->uniqueId % MAX_SND_CHANNELS, u->x, u->y);
} }
} }

View File

@ -111,6 +111,7 @@ extern void drawWidgetFrame(void);
extern void retryMission(void); extern void retryMission(void);
extern void returnToHub(void); extern void returnToHub(void);
extern void returnToTitle(void); extern void returnToTitle(void);
extern void playBattleSound(int snd, int ch, int x, int y);
extern App app; extern App app;
extern Colors colors; extern Colors colors;