Use entity id to play sounds.

This commit is contained in:
Steve 2018-02-25 17:29:44 +00:00
parent 5f7367403d
commit 501db4420b
29 changed files with 117 additions and 120 deletions

View File

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

View File

@ -89,6 +89,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define MAX_ENTS_TO_OBSERVE 12
#define MAX_SND_CHANNELS 64
enum
{
ET_NONE,
@ -314,20 +316,6 @@ enum
SND_MAX
};
enum
{
CH_ANY = -1,
CH_BOB,
CH_EXPLODE,
CH_WEAPON,
CH_DEATH,
CH_ITEM,
CH_TOUCH,
CH_MECHANICAL,
CH_EFFECTS,
CH_MAX
};
enum
{
WT_BUTTON,

View File

@ -352,7 +352,7 @@ static void doBobInWater(void)
if (world.bob->oxygen == 0 && (world.frameCounter % 30) == 0)
{
world.bob->health--;
playSound(SND_DROWN, CH_BOB);
playSound(SND_DROWN, world.bob->uniqueId % MAX_SND_CHANNELS);
}
}
}
@ -369,7 +369,7 @@ static void doDying(void)
world.state = WS_GAME_OVER;
playSound(SND_SPLAT, CH_BOB);
playSound(SND_SPLAT, world.bob->uniqueId % MAX_SND_CHANNELS);
game.stats[STAT_DEATHS]++;
}
@ -610,7 +610,7 @@ void resetAtCheckpoint(void)
addTeleportStars((Entity*)world.bob);
if (world.state == WS_IN_PROGRESS)
{
playSound(SND_APPEAR, CH_ANY);
playSound(SND_APPEAR, -1);
}
}
@ -630,15 +630,15 @@ static void die(void)
switch (rand() % 3)
{
case 0:
playSound(SND_DEATH_1, CH_DEATH);
playSound(SND_DEATH_1, world.bob->uniqueId % MAX_SND_CHANNELS);
break;
case 1:
playSound(SND_DEATH_2, CH_DEATH);
playSound(SND_DEATH_2, world.bob->uniqueId % MAX_SND_CHANNELS);
break;
case 2:
playSound(SND_DEATH_3, CH_DEATH);
playSound(SND_DEATH_3, world.bob->uniqueId % MAX_SND_CHANNELS);
break;
}
}

View File

@ -115,7 +115,7 @@ static void touch(Entity *other)
setGameplayMessage(MSG_OBJECTIVE, _("Rescued %s"), m->name);
m->isMissionTarget = 0;
m->flags |= EF_ALWAYS_PROCESS;
playSound(SND_MIA, CH_ANY);
playSound(SND_MIA, m->uniqueId % MAX_SND_CHANNELS);
}
}

View File

@ -119,7 +119,7 @@ static void lookForEnemies(void)
{
addTeleportStars(self);
u->alive = ALIVE_DEAD;
playSound(SND_APPEAR, CH_ANY);
playSound(SND_APPEAR, u->uniqueId % MAX_SND_CHANNELS);
}
else
{
@ -175,7 +175,7 @@ static void attack(void)
((Unit*)self)->reload = 8;
playSound(SND_PISTOL, CH_WEAPON);
playSound(SND_PISTOL, self->uniqueId % MAX_SND_CHANNELS);
}
void teekaExitMission(void)

View File

@ -165,15 +165,15 @@ static void die1(void)
switch (rand() % 3)
{
case 0:
playSound(SND_DEATH_1, CH_DEATH);
playSound(SND_DEATH_1, b->uniqueId % MAX_SND_CHANNELS);
break;
case 1:
playSound(SND_DEATH_2, CH_DEATH);
playSound(SND_DEATH_2, b->uniqueId % MAX_SND_CHANNELS);
break;
case 2:
playSound(SND_DEATH_3, CH_DEATH);
playSound(SND_DEATH_3, b->uniqueId % MAX_SND_CHANNELS);
break;
}
@ -306,26 +306,29 @@ static void attack(void)
float dx, dy;
int bx, by;
bx = (int) (world.bob->x + rrnd(-8, 24));
by = (int) (world.bob->y + rrnd(-8, 24));
if (self->facing != FACING_DIE)
{
bx = (int) (world.bob->x + rrnd(-8, 24));
by = (int) (world.bob->y + rrnd(-8, 24));
getSlope(bx, by, self->x, self->y, &dx, &dy);
getSlope(bx, by, self->x, self->y, &dx, &dy);
bullet = createBaseBullet((Unit*)self);
bullet->x = self->x;
bullet->y = (self->y + self->h / 2) - 3;
bullet->facing = self->facing;
bullet->damage = 1;
bullet->owner = self;
bullet->health = FPS * 3;
bullet->weaponType = WPN_AIMED_PISTOL;
bullet->dx = dx * 12;
bullet->dy = dy * 12;
bullet->sprite[0] = bullet->sprite[1] = aimedSprite;
bullet = createBaseBullet((Unit*)self);
bullet->x = self->x;
bullet->y = (self->y + self->h / 2) - 3;
bullet->facing = self->facing;
bullet->damage = 1;
bullet->owner = self;
bullet->health = FPS * 3;
bullet->weaponType = WPN_AIMED_PISTOL;
bullet->dx = dx * 12;
bullet->dy = dy * 12;
bullet->sprite[0] = bullet->sprite[1] = aimedSprite;
((Boss*)self)->reload = 4;
((Boss*)self)->reload = 4;
playSound(SND_MACHINE_GUN, CH_WEAPON);
playSound(SND_MACHINE_GUN, self->uniqueId % MAX_SND_CHANNELS);
}
}
static void walk(void)
@ -356,7 +359,7 @@ void reappear(void)
addTeleportStars(self);
playSound(SND_APPEAR, CH_ANY);
playSound(SND_APPEAR, -1);
}
static void applyDamage(int amount)
@ -381,7 +384,7 @@ static void teleport(void)
self->flags |= EF_GONE;
self->thinkTime = FPS * rrnd(3, 6);
addTeleportStars(self);
playSound(SND_APPEAR, CH_ANY);
playSound(SND_APPEAR, -1);
}
}
@ -397,7 +400,7 @@ static void die2(void)
{
addTeleportStars(self);
playSound(SND_APPEAR, CH_ANY);
playSound(SND_APPEAR, -1);
/* don't die! */
b->flags |= EF_GONE;

View File

@ -243,21 +243,24 @@ static void attack(void)
{
Boss *b;
b = (Boss*)self;
switch (b->weaponType)
if (self->facing != FACING_DIE)
{
case WPN_AIMED_PISTOL:
attackPistol();
break;
case WPN_MISSILE:
attackMissile();
break;
case WPN_PLASMA:
attackPlasma();
break;
default:
break;
b = (Boss*)self;
switch (b->weaponType)
{
case WPN_AIMED_PISTOL:
attackPistol();
break;
case WPN_MISSILE:
attackMissile();
break;
case WPN_PLASMA:
attackPlasma();
break;
default:
break;
}
}
}
@ -289,7 +292,7 @@ static void attackPistol(void)
b->reload = 4;
playSound(SND_MACHINE_GUN, CH_WEAPON);
playSound(SND_MACHINE_GUN, b->uniqueId % MAX_SND_CHANNELS);
}
static void attackPlasma(void)
@ -314,7 +317,7 @@ static void attackPlasma(void)
b->reload = 4;
playSound(SND_PLASMA, CH_WEAPON);
playSound(SND_PLASMA, b->uniqueId % MAX_SND_CHANNELS);
}
static void attackMissile(void)
@ -338,7 +341,7 @@ static void attackMissile(void)
b->reload = 15;
playSound(SND_MISSILE, CH_WEAPON);
playSound(SND_MISSILE, b->uniqueId % MAX_SND_CHANNELS);
}
static void applyDamage(int amount)
@ -371,11 +374,11 @@ static void die(void)
if (rand() % 2)
{
playSound(SND_DROID_DIE_1, CH_DEATH);
playSound(SND_DROID_DIE_1, b->uniqueId % MAX_SND_CHANNELS);
}
else
{
playSound(SND_DROID_DIE_2, CH_DEATH);
playSound(SND_DROID_DIE_2, b->uniqueId % MAX_SND_CHANNELS);
}
}
@ -389,7 +392,7 @@ static void die2()
{
addTeleportStars(self);
playSound(SND_APPEAR, CH_ANY);
playSound(SND_APPEAR, -1);
/* don't die! */
b->flags |= EF_GONE;

View File

@ -216,18 +216,21 @@ static void attack(void)
{
Boss *b;
b = (Boss*)self;
switch (b->weaponType)
if (self->facing != FACING_DIE)
{
case WPN_AIMED_PISTOL:
attackPistol();
break;
case WPN_MISSILE:
attackMissile();
break;
default:
break;
b = (Boss*)self;
switch (b->weaponType)
{
case WPN_AIMED_PISTOL:
attackPistol();
break;
case WPN_MISSILE:
attackMissile();
break;
default:
break;
}
}
}
@ -259,7 +262,7 @@ static void attackPistol(void)
b->reload = 4;
playSound(SND_MACHINE_GUN, CH_WEAPON);
playSound(SND_MACHINE_GUN, b->uniqueId % MAX_SND_CHANNELS);
}
static void attackMissile(void)
@ -285,7 +288,7 @@ static void attackMissile(void)
initMissile(missile);
playSound(SND_MISSILE, CH_WEAPON);
playSound(SND_MISSILE, b->uniqueId % MAX_SND_CHANNELS);
}
static void die1(void)
@ -327,7 +330,7 @@ static void die2(void)
addTeleportStars(self);
addTeleportStars(tankTrack);
playSound(SND_APPEAR, CH_ANY);
playSound(SND_APPEAR, -1);
/* don't die! */
b->flags |= EF_GONE;

View File

@ -78,7 +78,7 @@ static void touch(Entity *other)
{
if (other == (Entity*)world.bob && !world.bob->stunTimer && (world.bob->flags & EF_IMMUNE) == 0)
{
playSound(SND_FLESH_HIT, CH_ANY);
playSound(SND_FLESH_HIT, world.bob->uniqueId % MAX_SND_CHANNELS);
world.bob->dx = rrnd(-5, 5);
world.bob->dy = JUMP_POWER;
world.bob->applyDamage(3);

View File

@ -88,11 +88,11 @@ static void touch(Entity *other)
if (rand() % 2)
{
playSound(SND_RICO_1, CH_ANY);
playSound(SND_RICO_1, b->uniqueId % MAX_SND_CHANNELS);
}
else
{
playSound(SND_RICO_2, CH_ANY);
playSound(SND_RICO_2, b->uniqueId % MAX_SND_CHANNELS);
}
}
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, CH_ANY);
playSound(SND_METAL_HIT, b->uniqueId % MAX_SND_CHANNELS);
addSparkParticles(b->x, b->y);
}
else
{
playSound(SND_FLESH_HIT, CH_ANY);
playSound(SND_FLESH_HIT, b->uniqueId % MAX_SND_CHANNELS);
addSmallFleshChunk(b->x, b->y);
}

View File

@ -106,7 +106,7 @@ static float bounce(float x)
if (b->environment == ENV_AIR)
{
playSound(SND_GRENADE_BOUNCE, CH_EFFECTS);
playSound(SND_GRENADE_BOUNCE, b->uniqueId % MAX_SND_CHANNELS);
}
return superBounce(x);

View File

@ -60,12 +60,12 @@ static void touch(Entity *other)
if (other->flags & EF_EXPLODES)
{
addSparkParticles(b->x, b->y);
playSound(SND_METAL_HIT, CH_ANY);
playSound(SND_METAL_HIT, b->uniqueId % MAX_SND_CHANNELS);
}
else
{
addSmallFleshChunk(b->x, b->y);
playSound(SND_FLESH_HIT, CH_ANY);
playSound(SND_FLESH_HIT, b->uniqueId % MAX_SND_CHANNELS);
}
swapSelf(other);

View File

@ -94,7 +94,7 @@ static void die2(void)
my = (int) (u->y / MAP_TILE_SIZE) + 1;
addBloodDecal(mx, my);
playSound(SND_SPLAT, CH_ANY);
playSound(SND_SPLAT, u->uniqueId % MAX_SND_CHANNELS);
}
}
@ -297,15 +297,15 @@ static void die(void)
switch (rand() % 3)
{
case 0:
playSound(SND_DEATH_1, CH_DEATH);
playSound(SND_DEATH_1, u->uniqueId % MAX_SND_CHANNELS);
break;
case 1:
playSound(SND_DEATH_2, CH_DEATH);
playSound(SND_DEATH_2, u->uniqueId % MAX_SND_CHANNELS);
break;
case 2:
playSound(SND_DEATH_3, CH_DEATH);
playSound(SND_DEATH_3, u->uniqueId % MAX_SND_CHANNELS);
break;
}
}

View File

@ -134,11 +134,11 @@ static void die(void)
if (rand() % 2)
{
playSound(SND_DROID_DIE_1, CH_DEATH);
playSound(SND_DROID_DIE_1, u->uniqueId % MAX_SND_CHANNELS);
}
else
{
playSound(SND_DROID_DIE_2, CH_DEATH);
playSound(SND_DROID_DIE_2, u->uniqueId % MAX_SND_CHANNELS);
}
}

View File

@ -50,7 +50,7 @@ static void touch(Entity *other)
pickupItem();
playSound(SND_ITEM, CH_ITEM);
playSound(SND_ITEM, i->uniqueId % MAX_SND_CHANNELS);
game.stats[STAT_BATTERIES_PICKED_UP]++;
}

View File

@ -56,7 +56,7 @@ static void touch(Entity *other)
setGameplayMessage(MSG_OBJECTIVE, _("Found a battery cell - Max power increased!"));
playSound(SND_HEART_CELL, CH_ITEM);
playSound(SND_HEART_CELL, self->uniqueId % MAX_SND_CHANNELS);
self->alive = ALIVE_DEAD;

View File

@ -47,7 +47,7 @@ static void touch(Entity *other)
pickupItem();
playSound(SND_CHERRY, CH_BOB);
playSound(SND_CHERRY, i->uniqueId % MAX_SND_CHANNELS);
game.stats[STAT_CHERRIES_PICKED_UP]++;
}

View File

@ -68,7 +68,7 @@ static void touch(Entity *other)
setGameplayMessage(MSG_OBJECTIVE, _("Found a heart - Max health increased!"));
playSound(SND_HEART_CELL, CH_ITEM);
playSound(SND_HEART_CELL, self->uniqueId % MAX_SND_CHANNELS);
self->alive = ALIVE_DEAD;

View File

@ -141,7 +141,7 @@ static void bobPickupItem(void)
setGameplayMessage(MSG_STANDARD, _("Picked up a %s"), i->name);
playSound(SND_KEY, CH_ITEM);
playSound(SND_KEY, i->uniqueId % MAX_SND_CHANNELS);
}
else
{
@ -161,7 +161,7 @@ static void bobPickupItem(void)
setGameplayMessage(MSG_STANDARD, _("Picked up a %s"), i->name);
playSound(SND_ITEM, CH_ITEM);
playSound(SND_ITEM, i->uniqueId % MAX_SND_CHANNELS);
}
else
{
@ -178,7 +178,7 @@ static void bobPickupItem(void)
setGameplayMessage(MSG_STANDARD, _("Picked up a %s"), i->name);
}
playSound(SND_ITEM, CH_ITEM);
playSound(SND_ITEM, i->uniqueId % MAX_SND_CHANNELS);
}
}
@ -222,7 +222,7 @@ static void changeEnvironment(void)
i->x = i->startX;
i->y = i->startY;
addTeleportStars(self);
playSound(SND_APPEAR, CH_ANY);
playSound(SND_APPEAR, -1);
}
}

View File

@ -99,7 +99,7 @@ static void touch(Entity *other)
pickupItem();
playSound(SND_WEAPON, CH_ITEM);
playSound(SND_WEAPON, i->uniqueId % MAX_SND_CHANNELS);
game.stats[STAT_WEAPONS_PICKED_UP]++;
}

View File

@ -98,12 +98,12 @@ static void touch(Entity *other)
s->spriteTime = 0;
s->spriteFrame = 0;
playSound(SND_CONFIRMED, CH_TOUCH);
playSound(SND_CONFIRMED, s->uniqueId % MAX_SND_CHANNELS);
}
else if (s->bobTouching == 0)
{
setGameplayMessage(MSG_GAMEPLAY, _("%s required"), s->requiredItem);
playSound(SND_DENIED, CH_TOUCH);
playSound(SND_DENIED, s->uniqueId % MAX_SND_CHANNELS);
}
s->bobTouching = 2;

View File

@ -166,7 +166,7 @@ static void tick(void)
{
s->isStatic = 1;
playSound(SND_DOOR_FINISH, CH_MECHANICAL);
playSound(SND_DOOR_FINISH, s->uniqueId % MAX_SND_CHANNELS);
}
}
@ -193,7 +193,7 @@ static void touch(Entity *other)
{
setGameplayMessage(MSG_GAMEPLAY, _("Door is locked"));
playSound(SND_DENIED, CH_MECHANICAL);
playSound(SND_DENIED, s->uniqueId % MAX_SND_CHANNELS);
}
s->thinkTime = 2;
@ -208,7 +208,7 @@ static void touch(Entity *other)
if (s->state != DOOR_OPEN)
{
playSound(SND_DOOR_START, CH_MECHANICAL);
playSound(SND_DOOR_START, s->uniqueId % MAX_SND_CHANNELS);
}
s->state = DOOR_OPEN;
@ -231,7 +231,7 @@ static void openWithKey(void)
if (s->state != DOOR_OPEN)
{
playSound(SND_DOOR_START, CH_MECHANICAL);
playSound(SND_DOOR_START, s->uniqueId % MAX_SND_CHANNELS);
}
s->state = DOOR_OPEN;
@ -243,7 +243,7 @@ static void openWithKey(void)
{
setGameplayMessage(MSG_GAMEPLAY, _("%s required"), s->requiredItem);
playSound(SND_DENIED, CH_MECHANICAL);
playSound(SND_DENIED, s->uniqueId % MAX_SND_CHANNELS);
}
s->thinkTime = 2;
@ -276,7 +276,7 @@ static void activate(int active)
s->state = (s->state == DOOR_CLOSED) ? DOOR_OPEN : DOOR_CLOSED;
playSound(SND_DOOR_START, CH_MECHANICAL);
playSound(SND_DOOR_START, s->uniqueId % MAX_SND_CHANNELS);
if (active)
{

View File

@ -101,7 +101,7 @@ static void touch(Entity *other)
{
activateEntities(s->targetNames, 1);
playSound(SND_PRESSURE_PLATE, CH_MECHANICAL);
playSound(SND_PRESSURE_PLATE, s->uniqueId % MAX_SND_CHANNELS);
}
s->active = 1;

View File

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

View File

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

View File

@ -138,7 +138,7 @@ static void touch(Entity *other)
swapSelf(other);
}
playSound(SND_FLESH_HIT, CH_ANY);
playSound(SND_FLESH_HIT, other->uniqueId % MAX_SND_CHANNELS);
}
if (other == (Entity*)world.bob && world.bob->stunTimer == 0)

View File

@ -158,7 +158,7 @@ static void reappear(void)
addTeleportStars(self);
playSound(SND_APPEAR, CH_ANY);
playSound(SND_APPEAR, self->uniqueId % MAX_SND_CHANNELS);
}
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, CH_ANY);
playSound(SND_APPEAR, self->uniqueId % MAX_SND_CHANNELS);
}
}
}

View File

@ -83,7 +83,7 @@ void initSDL(void)
exit(1);
}
Mix_AllocateChannels(64);
Mix_AllocateChannels(MAX_SND_CHANNELS);
Mix_Volume(-1, app.config.soundVolume);
Mix_VolumeMusic(app.config.musicVolume);

View File

@ -490,7 +490,7 @@ static void doWorldComplete(void)
dropCarriedItems();
world.bob->flags |= EF_GONE;
addTeleportStars((Entity*)world.bob);
playSound(SND_TELEPORT, CH_BOB);
playSound(SND_TELEPORT, world.bob->uniqueId % MAX_SND_CHANNELS);
}
else
{
@ -640,7 +640,7 @@ static void spawnEnemies(void)
u->spawnedIn = 1;
u->canCarryItem = 0;
addTeleportStars((Entity*)u);
playSound(SND_APPEAR, CH_ANY);
playSound(SND_APPEAR, u->uniqueId % MAX_SND_CHANNELS);
}
}