mirror of
https://github.com/cxong/cdogs-sdl.git
synced 2025-07-23 07:23:01 +02:00
Refactor UpdateTriggeredMine away (#64)
Add trigger sound for mine (#39)
This commit is contained in:
4
sounds/mine_trigger.txt
Normal file
4
sounds/mine_trigger.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
Derived from Radio Beep by Kijadzel
|
||||
http://freesound.org/people/Kijadzel/sounds/170608/
|
||||
|
||||
http://creativecommons.org/licenses/by/3.0/
|
BIN
sounds/mine_trigger.wav
Normal file
BIN
sounds/mine_trigger.wav
Normal file
Binary file not shown.
@@ -382,14 +382,14 @@ static Vec2i SeekTowards(
|
||||
}
|
||||
|
||||
|
||||
int UpdateBullet(TMobileObject *obj, int ticks)
|
||||
bool UpdateBullet(TMobileObject *obj, const int ticks)
|
||||
{
|
||||
MobileObjectUpdate(obj, ticks);
|
||||
if (obj->count < 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (obj->count > obj->range)
|
||||
if (obj->range >= 0 && obj->count > obj->range)
|
||||
{
|
||||
if (obj->bulletClass->OutOfRangeFunc)
|
||||
{
|
||||
@@ -580,10 +580,36 @@ int UpdateBullet(TMobileObject *obj, int ticks)
|
||||
}
|
||||
}
|
||||
|
||||
// Proximity function, destroy
|
||||
// Only check proximity every now and then
|
||||
if (obj->bulletClass->ProximityFunc && !(obj->count & 3))
|
||||
{
|
||||
// Detonate the mine if there are characters in the tiles around it
|
||||
const Vec2i tv =
|
||||
Vec2iToTile(Vec2iFull2Real(Vec2iNew(obj->x, obj->y)));
|
||||
Vec2i dv;
|
||||
for (dv.y = -1; dv.y <= 1; dv.y++)
|
||||
{
|
||||
for (dv.x = -1; dv.x <= 1; dv.x++)
|
||||
{
|
||||
const Vec2i dtv = Vec2iAdd(tv, dv);
|
||||
if (!MapIsTileIn(&gMap, dtv))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (TileHasCharacter(MapGetTile(&gMap, dtv)))
|
||||
{
|
||||
obj->bulletClass->ProximityFunc(obj);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int UpdateTriggeredMine(TMobileObject *obj, int ticks)
|
||||
bool UpdateTriggeredMine(TMobileObject *obj, const int ticks)
|
||||
{
|
||||
MobileObjectUpdate(obj, ticks);
|
||||
if (obj->count >= obj->range)
|
||||
@@ -594,45 +620,7 @@ int UpdateTriggeredMine(TMobileObject *obj, int ticks)
|
||||
return true;
|
||||
}
|
||||
|
||||
int UpdateActiveMine(TMobileObject *obj, int ticks)
|
||||
{
|
||||
Vec2i tv = Vec2iToTile(Vec2iFull2Real(Vec2iNew(obj->x, obj->y)));
|
||||
Vec2i dv;
|
||||
|
||||
MobileObjectUpdate(obj, ticks);
|
||||
|
||||
// Check if the mine is still arming
|
||||
if (obj->count & 3)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!MapIsTileIn(&gMap, tv))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Detonate the mine if there are characters in the tiles around it
|
||||
for (dv.y = -1; dv.y <= 1; dv.y++)
|
||||
{
|
||||
for (dv.x = -1; dv.x <= 1; dv.x++)
|
||||
{
|
||||
if (TileHasCharacter(MapGetTile(&gMap, Vec2iAdd(tv, dv))))
|
||||
{
|
||||
SetBulletProps(obj, obj->z, BULLET_TRIGGEREDMINE, obj->flags);
|
||||
obj->count = 0;
|
||||
SoundPlayAt(
|
||||
&gSoundDevice,
|
||||
SND_HAHAHA,
|
||||
Vec2iNew(obj->tileItem.x, obj->tileItem.y));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void AddActiveMine(const TMobileObject *obj)
|
||||
static void AddActiveMine(const TMobileObject *obj)
|
||||
{
|
||||
GameEvent e;
|
||||
e.Type = GAME_EVENT_ADD_BULLET;
|
||||
@@ -650,6 +638,24 @@ void AddActiveMine(const TMobileObject *obj)
|
||||
sound.u.SoundAt.Pos = Vec2iFull2Real(Vec2iNew(obj->x, obj->y));
|
||||
GameEventsEnqueue(&gGameEvents, sound);
|
||||
}
|
||||
static void AddTriggeredMine(const TMobileObject *obj)
|
||||
{
|
||||
GameEvent e;
|
||||
e.Type = GAME_EVENT_ADD_BULLET;
|
||||
e.u.AddBullet.Bullet = BULLET_TRIGGEREDMINE;
|
||||
e.u.AddBullet.MuzzlePos = Vec2iNew(obj->x, obj->y);
|
||||
e.u.AddBullet.MuzzleHeight = obj->z;
|
||||
e.u.AddBullet.Angle = 0;
|
||||
e.u.AddBullet.Direction = DIRECTION_UP;
|
||||
e.u.AddBullet.Flags = obj->flags;
|
||||
e.u.AddBullet.PlayerIndex = obj->player;
|
||||
GameEventsEnqueue(&gGameEvents, e);
|
||||
GameEvent sound;
|
||||
sound.Type = GAME_EVENT_SOUND_AT;
|
||||
sound.u.SoundAt.Sound = SND_MINE_TRIGGER;
|
||||
sound.u.SoundAt.Pos = Vec2iFull2Real(Vec2iNew(obj->x, obj->y));
|
||||
GameEventsEnqueue(&gGameEvents, sound);
|
||||
}
|
||||
|
||||
|
||||
void BulletInitialize(void)
|
||||
@@ -1018,7 +1024,7 @@ void BulletInitialize(void)
|
||||
|
||||
b = &gBulletClasses[BULLET_SPARK];
|
||||
b->Name = "spark";
|
||||
b->UpdateFunc = UpdateSpark;
|
||||
b->UpdateFunc = UpdateMobileObject;
|
||||
b->DrawFunc = (TileItemDrawFunc)DrawBullet;
|
||||
b->DrawData.u.Bullet.Ofspic = OFSPIC_SPARK;
|
||||
b->DrawData.u.Bullet.UseMask = true;
|
||||
@@ -1029,17 +1035,17 @@ void BulletInitialize(void)
|
||||
|
||||
b = &gBulletClasses[BULLET_ACTIVEMINE];
|
||||
b->Name = "activemine";
|
||||
b->UpdateFunc = UpdateActiveMine;
|
||||
b->DrawFunc = (TileItemDrawFunc)DrawBullet;
|
||||
b->DrawData.u.Bullet.Pic = PicManagerGetPic(&gPicManager, "mine_active");
|
||||
b->DrawData.u.Bullet.Ofspic = OFSPIC_MINE;
|
||||
b->DrawData.u.Bullet.UseMask = true;
|
||||
b->DrawData.u.Bullet.Mask = colorWhite;
|
||||
b->SpeedLow = b->SpeedHigh = 0;
|
||||
b->RangeLow = b->RangeHigh = 5;
|
||||
b->RangeLow = b->RangeHigh = -1;
|
||||
b->Power = 0;
|
||||
b->Persists = true;
|
||||
b->HitsObjects = false;
|
||||
b->ProximityFunc = AddTriggeredMine;
|
||||
|
||||
b = &gBulletClasses[BULLET_TRIGGEREDMINE];
|
||||
b->Name = "triggeredmine";
|
||||
|
@@ -91,7 +91,7 @@ typedef enum
|
||||
|
||||
BULLET_COUNT
|
||||
} BulletType;
|
||||
typedef int (*BulletUpdateFunc)(struct MobileObject *, int);
|
||||
typedef bool (*BulletUpdateFunc)(struct MobileObject *, int);
|
||||
typedef enum
|
||||
{
|
||||
FALLING_TYPE_BOUNCE,
|
||||
@@ -110,6 +110,7 @@ typedef struct
|
||||
int SpeedHigh;
|
||||
bool SpeedScale; // whether to scale X/Y speed based on perspective
|
||||
Vec2i Friction; // Amount to subtract from velocity per tick
|
||||
// -1 is infinite range
|
||||
int RangeLow;
|
||||
int RangeHigh;
|
||||
int Power;
|
||||
@@ -132,6 +133,7 @@ typedef struct
|
||||
bool RandomAnimation;
|
||||
bool Seeking;
|
||||
bool Erratic;
|
||||
void (*ProximityFunc)(const struct MobileObject *); // Mines
|
||||
} BulletClass;
|
||||
extern BulletClass gBulletClasses[BULLET_COUNT];
|
||||
|
||||
|
@@ -404,12 +404,7 @@ void MobileObjectUpdate(TMobileObject *obj, int ticks)
|
||||
obj->count += ticks;
|
||||
obj->soundLock = MAX(0, obj->soundLock - ticks);
|
||||
}
|
||||
static int UpdateMobileObject(TMobileObject *obj, int ticks)
|
||||
{
|
||||
MobileObjectUpdate(obj, ticks);
|
||||
return obj->count <= obj->range;
|
||||
}
|
||||
int UpdateSpark(TMobileObject *obj, const int ticks)
|
||||
bool UpdateMobileObject(TMobileObject *obj, const int ticks)
|
||||
{
|
||||
MobileObjectUpdate(obj, ticks);
|
||||
return obj->count <= obj->range;
|
||||
@@ -587,5 +582,5 @@ void AddMuzzleFlash(
|
||||
obj->tileItem.drawData.u.MuzzleFlash.Color = color;
|
||||
obj->tileItem.drawData.u.MuzzleFlash.SpriteName = spriteName;
|
||||
obj->tileItem.drawData.u.MuzzleFlash.Dir = d;
|
||||
obj->updateFunc = UpdateSpark;
|
||||
obj->updateFunc = UpdateMobileObject;
|
||||
}
|
||||
|
@@ -198,7 +198,7 @@ void AddFireball(const AddFireballEvent e);
|
||||
void MobileObjectUpdate(TMobileObject *obj, int ticks);
|
||||
int HitItem(TMobileObject *obj, Vec2i pos);
|
||||
|
||||
int UpdateSpark(TMobileObject *obj, const int ticks);
|
||||
bool UpdateMobileObject(TMobileObject *obj, const int ticks);
|
||||
void DrawFireball(Vec2i pos, TileItemDrawFuncData *data);
|
||||
|
||||
void AddMuzzleFlash(
|
||||
|
@@ -97,6 +97,7 @@ SoundDevice gSoundDevice =
|
||||
{"powergun_r", false, NULL},
|
||||
{"package_r", false, NULL},
|
||||
{"mine_arm", false, NULL},
|
||||
{"mine_trigger",false, NULL},
|
||||
{"knife_flesh", false, NULL},
|
||||
{"knife_hard", false, NULL},
|
||||
{"ricochet", false, NULL},
|
||||
|
@@ -84,6 +84,7 @@ typedef enum
|
||||
SND_LASER_R,
|
||||
SND_PACKAGE_R,
|
||||
SND_MINE_ARM,
|
||||
SND_MINE_TRIGGER,
|
||||
SND_KNIFE_FLESH,
|
||||
SND_KNIFE_HARD,
|
||||
SND_HIT_WALL,
|
||||
|
Reference in New Issue
Block a user