Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
<script type='text/javascript' src="js/input.js"></script>
<script type='text/javascript' src="js/main.js"></script>
<script type='text/javascript' src="js/initialization.js"></script>
<script type='text/javascript' src="js/sound.js"></script>
<script type='text/javascript' src="js/BufferLoader.js"></script>
<script type='text/javascript' charset='utf-8' src='cordova.js'></script>
<script src="vendor/sweet-alert.min.js"></script>
<link rel="stylesheet" href="style/rrssb.css"/>
Expand Down
49 changes: 49 additions & 0 deletions js/BufferLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
function BufferLoader(context,urlList,callback) {
this.context = context;
this.urlList = urlList;
this.onload = callback;
this.bufferList = new Array();
this.loadCount = 0;
}

BufferLoader.prototype.loadBuffer = function(url,index) {
var request = new XMLHttpRequest();
request.open("GET",url,true);
request.responseType = "arraybuffer";

var loader = this;
request.onload= function() {
loader.context.decodeAudioData(request.response, function(buffer) {

if(!buffer){
console.log("error decoding"+url);
alert('Error decoding: '+url);
return;
}
loader.bufferList[index]= buffer;
if(++loader.loadCount == loader.urlList.length)
loader.onload(loader.bufferList);
}
);
};

request.onerror = function() {
console.log("XMLHttpRequest error");
alert('BufferLoader: XMLHttpRequest error');
}
request.ontimeout = function () {
console.log("XMLHttpRequest timeout");
}
request.onreadystatechange = function() {
if(request.readyState ==4 && request.status == 200){

}
}
request.send();
}

BufferLoader.prototype.load = function() {
for(var i = 0; i < this.urlList.length; i++){
this.loadBuffer(this.urlList[i],i);
}
}
3 changes: 2 additions & 1 deletion js/Hex.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function Hex(sideLength) {

this.targetAngle = this.targetAngle - steps * 60;
this.lastRotate = Date.now();
playRotationSound();
};

this.draw = function() {
Expand Down Expand Up @@ -160,7 +161,7 @@ function Hex(sideLength) {
else {
this.angle += this.angularVelocity;
}
drawPolygon(this.x + gdx, this.y + gdy + this.dy, this.sides, this.sideLength, this.angle,arrayToColor(this.fillColor) , 0, 'rgba(0,0,0,0)');
};
}
Expand Down
3 changes: 2 additions & 1 deletion js/checking.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function consolidateBlocks(hex,side,index){
var deletedBlocks = [];
//add start case
deleting.push([side,index]);
//fill deleting
//fill deleting
floodFill(hex,side,index,deleting);
//make sure there are more than 3 blocks to be deleted
if(deleting.length<3){return;}
Expand Down Expand Up @@ -81,4 +81,5 @@ function consolidateBlocks(hex,side,index){
hex.texts.push(new Text(hex.x,hex.y,"+ "+adder.toString(),"bold Q ",deletedBlocks[0].color,fadeUpAndOut));
hex.lastColorScored = deletedBlocks[0].color;
score += adder;
playCompletionSound(hex.comboMultiplier);
}
18 changes: 11 additions & 7 deletions js/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function addKeyListeners() {
if (gameState != 1 && gameState != -1) {
return;
}

playBackgroundMusic();
if ($('#helpScreen').is(":visible")) {
$('#helpScreen').fadeOut(150, "linear");
}
Expand Down Expand Up @@ -108,6 +108,8 @@ function addKeyListeners() {
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
$("#restart").on('touchstart', function() {
init();
playBackgroundMusic();

canRestart = false;
$("#gameoverscreen").fadeOut();
});
Expand All @@ -116,6 +118,7 @@ function addKeyListeners() {
else {
$("#restart").on('mousedown', function() {
init();
playBackgroundMusic();
canRestart = false;
$("#gameoverscreen").fadeOut();
});
Expand All @@ -124,6 +127,7 @@ function addKeyListeners() {
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
$("#restartBtn").on('touchstart', function() {
init(1);
playBackgroundMusic();
canRestart = false;
$("#gameoverscreen").fadeOut();
});
Expand All @@ -132,6 +136,7 @@ function addKeyListeners() {
else {
$("#restartBtn").on('mousedown', function() {
init(1);
playBackgroundMusic();
canRestart = false;
$("#gameoverscreen").fadeOut();
});
Expand All @@ -143,19 +148,19 @@ function addKeyListeners() {
function inside (point, vs) {
// ray-casting algorithm based on
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html

var x = point[0], y = point[1];

var inside = false;
for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) {
var xi = vs[i][0], yi = vs[i][1];
var xj = vs[j][0], yj = vs[j][1];

var intersect = ((yi > y) != (yj > y))
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
if (intersect) inside = !inside;
}

return inside;
};

Expand All @@ -174,7 +179,7 @@ function handleClickTap(x,y) {
[-radius,0],
[-halfRadius,triHeight],
[halfRadius,triHeight]];
Vertexes = Vertexes.map(function(coord){
Vertexes = Vertexes.map(function(coord){
return [coord[0] + trueCanvas.width/2, coord[1] + trueCanvas.height/2]});

if (!MainHex || gameState === 0 || gameState==-1) {
Expand All @@ -188,4 +193,3 @@ function handleClickTap(x,y) {
MainHex.rotate(-1);
}
}

73 changes: 73 additions & 0 deletions js/sound.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
var audioCtx;
var bufferLoader;
var sourceList = new Array();
var gainNodeList = new Array();
var webAudioSupported= true;
$(document).ready( function() {
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
if(!audioCtx) {
webAudioSupported=false;
}
else {
bufferLoader = new BufferLoader(
audioCtx,
[
"sounds/ville_seppanen-1_g.mp3",
"sounds/button1.mp3",
"sounds/complete.mp3",
],
loadComplete
);
bufferLoader.load();
}
});
function playOneShot(AudioBuffer,volume,playbackRate) {
var sourceCpy = audioCtx.createBufferSource();
sourceCpy.buffer = AudioBuffer;
sourceCpy.playbackRate.value = playbackRate;
var gainCpy = audioCtx.createGain();
gainCpy.gain.value = volume;
sourceCpy.connect(gainCpy);
gainCpy.connect(audioCtx.destination);
sourceCpy.start(0);
}
function playRotationSound(){
if(webAudioSupported) {
playOneShot(sourceList[1].buffer,1.0,1.0);
}
}
function playCompletionSound(playbackRate){
if(webAudioSupported) {
playOneShot(sourceList[2].buffer,0.3,playbackRate);
}
}

function playBackgroundMusic() {
if(webAudioSupported) {

gainNodeList[0].gain.value = 0.4;
}
}
function muteBackgroundMusic() {
if(webAudioSupported) {
gainNodeList[0].gain.value = 0.0;
}
}
function loadComplete(bufferList) {
for(var i = 0; i < bufferList.length; i++) {
var source = audioCtx.createBufferSource();
source.buffer = bufferList[i];
var gainNode = audioCtx.createGain();
source.connect(gainNode);
gainNode.connect(audioCtx.destination);

if(i==0) {
source.loop = true;
gainNode.gain.value = 0.4;
source.start(0);
}

sourceList[i] = source;
gainNodeList[i] = gainNode;
}
}
1 change: 1 addition & 0 deletions js/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,6 @@ function pause(o) {
pausable = true;
}, 400);
gameState = -1;
muteBackgroundMusic();
}
}
Binary file added sounds/button1.mp3
Binary file not shown.
Binary file added sounds/button1.ogg
Binary file not shown.
Binary file added sounds/complete.mp3
Binary file not shown.
Binary file added sounds/complete.ogg
Binary file not shown.
Binary file added sounds/ville_seppanen-1_g.mp3
Binary file not shown.