Add mission end pulse and sfx (fixes #431)

This commit is contained in:
Cong Xu
2019-01-03 22:40:46 +11:00
parent c5b4c47adf
commit e0992bb843
10 changed files with 33 additions and 88 deletions

BIN
sounds/mission_complete.ogg Normal file

Binary file not shown.

View File

@@ -0,0 +1,4 @@
Derived from
UI and Item sound effect Jingles Sample 2 by ViRiX Dreamcore soundcloud.com/virix
https://opengameart.org/content/ui-and-item-sound-effect-jingles-sample-2
http://creativecommons.org/licenses/by/3.0/

View File

@@ -264,54 +264,6 @@ void CharColorsGetMaskedName(char *buf, const char *base, const CharColors *c)
sprintf(buf, "%s/%s/%s/%s/%s/%s", base,
bufSkin, bufArms, bufBody, bufLegs, bufHair);
}
void BlitBlend(
GraphicsDevice *g, const Pic *pic, struct vec2i pos, const color_t blend)
{
Uint32 *current = pic->Data;
pos = svec2i_add(pos, pic->offset);
for (int i = 0; i < pic->size.y; i++)
{
int yoff = i + pos.y;
if (yoff > g->clipping.bottom)
{
break;
}
if (yoff < g->clipping.top)
{
current += pic->size.x;
continue;
}
yoff *= g->cachedConfig.Res.x;
for (int j = 0; j < pic->size.x; j++)
{
int xoff = j + pos.x;
if (xoff < g->clipping.left)
{
current++;
continue;
}
if (xoff > g->clipping.right)
{
current += pic->size.x - j;
break;
}
if (*current == 0)
{
current++;
continue;
}
Uint32 *target = g->buf + yoff + xoff;
const color_t currentColor = PIXEL2COLOR(*current);
color_t blendedColor = ColorMult(
currentColor, blend);
blendedColor.a = blend.a;
const color_t targetColor = PIXEL2COLOR(*target);
blendedColor = ColorAlphaBlend(targetColor, blendedColor);
*target = COLOR2PIXEL(blendedColor);
current++;
}
}
}
void BlitClearBuf(GraphicsDevice *g)
{

View File

@@ -80,8 +80,6 @@ void BlitMasked(
struct vec2i pos,
color_t mask,
int isTransparent);
void BlitBlend(
GraphicsDevice *g, const Pic *pic, struct vec2i pos, const color_t blend);
void BlitPicHighlight(
GraphicsDevice *g, const Pic *pic, const struct vec2i pos, const color_t color);
void BlitClearBuf(GraphicsDevice *g);

View File

@@ -114,14 +114,7 @@ static void DrawObjectiveHighlight(
const struct vec2i pos = svec2i(
(int)ti->Pos.x - b->xTop + offset.x,
(int)ti->Pos.y - b->yTop + offset.y);
const int pulsePeriod = ConfigGetInt(&gConfig, "Game.FPS");
int alphaUnscaled =
(gMission.time % pulsePeriod) * 255 / (pulsePeriod / 2);
if (alphaUnscaled > 255)
{
alphaUnscaled = 255 * 2 - alphaUnscaled;
}
color.a = (Uint8)alphaUnscaled;
color.a = (Uint8)Pulse256(gMission.time);
if (ti->kind == KIND_CHARACTER)
{
TActor *a = CArrayGet(&gActors, ti->id);

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2014-2017 Cong Xu
Copyright (c) 2014-2017, 2019 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -208,14 +208,7 @@ struct vec2i FontCh(const char c, const struct vec2i pos)
{
return FontChMask(c, pos, colorWhite);
}
static struct vec2i FontChColor(
const char c, const struct vec2i pos, const color_t color, const bool blend);
struct vec2i FontChMask(const char c, const struct vec2i pos, const color_t mask)
{
return FontChColor(c, pos, mask, false);
}
static struct vec2i FontChColor(
const char c, const struct vec2i pos, const color_t color, const bool blend)
{
int idx = (int)c - FIRST_CHAR;
if (idx < 0)
@@ -228,14 +221,7 @@ static struct vec2i FontChColor(
idx = FIRST_CHAR;
}
const Pic *pic = CArrayGet(&gFont.Chars, idx);
if (blend)
{
BlitBlend(&gGraphicsDevice, pic, pos, color);
}
else
{
BlitMasked(&gGraphicsDevice, pic, pos, color, true);
}
BlitMasked(&gGraphicsDevice, pic, pos, mask, true);
// Add gap between characters
return svec2i(pos.x + pic->size.x + gFont.Gap.x, pos.y);
}
@@ -243,14 +229,7 @@ struct vec2i FontStr(const char *s, struct vec2i pos)
{
return FontStrMask(s, pos, colorWhite);
}
static struct vec2i FontStrColor(
const char *s, struct vec2i pos, const color_t c, const bool blend);
struct vec2i FontStrMask(const char *s, struct vec2i pos, const color_t mask)
{
return FontStrColor(s, pos, mask, false);
}
static struct vec2i FontStrColor(
const char *s, struct vec2i pos, const color_t c, const bool blend)
{
if (s == NULL)
{
@@ -266,7 +245,7 @@ static struct vec2i FontStrColor(
}
else
{
pos = FontChColor(*s, pos, c, blend);
pos = FontChMask(*s, pos, mask);
}
s++;
}

View File

@@ -588,9 +588,13 @@ static void HandleGameEvent(
}
break;
case GAME_EVENT_MISSION_COMPLETE:
if (camera != NULL && e.u.MissionComplete.ShowMsg)
if (e.u.MissionComplete.ShowMsg)
{
HUDDisplayMessage(&camera->HUD, "Mission complete", -1);
SoundPlay(&gSoundDevice, StrSound("mission_complete"));
if (camera != NULL)
{
HUDDisplayMessage(&camera->HUD, "Mission complete", -1);
}
}
// Don't show exit area or arrow if PVP
if (!IsPVP(gCampaign.Entry.Mode))

View File

@@ -22,7 +22,7 @@
This file incorporates work covered by the following copyright and
permission notice:
Copyright (c) 2013-2017 Cong Xu
Copyright (c) 2013-2017, 2019 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -1010,7 +1010,9 @@ static void DrawHUDMessage(HUD *hud)
(hud->device->cachedConfig.Res.x -
FontStrW(hud->message)) / 2,
AUTOMAP_SIZE + AUTOMAP_PADDING + AUTOMAP_PADDING);
FontStrMask(hud->message, pos, colorCyan);
const HSV tint = { -1.0, 1.0, Pulse256(hud->mission->time) / 256.0};
const color_t mask = ColorTint(colorCyan, tint);
FontStrMask(hud->message, pos, mask);
}
}

View File

@@ -22,7 +22,7 @@
This file incorporates work covered by the following copyright and
permission notice:
Copyright (c) 2013-2017, Cong Xu
Copyright (c) 2013-2017, 2019 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -506,3 +506,14 @@ BodyPart StrBodyPart(const char *s)
S2T(BODY_PART_GUN, "gun");
return BODY_PART_HEAD;
}
int Pulse256(const int t)
{
const int pulsePeriod = ConfigGetInt(&gConfig, "Game.FPS");
int alphaUnscaled = (t % pulsePeriod) * 255 / (pulsePeriod / 2);
if (alphaUnscaled > 255)
{
alphaUnscaled = 255 * 2 - alphaUnscaled;
}
return alphaUnscaled;
}

View File

@@ -22,7 +22,7 @@
This file incorporates work covered by the following copyright and
permission notice:
Copyright (c) 2013-2017, Cong Xu
Copyright (c) 2013-2017, 2019 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -210,3 +210,5 @@ typedef enum
PLACEMENT_ACCESS_LOCKED, // place in locked rooms
PLACEMENT_ACCESS_NOT_LOCKED // don't place in locked rooms
} PlacementAccessFlags;
int Pulse256(const int t);