Skip to content

Commit

Permalink
team member spawn notification now has a blinking text and sound
Browse files Browse the repository at this point in the history
  • Loading branch information
infidel- committed Aug 10, 2019
1 parent 51793dc commit 10b8893
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/GameScene.hx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class GameScene extends Scene
public var hud: HUD; // ingame HUD
public var win: Window;
public var font: Font;
public var font40: Font;
public var soundManager: SoundManager;
// public var font10: Font;
var uiQueue: List<_UIEvent>; // gui event queue
Expand Down Expand Up @@ -141,6 +142,7 @@ class GameScene extends Scene
tileAtlas = res.gridFlatten(Const.TILE_SIZE_CLEAN);
font = hxd.Res.load('font/OrkneyRegular' +
game.config.fontSize + '.fnt').to(hxd.res.BitmapFont).toFont();
font40 = hxd.Res.font.OrkneyRegular40.toFont();

// scale atlases if needed
if (game.config.mapScale != 1)
Expand Down
1 change: 1 addition & 0 deletions src/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Main extends hxd.App
{
game.scene.mouse.update();
game.scene.checkPath();
game.scene.hud.updateAnimation(dt);
}


Expand Down
2 changes: 2 additions & 0 deletions src/ai/TeamMemberAI.hx
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,7 @@ class TeamMemberAI extends HumanAI
public override function onNotice()
{
game.log('You feel someone watching you.', COLOR_ALERT);
game.scene.hud.blinkingText.show(3);
game.scene.soundManager.playSound('team_notify', true);
}
}
1 change: 1 addition & 0 deletions src/const/SoundConst.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class SoundConst
'watcher_ambush',
'parasite_attach1',
'parasite_detach1',
'team_notify',
];

// dog sounds
Expand Down
81 changes: 81 additions & 0 deletions src/ui/BlinkingText.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// blinking text in the middle of the screen

package ui;

import h2d.Graphics;
import h2d.Object;
import game.Game;

class BlinkingText
{
var game: Game; // game state link
var text: h2d.Text; // team member notification
var back: Graphics; // notification background
var textAlphaTarget: Float; // notification alpha animation
var times: Int; // times to blink until hiding

public function new(g: Game, container: Object)
{
game = g;

times = 0;
back = new Graphics(container);
text = new h2d.Text(game.scene.font40, back);
text.textAlign = Left;
text.text = 'You feel someone watching you.';
text.textColor = 0xff3333;
back.x = Std.int(game.scene.win.width / 2 -
text.textWidth / 2);
back.y = game.scene.win.height / 2;
back.clear();
back.beginFill(0x202020, 0.75);
back.drawRect(0, 0, text.textWidth,
text.textHeight);
back.endFill();
back.visible = false;
textAlphaTarget = 1.0;
}


// resize notification
public function resize()
{
back.x = Std.int(game.scene.win.width / 2 -
text.textWidth / 2);
back.y = game.scene.win.height / 2;
}


// show for a given amount of time
public function show(t: Int)
{
back.visible = true;
times = t;
}


// periodic update for animation
public function update(dt: Float)
{
if (!back.visible)
return;

if (textAlphaTarget == 1.0)
{
back.alpha += 0.02;
if (back.alpha >= 1.0)
textAlphaTarget = 0.0;
}
else
{
back.alpha -= 0.02;
if (back.alpha <= 0.0)
{
textAlphaTarget = 1.0;
times--;
if (times <= 0) // hide
back.visible = false;
}
}
}
}
12 changes: 12 additions & 0 deletions src/ui/HUD.hx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class HUD
var _consoleBack: Graphics; // console background
var _goals: HtmlText; // goals list
var _goalsBack: Graphics; // goals list background
public var blinkingText: BlinkingText; // blinking text

public function new(g: Game)
{
Expand Down Expand Up @@ -107,6 +108,9 @@ class HUD
_goals.textAlign = Left;
_goalsBack.x = game.scene.win.width - 420;

// team member notification
blinkingText = new BlinkingText(game, _container);

@:privateAccess game.scene.window.addEventTarget(onEvent);
}

Expand Down Expand Up @@ -675,7 +679,15 @@ class HUD
_goalsBack.x = game.scene.win.width - 420;
for (m in _menuButtons)
m.back.y = game.scene.win.height - game.config.fontSize - 8;
blinkingText.resize();

update();
}


// periodic update for animation
public function updateAnimation(dt: Float)
{
blinkingText.update(dt);
}
}

0 comments on commit 10b8893

Please sign in to comment.