Skip to content
Browse files

Add music and warning effect.

  • Loading branch information...
1 parent 6416838 commit 76909827f51ffb96ad7b1bc44aa71af943837896 @Osmose committed
View
6 LICENSE
@@ -34,3 +34,9 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+---
+
+Stage Music - Show No Tears
+by NemesisTheory <http://nemesistheory.newgrounds.com/>
+This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
View
BIN audio/alarm.ogg
Binary file not shown.
View
BIN audio/show_no_tears.mp3
Binary file not shown.
View
BIN audio/show_no_tears.ogg
Binary file not shown.
View
BIN img/warning.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN img/warning_stripe.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
2 index.html
@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
- <title>House Blend</title>
+ <title>Magma Force</title>
<link href="css/bootstrap.cyborg.min.css" rel="stylesheet" media="screen">
<link href="css/magmaforce.css" rel="stylesheet" media="screen">
</head>
View
8 js/game/game.js
@@ -6,6 +6,7 @@ define(function(require) {
var Player = require('game/player');
var BallWorld = require('game/world');
+ var WarningWorld = require('game/warning');
var loader = require('game/loader');
loader.register('balls','img/balls.png', 'image');
@@ -73,15 +74,16 @@ define(function(require) {
this.bg_color = this.bg_gradients[this.gradient_indexes[this.gradient_count++ % this.gradient_indexes.length]];
}
-
loader.loadAll().done(function() {
// Initialize engine.
var COLS = 12;
var ROWS = 12;
- var engine = new MagmaEngine(COLS * 16, ROWS * 16+16, 3, new BallWorld(ROWS,COLS));
+ var ballworld = new BallWorld(ROWS,COLS);
+ var engine = new MagmaEngine(COLS * 16, ROWS * 16+16, 3, ballworld);
engine.cols = COLS;
engine.rows = ROWS;
- engine.addEntity(new Player(0, 11 * 16));
+ ballworld.addEntity(new Player(6 * 16, 11 * 16));
+ engine.pushWorld(new WarningWorld(ballworld), true, false);
// Append canvas to screen and start the engine!
document.querySelector('#game').appendChild(engine.canvas);
View
13 js/game/player.js
@@ -5,7 +5,7 @@ define(function(require) {
var loader = require('game/loader');
function Player(x, y) {
Entity.call(this, x, y);
- this.col = 0;
+ this.col = 6;
this.playertiles = new TiledGraphic(loader.get('player'),16,24);
this.currentSprite = 0;
@@ -34,11 +34,11 @@ define(function(require) {
if (kb.check(kb.D) && !this.grabkey) {
this.grabkey = true;
if (this.heldblocks.length === 0) {
- var addblocks = this.engine.world.getBlocks(this.col);
+ var addblocks = this.world.getBlocks(this.col);
this.heldblocks = this.heldblocks.concat(addblocks);
} else {
// Let them pick up more of the same color if they want
- var addblocks = this.engine.world.getBlocks(this.col, this.heldblocks[0]);
+ var addblocks = this.world.getBlocks(this.col, this.heldblocks[0]);
this.heldblocks = this.heldblocks.concat(addblocks);
}
}
@@ -55,7 +55,7 @@ define(function(require) {
if (kb.check(kb.F) && !this.throwkey) {
this.throwkey = true;
if (this.heldblocks.length > 0) {
- this.engine.world.pushBlocks(this.heldblocks, this.col);
+ this.world.pushBlocks(this.heldblocks, this.col);
this.heldblocks = [];
}
}
@@ -63,9 +63,6 @@ define(function(require) {
this.throwkey = false;
}
-
-
-
var keydown = kb.check(kb.LEFT) || kb.check(kb.RIGHT);
if (this.keydown_delay <= 0) {
this.col += dx;
@@ -93,7 +90,7 @@ define(function(require) {
this.playertiles.renderTile(ctx, this.currentSprite, this.x, this.y);
- var world = this.engine.world;
+ var world = this.world;
var x = this.x + 7;
for (var row = this.engine.rows - 2; row >= 0; row--) {
View
128 js/game/warning.js
@@ -0,0 +1,128 @@
+define(function(require) {
+ var DefaultWorld = require('flux/worlds/default');
+ var Graphic = require('flux/graphics/graphic');
+ var Sound = require('flux/sound');
+
+ var loader = require('game/loader');
+ loader.register('warning', 'img/warning.png', 'image');
+ loader.register('warning_stripe', 'img/warning_stripe.png', 'image');
+ loader.register('warning_sound', 'audio/alarm.ogg', 'audio');
+
+ var FAST_STRIPE = 6;
+ var SLOW_STRIPE = 1;
+ var WARNING_TOP = 80;
+
+ function WarningWorld(ballworld) {
+ DefaultWorld.call(this);
+ var self = this;
+
+ this.ballworld = ballworld;
+
+ this.warning = new Graphic(loader.get('warning'));
+ this.warning_stripe = new Graphic(loader.get('warning_stripe'));
+
+ this.alarm = new Sound(loader.get('warning_sound'));
+ this.alarm.audio.addEventListener('ended', function(e) {
+ self.state = 2;
+ self.alarm_playing = false;
+ }, true);
+ this.alarm_playing = false;
+
+ this.stripe1x = 192;
+ this.stripe2x = -this.warning_stripe.width;
+
+ // 0 = Stripes flying in
+ // 1 = Warning glow
+ // 2 = Stripes flying out
+ this.state = 0;
+ }
+ WarningWorld.prototype = Object.create(DefaultWorld.prototype);
+
+ WarningWorld.prototype.tick = function() {
+ switch (this.state) {
+ case 0:
+ if (this.stripe1x > 0) {
+ this.stripe1x -= FAST_STRIPE;
+ this.stripe2x += FAST_STRIPE;
+ } else {
+ this.state = 1;
+
+ this.alarm_playing = true;
+ this.alarm.play();
+ }
+ break;
+ case 1:
+ this.stripe1x = (this.stripe1x - SLOW_STRIPE) % 32;
+ this.stripe2x = ((this.stripe2x + SLOW_STRIPE) % 32) - 32;
+ break;
+ case 2:
+ if (this.stripe2x < 192) {
+ this.stripe1x -= FAST_STRIPE;
+ this.stripe2x += FAST_STRIPE;
+ } else {
+ this.engine.popWorld();
+ this.ballworld.running = true;
+ this.ballworld.start();
+ }
+ }
+ };
+
+ function flashToAlpha(progress) {
+ if (progress < 0.5) {
+ return progress / 0.5;
+ } else if (progress < 1) {
+ return 1;
+ } else if (progress < 1.5) {
+ return 1 - ((progress - 1) / 0.5);
+ } else {
+ return 0;
+ }
+ }
+
+ WarningWorld.prototype.render = function(ctx) {
+ switch (this.state) {
+ case 0:
+ // Box height is determined by how far the stripes are.
+ var box_half_height = Math.floor(((192 - this.stripe1x) / 192) * 24);
+ var box_top = WARNING_TOP + 24 - box_half_height;
+ ctx.fillStyle = 'rgba(91, 0, 0, 0.6)';
+ ctx.fillRect(0, box_top, 192, box_half_height * 2);
+ break;
+ case 1:
+ // Tie the warning's flashing to the audio's progress.
+ var audio = this.alarm.audio;
+ var audio_progress = audio.currentTime / audio.duration;
+ var flash_progress = (audio_progress * 8) % 2;
+
+ ctx.fillStyle = 'rgba(91, 0, 0, 0.6)';
+ ctx.fillRect(0, WARNING_TOP, 192, 48);
+ console.log(flash_progress + '-' + flashToAlpha(flash_progress));
+ ctx.globalAlpha = flashToAlpha(flash_progress);
+ this.warning.render(ctx, 0, WARNING_TOP);
+ ctx.globalAlpha = 1;
+ break;
+ case 2:
+ var box_half_height = 24 - Math.floor(Math.max(0, (this.stripe2x / 192)) * 24);
+ var box_top = WARNING_TOP + 24 - box_half_height;
+ ctx.fillStyle = 'rgba(91, 0, 0, 0.6)';
+ ctx.fillRect(0, box_top, 192, box_half_height * 2);
+
+ }
+
+
+ this.warning_stripe.render(ctx, this.stripe1x, WARNING_TOP);
+ this.warning_stripe.render(ctx, this.stripe2x, WARNING_TOP + 40);
+ };
+
+ WarningWorld.prototype.start = function() {
+ if (this.alarm_playing) {
+ this.alarm.play();
+ }
+ };
+
+ WarningWorld.prototype.stop = function() {
+ this.alarm.pause();
+ }
+
+ return WarningWorld;
+});
View
15 js/game/world.js
@@ -1,9 +1,11 @@
define(function(require) {
var DefaultWorld = require('flux/worlds/default');
var Graphic = require('flux/graphics/graphic');
+ var Sound = require('flux/sound');
var TiledGraphic = require('flux/graphics/tiled');
var loader = require('game/loader');
+ loader.register('stage_music', 'audio/show_no_tears.ogg', 'audio');
var SHOW_MATCH_LENGTH = 32;
@@ -35,6 +37,9 @@ define(function(require) {
for (var k = 0; k < 3; k++) {
this.generateRow();
}
+
+ this.music = new Sound(loader.get('stage_music'));
+ this.running = false;
}
BallWorld.prototype = Object.create(DefaultWorld.prototype);
@@ -283,5 +288,15 @@ define(function(require) {
return affected;
};
+ BallWorld.prototype.start = function() {
+ if (this.running) {
+ this.music.loop();
+ }
+ };
+
+ BallWorld.prototype.stop = function() {
+ this.music.pause();
+ }
+
return BallWorld;
});
2 js/lib/flux
@@ -1 +1 @@
-Subproject commit edb1a973c7b7964c32e7d6b99466274700e7c2b5
+Subproject commit 07ac9b9b74646b6b9a4a911810622ff9324e8296

0 comments on commit 7690982

Please sign in to comment.
Something went wrong with that request. Please try again.