Add basic sounds

This commit is contained in:
tobspr 2020-05-14 19:12:58 +02:00
parent e960773a15
commit af0f56b5e4
24 changed files with 87 additions and 56 deletions

View File

@ -19,6 +19,7 @@ function gulptasksSounds($, gulp, buildFolder) {
gulp.task("sounds.encodeMusic", () => { gulp.task("sounds.encodeMusic", () => {
return gulp return gulp
.src([path.join(soundsDir, "music", "**", "*.wav"), path.join(soundsDir, "music", "**", "*.mp3")]) .src([path.join(soundsDir, "music", "**", "*.wav"), path.join(soundsDir, "music", "**", "*.mp3")])
.pipe($.plumber())
.pipe( .pipe(
$.cache( $.cache(
$.fluentFfmpeg("mp3", function (cmd) { $.fluentFfmpeg("mp3", function (cmd) {
@ -42,6 +43,7 @@ function gulptasksSounds($, gulp, buildFolder) {
gulp.task("sounds.encodeUi", () => { gulp.task("sounds.encodeUi", () => {
return gulp return gulp
.src([path.join(soundsDir, "ui", "**", "*.wav"), path.join(soundsDir, "ui", "**", "*.mp3")]) .src([path.join(soundsDir, "ui", "**", "*.wav"), path.join(soundsDir, "ui", "**", "*.mp3")])
.pipe($.plumber())
.pipe( .pipe(
$.cache( $.cache(
$.fluentFfmpeg("mp3", function (cmd) { $.fluentFfmpeg("mp3", function (cmd) {
@ -64,7 +66,9 @@ function gulptasksSounds($, gulp, buildFolder) {
// Encodes the game sounds // Encodes the game sounds
gulp.task("sounds.encodeGame", () => { gulp.task("sounds.encodeGame", () => {
return gulp return gulp
.src([path.join(soundsDir, "game", "**", "*.wav"), path.join(soundsDir, "game", "**", "*.mp3")]) .src([path.join(soundsDir, "game", "**", "*.wav"), path.join(soundsDir, "game", "**", "*.mp3")])
.pipe($.plumber())
.pipe( .pipe(
$.cache( $.cache(
$.fluentFfmpeg("mp3", function (cmd) { $.fluentFfmpeg("mp3", function (cmd) {
@ -87,6 +91,7 @@ function gulptasksSounds($, gulp, buildFolder) {
gulp.task("sounds.copy", () => { gulp.task("sounds.copy", () => {
return gulp return gulp
.src(path.join(builtSoundsDir, "**", "*.mp3")) .src(path.join(builtSoundsDir, "**", "*.mp3"))
.pipe($.plumber())
.pipe($.cached("sounds.copy")) .pipe($.cached("sounds.copy"))
.pipe(gulp.dest(path.join(buildFolder, "res", "sounds"))); .pipe(gulp.dest(path.join(buildFolder, "res", "sounds")));
}); });

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d802fdcef7ae2d9486b362bca260e64383c690e14d7246e632324e49bed76abe
size 24580

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ecd3d0d02bcc16363cd977b70cd94dddc774e809e2670d903b6dc62a0e2ff291
size 238210

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:811a57acb5a16af8079744e048c3809799211f1d7c6e79eaa5247ed852b5d4eb
size 23990546

Binary file not shown.

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6b4cbf863591aba38d1729fb1cbaa792323f045722279f0deca2492acaaf19b5
size 123844300

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a4f810fcfbfcea08cfb48a8d58f9b65d1fd14cd20ff3cabf94a03c39b5250547
size 1765124

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:7f4c56728534d030fca2d75f297027a2774d6f765f5be84a27a3705569f878f2 oid sha256:75b848d50cd6c02ee7ba53424ce0e1d8432b35bc044aa195b0b3e35b5021c92d
size 20158 size 43630

View File

@ -102,7 +102,7 @@
.badge { .badge {
position: absolute; position: absolute;
@include S(bottom, -12px); @include S(bottom, -8px);
left: 50%; left: 50%;
transform: translateX(-50%); transform: translateX(-50%);

View File

@ -4,10 +4,10 @@
left: 0; left: 0;
right: 0; right: 0;
bottom: 0; bottom: 0;
background: rgba(#333538, 0.95) uiResource("dialog_bg_pattern.png") top left / #{D(10px)} repeat; background: rgba(#333538, 0.98) uiResource("dialog_bg_pattern.png") top left / #{D(10px)} repeat;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: flex-start; align-items: center;
pointer-events: all; pointer-events: all;
@include InlineAnimation(0.1s ease-in-out) { @include InlineAnimation(0.1s ease-in-out) {
0% { 0% {
@ -16,7 +16,8 @@
} }
.dialog { .dialog {
background: rgba(#333539, 0.5); background: rgba(#222428, 0.5);
@include S(border-radius, 4px);
@include S(padding, 30px); @include S(padding, 30px);
@include InlineAnimation(0.5s ease-in-out) { @include InlineAnimation(0.5s ease-in-out) {
@ -117,15 +118,12 @@
button.close { button.close {
border: 0; border: 0;
@include InlineAnimation(0.5s ease-in-out) { @include InlineAnimation(2s ease-in-out) {
0% { 0% {
transform: translateY(50vh); opacity: 0;
} }
50% { 95% {
transform: translateY(-5vh); opacity: 0;
}
75% {
transform: translateY(2vh);
} }
} }
@include S(margin-top, 30px); @include S(margin-top, 30px);

View File

@ -22,7 +22,7 @@ const essentialMainMenuSounds = [
const essentialBareGameAtlases = atlasFiles; const essentialBareGameAtlases = atlasFiles;
const essentialBareGameSprites = G_ALL_UI_IMAGES; const essentialBareGameSprites = G_ALL_UI_IMAGES;
const essentialBareGameSounds = [MUSIC.gameBg]; const essentialBareGameSounds = [MUSIC.theme];
const additionalGameSprites = []; const additionalGameSprites = [];
const additionalGameSounds = []; const additionalGameSounds = [];

View File

@ -4,6 +4,8 @@ import { Signal } from "../core/signal";
import { fastArrayDelete, fastArrayDeleteValueIfContained } from "./utils"; import { fastArrayDelete, fastArrayDeleteValueIfContained } from "./utils";
import { Vector } from "./vector"; import { Vector } from "./vector";
import { IS_MOBILE } from "./config"; import { IS_MOBILE } from "./config";
import { SOUNDS } from "../platform/sound";
import { GLOBAL_APP } from "./globals";
const logger = createLogger("click_detector"); const logger = createLogger("click_detector");
@ -63,7 +65,7 @@ export class ClickDetector {
captureTouchmove = false, captureTouchmove = false,
targetOnly = false, targetOnly = false,
maxDistance = MAX_MOVE_DISTANCE_PX, maxDistance = MAX_MOVE_DISTANCE_PX,
clickSound = null, clickSound = SOUNDS.uiClick,
} }
) { ) {
assert(element, "No element given!"); assert(element, "No element given!");
@ -321,8 +323,7 @@ export class ClickDetector {
// If we should play any sound, do this // If we should play any sound, do this
if (this.clickSound) { if (this.clickSound) {
throw new Error("TODO: Play sounds on click"); GLOBAL_APP.sound.playUiSound(this.clickSound);
// GLOBAL_APP.sound.playUiSound(this.clickSound);
} }
return false; return false;

View File

@ -77,14 +77,14 @@ export const globalConfig = {
showEntityBounds: false, showEntityBounds: false,
showAcceptorEjectors: false, showAcceptorEjectors: false,
usePlainShapeIds: true, usePlainShapeIds: true,
disableMusic: true, // disableMusic: true,
doNotRenderStatics: false, doNotRenderStatics: false,
disableZoomLimits: false, disableZoomLimits: false,
showChunkBorders: false, showChunkBorders: false,
rewardsInstant: false, rewardsInstant: false,
allBuildingsUnlocked: true, allBuildingsUnlocked: true,
upgradesNoCost: true, upgradesNoCost: true,
disableUnlockDialog: true, disableUnlockDialog: false,
/* dev:end */ /* dev:end */
}, },

View File

@ -252,7 +252,7 @@ export class GameState {
* @returns {string|null} * @returns {string|null}
*/ */
getThemeMusic() { getThemeMusic() {
return MUSIC.mainMenu; return null;
} }
//////////////////// ////////////////////

View File

@ -7,6 +7,7 @@ import { ReplaceableMapEntityComponent } from "../components/replaceable_map_ent
import { Entity } from "../entity"; import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building"; import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root"; import { GameRoot } from "../root";
import { SOUNDS } from "../../platform/sound";
export const arrayBeltVariantToRotation = [enumDirection.top, enumDirection.left, enumDirection.right]; export const arrayBeltVariantToRotation = [enumDirection.top, enumDirection.left, enumDirection.right];
@ -69,6 +70,10 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
return true; return true;
} }
getPlacementSound() {
return SOUNDS.placeBelt;
}
/** /**
* Creates the entity at the given location * Creates the entity at the given location
* @param {Entity} entity * @param {Entity} entity

View File

@ -1,8 +1,8 @@
import { BaseHUDPart } from "../base_hud_part";
import { makeDiv, removeAllChildren, formatBigNumber } from "../../../core/utils";
import { ClickDetector } from "../../../core/click_detector";
import { ShapeDefinition } from "../../shape_definition";
import { Math_max } from "../../../core/builtins"; import { Math_max } from "../../../core/builtins";
import { ClickDetector } from "../../../core/click_detector";
import { formatBigNumber, makeDiv } from "../../../core/utils";
import { ShapeDefinition } from "../../shape_definition";
import { BaseHUDPart } from "../base_hud_part";
export class HUDPinnedShapes extends BaseHUDPart { export class HUDPinnedShapes extends BaseHUDPart {
createElements(parent) { createElements(parent) {

View File

@ -14,6 +14,7 @@ import { MetaRotaterBuilding } from "../../buildings/rotater";
import { MetaStackerBuilding } from "../../buildings/stacker"; import { MetaStackerBuilding } from "../../buildings/stacker";
import { MetaUndergroundBeltBuilding } from "../../buildings/underground_belt"; import { MetaUndergroundBeltBuilding } from "../../buildings/underground_belt";
import { globalConfig } from "../../../core/config"; import { globalConfig } from "../../../core/config";
import { SOUNDS } from "../../../platform/sound";
export class HUDUnlockNotification extends BaseHUDPart { export class HUDUnlockNotification extends BaseHUDPart {
initialize() { initialize() {
@ -110,6 +111,8 @@ export class HUDUnlockNotification extends BaseHUDPart {
this.elemContents.innerHTML = html; this.elemContents.innerHTML = html;
this.visible = true; this.visible = true;
this.root.soundProxy.playUi(SOUNDS.levelComplete);
} }
close() { close() {

View File

@ -4,9 +4,9 @@ import { Vector, enumDirectionToVector, enumDirection } from "../core/vector";
import { MetaBuilding } from "./meta_building"; import { MetaBuilding } from "./meta_building";
import { StaticMapEntityComponent } from "./components/static_map_entity"; import { StaticMapEntityComponent } from "./components/static_map_entity";
import { Math_abs } from "../core/builtins"; import { Math_abs } from "../core/builtins";
import { Rectangle } from "../core/rectangle";
import { createLogger } from "../core/logging"; import { createLogger } from "../core/logging";
import { MetaBeltBaseBuilding, arrayBeltVariantToRotation } from "./buildings/belt_base"; import { MetaBeltBaseBuilding, arrayBeltVariantToRotation } from "./buildings/belt_base";
import { SOUNDS } from "../platform/sound";
const logger = createLogger("ingame/logic"); const logger = createLogger("ingame/logic");
@ -175,6 +175,9 @@ export class GameLogic {
rotationVariant, rotationVariant,
originalRotation, originalRotation,
}); });
this.root.soundProxy.playUi(building.getPlacementSound());
return true; return true;
} }
return false; return false;

View File

@ -4,6 +4,7 @@ import { GameRoot } from "./root";
import { AtlasSprite } from "../core/sprites"; import { AtlasSprite } from "../core/sprites";
import { Entity } from "./entity"; import { Entity } from "./entity";
import { StaticMapEntityComponent } from "./components/static_map_entity"; import { StaticMapEntityComponent } from "./components/static_map_entity";
import { SOUNDS } from "../platform/sound";
export class MetaBuilding { export class MetaBuilding {
/** /**
@ -64,6 +65,14 @@ export class MetaBuilding {
return false; return false;
} }
/**
* Returns the placement sound
* @returns {string}
*/
getPlacementSound() {
return SOUNDS.placeBuilding;
}
/** /**
* Returns a preview sprite * Returns a preview sprite
* @returns {AtlasSprite} * @returns {AtlasSprite}

View File

@ -55,11 +55,6 @@ export class SoundProxy {
if (this.playingSounds.length > maxOngoingSounds) { if (this.playingSounds.length > maxOngoingSounds) {
// Too many ongoing sounds // Too many ongoing sounds
// console.warn(
// "Not playing",
// id,
// "because there are too many sounds playing"
// );
return false; return false;
} }

View File

@ -49,17 +49,23 @@ export class HubSystem extends GameSystemWithFilter {
const textOffsetY = -6; const textOffsetY = -6;
// Deliver count // Deliver count
const delivered = this.root.hubGoals.getCurrentGoalDelivered();
if (delivered > 9999) {
context.font = "bold 16px GameFont";
} else if (delivered > 999) {
context.font = "bold 20px GameFont";
} else {
context.font = "bold 25px GameFont"; context.font = "bold 25px GameFont";
}
context.fillStyle = "#64666e"; context.fillStyle = "#64666e";
context.textAlign = "left"; context.textAlign = "left";
context.fillText( context.fillText("" + formatBigNumber(delivered), pos.x + textOffsetX, pos.y + textOffsetY);
"" + formatBigNumber(this.root.hubGoals.getCurrentGoalDelivered()),
pos.x + textOffsetX,
pos.y + textOffsetY
);
// Required // Required
context.font = "13px GameFont"; context.font = "13px GameFont";
context.fillStyle = "#a4a6b0"; context.fillStyle = "#a4a6b0";
context.fillText( context.fillText(
"/ " + formatBigNumber(goals.required), "/ " + formatBigNumber(goals.required),

View File

@ -10,7 +10,6 @@ class SoundInstance extends SoundInstanceInterface {
constructor(key, url) { constructor(key, url) {
super(key, url); super(key, url);
this.howl = null; this.howl = null;
this.instance = null;
} }
load() { load() {
@ -25,6 +24,7 @@ class SoundInstance extends SoundInstanceInterface {
loop: false, loop: false,
volume: 0, volume: 0,
preload: true, preload: true,
pool: 20,
onload: () => { onload: () => {
resolve(); resolve();
}, },
@ -43,13 +43,8 @@ class SoundInstance extends SoundInstanceInterface {
play(volume) { play(volume) {
if (this.howl) { if (this.howl) {
if (!this.instance) { const instance = this.howl.play();
this.instance = this.howl.play(); this.howl.volume(volume, instance);
} else {
this.howl.play(this.instance);
this.howl.seek(0, this.instance);
}
this.howl.volume(volume, this.instance);
} }
} }
@ -57,7 +52,6 @@ class SoundInstance extends SoundInstanceInterface {
if (this.howl) { if (this.howl) {
this.howl.unload(); this.howl.unload();
this.howl = null; this.howl = null;
this.instance = null;
} }
} }
} }
@ -80,7 +74,7 @@ class MusicInstance extends MusicInstanceInterface {
autoplay: false, autoplay: false,
loop: true, loop: true,
html5: true, html5: true,
volume: 1, volume: 0.3,
preload: true, preload: true,
pool: 2, pool: 2,
@ -133,6 +127,12 @@ class MusicInstance extends MusicInstanceInterface {
export class SoundImplBrowser extends SoundInterface { export class SoundImplBrowser extends SoundInterface {
constructor(app) { constructor(app) {
Howler.mobileAutoEnable = true;
Howler.autoUnlock = true;
Howler.autoSuspend = false;
Howler.html5PoolSize = 20;
Howler.pos(0, 0, 0);
super(app, SoundInstance, MusicInstance); super(app, SoundInstance, MusicInstance);
} }

View File

@ -18,11 +18,15 @@ export const SOUNDS = {
dialogOk: "ui/dialog_ok.mp3", dialogOk: "ui/dialog_ok.mp3",
swishHide: "ui/ui_swish_hide.mp3", swishHide: "ui/ui_swish_hide.mp3",
swishShow: "ui/ui_swish_show.mp3", swishShow: "ui/ui_swish_show.mp3",
levelComplete: "ui/level_complete.mp3",
placeBuilding: "game/place_building.mp3",
placeBelt: "game/place_belt.mp3",
}; };
export const MUSIC = { export const MUSIC = {
mainMenu: "main_menu.mp3", theme: "theme.mp3",
gameBg: "theme_full.mp3",
}; };
export class SoundInstanceInterface { export class SoundInstanceInterface {

View File

@ -91,8 +91,7 @@ export class InGameState extends GameState {
} }
getThemeMusic() { getThemeMusic() {
// set later return MUSIC.theme;
return MUSIC.mainMenu;
} }
onBeforeExit() { onBeforeExit() {