Skip to content
Browse files

Added alert image and sound

  • Loading branch information...
1 parent 0f016a3 commit 4d9fe2f9190343d8a78f9eb8de93c3d776ad778f @alexanderzeillinger committed
Showing with 46 additions and 17 deletions.
  1. BIN assets/alert.png
  2. BIN images/alert.png
  3. +46 −17 machina.js
  4. BIN sounds/alert.ogg
View
BIN assets/alert.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN images/alert.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
63 machina.js
@@ -4,9 +4,13 @@ var game = {
tileSize: 79,
speed: 8,
running: null,
- alert: null,
mode: null,
- cycles: 0
+ cycles: 0,
+ alert: {
+ x: 0,
+ y: 0,
+ message: null
+ }
};
var engine = {
@@ -187,15 +191,20 @@ function Waldo (pX, pY, pImage, pColor) {
this.waitForSync = false;
this.checkCollision = function() {
// check collision against border
- if (this.x < -5 || this.x > 716 || this.y < -5 || this.y > 559)
- game.alert = "collision";
+ if (this.x < -5 || this.x > 716 || this.y < -5 || this.y > 559) {
+ game.alert.message = "collision";
+ game.alert.x = this.x;
+ game.alert.y = this.y;
+ }
// check collision against solid tiles
for (var i in game.level.areas) {
if (game.level.areas[i].name == "SOLID") {
for (var j in game.level.areas[i].tiles) {
//if (Math.sqrt(Math.pow(this.x - game.level.areas[i].tiles[j].x * game.tileSize,2) + Math.pow(this.y - game.level.areas[i].tiles[j].y * game.tileSize,2)) < tileSize) {
if (Math.pow(this.x - game.level.areas[i].tiles[j].x * game.tileSize,2) + Math.pow(this.y - game.level.areas[i].tiles[j].y * game.tileSize,2) < Math.pow(game.tileSize,2)) { // should be faster in theory
- game.alert = "collision";
+ game.alert.message = "collision";
+ game.alert.x = this.x;
+ game.alert.y = this.y;
}
}
}
@@ -1245,9 +1254,13 @@ function init() {
Sounds = new Array();
addSound("click","ogg");
addSound("beep","ogg");
+ addSound("alert","ogg");
// Load images
Images = new Array();
+
+ addImage("alert");
+
// balls
addImage("ball_1");
addImage("ball_2");
@@ -1416,7 +1429,7 @@ function reset() {
outCurrentPhi = 0;
outCurrentOmega = 0;
- game.alert = null;
+ game.alert.message = null;
menuSymbolColor = "red";
tileSel = "clear";
@@ -1872,7 +1885,7 @@ function output(pArea, pWaldo) {
}
if (!found) {
groupIsOk = false;
- game.alert = "wrong";
+ game.alert.message = "wrong";
break;
}
}
@@ -1880,7 +1893,7 @@ function output(pArea, pWaldo) {
else {
if (groups[i].balls.length != area.template.balls.length || groups[i].balls[0].number != area.template.balls[0].number) {
groupIsOk = false;
- game.alert = "wrong";
+ game.alert.message = "wrong";
}
}
}
@@ -2376,8 +2389,11 @@ function swap() {
function rotateWaldo(pWaldo) {
// stop the simulation when both waldos try to rotate the same group
- if (pWaldo.group != null && waldoRed.group == waldoBlue.group)
- game.alert = "broken";
+ if (pWaldo.group != null && waldoRed.group == waldoBlue.group) {
+ game.alert.message = "broken";
+ game.alert.x = waldoRed.x;
+ game.alert.y = waldoRed.y;
+ }
var centerX = pWaldo.x + 40;
var centerY = pWaldo.y + 40;
@@ -2588,8 +2604,11 @@ function moveWaldo(pWaldo) {
function moveGroup(pWaldo) {
if (pWaldo.status == "closed") {
// stop the simulation when both waldos try to move the same group into different directions
- if (waldoRed.group == waldoBlue.group && waldoRed.direction != waldoBlue.direction)
- game.alert = "broken";
+ if (waldoRed.group == waldoBlue.group && waldoRed.direction != waldoBlue.direction) {
+ game.alert.message = "broken";
+ game.alert.x = waldoRed.x;
+ game.alert.y = waldoRed.y;
+ }
if (waldoRed.group == waldoBlue.group) {
if (pWaldo.color == "red") {
@@ -2951,7 +2970,9 @@ function simulation() {
for (var j in groups[i].balls) {
if (groups[i].balls[j].x < -5 || groups[i].balls[j].x > 716 || groups[i].balls[j].y < -5 || groups[i].balls[j].y > 559) {
//$("#debug").append("Collision at " + groups[i].balls[j].x + "/" + groups[i].balls[j].y + "</br>");
- game.alert = "collision";
+ game.alert.message = "collision";
+ game.alert.x = groups[i].balls[j].x;
+ game.alert.y = groups[i].balls[j].y;
break outer;
}
}
@@ -2965,7 +2986,9 @@ function simulation() {
for (var l in groups[k].balls) {
if (Math.pow(groups[k].balls[l].x - groups[i].balls[j].x,2) + Math.pow(groups[k].balls[l].y - groups[i].balls[j].y,2) < 3600) { // should be faster in theory
//if (Math.sqrt(Math.pow(groups[k].balls[l].x - groups[i].balls[j].x,2) + Math.pow(groups[k].balls[l].y - groups[i].balls[j].y,2)) < 60) {
- game.alert = "collision";
+ game.alert.message = "collision";
+ game.alert.x = groups[i].balls[j].x;
+ game.alert.y = groups[i].balls[j].y;
//$("#debug").append("Collision between " + groups[i].balls[j].x + "/" + groups[i].balls[j].y + " and " + groups[k].balls[l].x + "/" + groups[k].balls[l].y + "</br>");
break outer;
}
@@ -3030,18 +3053,24 @@ function simulation() {
pause();
}
- if (game.alert == "collision") {
+ if (game.alert.message == "collision") {
$("#status").html('<span class="red">COLLISION</span>');
+ Sounds["alert"].play();
+ ctxBuffer.drawImage(Images["alert"], game.alert.x, game.alert.y);
pause();
}
- if (game.alert == "broken") {
+ if (game.alert.message == "broken") {
$("#status").html('<span class="red">BROKEN</span>');
+ Sounds["alert"].play();
+ ctxBuffer.drawImage(Images["alert"], game.alert.x, game.alert.y);
pause();
}
- if (game.alert == "wrong") {
+ if (game.alert.message == "wrong") {
$("#status").html('<span class="red">WRONG OUTPUT</span>');
+ Sounds["alert"].play();
+ ctxBuffer.drawImage(Images["alert"], game.alert.x, game.alert.y);
pause();
}
View
BIN sounds/alert.ogg
Binary file not shown.

0 comments on commit 4d9fe2f

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