Initial Commit
@@ -0,0 +1 @@
/output
@@ -0,0 +1 @@/output@@ -0,0 +1,50 @@
//<DOC> category GameAudio
var GameAudio =
{
active: false,
//<DOC> <function> GameAudio.init(collection, containingFolder)<br><br>Starts the audio system, using an array of audio names 'collection' and a path 'containingFolder' in which the sounds can be found. Do not include file extentions in sound names!
init: function(collection, containingFolder)
{
console.log("GAME: Loading sounds. (Note: Only supported from online-source, will fail when executed on local files.)");
try
{
var soundColl = [];
for(var i = 0; i < collection.length; i++)
{
soundColl.push({name: collection[i], preload: true});
}
if(containingFolder == null)
containingFolder = "";
if(containingFolder != "")
containingFolder += "/";
ion.sound
({
sounds: soundColl,
volume: 1,
preload: true,
multiplay: true,
path: containingFolder
});
this.active = true;
}
catch(err)
{
console.log("GAME: ERROR: Sounds could not be loaded. Sound will not be available.");
}
},
//<DOC> <function> GameAudio.play(name)<br><br>plays a sound with the name 'name'.
play: function(name)
{
if(this.active)
ion.sound.play(name);
}
}
@@ -0,0 +1,50 @@//<DOC> category GameAudiovar GameAudio = { active: false, //<DOC> <function> GameAudio.init(collection, containingFolder)<br><br>Starts the audio system, using an array of audio names 'collection' and a path 'containingFolder' in which the sounds can be found. Do not include file extentions in sound names! init: function(collection, containingFolder) { console.log("GAME: Loading sounds. (Note: Only supported from online-source, will fail when executed on local files.)"); try { var soundColl = []; for(var i = 0; i < collection.length; i++) { soundColl.push({name: collection[i], preload: true}); } if(containingFolder == null) containingFolder = ""; if(containingFolder != "") containingFolder += "/"; ion.sound ({ sounds: soundColl, volume: 1, preload: true, multiplay: true, path: containingFolder }); this.active = true; } catch(err) { console.log("GAME: ERROR: Sounds could not be loaded. Sound will not be available."); } }, //<DOC> <function> GameAudio.play(name)<br><br>plays a sound with the name 'name'. play: function(name) { if(this.active) ion.sound.play(name); }}@@ -0,0 +1,6 @@
copy /b *.js output\framework.js
@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a:%%b)
echo %mydate% %mytime% >> output\lastbuild.txt
@@ -0,0 +1,6 @@copy /b *.js output\framework.js@echo offFor /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a:%%b)echo %mydate% %mytime% >> output\lastbuild.txt@@ -0,0 +1,368 @@
var ease = {
//
// Basic ease functions
//
easeConstant: function (time, begin, change, duration) {
"use strict";
return begin;
},
easeLinear: function (time, begin, change, duration) {
"use strict";
var val = time/duration;
return begin + change * val;
},
easeInPower: function (time, begin, change, duration, power) {
"use strict";
var val;
if (power === undefined) { power = 3; }
val = Math.pow(time/duration, power);
return begin + change * val;
},
easeOutPower: function (time, begin, change, duration, power) {
"use strict";
var val = tbEase.easeInPower(duration-time, 1, -1, duration, power);
return begin + change * val;
},
easeInOutPower: function (time, begin, change, duration, power) {
"use strict";
var val;
if (time < duration/2) {
val = tbEase.easeInPower(time, 0, 0.5, duration/2, power);
} else {
val = tbEase.easeInPower(duration-time, 1, -0.5, duration/2, power);
}
return begin + change * val;
},
easeOutInPower: function (time, begin, change, duration, power) {
"use strict";
var val;
if (time < duration/2) {
val = tbEase.easeInPower(duration/2-time, 0.5, -0.5, duration/2, power);
} else {
val = tbEase.easeInPower(time-duration/2, 0.5, 0.5, duration/2, power);
}
return begin + change * val;
},
easeInQuadratic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeInPower(time, begin, change, duration, 2);
},
easeOutQuadratic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeOutPower(time, begin, change, duration, 2);
},
easeInOutQuadratic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeInOutPower(time, begin, change, duration, 2);
},
easeOutInQuadratic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeOutInPower(time, begin, change, duration, 2);
},
easeInCubic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeInPower(time, begin, change, duration, 3);
},
easeOutCubic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeOutPower(time, begin, change, duration, 3);
},
easeInOutCubic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeInOutPower(time, begin, change, duration, 3);
},
easeOutInCubic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeOutInPower(time, begin, change, duration, 3);
},
easeInQuartic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeInPower(time, begin, change, duration, 4);
},
easeOutQuartic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeOutPower(time, begin, change, duration, 4);
},
easeInOutQuartic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeInOutPower(time, begin, change, duration, 4);
},
easeOutInQuartic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeOutInPower(time, begin, change, duration, 4);
},
easeInQuintic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeInPower(time, begin, change, duration, 5);
},
easeOutQuintic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeOutPower(time, begin, change, duration, 5);
},
easeInOutQuintic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeInOutPower(time, begin, change, duration, 5);
},
easeOutInQuintic: function (time, begin, change, duration) {
"use strict";
return tbEase.easeOutInPower(time, begin, change, duration, 5);
},
easeInExponential: function (time, begin, change, duration, power) {
"use strict";
var val, base;
if (power === undefined) { power = 8; }
base = Math.pow(2, -power); // The exponential function will not cover the whole range from 0-1 so we must correct it
val = (Math.pow(2, power * time/duration - power) - base) / (1-base);
return begin + change * val;
},
easeOutExponential: function (time, begin, change, duration, power) {
"use strict";
var val = tbEase.easeInExponential(duration-time, 1, -1, duration, power);
return begin + change * val;
},
easeInOutExponential: function (time, begin, change, duration, power) {
"use strict";
var val;
if (time < duration/2) {
val = tbEase.easeInExponential(time, 0, 0.5, duration/2, power);
} else {
val = tbEase.easeInExponential(duration-time, 1, -0.5, duration/2, power);
}
return begin + change * val;
},
easeOutInExponential: function (time, begin, change, duration, power) {
"use strict";
var val;
if (time < duration/2) {
val = tbEase.easeInExponential(duration/2-time, 0.5, -0.5, duration/2, power);
} else {
val = tbEase.easeInExponential(time-duration/2, 0.5, 0.5, duration/2, power);
}
return begin + change * val;
},
easeInSine: function (time, begin, change, duration) {
"use strict";
var val = 1 - Math.cos(time/duration * Math.PI/2);
return begin + change * val;
},
easeOutSine: function (time, begin, change, duration) {
"use strict";
var val = tbEase.easeInSine(duration-time, 1, -1, duration);
return begin + change * val;
},
easeInOutSine: function (time, begin, change, duration) {
"use strict";
var val;
if (time < duration/2) {
val = tbEase.easeInSine(time, 0, 0.5, duration/2);
} else {
val = tbEase.easeInSine(duration-time, 1, -0.5, duration/2);
}
return begin + change * val;
},
easeOutInSine: function (time, begin, change, duration) {
"use strict";
var val;
if (time < duration/2) {
val = tbEase.easeInSine(duration/2-time, 0.5, -0.5, duration/2);
} else {
val = tbEase.easeInSine(time-duration/2, 0.5, 0.5, duration/2);
}
return begin + change * val;
},
easeInCircular: function (time, begin, change, duration) {
"use strict";
var val = 1 - Math.sqrt(1 - Math.pow(time/duration, 2));
return begin + change * val;
},
easeOutCircular: function (time, begin, change, duration) {
"use strict";
var val = tbEase.easeInCircular(duration-time, 1, -1, duration);
return begin + change * val;
},
easeInOutCircular: function (time, begin, change, duration) {
"use strict";
var val;
if (time < duration/2) {
val = tbEase.easeInCircular(time, 0, 0.5, duration/2);
} else {
val = tbEase.easeInCircular(duration-time, 1, -0.5, duration/2);
}
return begin + change * val;
},
easeOutInCircular: function (time, begin, change, duration) {
"use strict";
var val;
if (time < duration/2) {
val = tbEase.easeInCircular(duration/2-time, 0.5, -0.5, duration/2);
} else {
val = tbEase.easeInCircular(time-duration/2, 0.5, 0.5, duration/2);
}
return begin + change * val;
},
easeInElastic: function (time, begin, change, duration, oscillations, stiffness) {
"use strict";
var val;
if (oscillations === undefined) { oscillations = 3; }
if (stiffness === undefined) { stiffness = 8; }
val = Math.sin((1-time/duration)*2*Math.PI*oscillations + Math.PI/2); // Create the correct sign
val *= tbEase.easeInExponential(time, 0, 1, duration, stiffness); // Multiply with an exponential ease in
return begin + change * val;
},
easeOutElastic: function (time, begin, change, duration, oscillations, stiffness) {
"use strict";
var val = tbEase.easeInElastic(duration-time, 1, -1, duration, oscillations, stiffness);
return begin + change * val;
},
easeInOutElastic: function (time, begin, change, duration, oscillations, stiffness) {
"use strict";
var val;
if (time < duration/2) {
val = tbEase.easeInElastic(time, 0, 0.5, duration/2, oscillations, stiffness);
} else {
val = tbEase.easeInElastic(duration-time, 1, -0.5, duration/2, oscillations, stiffness);
}
return begin + change * val;
},
easeOutInElastic: function (time, begin, change, duration, oscillations, stiffness) {
"use strict";
var val;
if (time < duration/2) {
val = tbEase.easeInElastic(duration/2-time, 0.5, -0.5, duration/2, oscillations, stiffness);
} else {
val = tbEase.easeInElastic(time-duration/2, 0.5, 0.5, duration/2, oscillations, stiffness);
}
return begin + change * val;
},
easeInOvershoot: function (time, begin, change, duration, overshoot) {
"use strict";
var val;
if (overshoot === undefined) { overshoot = 1.70158; }
val = (1+overshoot) * Math.pow(time/duration, 3) - overshoot * Math.pow(time/duration, 2);
return begin + change * val;
},
easeOutOvershoot: function (time, begin, change, duration, overshoot) {
"use strict";
var val = tbEase.easeInOvershoot(duration-time, 1, -1, duration, overshoot);
return begin + change * val;
},
easeInOutOvershoot: function (time, begin, change, duration, overshoot) {
"use strict";
var val;
if (time < duration/2) {
val = tbEase.easeInOvershoot(time, 0, 0.5, duration/2, overshoot);
} else {
val = tbEase.easeInOvershoot(duration-time, 1, -0.5, duration/2, overshoot);
}
return begin + change * val;
},
easeOutInOvershoot: function (time, begin, change, duration, overshoot) {
"use strict";
var val;
if (time < duration/2) {
val = tbEase.easeInOvershoot(duration/2-time, 0.5, -0.5, duration/2, overshoot);
} else {
val = tbEase.easeInOvershoot(time-duration/2, 0.5, 0.5, duration/2, overshoot);
}
return begin + change * val;
},
easeInBounce: function (time, begin, change, duration, number, factor) {
"use strict";
var bounces, i, w, width, height, val;
// Correct the arguments
if (number === undefined) { number = 4; }
if (factor === undefined) { factor = 2; } else { factor = Math.sqrt(factor); }
// Create the list of bounces
bounces = [1];
width = 1;
for (i = 1; i < number; i += 1) {
bounces.push(bounces[i-1]*factor);
width += bounces[i];
}
// Compute total size
width -= bounces[number-1]/2; // We don't use the last half bounce
height = Math.pow(bounces[number-1],2);
time = time/duration * width;
// Find the correct bounce
w = 0;
for (i = 0; i < number; i += 1) {
if (time > bounces[i]) { time -= bounces[i];} else { w = bounces[i]; break; }
}
// Now compute the value
val = -4 * Math.pow(time-w/2,2) + w * w;
return begin + change * val / height;
},
easeOutBounce: function (time, begin, change, duration, number, factor) {
"use strict";
var val = tbEase.easeInBounce(duration-time, 1, -1, duration, number, factor);
return begin + change * val;
},
easeInOutBounce: function (time, begin, change, duration, number, factor) {
"use strict";
var val;
if (time < duration/2) {
val = tbEase.easeInBounce(time, 0, 0.5, duration/2, number, factor);
} else {
val = tbEase.easeInBounce(duration-time, 1, -0.5, duration/2, number, factor);
}
return begin + change * val;
},
easeOutInBounce: function (time, begin, change, duration, number, factor) {
"use strict";
var val;
if (time < duration/2) {
val = tbEase.easeInBounce(duration/2-time, 0.5, -0.5, duration/2, number, factor);
} else {
val = tbEase.easeInBounce(time-duration/2, 0.5, 0.5, duration/2, number, factor);
}
return begin + change * val;
}
};
@@ -0,0 +1,368 @@var ease = {//// Basic ease functions// easeConstant: function (time, begin, change, duration) { "use strict"; return begin; }, easeLinear: function (time, begin, change, duration) { "use strict"; var val = time/duration; return begin + change * val; }, easeInPower: function (time, begin, change, duration, power) { "use strict"; var val; if (power === undefined) { power = 3; } val = Math.pow(time/duration, power); return begin + change * val; }, easeOutPower: function (time, begin, change, duration, power) { "use strict"; var val = tbEase.easeInPower(duration-time, 1, -1, duration, power); return begin + change * val; }, easeInOutPower: function (time, begin, change, duration, power) { "use strict"; var val; if (time < duration/2) { val = tbEase.easeInPower(time, 0, 0.5, duration/2, power); } else { val = tbEase.easeInPower(duration-time, 1, -0.5, duration/2, power); } return begin + change * val; }, easeOutInPower: function (time, begin, change, duration, power) { "use strict"; var val; if (time < duration/2) { val = tbEase.easeInPower(duration/2-time, 0.5, -0.5, duration/2, power); } else { val = tbEase.easeInPower(time-duration/2, 0.5, 0.5, duration/2, power); } return begin + change * val; }, easeInQuadratic: function (time, begin, change, duration) { "use strict"; return tbEase.easeInPower(time, begin, change, duration, 2); }, easeOutQuadratic: function (time, begin, change, duration) { "use strict"; return tbEase.easeOutPower(time, begin, change, duration, 2); }, easeInOutQuadratic: function (time, begin, change, duration) { "use strict"; return tbEase.easeInOutPower(time, begin, change, duration, 2); }, easeOutInQuadratic: function (time, begin, change, duration) { "use strict"; return tbEase.easeOutInPower(time, begin, change, duration, 2); }, easeInCubic: function (time, begin, change, duration) { "use strict"; return tbEase.easeInPower(time, begin, change, duration, 3); }, easeOutCubic: function (time, begin, change, duration) { "use strict"; return tbEase.easeOutPower(time, begin, change, duration, 3); }, easeInOutCubic: function (time, begin, change, duration) { "use strict"; return tbEase.easeInOutPower(time, begin, change, duration, 3); }, easeOutInCubic: function (time, begin, change, duration) { "use strict"; return tbEase.easeOutInPower(time, begin, change, duration, 3); }, easeInQuartic: function (time, begin, change, duration) { "use strict"; return tbEase.easeInPower(time, begin, change, duration, 4); }, easeOutQuartic: function (time, begin, change, duration) { "use strict"; return tbEase.easeOutPower(time, begin, change, duration, 4); }, easeInOutQuartic: function (time, begin, change, duration) { "use strict"; return tbEase.easeInOutPower(time, begin, change, duration, 4); }, easeOutInQuartic: function (time, begin, change, duration) { "use strict"; return tbEase.easeOutInPower(time, begin, change, duration, 4); }, easeInQuintic: function (time, begin, change, duration) { "use strict"; return tbEase.easeInPower(time, begin, change, duration, 5); }, easeOutQuintic: function (time, begin, change, duration) { "use strict"; return tbEase.easeOutPower(time, begin, change, duration, 5); }, easeInOutQuintic: function (time, begin, change, duration) { "use strict"; return tbEase.easeInOutPower(time, begin, change, duration, 5); }, easeOutInQuintic: function (time, begin, change, duration) { "use strict"; return tbEase.easeOutInPower(time, begin, change, duration, 5); }, easeInExponential: function (time, begin, change, duration, power) { "use strict"; var val, base; if (power === undefined) { power = 8; } base = Math.pow(2, -power); // The exponential function will not cover the whole range from 0-1 so we must correct it val = (Math.pow(2, power * time/duration - power) - base) / (1-base); return begin + change * val; }, easeOutExponential: function (time, begin, change, duration, power) { "use strict"; var val = tbEase.easeInExponential(duration-time, 1, -1, duration, power); return begin + change * val; }, easeInOutExponential: function (time, begin, change, duration, power) { "use strict"; var val; if (time < duration/2) { val = tbEase.easeInExponential(time, 0, 0.5, duration/2, power); } else { val = tbEase.easeInExponential(duration-time, 1, -0.5, duration/2, power); } return begin + change * val; }, easeOutInExponential: function (time, begin, change, duration, power) { "use strict"; var val; if (time < duration/2) { val = tbEase.easeInExponential(duration/2-time, 0.5, -0.5, duration/2, power); } else { val = tbEase.easeInExponential(time-duration/2, 0.5, 0.5, duration/2, power); } return begin + change * val; }, easeInSine: function (time, begin, change, duration) { "use strict"; var val = 1 - Math.cos(time/duration * Math.PI/2); return begin + change * val; }, easeOutSine: function (time, begin, change, duration) { "use strict"; var val = tbEase.easeInSine(duration-time, 1, -1, duration); return begin + change * val; }, easeInOutSine: function (time, begin, change, duration) { "use strict"; var val; if (time < duration/2) { val = tbEase.easeInSine(time, 0, 0.5, duration/2); } else { val = tbEase.easeInSine(duration-time, 1, -0.5, duration/2); } return begin + change * val; }, easeOutInSine: function (time, begin, change, duration) { "use strict"; var val; if (time < duration/2) { val = tbEase.easeInSine(duration/2-time, 0.5, -0.5, duration/2); } else { val = tbEase.easeInSine(time-duration/2, 0.5, 0.5, duration/2); } return begin + change * val; }, easeInCircular: function (time, begin, change, duration) { "use strict"; var val = 1 - Math.sqrt(1 - Math.pow(time/duration, 2)); return begin + change * val; }, easeOutCircular: function (time, begin, change, duration) { "use strict"; var val = tbEase.easeInCircular(duration-time, 1, -1, duration); return begin + change * val; }, easeInOutCircular: function (time, begin, change, duration) { "use strict"; var val; if (time < duration/2) { val = tbEase.easeInCircular(time, 0, 0.5, duration/2); } else { val = tbEase.easeInCircular(duration-time, 1, -0.5, duration/2); } return begin + change * val; }, easeOutInCircular: function (time, begin, change, duration) { "use strict"; var val; if (time < duration/2) { val = tbEase.easeInCircular(duration/2-time, 0.5, -0.5, duration/2); } else { val = tbEase.easeInCircular(time-duration/2, 0.5, 0.5, duration/2); } return begin + change * val; }, easeInElastic: function (time, begin, change, duration, oscillations, stiffness) { "use strict"; var val; if (oscillations === undefined) { oscillations = 3; } if (stiffness === undefined) { stiffness = 8; } val = Math.sin((1-time/duration)*2*Math.PI*oscillations + Math.PI/2); // Create the correct sign val *= tbEase.easeInExponential(time, 0, 1, duration, stiffness); // Multiply with an exponential ease in return begin + change * val; }, easeOutElastic: function (time, begin, change, duration, oscillations, stiffness) { "use strict"; var val = tbEase.easeInElastic(duration-time, 1, -1, duration, oscillations, stiffness); return begin + change * val; }, easeInOutElastic: function (time, begin, change, duration, oscillations, stiffness) { "use strict"; var val; if (time < duration/2) { val = tbEase.easeInElastic(time, 0, 0.5, duration/2, oscillations, stiffness); } else { val = tbEase.easeInElastic(duration-time, 1, -0.5, duration/2, oscillations, stiffness); } return begin + change * val; }, easeOutInElastic: function (time, begin, change, duration, oscillations, stiffness) { "use strict"; var val; if (time < duration/2) { val = tbEase.easeInElastic(duration/2-time, 0.5, -0.5, duration/2, oscillations, stiffness); } else { val = tbEase.easeInElastic(time-duration/2, 0.5, 0.5, duration/2, oscillations, stiffness); } return begin + change * val; }, easeInOvershoot: function (time, begin, change, duration, overshoot) { "use strict"; var val; if (overshoot === undefined) { overshoot = 1.70158; } val = (1+overshoot) * Math.pow(time/duration, 3) - overshoot * Math.pow(time/duration, 2); return begin + change * val; }, easeOutOvershoot: function (time, begin, change, duration, overshoot) { "use strict"; var val = tbEase.easeInOvershoot(duration-time, 1, -1, duration, overshoot); return begin + change * val; }, easeInOutOvershoot: function (time, begin, change, duration, overshoot) { "use strict"; var val; if (time < duration/2) { val = tbEase.easeInOvershoot(time, 0, 0.5, duration/2, overshoot); } else { val = tbEase.easeInOvershoot(duration-time, 1, -0.5, duration/2, overshoot); } return begin + change * val; }, easeOutInOvershoot: function (time, begin, change, duration, overshoot) { "use strict"; var val; if (time < duration/2) { val = tbEase.easeInOvershoot(duration/2-time, 0.5, -0.5, duration/2, overshoot); } else { val = tbEase.easeInOvershoot(time-duration/2, 0.5, 0.5, duration/2, overshoot); } return begin + change * val; }, easeInBounce: function (time, begin, change, duration, number, factor) { "use strict"; var bounces, i, w, width, height, val; // Correct the arguments if (number === undefined) { number = 4; } if (factor === undefined) { factor = 2; } else { factor = Math.sqrt(factor); } // Create the list of bounces bounces = [1]; width = 1; for (i = 1; i < number; i += 1) { bounces.push(bounces[i-1]*factor); width += bounces[i]; } // Compute total size width -= bounces[number-1]/2; // We don't use the last half bounce height = Math.pow(bounces[number-1],2); time = time/duration * width; // Find the correct bounce w = 0; for (i = 0; i < number; i += 1) { if (time > bounces[i]) { time -= bounces[i];} else { w = bounces[i]; break; } } // Now compute the value val = -4 * Math.pow(time-w/2,2) + w * w; return begin + change * val / height; }, easeOutBounce: function (time, begin, change, duration, number, factor) { "use strict"; var val = tbEase.easeInBounce(duration-time, 1, -1, duration, number, factor); return begin + change * val; }, easeInOutBounce: function (time, begin, change, duration, number, factor) { "use strict"; var val; if (time < duration/2) { val = tbEase.easeInBounce(time, 0, 0.5, duration/2, number, factor); } else { val = tbEase.easeInBounce(duration-time, 1, -0.5, duration/2, number, factor); } return begin + change * val; }, easeOutInBounce: function (time, begin, change, duration, number, factor) { "use strict"; var val; if (time < duration/2) { val = tbEase.easeInBounce(duration/2-time, 0.5, -0.5, duration/2, number, factor); } else { val = tbEase.easeInBounce(time-duration/2, 0.5, 0.5, duration/2, number, factor); } return begin + change * val; }};@@ -0,0 +1,178 @@
var baseURL = "http://www.timfalken.com/GameBuilder/v2";
var requiredFiles =
[
baseURL + "/vector.js",
baseURL + "/object.js",
baseURL + "/window.js",
baseURL + "/input.js",
baseURL + "/ion.sound.min.js",
baseURL + "/audio.js"
];
var Engine =
{
x: 0,
y: 0,
w: 0,
h: 0,//stored for window-building
loadRequiredFiles: function(callback)
{
Engine.loadScripts(requiredFiles, callback);
},
/*
//function that can include an array of scripts one-by-one
Usage: Engine.loadScripts(scripts, callback)
scripts: Array of strings, each an URL to a .js file.
callback: A function to call when loading has finished.
Note: Function has an "index" parameter. This is for internal use and should be ignored.
*/
//<DOC> category Engine
//<DOC> <function> Engine.loadScripts(scripts, callback)<br><br>Include an array 'scripts' from an external source. When finished, start the function 'callback'.
loadScripts: function(scripts, callback, index)
{
if(index == null)
{
index = 0;
console.log("GAME: Loading " + scripts.length + " scripts.");
}
console.log("GAME: Loading [" + scripts[index] + "]");
$.getScript(scripts[index], function() //jQuery required for convenience! It's either that, or manually loading each required file.
{
if(index <= scripts.length - 2)
Engine.loadScripts(scripts, callback, index + 1);
else
{
console.log("GAME: Scripts loaded.");
callback();
}
});
}
}
//<DOC> category Game
var Game =
{
stepPrevious: 0,
//<DOC> <parameter> Game.activeObjects<br><br>array containing all existing objects.
activeObjects: [],
userUpdateCallback: null,
//<DOC> <parameter> Game.stepsSinceStart<br><br> Total amount of update steps since the start of the game.
stepsSinceStart: 0,
//<DOC> <function> Game.initialize(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)<br><br>Starts the game, and creates a window at ('windowX', 'windowY'), using 'windowWidth' and 'windowHeight' as sizes for the game window in pixels. 'fps' controls the game's frames-per-second'. As soon as the game is loaded up, it'll call the function 'loadedCallback', so you can properly start the game.
initialize: function(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)
{
console.log("GAME: Initializing. Loading dependencies...");
Engine.x = windowX;
Engine.y = windowY;
Engine.w = windowWidth;
Engine.h = windowHeight;
Engine.loadRequiredFiles(function()
{
GameWindow.init(Engine.x, Engine.y, Engine.w, Engine.h);
GameInput.g_init();
window.setInterval(Game.gameStep, 1000 / fps);
loadedCallback();
});
},
//<DOC> <function> Game.setUpdateFunction(callback)<br><br>Assigns a function 'callback(deltaTime)' to be called every frame of the game. You can use this to run global code for your game.
setUpdateFunction: function(callback)
{
Game.userUpdateCallback = callback;
},
//<DOC> <function> Game.clearScene()<br><br>destroys every object in the scene.
clearScene: function()
{
for(var i = 0; i < Game.activeObjects.length; i++)
Game.activeObjects[i].destroy();
},
gameStep: function()
{
var stepTime = Date.now();
var stepTimeCurr = (stepTime - this.stepPrevious) * 0.001;
if(isNaN(stepTimeCurr))
stepTimeCurr = 0;
Game.stepsSinceStart++;
GameInput.g_updateKeys();
var toUpdate = Game.activeObjects.slice();
for(var i = 0; i < toUpdate.length; i++)
{
if(toUpdate[i].active)
toUpdate[i].g_updateStep(stepTimeCurr);
}
if (typeof Game.userUpdateCallback == 'function') { Game.userUpdateCallback(stepTimeCurr); }
GameWindow.redraw();
this.stepPrevious = stepTime;
}
};
//<DOC> <category> Image
//<DOC> <function> Constructor: new image(urlToImage, subImages = 1, subImagesPerRow = 1)
function image(url, subImgTotal = 1, perRow = 1)
{
//<DOC> <parameter> image.subImages<br><br>The total number of subimages in the image. Defaults to 1.
this.subImages = subImgTotal;
//<DOC> <parameter> image.subImagesPerRow<br><br>The total number of subimages per row. Defaults to 1.
this.subImagesPerRow = perRow;
$("body").append('<img id="image" src="' + url + '" style="display:none;"></img>');
this.g_image = $("#image")[0];
$("#image").attr("id","");
//<DOC> <function> image.draw(sourceX, sourceY, sourceWidth, destX, destY, destWidth, destHeight, rotation, alpha)<br><br>Draw the image on screen.
this.draw = function(sx, sy, sw, sh, dx, dy, dw, dh, rotation, alpha)
{
var shouldDraw = true;
if(dx < -Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2)))
shouldDraw = false;
if(dy < -Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2)))
shouldDraw = false;
if(dx > GameWindow.width + Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2)))
shouldDraw = false;
if(dy > GameWindow.height + Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2)))
shouldDraw = false;
if(shouldDraw)
{
var context = GameWindow.canvasContext;
context.save();
var oldAlpha = context.globalAlpha;
context.globalAlpha = alpha;
context.translate(dx, dy);
context.rotate(rotation * (Math.PI/180));
context.drawImage(this.g_image, sx, sy, sw, sh, -dw/2, -dh/2, dw, dh);
context.restore();
context.globalAlpha = oldAlpha;
}
}
}
@@ -0,0 +1,178 @@var baseURL = "http://www.timfalken.com/GameBuilder/v2";var requiredFiles = [ baseURL + "/vector.js", baseURL + "/object.js", baseURL + "/window.js", baseURL + "/input.js", baseURL + "/ion.sound.min.js", baseURL + "/audio.js"];var Engine = { x: 0, y: 0, w: 0, h: 0,//stored for window-building loadRequiredFiles: function(callback) { Engine.loadScripts(requiredFiles, callback); }, /* //function that can include an array of scripts one-by-one Usage: Engine.loadScripts(scripts, callback) scripts: Array of strings, each an URL to a .js file. callback: A function to call when loading has finished. Note: Function has an "index" parameter. This is for internal use and should be ignored. */ //<DOC> category Engine //<DOC> <function> Engine.loadScripts(scripts, callback)<br><br>Include an array 'scripts' from an external source. When finished, start the function 'callback'. loadScripts: function(scripts, callback, index) { if(index == null) { index = 0; console.log("GAME: Loading " + scripts.length + " scripts."); } console.log("GAME: Loading [" + scripts[index] + "]"); $.getScript(scripts[index], function() //jQuery required for convenience! It's either that, or manually loading each required file. { if(index <= scripts.length - 2) Engine.loadScripts(scripts, callback, index + 1); else { console.log("GAME: Scripts loaded."); callback(); } }); }}//<DOC> category Gamevar Game = { stepPrevious: 0, //<DOC> <parameter> Game.activeObjects<br><br>array containing all existing objects. activeObjects: [], userUpdateCallback: null, //<DOC> <parameter> Game.stepsSinceStart<br><br> Total amount of update steps since the start of the game. stepsSinceStart: 0, //<DOC> <function> Game.initialize(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)<br><br>Starts the game, and creates a window at ('windowX', 'windowY'), using 'windowWidth' and 'windowHeight' as sizes for the game window in pixels. 'fps' controls the game's frames-per-second'. As soon as the game is loaded up, it'll call the function 'loadedCallback', so you can properly start the game. initialize: function(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback) { console.log("GAME: Initializing. Loading dependencies..."); Engine.x = windowX; Engine.y = windowY; Engine.w = windowWidth; Engine.h = windowHeight; Engine.loadRequiredFiles(function() { GameWindow.init(Engine.x, Engine.y, Engine.w, Engine.h); GameInput.g_init(); window.setInterval(Game.gameStep, 1000 / fps); loadedCallback(); }); }, //<DOC> <function> Game.setUpdateFunction(callback)<br><br>Assigns a function 'callback(deltaTime)' to be called every frame of the game. You can use this to run global code for your game. setUpdateFunction: function(callback) { Game.userUpdateCallback = callback; }, //<DOC> <function> Game.clearScene()<br><br>destroys every object in the scene. clearScene: function() { for(var i = 0; i < Game.activeObjects.length; i++) Game.activeObjects[i].destroy(); }, gameStep: function() { var stepTime = Date.now(); var stepTimeCurr = (stepTime - this.stepPrevious) * 0.001; if(isNaN(stepTimeCurr)) stepTimeCurr = 0; Game.stepsSinceStart++; GameInput.g_updateKeys(); var toUpdate = Game.activeObjects.slice(); for(var i = 0; i < toUpdate.length; i++) { if(toUpdate[i].active) toUpdate[i].g_updateStep(stepTimeCurr); } if (typeof Game.userUpdateCallback == 'function') { Game.userUpdateCallback(stepTimeCurr); } GameWindow.redraw(); this.stepPrevious = stepTime; }};//<DOC> <category> Image//<DOC> <function> Constructor: new image(urlToImage, subImages = 1, subImagesPerRow = 1)function image(url, subImgTotal = 1, perRow = 1){ //<DOC> <parameter> image.subImages<br><br>The total number of subimages in the image. Defaults to 1. this.subImages = subImgTotal; //<DOC> <parameter> image.subImagesPerRow<br><br>The total number of subimages per row. Defaults to 1. this.subImagesPerRow = perRow; $("body").append('<img id="image" src="' + url + '" style="display:none;"></img>'); this.g_image = $("#image")[0]; $("#image").attr("id",""); //<DOC> <function> image.draw(sourceX, sourceY, sourceWidth, destX, destY, destWidth, destHeight, rotation, alpha)<br><br>Draw the image on screen. this.draw = function(sx, sy, sw, sh, dx, dy, dw, dh, rotation, alpha) { var shouldDraw = true; if(dx < -Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2))) shouldDraw = false; if(dy < -Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2))) shouldDraw = false; if(dx > GameWindow.width + Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2))) shouldDraw = false; if(dy > GameWindow.height + Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2))) shouldDraw = false; if(shouldDraw) { var context = GameWindow.canvasContext; context.save(); var oldAlpha = context.globalAlpha; context.globalAlpha = alpha; context.translate(dx, dy); context.rotate(rotation * (Math.PI/180)); context.drawImage(this.g_image, sx, sy, sw, sh, -dw/2, -dh/2, dw, dh); context.restore(); context.globalAlpha = oldAlpha; } }}@@ -0,0 +1,21 @@
<html>
<head>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<section id="textBox">
<div class="exampleContainer">
<p class="exampleName"> <a href="template"> Empty Template </a> </p>
<p class="exampleDescription"> An empty template to start a project with! </p>
</div>
<div class="exampleContainer">
<p class="exampleName"> <a href="space"> Spaceship! </a> </p>
<p class="exampleDescription"> Fly around in space and shoot stuff. Infinite scrolling! </p>
</div>
</section>
</body>
</html>
@@ -0,0 +1,21 @@<html> <head> <link rel="stylesheet" href="style.css"/> </head> <body> <section id="textBox"> <div class="exampleContainer"> <p class="exampleName"> <a href="template"> Empty Template </a> </p> <p class="exampleDescription"> An empty template to start a project with! </p> </div> <div class="exampleContainer"> <p class="exampleName"> <a href="space"> Spaceship! </a> </p> <p class="exampleDescription"> Fly around in space and shoot stuff. Infinite scrolling! </p> </div> </section> </body></html>The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -0,0 +1,17 @@
<html>
<head>
</head>
<body>
<script src="http://www.timfalken.com/jquery.js"></script> <!--jQuery, which is required by game engine -->
<script src="http://www.timfalken.com/GameBuilder/v2/engine.js"></script> <!-- the actual game engine to do cool stuff with -->
<script src="main.js"></script> <!-- Our own script, which will interact with the engine to make a game! -->
<div style="position: absolute; top: 90%;"> <!-- tiny block of text containing download link, you can delete these as I'm guessing you won't need them. -->
Arrow keys to move, space to shoot!<br>
<a href="space.zip" target="blank">Download this example</a>
</div>
</body>
</html>
@@ -0,0 +1,17 @@<html> <head> </head> <body> <script src="http://www.timfalken.com/jquery.js"></script> <!--jQuery, which is required by game engine --> <script src="http://www.timfalken.com/GameBuilder/v2/engine.js"></script> <!-- the actual game engine to do cool stuff with --> <script src="main.js"></script> <!-- Our own script, which will interact with the engine to make a game! --> <div style="position: absolute; top: 90%;"> <!-- tiny block of text containing download link, you can delete these as I'm guessing you won't need them. --> Arrow keys to move, space to shoot!<br> <a href="space.zip" target="blank">Download this example</a> </div> </body> </html>@@ -0,0 +1,202 @@
$(init);
//load in images
var s_bullet = new image("images/bullet.gif");
var s_ship = new image("images/ship.png");
var s_star = new image("images/star.png");
var s_timer = new image("images/timerPlaceholder.png", 10, 10); //10 subimages, with 10 per row. (So just one row in this example.)
var soundsFolder = "sounds";
var sounds =
[
"shoot"
]; //List of all sound files as strings (do not include file extension)
function init()
{
Game.initialize(20, 20, 500, 500, 60, gameStart); //Start game engine. Create a window at 20,20, width 500 and height 500, 60 frames per second. As soon as loading is done, it'll call gameStart().
}
function gameStart()
{
GameWindow.backgroundColor = {r:0, g:0, b:0};
Game.setUpdateFunction(update); //Let the game engine know we want to link our 'update()' to the game's update step.
GameAudio.init(sounds, soundsFolder);
GameObject.create(backgroundTemplate, 250, 250); //create the background object! (Big black block)
player = GameObject.create(player, 250, 250); //create the player ship at the center of the screen
GameObject.create(block, 300, 300); //create an empty block which does nothing
for(var i = 0; i < 20; i++) //create a bunch of stars!
GameObject.create(star, Math.random() * GameWindow.width, Math.random() * GameWindow.height);
}
function update()
{
for(var i = 0; i < Game.activeObjects.length; i++)//loop through all existing objects
{
if(Game.activeObjects[i].name != "player") //if the current object is not the player...
{
var obj = Game.activeObjects[i]; //put object reference into a variable
obj.transform.position = obj.transform.position.add(player.velocity.stretch(-1)); //move object according to player's velocity vector.
/*
* We're doing this to create an illusion of movement. By moving everything but the player,
* it will appear as if the player is moving, and the camera follows.
* Objects can still manipulate their position.
*/
if(obj.transform.position.distanceTo(player.transform.position) > 1000) //If the object is really far away...
obj.destroy(); //just delete it. (If you're expanding this, make sure not to delete important objects!)
}
}
//You can add code here which will be executed every frame. (recommended to do this in individual objects whenever possible)
}
var block =
{
start: function()
{
this.renderer.image = s_timer;
},
update: function(deltaTime)
{
this.renderer.subImage += deltaTime;
}
}
var bullet =
{
start: function()
{
this.additionalSpeed = player.velocity.getCopy(); //Bullets copy the initial speed of the shooter. Like throwing an apple out of a moving car; it'll still be moving along with the car until it hits the ground and explodes. Waste of an apple, really.
this.renderer.image = s_bullet;
this.transform.width = 10;
this.transform.height = 30; //it's a bit stretched, but it'll look fun that way. Collision detection will be off, but there are no enemies here anyway so whatever.
},
update: function()
{
this.transform.position = this.transform.position.add( this.transform.forward().stretch(25) ).add(this.additionalSpeed); //Make bullet move forwards!
},
onCollision: function(other)
{
if(other.name != "player") //If i'm colliding with something that's not the player, delete myself.
this.destroy();
}
}
var star =
{
start: function()
{
this.ignoreCollisions = true; //Stars are background objects, so we don't want to check for collisions.
this.name = "star"; //It's a star, what else is there to say?
this.transform.width = 2; //tiny star.
this.transform.height = 2;
this.color = "white"; //You can change this, but most stars are white so I made these white too.
this.renderer.image = s_star;
},
update: function()
{
if(this.transform.position.x < 0 || this.transform.position.x > GameWindow.width || this.transform.position.y < 0 || this.transform.position.y > GameWindow.height)
this.reposition(); //If I'm at the border of the screen, or past it, reposition myself!
},
reposition: function()
{
//Put myself at a random spot at a screen border
if(Math.random() > 0.5) //Horizontal of vertical? Coin flip it is!
{
this.transform.position.x = (Math.random() > 0.5? 0 : GameWindow.width); //Another coinflip to decide which side to go to.
this.transform.position.y = Math.random() * GameWindow.width; //random point along the border.
}
else
{
this.transform.position.y = (Math.random() > 0.5? 0 : GameWindow.height); //Same as above, but on another axis.
this.transform.position.x = Math.random() * GameWindow.height;
}
},
onDestroy: function()
{
GameObject.create(star, -100, -100); //Stars should never be destroyed. If it is anyway, make a new one.
}
}
var player = //Player ship that flies around and shoots and stuff.
{
start: function()
{
this.cooldown = 30; //gun cooldown variable!
this.name = "player";
this.renderer.image = s_ship;
this.rotSpeed = 2; //how fast can we turn?
this.accelleration = 0.2; //Engine power!
this.gunOffset = 13; //This will help shoot the bullets from the wings instead of the center.
this.velocity = new vector(0, 0); //We start out stationary.
},
update: function()
{
if(GameInput.isHeld(37)) //Left key pressed? Turn left!
this.transform.rotation -= this.rotSpeed;
if(GameInput.isHeld(39)) //right key pressed? Turn right!
this.transform.rotation += this.rotSpeed;
if(GameInput.isHeld(38)) //Forward key held? Geronimo!
this.velocity = this.velocity.add(this.transform.forward().stretch(this.accelleration));
if(GameInput.isHeld(40)) //Backwards key held? Retreat!
this.velocity = this.velocity.add(this.transform.back().stretch(this.accelleration));
this.cooldown--; //let gun cooldown timer run
if(GameInput.isHeld(32)) //fire key held?
{
if(this.cooldown < 0) //cooldown timer expired?
{
GameAudio.play("shoot"); //Pew pew pew
this.gunOffset *= -1; //reverse gun offset to alternate the bullet origin
var creationPos = this.transform.position.add(this.transform.forward().stretch(1).add(this.transform.right().stretch(this.gunOffset))); //determine position at which the bullet will be created.
var newBullet = GameObject.create(bullet, creationPos.x, creationPos.y); //make a new bullet
newBullet.transform.rotation = this.transform.rotation; //rotate the bullet
newBullet.transform.rotation += -5 + (Math.random() * 10); //wiggle the bullet for a bit so we're not insanely accurate. Looks cooler.
this.cooldown = 5; //set the cooldown to some number to delay the next shot.
this.velocity = this.velocity.add(this.transform.back().stretch(this.accelleration * 0.1)); //Knockback in space!
}
}
}
}
var backgroundTemplate = //Big block which sticks to screen center!
{
start: function()
{
this.ignoreCollisions = true;
this.name = "background";
this.color = "black";
this.transform.width = 1000;
this.transform.height = 1000;
},
update: function()
{
this.transform.position.x = 250;
this.transform.position.y = 250;
}
}
@@ -0,0 +1,202 @@$(init);//load in imagesvar s_bullet = new image("images/bullet.gif");var s_ship = new image("images/ship.png");var s_star = new image("images/star.png");var s_timer = new image("images/timerPlaceholder.png", 10, 10); //10 subimages, with 10 per row. (So just one row in this example.)var soundsFolder = "sounds";var sounds = [ "shoot"]; //List of all sound files as strings (do not include file extension)function init(){ Game.initialize(20, 20, 500, 500, 60, gameStart); //Start game engine. Create a window at 20,20, width 500 and height 500, 60 frames per second. As soon as loading is done, it'll call gameStart().}function gameStart(){ GameWindow.backgroundColor = {r:0, g:0, b:0}; Game.setUpdateFunction(update); //Let the game engine know we want to link our 'update()' to the game's update step. GameAudio.init(sounds, soundsFolder); GameObject.create(backgroundTemplate, 250, 250); //create the background object! (Big black block) player = GameObject.create(player, 250, 250); //create the player ship at the center of the screen GameObject.create(block, 300, 300); //create an empty block which does nothing for(var i = 0; i < 20; i++) //create a bunch of stars! GameObject.create(star, Math.random() * GameWindow.width, Math.random() * GameWindow.height);}function update(){ for(var i = 0; i < Game.activeObjects.length; i++)//loop through all existing objects { if(Game.activeObjects[i].name != "player") //if the current object is not the player... { var obj = Game.activeObjects[i]; //put object reference into a variable obj.transform.position = obj.transform.position.add(player.velocity.stretch(-1)); //move object according to player's velocity vector. /* * We're doing this to create an illusion of movement. By moving everything but the player, * it will appear as if the player is moving, and the camera follows. * Objects can still manipulate their position. */ if(obj.transform.position.distanceTo(player.transform.position) > 1000) //If the object is really far away... obj.destroy(); //just delete it. (If you're expanding this, make sure not to delete important objects!) } } //You can add code here which will be executed every frame. (recommended to do this in individual objects whenever possible)}var block = { start: function() { this.renderer.image = s_timer; }, update: function(deltaTime) { this.renderer.subImage += deltaTime; }}var bullet ={ start: function() { this.additionalSpeed = player.velocity.getCopy(); //Bullets copy the initial speed of the shooter. Like throwing an apple out of a moving car; it'll still be moving along with the car until it hits the ground and explodes. Waste of an apple, really. this.renderer.image = s_bullet; this.transform.width = 10; this.transform.height = 30; //it's a bit stretched, but it'll look fun that way. Collision detection will be off, but there are no enemies here anyway so whatever. }, update: function() { this.transform.position = this.transform.position.add( this.transform.forward().stretch(25) ).add(this.additionalSpeed); //Make bullet move forwards! }, onCollision: function(other) { if(other.name != "player") //If i'm colliding with something that's not the player, delete myself. this.destroy(); }}var star = { start: function() { this.ignoreCollisions = true; //Stars are background objects, so we don't want to check for collisions. this.name = "star"; //It's a star, what else is there to say? this.transform.width = 2; //tiny star. this.transform.height = 2; this.color = "white"; //You can change this, but most stars are white so I made these white too. this.renderer.image = s_star; }, update: function() { if(this.transform.position.x < 0 || this.transform.position.x > GameWindow.width || this.transform.position.y < 0 || this.transform.position.y > GameWindow.height) this.reposition(); //If I'm at the border of the screen, or past it, reposition myself! }, reposition: function() { //Put myself at a random spot at a screen border if(Math.random() > 0.5) //Horizontal of vertical? Coin flip it is! { this.transform.position.x = (Math.random() > 0.5? 0 : GameWindow.width); //Another coinflip to decide which side to go to. this.transform.position.y = Math.random() * GameWindow.width; //random point along the border. } else { this.transform.position.y = (Math.random() > 0.5? 0 : GameWindow.height); //Same as above, but on another axis. this.transform.position.x = Math.random() * GameWindow.height; } }, onDestroy: function() { GameObject.create(star, -100, -100); //Stars should never be destroyed. If it is anyway, make a new one. } }var player = //Player ship that flies around and shoots and stuff.{ start: function() { this.cooldown = 30; //gun cooldown variable! this.name = "player"; this.renderer.image = s_ship; this.rotSpeed = 2; //how fast can we turn? this.accelleration = 0.2; //Engine power! this.gunOffset = 13; //This will help shoot the bullets from the wings instead of the center. this.velocity = new vector(0, 0); //We start out stationary. }, update: function() { if(GameInput.isHeld(37)) //Left key pressed? Turn left! this.transform.rotation -= this.rotSpeed; if(GameInput.isHeld(39)) //right key pressed? Turn right! this.transform.rotation += this.rotSpeed; if(GameInput.isHeld(38)) //Forward key held? Geronimo! this.velocity = this.velocity.add(this.transform.forward().stretch(this.accelleration)); if(GameInput.isHeld(40)) //Backwards key held? Retreat! this.velocity = this.velocity.add(this.transform.back().stretch(this.accelleration)); this.cooldown--; //let gun cooldown timer run if(GameInput.isHeld(32)) //fire key held? { if(this.cooldown < 0) //cooldown timer expired? { GameAudio.play("shoot"); //Pew pew pew this.gunOffset *= -1; //reverse gun offset to alternate the bullet origin var creationPos = this.transform.position.add(this.transform.forward().stretch(1).add(this.transform.right().stretch(this.gunOffset))); //determine position at which the bullet will be created. var newBullet = GameObject.create(bullet, creationPos.x, creationPos.y); //make a new bullet newBullet.transform.rotation = this.transform.rotation; //rotate the bullet newBullet.transform.rotation += -5 + (Math.random() * 10); //wiggle the bullet for a bit so we're not insanely accurate. Looks cooler. this.cooldown = 5; //set the cooldown to some number to delay the next shot. this.velocity = this.velocity.add(this.transform.back().stretch(this.accelleration * 0.1)); //Knockback in space! } } }}var backgroundTemplate = //Big block which sticks to screen center!{ start: function() { this.ignoreCollisions = true; this.name = "background"; this.color = "black"; this.transform.width = 1000; this.transform.height = 1000; }, update: function() { this.transform.position.x = 250; this.transform.position.y = 250; }}The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -0,0 +1,24 @@
#textBox
{
align-content: center;
position: absolute;
}
.exampleName
{
border-bottom: 1px dotted black;
font-size: 30;
padding: 10px;
}
.exampleDescription
{
padding: 10px;
}
.exampleContainer
{
border: 1px solid black;
float: left;
margin: 5px;
}
@@ -0,0 +1,24 @@#textBox{ align-content: center; position: absolute;}.exampleName{ border-bottom: 1px dotted black; font-size: 30; padding: 10px;}.exampleDescription{ padding: 10px;}.exampleContainer{ border: 1px solid black; float: left; margin: 5px;}The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -0,0 +1,17 @@
<html>
<head>
</head>
<body>
<script src="http://www.timfalken.com/jquery.js"></script> <!--jQuery, which is required by game engine -->
<script src="http://www.timfalken.com/GameBuilder/v2/engine.js"></script> <!-- the actual game engine to do cool stuff with -->
<script src="main.js"></script> <!-- Our own script, which will interact with the engine to make a game! -->
<div style="position: absolute; top: 90%;"> <!-- tiny block of text containing download link, you can delete these as I'm guessing you won't need them. -->
Arrow keys to move, space to shoot!<br>
<a href="space.zip" target="blank">Download this example</a>
</div>
</body>
</html>
@@ -0,0 +1,17 @@<html> <head> </head> <body> <script src="http://www.timfalken.com/jquery.js"></script> <!--jQuery, which is required by game engine --> <script src="http://www.timfalken.com/GameBuilder/v2/engine.js"></script> <!-- the actual game engine to do cool stuff with --> <script src="main.js"></script> <!-- Our own script, which will interact with the engine to make a game! --> <div style="position: absolute; top: 90%;"> <!-- tiny block of text containing download link, you can delete these as I'm guessing you won't need them. --> Arrow keys to move, space to shoot!<br> <a href="space.zip" target="blank">Download this example</a> </div> </body> </html>@@ -0,0 +1,46 @@
$(init);
//load in images
var s_timer = new image("images/timerPlaceholder.png", 10, 10); //10 subimages, with 10 per row. (So just one row in this example.)
var soundsFolder = "sounds";
var sounds =
[
"shoot"
]; //List of all sound files as strings (do not include file extension)
function init()
{
Game.initialize(20, 20, 500, 500, 60, gameStart); //Start game engine. Create a window at 20,20, width 500 and height 500, 60 frames per second. As soon as loading is done, it'll call gameStart().
}
function gameStart()
{
GameWindow.backgroundColor = {r:0, g:0, b:0};
Game.setUpdateFunction(update); //Let the game engine know we want to link our 'update()' to the game's update step.
GameAudio.init(sounds, soundsFolder);
GameObject.create(block, 300, 300); //create an empty block which does nothing
}
function update()
{
//You can add code here which will be executed every frame. (recommended to do this in individual objects whenever possible)
}
var block =
{
start: function()
{
this.renderer.image = s_timer;
this.renderer.image.subImages = 10;
this.renderer.image.subImagesPerRow = 10;
},
update: function(deltaTime)
{
this.renderer.subImage += deltaTime;
}
}
@@ -0,0 +1,46 @@$(init);//load in imagesvar s_timer = new image("images/timerPlaceholder.png", 10, 10); //10 subimages, with 10 per row. (So just one row in this example.)var soundsFolder = "sounds";var sounds = [ "shoot"]; //List of all sound files as strings (do not include file extension)function init(){ Game.initialize(20, 20, 500, 500, 60, gameStart); //Start game engine. Create a window at 20,20, width 500 and height 500, 60 frames per second. As soon as loading is done, it'll call gameStart().}function gameStart(){ GameWindow.backgroundColor = {r:0, g:0, b:0}; Game.setUpdateFunction(update); //Let the game engine know we want to link our 'update()' to the game's update step. GameAudio.init(sounds, soundsFolder); GameObject.create(block, 300, 300); //create an empty block which does nothing}function update(){ //You can add code here which will be executed every frame. (recommended to do this in individual objects whenever possible)}var block = { start: function() { this.renderer.image = s_timer; this.renderer.image.subImages = 10; this.renderer.image.subImagesPerRow = 10; }, update: function(deltaTime) { this.renderer.subImage += deltaTime; }}@@ -0,0 +1,2 @@
Sounds originated from ion.sound 3.0.0 and were included in the downloadable bundle, which is also used to produce sound in your games!
Find it here -> http://ionden.com/a/plugins/ion.sound/en.html
@@ -0,0 +1,2 @@Sounds originated from ion.sound 3.0.0 and were included in the downloadable bundle, which is also used to produce sound in your games! Find it here -> http://ionden.com/a/plugins/ion.sound/en.htmlThe contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -0,0 +1,35 @@
//<DOC> category Image. Create using: new image(urlToImage)
function image(url)
{
//<DOC> <parameter> image.subImages<br><br>The total number of subimages in the image. Defaults to 1.
this.subImages = 1;
//<DOC> <parameter> image.subImagesPerRow<br><br>The total number of subimages per row. Defaults to 1.
this.subImagesPerRow = 1;
$("body").append('<img id="image" src="' + url + '" style="display:none;"></img>');
this.g_image = $("#image")[0];
$("#image").attr("id","");
//<DOC> <function> image.draw(subImg, x, y, w, h, rotation)<br><br>Draw an image at (x,y), size (w,h), at an angle in degrees.
this.draw = function(subImg, x, y, w, h, rotation)
{
subImg %= this.subImages;
var context = GameWindow.canvasContext;
context.save();
context.translate(x, y);
context.rotate(rotation * (Math.PI/180));
var c = subImg % this.subImagesPerRow;
var r = Math.ceil(subImg / this.subImagesPerRow);
var sw = (this.g_image.width / this.subImagesPerRow);
var sh = (this.g_image.height / Math.ceil(this.subImages / this.subImagesPerRow));
var sx = sw * c;
var sy = sh * r;
context.drawImage(this.g_image, sx, sy, sw, sh, -w/2, -h/2, w, h);
context.restore();
}
}
@@ -0,0 +1,35 @@//<DOC> category Image. Create using: new image(urlToImage)function image(url){ //<DOC> <parameter> image.subImages<br><br>The total number of subimages in the image. Defaults to 1. this.subImages = 1; //<DOC> <parameter> image.subImagesPerRow<br><br>The total number of subimages per row. Defaults to 1. this.subImagesPerRow = 1; $("body").append('<img id="image" src="' + url + '" style="display:none;"></img>'); this.g_image = $("#image")[0]; $("#image").attr("id",""); //<DOC> <function> image.draw(subImg, x, y, w, h, rotation)<br><br>Draw an image at (x,y), size (w,h), at an angle in degrees. this.draw = function(subImg, x, y, w, h, rotation) { subImg %= this.subImages; var context = GameWindow.canvasContext; context.save(); context.translate(x, y); context.rotate(rotation * (Math.PI/180)); var c = subImg % this.subImagesPerRow; var r = Math.ceil(subImg / this.subImagesPerRow); var sw = (this.g_image.width / this.subImagesPerRow); var sh = (this.g_image.height / Math.ceil(this.subImages / this.subImagesPerRow)); var sx = sw * c; var sy = sh * r; context.drawImage(this.g_image, sx, sy, sw, sh, -w/2, -h/2, w, h); context.restore(); }}@@ -0,0 +1,53 @@
//<DOC> category GameInput
var GameInput =
{
g_keyStatus: [],
g_pKeyStatus: [],
g_pressKeyStatus: [],
g_ppressKeyStatus: [],
g_pressBlacklist: [],
g_init: function()
{
document.onkeydown = GameInput.g_setKeyStatus;
document.onkeyup = GameInput.g_setKeyStatus;
},
g_setKeyStatus: function(e)
{
GameInput.g_keyStatus[e.which] = (e.type == "keydown");
if(!GameInput.g_pressBlacklist[e.which])
GameInput.g_pressKeyStatus[e.which] = (e.type == "keydown");
GameInput.g_pressBlacklist[e.which] = (e.type == "keydown"); //only allow single presses if key has been released once
},
g_updateKeys: function()
{
GameInput.g_pKeyStatus = GameInput.g_keyStatus;
GameInput.g_ppressKeyStatus = GameInput.g_pressKeyStatus;
GameInput.g_pressKeyStatus = [];
},
//<DOC> <function> GameInput.IsPressed(keyCode)<br><br>Returns true if the key with given code 'keyCode' was pressed this frame. Only returns true the frame the key is pressed once until the key is released and pressed again.
isPressed: function(keyCode)
{
if(GameInput.g_ppressKeyStatus[keyCode] == null)
return false;
else
return GameInput.g_ppressKeyStatus[keyCode];
},
//<DOC> <function> GameInput.isHeld(keyCode)<br><br>returns true if the key with given code 'keyCode' is currently pressed.
isHeld: function(keyCode)
{
if(GameInput.g_pKeyStatus[keyCode] == null)
return false;
else
return GameInput.g_pKeyStatus[keyCode];
}
}
@@ -0,0 +1,53 @@//<DOC> category GameInputvar GameInput = { g_keyStatus: [], g_pKeyStatus: [], g_pressKeyStatus: [], g_ppressKeyStatus: [], g_pressBlacklist: [], g_init: function() { document.onkeydown = GameInput.g_setKeyStatus; document.onkeyup = GameInput.g_setKeyStatus; }, g_setKeyStatus: function(e) { GameInput.g_keyStatus[e.which] = (e.type == "keydown"); if(!GameInput.g_pressBlacklist[e.which]) GameInput.g_pressKeyStatus[e.which] = (e.type == "keydown"); GameInput.g_pressBlacklist[e.which] = (e.type == "keydown"); //only allow single presses if key has been released once }, g_updateKeys: function() { GameInput.g_pKeyStatus = GameInput.g_keyStatus; GameInput.g_ppressKeyStatus = GameInput.g_pressKeyStatus; GameInput.g_pressKeyStatus = []; }, //<DOC> <function> GameInput.IsPressed(keyCode)<br><br>Returns true if the key with given code 'keyCode' was pressed this frame. Only returns true the frame the key is pressed once until the key is released and pressed again. isPressed: function(keyCode) { if(GameInput.g_ppressKeyStatus[keyCode] == null) return false; else return GameInput.g_ppressKeyStatus[keyCode]; }, //<DOC> <function> GameInput.isHeld(keyCode)<br><br>returns true if the key with given code 'keyCode' is currently pressed. isHeld: function(keyCode) { if(GameInput.g_pKeyStatus[keyCode] == null) return false; else return GameInput.g_pKeyStatus[keyCode]; }}@@ -0,0 +1,39 @@
// Ion.Sound | version 3.0.0 | https://github.com/IonDen/ion.sound
/*
MIT licence
Copyright (C) 2014 by Denis Ineshin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function(l,e,n,r){l.ion=l.ion||{};if(!ion.sound){var m=function(a){a||(a="undefined");if(l.console){console.warn&&"function"===typeof console.warn?console.warn(a):console.log&&"function"===typeof console.log&&console.log(a);var g=n("#debug");if(g.length){var b=g.html();g.html(b+a+"<br/>")}}},f=function(a,b){var c;b=b||{};for(c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b};if("function"!==typeof Audio&&"object"!==typeof Audio)e=function(){m("HTML5 Audio is not supported in this browser")},ion.sound=
e,ion.sound.play=e,ion.sound.stop=e,ion.sound.pause=e,ion.sound.preload=e,ion.sound.destroy=e,e();else{e=/iPad|iPhone|iPod/.test(e.appVersion);var q=0,c={},d={},b;!c.supported&&e?c.supported=["mp3","mp4","aac"]:c.supported||(c.supported=["mp3","ogg","mp4","aac","wav"]);ion.sound=function(a){f(a,c);c.path=c.path||"";c.volume=c.volume||1;c.preload=c.preload||!1;c.multiplay=c.multiplay||!1;c.loop=c.loop||!1;c.sprite=c.sprite||null;c.scope=c.scope||null;c.ready_callback=c.ready_callback||null;c.ended_callback=
c.ended_callback||null;if(q=c.sounds.length)for(b=0;b<q;b++){if(!d[b]){a=c.sounds[b];var g=a.alias||a.name;d[g]||(d[g]=new p(a),d[g].init())}}else m("No sound-files provided!")};ion.sound.VERSION="3.0.0";ion.sound._method=function(a,c,e){if(c)d[c]&&d[c][a](e);else for(b in d)if(d.hasOwnProperty(b))d[b][a](e)};ion.sound.preload=function(a,b){b=b||{};f({preload:!0},b);ion.sound._method("init",a,b)};ion.sound.destroy=function(a){ion.sound._method("destroy",a);if(a)d[a]=null;else for(b in d)d.hasOwnProperty(b)&&
d[b]&&(d[b]=null)};ion.sound.play=function(a,b){ion.sound._method("play",a,b)};ion.sound.stop=function(a,b){ion.sound._method("stop",a,b)};ion.sound.pause=function(a,b){ion.sound._method("pause",a,b)};n&&(n.ionSound=ion.sound);e=l.AudioContext||l.webkitAudioContext;var h;e&&(h=new e);var p=function(a){this.options=f(c);delete this.options.sounds;f(a,this.options);this.request=null;this.streams={};this.result={};this.ext=0;this.url="";this.autoplay=this.no_file=this.decoded=this.loaded=!1};p.prototype=
{init:function(a){a&&f(a,this.options);this.options.preload&&this.load()},destroy:function(){var a;for(b in this.streams)(a=this.streams[b])&&a.destroy();this.streams={};this.result=null;this.options=this.options.buffer=null;this.request&&(this.request.removeEventListener("load",this.ready.bind(this),!1),this.request.removeEventListener("error",this.error.bind(this),!1),this.request.abort(),this.request=null)},createUrl:function(){this.url=this.options.path+this.options.name+"."+this.options.supported[this.ext]+
"?"+(new Date).valueOf()},load:function(){this.no_file?m('No sources for "'+this.options.name+'" sound :('):(this.createUrl(),this.request=new XMLHttpRequest,this.request.open("GET",this.url,!0),this.request.responseType="arraybuffer",this.request.addEventListener("load",this.ready.bind(this),!1),this.request.addEventListener("error",this.error.bind(this),!1),this.request.send())},reload:function(){this.ext++;this.options.supported[this.ext]?this.load():(this.no_file=!0,m('No sources for "'+this.options.name+
'" sound :('))},ready:function(a){this.result=a.target;4!==this.result.readyState?this.reload():200!==this.result.status?(m(this.url+" was not found on server!"),this.reload()):(this.request.removeEventListener("load",this.ready.bind(this),!1),this.request.removeEventListener("error",this.error.bind(this),!1),this.request=null,this.loaded=!0,this.decode())},decode:function(){h&&h.decodeAudioData(this.result.response,this.setBuffer.bind(this),this.error.bind(this))},setBuffer:function(a){this.options.buffer=
a;this.decoded=!0;a={name:this.options.name,alias:this.options.alias,ext:this.options.supported[this.ext],duration:this.options.buffer.duration};this.options.ready_callback&&"function"===typeof this.options.ready_callback&&this.options.ready_callback.call(this.options.scope,a);if(this.options.sprite)for(b in this.options.sprite)this.options.start=this.options.sprite[b][0],this.options.end=this.options.sprite[b][1],this.streams[b]=new k(this.options,b);else this.streams[0]=new k(this.options);this.autoplay&&
(this.autoplay=!1,this.play())},error:function(){this.reload()},play:function(a){delete this.options.part;a&&f(a,this.options);if(!this.loaded)this.options.preload||(this.autoplay=!0,this.load());else if(!this.no_file&&this.decoded)if(this.options.sprite)if(this.options.part)this.streams[this.options.part].play(this.options);else for(b in this.options.sprite)this.streams[b].play(this.options);else this.streams[0].play(this.options)},stop:function(a){if(this.options.sprite)if(a)this.streams[a.part].stop();
else for(b in this.options.sprite)this.streams[b].stop();else this.streams[0].stop()},pause:function(a){if(this.options.sprite)if(a)this.streams[a.part].pause();else for(b in this.options.sprite)this.streams[b].pause();else this.streams[0].pause()}};var k=function(a,b){this.alias=a.alias;this.name=a.name;this.sprite_part=b;this.buffer=a.buffer;this.start=a.start||0;this.end=a.end||this.buffer.duration;this.multiplay=a.multiplay||!1;this.volume=a.volume||1;this.scope=a.scope;this.ended_callback=a.ended_callback;
this.setLoop(a);this.gain=this.source=null;this.paused=this.playing=!1;this.time_offset=this.time_played=this.time_ended=this.time_started=0};k.prototype={destroy:function(){this.stop();this.source=this.buffer=null;this.gain&&this.gain.disconnect();this.source&&this.source.disconnect();this.source=this.gain=null},setLoop:function(a){!0===a.loop?this.loop=9999999:"number"===typeof a.loop&&(this.loop=+a.loop-1)},update:function(a){this.setLoop(a);"volume"in a&&(this.volume=a.volume)},play:function(a){a&&
this.update(a);if(this.multiplay||!this.playing)this.gain=h.createGain(),this.source=h.createBufferSource(),this.source.buffer=this.buffer,this.source.connect(this.gain),this.gain.connect(h.destination),this.gain.gain.value=this.volume,this.source.onended=this.ended.bind(this),this._play()},_play:function(){var a,b;this.paused?(a=this.start+this.time_offset,b=this.end-this.time_offset):(a=this.start,b=this.end);0>=b?this.clear():(this.source.start(0,a,b),this.playing=!0,this.paused=!1,this.time_started=
(new Date).valueOf())},stop:function(){this.source&&this.source.stop(0);this.clear()},pause:function(){this.paused?this.play():this.playing&&(this.source&&this.source.stop(0),this.paused=!0)},ended:function(){this.playing=!1;this.time_ended=(new Date).valueOf();this.time_played=(this.time_ended-this.time_started)/1E3;this.time_offset+=this.time_played;if(this.time_offset>=this.end||.015>this.end-this.time_offset)this._ended(),this.clear(),this.loop&&(this.loop--,this.play())},_ended:function(){var a=
{name:this.name,alias:this.alias,part:this.sprite_part,start:this.start,duration:this.end};this.ended_callback&&"function"===typeof this.ended_callback&&this.ended_callback.call(this.scope,a)},clear:function(){this.time_offset=this.time_played=0;this.playing=this.paused=!1}};h||(function(){var a=new Audio,b=a.canPlayType("audio/mpeg"),e=a.canPlayType("audio/ogg"),a=a.canPlayType('audio/mp4; codecs="mp4a.40.2"'),d,f;for(f=0;f<c.supported.length;f++)d=c.supported[f],b||"mp3"!==d||c.supported.splice(f,
1),e||"ogg"!==d||c.supported.splice(f,1),a||"aac"!==d||c.supported.splice(f,1),a||"mp4"!==d||c.supported.splice(f,1)}(),p.prototype={init:function(a){a&&f(a,this.options);this.inited=!0;this.options.preload&&this.load()},destroy:function(){var a;for(b in this.streams)(a=this.streams[b])&&a.destroy();this.streams={};this.inited=this.loaded=!1},load:function(){var a;this.options.preload=!0;this.options._ready=this.ready;this.options._scope=this;if(this.options.sprite)for(b in this.options.sprite)a=
this.options.sprite[b],this.options.start=a[0],this.options.end=a[1],this.streams[b]=new k(this.options,b);else this.streams[0]=new k(this.options)},ready:function(a){this.loaded||(this.loaded=!0,a={name:this.options.name,alias:this.options.alias,ext:this.options.supported[this.ext],duration:a},this.options.ready_callback&&"function"===typeof this.options.ready_callback&&this.options.ready_callback.call(this.options.scope,a),this.autoplay&&(this.autoplay=!1,this.play()))},play:function(a){if(this.inited)if(delete this.options.part,
a&&f(a,this.options),this.loaded)if(this.options.sprite)if(this.options.part)this.streams[this.options.part].play(this.options);else for(b in this.options.sprite)this.streams[b].play(this.options);else this.streams[0].play(this.options);else this.options.preload||(this.autoplay=!0,this.load())},stop:function(a){if(this.inited)if(this.options.sprite)if(a)this.streams[a.part].stop();else for(b in this.options.sprite)this.streams[b].stop();else this.streams[0].stop()},pause:function(a){if(this.inited)if(this.options.sprite)if(a)this.streams[a.part].pause();
else for(b in this.options.sprite)this.streams[b].pause();else this.streams[0].pause()}},k=function(a,b){this.name=a.name;this.alias=a.alias;this.sprite_part=b;this.multiplay=a.multiplay;this.volume=a.volume;this.preload=a.preload;this.path=c.path;this.start=a.start||0;this.end=a.end||0;this.scope=a.scope;this.ended_callback=a.ended_callback;this._scope=a._scope;this._ready=a._ready;this.setLoop(a);this.url=this.sound=null;this.loaded=!1;this.played_time=this.paused_time=this.start_time=0;this.init()},
k.prototype={init:function(){this.sound=new Audio;this.sound.volume=this.volume;this.createUrl();this.sound.addEventListener("ended",this.ended.bind(this),!1);this.sound.addEventListener("canplaythrough",this.can_play_through.bind(this),!1);this.sound.addEventListener("timeupdate",this._update.bind(this),!1);this.load()},destroy:function(){this.stop();this.sound.removeEventListener("ended",this.ended.bind(this),!1);this.sound.removeEventListener("canplaythrough",this.can_play_through.bind(this),!1);
this.sound.removeEventListener("timeupdate",this._update.bind(this),!1);this.sound=null;this.loaded=!1},createUrl:function(){this.url=this.path+this.name+"."+c.supported[0]+"?"+(new Date).valueOf()},can_play_through:function(){this.preload&&this.ready()},load:function(){this.sound.src=this.url;this.sound.preload=this.preload?"auto":"none";this.preload&&this.sound.load()},setLoop:function(a){!0===a.loop?this.loop=9999999:"number"===typeof a.loop&&(this.loop=+a.loop-1)},update:function(a){this.setLoop(a);
"volume"in a&&(this.volume=a.volume)},ready:function(){!this.loaded&&this.sound&&(this.loaded=!0,this._ready.call(this._scope,this.sound.duration),this.end||(this.end=this.sound.duration))},play:function(a){a&&this.update(a);!this.multiplay&&this.playing||this._play()},_play:function(){if(this.paused)this.paused=!1;else try{this.sound.currentTime=this.start}catch(a){}this.playing=!0;this.start_time=(new Date).valueOf();this.sound.volume=this.volume;this.sound.play()},stop:function(){if(this.playing){this.paused=
this.playing=!1;this.sound.pause();this.clear();try{this.sound.currentTime=this.start}catch(a){}}},pause:function(){this.paused?this._play():(this.playing=!1,this.paused=!0,this.sound.pause(),this.paused_time=(new Date).valueOf(),this.played_time+=this.paused_time-this.start_time)},_update:function(){this.start_time&&(this.played_time+((new Date).valueOf()-this.start_time))/1E3>=this.end&&this.playing&&(this.stop(),this._ended())},ended:function(){this.playing&&(this.stop(),this._ended())},_ended:function(){this.playing=
!1;var a={name:this.name,alias:this.alias,part:this.sprite_part,start:this.start,duration:this.end};this.ended_callback&&"function"===typeof this.ended_callback&&this.ended_callback.call(this.scope,a);this.loop&&setTimeout(this.looper.bind(this),15)},looper:function(){this.loop--;this.play()},clear:function(){this.paused_time=this.played_time=this.start_time=0}})}}})(window,navigator,jQuery||$);
@@ -0,0 +1,39 @@// Ion.Sound | version 3.0.0 | https://github.com/IonDen/ion.sound/*MIT licenceCopyright (C) 2014 by Denis IneshinPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/(function(l,e,n,r){l.ion=l.ion||{};if(!ion.sound){var m=function(a){a||(a="undefined");if(l.console){console.warn&&"function"===typeof console.warn?console.warn(a):console.log&&"function"===typeof console.log&&console.log(a);var g=n("#debug");if(g.length){var b=g.html();g.html(b+a+"<br/>")}}},f=function(a,b){var c;b=b||{};for(c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b};if("function"!==typeof Audio&&"object"!==typeof Audio)e=function(){m("HTML5 Audio is not supported in this browser")},ion.sound=e,ion.sound.play=e,ion.sound.stop=e,ion.sound.pause=e,ion.sound.preload=e,ion.sound.destroy=e,e();else{e=/iPad|iPhone|iPod/.test(e.appVersion);var q=0,c={},d={},b;!c.supported&&e?c.supported=["mp3","mp4","aac"]:c.supported||(c.supported=["mp3","ogg","mp4","aac","wav"]);ion.sound=function(a){f(a,c);c.path=c.path||"";c.volume=c.volume||1;c.preload=c.preload||!1;c.multiplay=c.multiplay||!1;c.loop=c.loop||!1;c.sprite=c.sprite||null;c.scope=c.scope||null;c.ready_callback=c.ready_callback||null;c.ended_callback=c.ended_callback||null;if(q=c.sounds.length)for(b=0;b<q;b++){if(!d[b]){a=c.sounds[b];var g=a.alias||a.name;d[g]||(d[g]=new p(a),d[g].init())}}else m("No sound-files provided!")};ion.sound.VERSION="3.0.0";ion.sound._method=function(a,c,e){if(c)d[c]&&d[c][a](e);else for(b in d)if(d.hasOwnProperty(b))d[b][a](e)};ion.sound.preload=function(a,b){b=b||{};f({preload:!0},b);ion.sound._method("init",a,b)};ion.sound.destroy=function(a){ion.sound._method("destroy",a);if(a)d[a]=null;else for(b in d)d.hasOwnProperty(b)&&d[b]&&(d[b]=null)};ion.sound.play=function(a,b){ion.sound._method("play",a,b)};ion.sound.stop=function(a,b){ion.sound._method("stop",a,b)};ion.sound.pause=function(a,b){ion.sound._method("pause",a,b)};n&&(n.ionSound=ion.sound);e=l.AudioContext||l.webkitAudioContext;var h;e&&(h=new e);var p=function(a){this.options=f(c);delete this.options.sounds;f(a,this.options);this.request=null;this.streams={};this.result={};this.ext=0;this.url="";this.autoplay=this.no_file=this.decoded=this.loaded=!1};p.prototype={init:function(a){a&&f(a,this.options);this.options.preload&&this.load()},destroy:function(){var a;for(b in this.streams)(a=this.streams[b])&&a.destroy();this.streams={};this.result=null;this.options=this.options.buffer=null;this.request&&(this.request.removeEventListener("load",this.ready.bind(this),!1),this.request.removeEventListener("error",this.error.bind(this),!1),this.request.abort(),this.request=null)},createUrl:function(){this.url=this.options.path+this.options.name+"."+this.options.supported[this.ext]+"?"+(new Date).valueOf()},load:function(){this.no_file?m('No sources for "'+this.options.name+'" sound :('):(this.createUrl(),this.request=new XMLHttpRequest,this.request.open("GET",this.url,!0),this.request.responseType="arraybuffer",this.request.addEventListener("load",this.ready.bind(this),!1),this.request.addEventListener("error",this.error.bind(this),!1),this.request.send())},reload:function(){this.ext++;this.options.supported[this.ext]?this.load():(this.no_file=!0,m('No sources for "'+this.options.name+'" sound :('))},ready:function(a){this.result=a.target;4!==this.result.readyState?this.reload():200!==this.result.status?(m(this.url+" was not found on server!"),this.reload()):(this.request.removeEventListener("load",this.ready.bind(this),!1),this.request.removeEventListener("error",this.error.bind(this),!1),this.request=null,this.loaded=!0,this.decode())},decode:function(){h&&h.decodeAudioData(this.result.response,this.setBuffer.bind(this),this.error.bind(this))},setBuffer:function(a){this.options.buffer=a;this.decoded=!0;a={name:this.options.name,alias:this.options.alias,ext:this.options.supported[this.ext],duration:this.options.buffer.duration};this.options.ready_callback&&"function"===typeof this.options.ready_callback&&this.options.ready_callback.call(this.options.scope,a);if(this.options.sprite)for(b in this.options.sprite)this.options.start=this.options.sprite[b][0],this.options.end=this.options.sprite[b][1],this.streams[b]=new k(this.options,b);else this.streams[0]=new k(this.options);this.autoplay&&(this.autoplay=!1,this.play())},error:function(){this.reload()},play:function(a){delete this.options.part;a&&f(a,this.options);if(!this.loaded)this.options.preload||(this.autoplay=!0,this.load());else if(!this.no_file&&this.decoded)if(this.options.sprite)if(this.options.part)this.streams[this.options.part].play(this.options);else for(b in this.options.sprite)this.streams[b].play(this.options);else this.streams[0].play(this.options)},stop:function(a){if(this.options.sprite)if(a)this.streams[a.part].stop();else for(b in this.options.sprite)this.streams[b].stop();else this.streams[0].stop()},pause:function(a){if(this.options.sprite)if(a)this.streams[a.part].pause();else for(b in this.options.sprite)this.streams[b].pause();else this.streams[0].pause()}};var k=function(a,b){this.alias=a.alias;this.name=a.name;this.sprite_part=b;this.buffer=a.buffer;this.start=a.start||0;this.end=a.end||this.buffer.duration;this.multiplay=a.multiplay||!1;this.volume=a.volume||1;this.scope=a.scope;this.ended_callback=a.ended_callback;this.setLoop(a);this.gain=this.source=null;this.paused=this.playing=!1;this.time_offset=this.time_played=this.time_ended=this.time_started=0};k.prototype={destroy:function(){this.stop();this.source=this.buffer=null;this.gain&&this.gain.disconnect();this.source&&this.source.disconnect();this.source=this.gain=null},setLoop:function(a){!0===a.loop?this.loop=9999999:"number"===typeof a.loop&&(this.loop=+a.loop-1)},update:function(a){this.setLoop(a);"volume"in a&&(this.volume=a.volume)},play:function(a){a&&this.update(a);if(this.multiplay||!this.playing)this.gain=h.createGain(),this.source=h.createBufferSource(),this.source.buffer=this.buffer,this.source.connect(this.gain),this.gain.connect(h.destination),this.gain.gain.value=this.volume,this.source.onended=this.ended.bind(this),this._play()},_play:function(){var a,b;this.paused?(a=this.start+this.time_offset,b=this.end-this.time_offset):(a=this.start,b=this.end);0>=b?this.clear():(this.source.start(0,a,b),this.playing=!0,this.paused=!1,this.time_started=(new Date).valueOf())},stop:function(){this.source&&this.source.stop(0);this.clear()},pause:function(){this.paused?this.play():this.playing&&(this.source&&this.source.stop(0),this.paused=!0)},ended:function(){this.playing=!1;this.time_ended=(new Date).valueOf();this.time_played=(this.time_ended-this.time_started)/1E3;this.time_offset+=this.time_played;if(this.time_offset>=this.end||.015>this.end-this.time_offset)this._ended(),this.clear(),this.loop&&(this.loop--,this.play())},_ended:function(){var a={name:this.name,alias:this.alias,part:this.sprite_part,start:this.start,duration:this.end};this.ended_callback&&"function"===typeof this.ended_callback&&this.ended_callback.call(this.scope,a)},clear:function(){this.time_offset=this.time_played=0;this.playing=this.paused=!1}};h||(function(){var a=new Audio,b=a.canPlayType("audio/mpeg"),e=a.canPlayType("audio/ogg"),a=a.canPlayType('audio/mp4; codecs="mp4a.40.2"'),d,f;for(f=0;f<c.supported.length;f++)d=c.supported[f],b||"mp3"!==d||c.supported.splice(f,1),e||"ogg"!==d||c.supported.splice(f,1),a||"aac"!==d||c.supported.splice(f,1),a||"mp4"!==d||c.supported.splice(f,1)}(),p.prototype={init:function(a){a&&f(a,this.options);this.inited=!0;this.options.preload&&this.load()},destroy:function(){var a;for(b in this.streams)(a=this.streams[b])&&a.destroy();this.streams={};this.inited=this.loaded=!1},load:function(){var a;this.options.preload=!0;this.options._ready=this.ready;this.options._scope=this;if(this.options.sprite)for(b in this.options.sprite)a=this.options.sprite[b],this.options.start=a[0],this.options.end=a[1],this.streams[b]=new k(this.options,b);else this.streams[0]=new k(this.options)},ready:function(a){this.loaded||(this.loaded=!0,a={name:this.options.name,alias:this.options.alias,ext:this.options.supported[this.ext],duration:a},this.options.ready_callback&&"function"===typeof this.options.ready_callback&&this.options.ready_callback.call(this.options.scope,a),this.autoplay&&(this.autoplay=!1,this.play()))},play:function(a){if(this.inited)if(delete this.options.part,a&&f(a,this.options),this.loaded)if(this.options.sprite)if(this.options.part)this.streams[this.options.part].play(this.options);else for(b in this.options.sprite)this.streams[b].play(this.options);else this.streams[0].play(this.options);else this.options.preload||(this.autoplay=!0,this.load())},stop:function(a){if(this.inited)if(this.options.sprite)if(a)this.streams[a.part].stop();else for(b in this.options.sprite)this.streams[b].stop();else this.streams[0].stop()},pause:function(a){if(this.inited)if(this.options.sprite)if(a)this.streams[a.part].pause();else for(b in this.options.sprite)this.streams[b].pause();else this.streams[0].pause()}},k=function(a,b){this.name=a.name;this.alias=a.alias;this.sprite_part=b;this.multiplay=a.multiplay;this.volume=a.volume;this.preload=a.preload;this.path=c.path;this.start=a.start||0;this.end=a.end||0;this.scope=a.scope;this.ended_callback=a.ended_callback;this._scope=a._scope;this._ready=a._ready;this.setLoop(a);this.url=this.sound=null;this.loaded=!1;this.played_time=this.paused_time=this.start_time=0;this.init()},k.prototype={init:function(){this.sound=new Audio;this.sound.volume=this.volume;this.createUrl();this.sound.addEventListener("ended",this.ended.bind(this),!1);this.sound.addEventListener("canplaythrough",this.can_play_through.bind(this),!1);this.sound.addEventListener("timeupdate",this._update.bind(this),!1);this.load()},destroy:function(){this.stop();this.sound.removeEventListener("ended",this.ended.bind(this),!1);this.sound.removeEventListener("canplaythrough",this.can_play_through.bind(this),!1);this.sound.removeEventListener("timeupdate",this._update.bind(this),!1);this.sound=null;this.loaded=!1},createUrl:function(){this.url=this.path+this.name+"."+c.supported[0]+"?"+(new Date).valueOf()},can_play_through:function(){this.preload&&this.ready()},load:function(){this.sound.src=this.url;this.sound.preload=this.preload?"auto":"none";this.preload&&this.sound.load()},setLoop:function(a){!0===a.loop?this.loop=9999999:"number"===typeof a.loop&&(this.loop=+a.loop-1)},update:function(a){this.setLoop(a);"volume"in a&&(this.volume=a.volume)},ready:function(){!this.loaded&&this.sound&&(this.loaded=!0,this._ready.call(this._scope,this.sound.duration),this.end||(this.end=this.sound.duration))},play:function(a){a&&this.update(a);!this.multiplay&&this.playing||this._play()},_play:function(){if(this.paused)this.paused=!1;else try{this.sound.currentTime=this.start}catch(a){}this.playing=!0;this.start_time=(new Date).valueOf();this.sound.volume=this.volume;this.sound.play()},stop:function(){if(this.playing){this.paused=this.playing=!1;this.sound.pause();this.clear();try{this.sound.currentTime=this.start}catch(a){}}},pause:function(){this.paused?this._play():(this.playing=!1,this.paused=!0,this.sound.pause(),this.paused_time=(new Date).valueOf(),this.played_time+=this.paused_time-this.start_time)},_update:function(){this.start_time&&(this.played_time+((new Date).valueOf()-this.start_time))/1E3>=this.end&&this.playing&&(this.stop(),this._ended())},ended:function(){this.playing&&(this.stop(),this._ended())},_ended:function(){this.playing=!1;var a={name:this.name,alias:this.alias,part:this.sprite_part,start:this.start,duration:this.end};this.ended_callback&&"function"===typeof this.ended_callback&&this.ended_callback.call(this.scope,a);this.loop&&setTimeout(this.looper.bind(this),15)},looper:function(){this.loop--;this.play()},clear:function(){this.paused_time=this.played_time=this.start_time=0}})}}})(window,navigator,jQuery||$);@@ -0,0 +1,272 @@
//<DOC> category GameObject
var GameObject =
{
textWarned: false,
//<DOC> <function> GameObject.create(template, x, y)<br><br>Creates a new Game Object using the object template 'template' at the position ('x', 'y')
create: function(template, x, y)
{
var newObj = $.extend(true, {}, template);
GameObject.object.call(newObj, x, y);
return newObj;
},
object: function(x, y) //DO NOT use any functions with prefix g_ in your game!
{
//<DOC> <parameter> object.active<br><br>Object is visible and executes it's code when this parameter is true. Set to false to hide and disable the object temporarily.
this.active = true;
//<DOC> <parameter> object.name<br><br>The name of the current object. Defaults to "Object".
this.name = "Object";
//<DOC> <parameter> object.image<br><br>An image object.
this.image = "";
//<DOC> <parameter> object.ignoreCollisions<br><br>Ignores this object when checking for collisions. Useful for background objects.
this.ignoreCollisions = false;
//<DOC> <parameter> object.renderer<br><br>Used for methods and variables related to drawing the object on the screen.
this.renderer = {
//<DOC> <parameter> object.renderer.image<br><br>The image to draw.
image: null,
//<DOC> <parameter> object.renderer.subImage<br><br>The current subimage to draw using the default draw method
subImage: 0,
//<DOC> <parameter> object.renderer.alpha<br><br>Image transparency (0-1) default: 1
alpha: 1,
//<DOC> <parameter> object.renderer.visible<br><br>Value indicating if the object should be drawn (true/false)
visible: true,
//used to correct NaN
g_subImgOld: 0,
//<DOC> <function> image.draw(x, y, w, h, rotation, alpha = 1)<br><br>Draw an image at (x,y), size (w,h), at an angle in degrees.
draw: function(x, y, w, h, rotation)
{
if(isNaN(this.subImage))
{
this.subImage = this.g_subImgOld;
}
else
{
this.g_subImgOld = this.subImage;
}
var subImage = Math.round(this.subImage);
subImage %= this.image.subImages;
var c = subImage % this.image.subImagesPerRow;
var r = Math.floor(subImage / this.image.subImagesPerRow);
var sw = (this.image.g_image.width / this.image.subImagesPerRow);
var sh = (this.image.g_image.height / Math.ceil(this.image.subImages / this.image.subImagesPerRow));
var sx = sw * c;
var sy = sh * r;
this.image.draw(sx, sy, sw, sh, x, y, w, h, rotation, this.alpha);
//context.drawImage(this.image.g_image, sx, sy, sw, sh, -w/2, -h/2, w, h
}
}
this.transform =
{
//<DOC> <parameter> object.transform.position<br><br>A vector() containing the object's position. (measured from object center)
position: new vector(x, y),
//<DOC> <parameter> object.transform.velocity<br><br>A vector() containing the object's speed. (measured from object center)
velocity: new vector(0, 0),
//<DOC> <parameter> object.transform.rotation<br><br>the object's rotation in degrees. Default is zero.
rotation: 0,
//<DOC> <parameter> object.transform.width<br><br>the width of the object, defaults to 32.
width: 32,
//<DOC> <parameter> object.transform.height<br><br>the height of the object, defaults to 32.
height: 32,
//<DOC> <function> object.transform.pointTowards(point)<br><br>Adjust object.transform.rotation to point at vector2() 'point'.
pointTowards: function(point)
{
var delta = point.subtract(this.position);
this.rotation = delta.toAngle();
},
//<DOC> <function> object.transform.left()<br><br>A single pixel left of the object, accounting for rotation.
left: function()
{
return this.g_dir(0);
},
//<DOC> <function> object.transform.right()<br><br>A single pixel right of the object, accounting for rotation.
right: function()
{
return this.g_dir(180);
},
//<DOC> <function> object.transform.forward()<br><br>A single pixel forwards of the object, accounting for rotation.
forward: function()
{
return this.g_dir(90);
},
//<DOC> <function> object.transform.back()<br><br>A single pixel backwards of the object, accounting for rotation.
back: function()
{
return this.g_dir(270);
},
g_dir: function(offset)
{
var myAngleInRadians = (this.rotation + offset) * (Math.PI / 180);
return angleVector = new vector( -Math.cos(myAngleInRadians), -Math.sin(myAngleInRadians) );
}
};
this.g_destroy = false;
this.g_init = function()
{
Game.activeObjects.push(this);
//<DOC> <function> object.start()<br><br>Called on object's creation. Override this on your own object templates!
if (typeof this.start == 'function') { this.start(); }
}
/*this.g_toHTML = function()
{
return '<object id="' + this.name + '" style="' +
'position: absolute;' +
'left:' + (this.transform.position.x - (this.transform.width / 2)) + 'px;' +
'top:' + (this.transform.position.y - (this.transform.height / 2)) + 'px;' +
'width:' + this.transform.width + 'px;' +
'height:' + this.transform.height + 'px;' +
(this.image != ''? 'background-image: url(' + this.image + ');' : 'border: 1px solid black;') +
'transform:rotate(' + this.transform.rotation + 'deg);' +
'background-color:' + this.color + ';' +
'background-repeat:no-repeat;' +
'background-size:100% 100%;' +
'">' + this.text + '</object>';
}*/
this.g_draw = function()
{
if(!this.g_destroy)
{
if(this.draw)
{
//<DOC> <function> object.draw()<br><br>Called on each draw step. If not overridden, default draw is used!
this.draw();
}
else
{
if(this.renderer.image)
this.renderer.draw(this.transform.position.x, this.transform.position.y, this.transform.width, this.transform.height, this.transform.rotation);
/*else //??? makes entire screen colored.
{
GameWindow.canvasContext.fillStyle = "rgb("+ this.transform.position.y+" ," + this.transform.position.x + ",0)"; // sets the color to fill in the rectangle with
GameWindow.canvasContext.fillRect( this.transform.position.x - this.transform.width / 2,
this.transform.position.y - this.transform.height / 2,
this.transform.width,
this.transform.height);
}*/
}
}
}
this.g_updateStep = function(deltaTime)
{
if(this.g_destroy)
{
Game.activeObjects.splice(Game.activeObjects.indexOf(this), 1);
delete this;
}
else
{
//<DOC> <function> object.update(deltaTime)<br><br>Called on each frame start! (Before collision checks of this frame) Override this on your own object templates!
if (typeof this.update == 'function') { this.update(deltaTime); }
this.transform.position.x += this.transform.velocity.x;
this.transform.position.y += this.transform.velocity.y;
if(!this.ignoreCollisions)
{
for(var i = 0; i < Game.activeObjects.length; i++)
{
if(Game.activeObjects[i] != this && !Game.activeObjects[i].ignoreCollisions)
{
var hit = false;
var o2 = Game.activeObjects[i];
//hw = halfWidth, hh = halfHeight
var hw = this.transform.width / 2;
var hh = this.transform.height / 2;
var ohw = o2.transform.width / 2;
var ohh = o2.transform.height / 2;
//CHECK FROM OBJ PERSPECTIVE
var p =
[
[this.transform.position.x - hw, this.transform.position.y - hh],
[this.transform.position.x + hw, this.transform.position.y - hh],
[this.transform.position.x - hw, this.transform.position.y + hh],
[this.transform.position.x + hw, this.transform.position.y + hh]
];
for(var pi = 0; pi < p.length; pi++)
{
if(p[pi][0] > o2.transform.position.x - ohw && p[pi][0] < o2.transform.position.x + ohw)
{
if(p[pi][1] > o2.transform.position.y - ohh && p[pi][1] < o2.transform.position.y + ohh)
{
hit = true;
}
}
}
//CHECK FROM OTHER PERSPECTIVE
var p =
[
[o2.transform.position.x - ohw, o2.transform.position.y - ohh],
[o2.transform.position.x + ohw, o2.transform.position.y - ohh],
[o2.transform.position.x - ohw, o2.transform.position.y + ohh],
[o2.transform.position.x + ohw, o2.transform.position.y + ohh]
];
for(var pi = 0; pi < p.length; pi++)
{
if(p[pi][0] > this.transform.position.x - hw && p[pi][0] < this.transform.position.x + hw)
{
if(p[pi][1] > this.transform.position.y - hh && p[pi][1] < this.transform.position.y + hh)
{
hit = true;
}
}
}
//<DOC> <function> object.onCollision(other)<br><br>Called on object collision. Parameter 'other' is a reference to the object you're colliding with! Override this on your own object templates!
if(hit)
if (typeof this.onCollision == 'function') { this.onCollision(o2); }
}
}
}
}
}
//<DOC> <function> object.destroy()<br><br>Destroys the current object at the end of the current update step.
this.destroy = function()
{
if(!this.g_destroy)
{
//<DOC> <function> object.onDestroy()<br><br>Called on object's destruction. Override this on your own object templates!
if (typeof this.onDestroy == 'function') { this.onDestroy(); }
this.g_destroy = true;
}
}
this.g_init();
}
}
@@ -0,0 +1,272 @@//<DOC> category GameObjectvar GameObject = { textWarned: false, //<DOC> <function> GameObject.create(template, x, y)<br><br>Creates a new Game Object using the object template 'template' at the position ('x', 'y') create: function(template, x, y) { var newObj = $.extend(true, {}, template); GameObject.object.call(newObj, x, y); return newObj; }, object: function(x, y) //DO NOT use any functions with prefix g_ in your game! { //<DOC> <parameter> object.active<br><br>Object is visible and executes it's code when this parameter is true. Set to false to hide and disable the object temporarily. this.active = true; //<DOC> <parameter> object.name<br><br>The name of the current object. Defaults to "Object". this.name = "Object"; //<DOC> <parameter> object.image<br><br>An image object. this.image = ""; //<DOC> <parameter> object.ignoreCollisions<br><br>Ignores this object when checking for collisions. Useful for background objects. this.ignoreCollisions = false; //<DOC> <parameter> object.renderer<br><br>Used for methods and variables related to drawing the object on the screen. this.renderer = { //<DOC> <parameter> object.renderer.image<br><br>The image to draw. image: null, //<DOC> <parameter> object.renderer.subImage<br><br>The current subimage to draw using the default draw method subImage: 0, //<DOC> <parameter> object.renderer.alpha<br><br>Image transparency (0-1) default: 1 alpha: 1, //<DOC> <parameter> object.renderer.visible<br><br>Value indicating if the object should be drawn (true/false) visible: true, //used to correct NaN g_subImgOld: 0, //<DOC> <function> image.draw(x, y, w, h, rotation, alpha = 1)<br><br>Draw an image at (x,y), size (w,h), at an angle in degrees. draw: function(x, y, w, h, rotation) { if(isNaN(this.subImage)) { this.subImage = this.g_subImgOld; } else { this.g_subImgOld = this.subImage; } var subImage = Math.round(this.subImage); subImage %= this.image.subImages; var c = subImage % this.image.subImagesPerRow; var r = Math.floor(subImage / this.image.subImagesPerRow); var sw = (this.image.g_image.width / this.image.subImagesPerRow); var sh = (this.image.g_image.height / Math.ceil(this.image.subImages / this.image.subImagesPerRow)); var sx = sw * c; var sy = sh * r; this.image.draw(sx, sy, sw, sh, x, y, w, h, rotation, this.alpha); //context.drawImage(this.image.g_image, sx, sy, sw, sh, -w/2, -h/2, w, h } } this.transform = { //<DOC> <parameter> object.transform.position<br><br>A vector() containing the object's position. (measured from object center) position: new vector(x, y), //<DOC> <parameter> object.transform.velocity<br><br>A vector() containing the object's speed. (measured from object center) velocity: new vector(0, 0), //<DOC> <parameter> object.transform.rotation<br><br>the object's rotation in degrees. Default is zero. rotation: 0, //<DOC> <parameter> object.transform.width<br><br>the width of the object, defaults to 32. width: 32, //<DOC> <parameter> object.transform.height<br><br>the height of the object, defaults to 32. height: 32, //<DOC> <function> object.transform.pointTowards(point)<br><br>Adjust object.transform.rotation to point at vector2() 'point'. pointTowards: function(point) { var delta = point.subtract(this.position); this.rotation = delta.toAngle(); }, //<DOC> <function> object.transform.left()<br><br>A single pixel left of the object, accounting for rotation. left: function() { return this.g_dir(0); }, //<DOC> <function> object.transform.right()<br><br>A single pixel right of the object, accounting for rotation. right: function() { return this.g_dir(180); }, //<DOC> <function> object.transform.forward()<br><br>A single pixel forwards of the object, accounting for rotation. forward: function() { return this.g_dir(90); }, //<DOC> <function> object.transform.back()<br><br>A single pixel backwards of the object, accounting for rotation. back: function() { return this.g_dir(270); }, g_dir: function(offset) { var myAngleInRadians = (this.rotation + offset) * (Math.PI / 180); return angleVector = new vector( -Math.cos(myAngleInRadians), -Math.sin(myAngleInRadians) ); } }; this.g_destroy = false; this.g_init = function() { Game.activeObjects.push(this); //<DOC> <function> object.start()<br><br>Called on object's creation. Override this on your own object templates! if (typeof this.start == 'function') { this.start(); } } /*this.g_toHTML = function() { return '<object id="' + this.name + '" style="' + 'position: absolute;' + 'left:' + (this.transform.position.x - (this.transform.width / 2)) + 'px;' + 'top:' + (this.transform.position.y - (this.transform.height / 2)) + 'px;' + 'width:' + this.transform.width + 'px;' + 'height:' + this.transform.height + 'px;' + (this.image != ''? 'background-image: url(' + this.image + ');' : 'border: 1px solid black;') + 'transform:rotate(' + this.transform.rotation + 'deg);' + 'background-color:' + this.color + ';' + 'background-repeat:no-repeat;' + 'background-size:100% 100%;' + '">' + this.text + '</object>'; }*/ this.g_draw = function() { if(!this.g_destroy) { if(this.draw) { //<DOC> <function> object.draw()<br><br>Called on each draw step. If not overridden, default draw is used! this.draw(); } else { if(this.renderer.image) this.renderer.draw(this.transform.position.x, this.transform.position.y, this.transform.width, this.transform.height, this.transform.rotation); /*else //??? makes entire screen colored. { GameWindow.canvasContext.fillStyle = "rgb("+ this.transform.position.y+" ," + this.transform.position.x + ",0)"; // sets the color to fill in the rectangle with GameWindow.canvasContext.fillRect( this.transform.position.x - this.transform.width / 2, this.transform.position.y - this.transform.height / 2, this.transform.width, this.transform.height); }*/ } } } this.g_updateStep = function(deltaTime) { if(this.g_destroy) { Game.activeObjects.splice(Game.activeObjects.indexOf(this), 1); delete this; } else { //<DOC> <function> object.update(deltaTime)<br><br>Called on each frame start! (Before collision checks of this frame) Override this on your own object templates! if (typeof this.update == 'function') { this.update(deltaTime); } this.transform.position.x += this.transform.velocity.x; this.transform.position.y += this.transform.velocity.y; if(!this.ignoreCollisions) { for(var i = 0; i < Game.activeObjects.length; i++) { if(Game.activeObjects[i] != this && !Game.activeObjects[i].ignoreCollisions) { var hit = false; var o2 = Game.activeObjects[i]; //hw = halfWidth, hh = halfHeight var hw = this.transform.width / 2; var hh = this.transform.height / 2; var ohw = o2.transform.width / 2; var ohh = o2.transform.height / 2; //CHECK FROM OBJ PERSPECTIVE var p = [ [this.transform.position.x - hw, this.transform.position.y - hh], [this.transform.position.x + hw, this.transform.position.y - hh], [this.transform.position.x - hw, this.transform.position.y + hh], [this.transform.position.x + hw, this.transform.position.y + hh] ]; for(var pi = 0; pi < p.length; pi++) { if(p[pi][0] > o2.transform.position.x - ohw && p[pi][0] < o2.transform.position.x + ohw) { if(p[pi][1] > o2.transform.position.y - ohh && p[pi][1] < o2.transform.position.y + ohh) { hit = true; } } } //CHECK FROM OTHER PERSPECTIVE var p = [ [o2.transform.position.x - ohw, o2.transform.position.y - ohh], [o2.transform.position.x + ohw, o2.transform.position.y - ohh], [o2.transform.position.x - ohw, o2.transform.position.y + ohh], [o2.transform.position.x + ohw, o2.transform.position.y + ohh] ]; for(var pi = 0; pi < p.length; pi++) { if(p[pi][0] > this.transform.position.x - hw && p[pi][0] < this.transform.position.x + hw) { if(p[pi][1] > this.transform.position.y - hh && p[pi][1] < this.transform.position.y + hh) { hit = true; } } } //<DOC> <function> object.onCollision(other)<br><br>Called on object collision. Parameter 'other' is a reference to the object you're colliding with! Override this on your own object templates! if(hit) if (typeof this.onCollision == 'function') { this.onCollision(o2); } } } } } } //<DOC> <function> object.destroy()<br><br>Destroys the current object at the end of the current update step. this.destroy = function() { if(!this.g_destroy) { //<DOC> <function> object.onDestroy()<br><br>Called on object's destruction. Override this on your own object templates! if (typeof this.onDestroy == 'function') { this.onDestroy(); } this.g_destroy = true; } } this.g_init(); }}@@ -0,0 +1,114 @@
//<DOC> category vector()
function vector(x, y)
{
//<DOC> <parameter> vector.x<br><br>the X axis of the vector.
this.x = x;
//<DOC> <parameter> vector.y<br><br>the Y axis of the vector.
this.y = y;
//<DOC> <function> vector.length()<br><br>returns the length of the vector.
this.length = function()
{
return Math.sqrt((this.x * this.x) + (this.y * this.y));
}
//<DOC> <function> vector.toAngle()<br><br>Get the angle towards the vector's direction in degrees.
this.toAngle = function()
{
return (Math.atan2(this.y, this.x) * 180 / Math.PI) + 90;
}
//<DOC> <function> vector.normalize()<br><br>returns a normalized copy of the vector. Original vector is not modified.
this.normalize = function()
{
var newVector = this.getCopy();
if(newVector.length() != 0)
{
var length = newVector.length();
newVector.x /= length;
newVector.y /= length;
}
return newVector;
}
//<DOC> <function> vector.lerpTo(otherVector, t)<br><br> Returns a new vector between this vector and 'otherVector' at point 't'. 0t = original vector, 1t = 'otherVector', 0.5t is halfway in between.
this.lerpTo = function(otherVector, t)
{
var delta = otherVector.subtract(this);
return this.add(delta.stretch(t));
}
//<DOC> <function> vector.distanceTo(otherVector)<br><br>returns the distance to another vector.
this.distanceTo = function(otherVector)
{
var dX = this.x - otherVector.x;
var dY = this.y - otherVector.y;
return new vector(dX, dY).length();
}
//<DOC> <function> vector.add(otherVector)<br><br>adds the two vectors together, and returns as a copy. Original vector is not modified.
this.add = function(otherVector)
{
var newVector = this.getCopy();
newVector.x += otherVector.x;
newVector.y += otherVector.y;
return newVector;
}
//<DOC> <function> vector.subtract(otherVector)<br><br>subtracts the second vector from this vector, and returns as a copy. Original vector is not modified.
this.subtract = function(otherVector)
{
var newVector = this.getCopy();
newVector.x -= otherVector.x;
newVector.y -= otherVector.y;
return newVector;
}
//<DOC> <function> vector.multiply(otherVector)<br><br>multiplies the first vector X by the second vector's X, and the first's Y by the second's Y, and returns as a copy. Original vector is not modified.
this.multiply = function(otherVector)
{
var newVector = this.getCopy();
newVector.x *= otherVector.x;
newVector.y *= otherVector.y;
return newVector;
}
//<DOC> <function> vector.divide(otherVector)<br><br>divides the first vector by the second, and returns as a copy. Original vector is not modified.
this.divide = function(otherVector)
{
var newVector = this.getCopy();
newVector.x /= otherVector.x;
newVector.y /= otherVector.y;
return newVector;
}
//<DOC> <function> vector.stretch(length)<br><br>Multiplies the vector by the given numeric value, and returns as a copy. Original vector is not modified.
this.stretch = function(length)
{
var newVector = this.getCopy();
newVector.x *= length;
newVector.y *= length;
return newVector;
}
//<DOC> <function> vector.getCopy()<br><br>returns a copy of this vector.
this.getCopy = function()
{
return new vector(this.x, this.y);
}
}
@@ -0,0 +1,114 @@//<DOC> category vector()function vector(x, y){ //<DOC> <parameter> vector.x<br><br>the X axis of the vector. this.x = x; //<DOC> <parameter> vector.y<br><br>the Y axis of the vector. this.y = y; //<DOC> <function> vector.length()<br><br>returns the length of the vector. this.length = function() { return Math.sqrt((this.x * this.x) + (this.y * this.y)); } //<DOC> <function> vector.toAngle()<br><br>Get the angle towards the vector's direction in degrees. this.toAngle = function() { return (Math.atan2(this.y, this.x) * 180 / Math.PI) + 90; } //<DOC> <function> vector.normalize()<br><br>returns a normalized copy of the vector. Original vector is not modified. this.normalize = function() { var newVector = this.getCopy(); if(newVector.length() != 0) { var length = newVector.length(); newVector.x /= length; newVector.y /= length; } return newVector; } //<DOC> <function> vector.lerpTo(otherVector, t)<br><br> Returns a new vector between this vector and 'otherVector' at point 't'. 0t = original vector, 1t = 'otherVector', 0.5t is halfway in between. this.lerpTo = function(otherVector, t) { var delta = otherVector.subtract(this); return this.add(delta.stretch(t)); } //<DOC> <function> vector.distanceTo(otherVector)<br><br>returns the distance to another vector. this.distanceTo = function(otherVector) { var dX = this.x - otherVector.x; var dY = this.y - otherVector.y; return new vector(dX, dY).length(); } //<DOC> <function> vector.add(otherVector)<br><br>adds the two vectors together, and returns as a copy. Original vector is not modified. this.add = function(otherVector) { var newVector = this.getCopy(); newVector.x += otherVector.x; newVector.y += otherVector.y; return newVector; } //<DOC> <function> vector.subtract(otherVector)<br><br>subtracts the second vector from this vector, and returns as a copy. Original vector is not modified. this.subtract = function(otherVector) { var newVector = this.getCopy(); newVector.x -= otherVector.x; newVector.y -= otherVector.y; return newVector; } //<DOC> <function> vector.multiply(otherVector)<br><br>multiplies the first vector X by the second vector's X, and the first's Y by the second's Y, and returns as a copy. Original vector is not modified. this.multiply = function(otherVector) { var newVector = this.getCopy(); newVector.x *= otherVector.x; newVector.y *= otherVector.y; return newVector; } //<DOC> <function> vector.divide(otherVector)<br><br>divides the first vector by the second, and returns as a copy. Original vector is not modified. this.divide = function(otherVector) { var newVector = this.getCopy(); newVector.x /= otherVector.x; newVector.y /= otherVector.y; return newVector; } //<DOC> <function> vector.stretch(length)<br><br>Multiplies the vector by the given numeric value, and returns as a copy. Original vector is not modified. this.stretch = function(length) { var newVector = this.getCopy(); newVector.x *= length; newVector.y *= length; return newVector; } //<DOC> <function> vector.getCopy()<br><br>returns a copy of this vector. this.getCopy = function() { return new vector(this.x, this.y); }}@@ -0,0 +1,50 @@
//<DOC> category GameWindow
var GameWindow =
{
//<DOC> <parameter> GameWindow.width<br>The game window's width. Cannot be changed.
width: 0,
//<DOC> <parameter> GameWindow.height<br>The game window's height. Cannot be changed.
height: 0,
//<DOC> <parameter> GameWindow.backgroundColor<br>Background color. Contains an r, g and b component (0-255).
backgroundColor:
{
r: 255,
g: 255,
b: 255
},
windowElement: null,
elementID: "GameBuilder_Window",
init: function(x, y, width, height)
{
GameWindow.width = width;
GameWindow.height = height;
$("body").append('<canvas id="' + GameWindow.elementID + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px; border: 1px solid black;" width="' + GameWindow.width + '" height="' + GameWindow.height + '"></canvas>');
//$("body").append('<div id="' + GameWindow.elementID + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px; width: ' + GameWindow.width + 'px; height: ' + GameWindow.height + 'px; overflow: hidden; border: 1px solid black;"></div>');
GameWindow.windowElement = $("#" + GameWindow.elementID);
//<DOC> <parameter> GameWindow.canvas <br><br> The game's canvas element
GameWindow.canvas = $("#" + GameWindow.elementID)[0];
//<DOC> <parameter> GameWindow.canvasContext <br><br>The game's canvasContext. Use this for drawing.
GameWindow.canvasContext = GameWindow.canvas.getContext('2d');
console.log("GAME: Window initialized: [" + width + ", " + height + "]");
},
redraw: function()
{
this.canvasContext.fillStyle = "rgb(" + this.backgroundColor.r + "," + this.backgroundColor.g + "," + this.backgroundColor.b + ")"; // sets the color to fill in the rectangle with
this.canvasContext.fillRect(0, 0, this.width, this.height);
for(var i = 0; i < Game.activeObjects.length; i++)
{
if(Game.activeObjects[i].active && Game.activeObjects[i].renderer.visible)
Game.activeObjects[i].g_draw(GameWindow.canvasContext);
}
}
}
@@ -0,0 +1,50 @@//<DOC> category GameWindowvar GameWindow = { //<DOC> <parameter> GameWindow.width<br>The game window's width. Cannot be changed. width: 0, //<DOC> <parameter> GameWindow.height<br>The game window's height. Cannot be changed. height: 0, //<DOC> <parameter> GameWindow.backgroundColor<br>Background color. Contains an r, g and b component (0-255). backgroundColor: { r: 255, g: 255, b: 255 }, windowElement: null, elementID: "GameBuilder_Window", init: function(x, y, width, height) { GameWindow.width = width; GameWindow.height = height; $("body").append('<canvas id="' + GameWindow.elementID + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px; border: 1px solid black;" width="' + GameWindow.width + '" height="' + GameWindow.height + '"></canvas>'); //$("body").append('<div id="' + GameWindow.elementID + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px; width: ' + GameWindow.width + 'px; height: ' + GameWindow.height + 'px; overflow: hidden; border: 1px solid black;"></div>'); GameWindow.windowElement = $("#" + GameWindow.elementID); //<DOC> <parameter> GameWindow.canvas <br><br> The game's canvas element GameWindow.canvas = $("#" + GameWindow.elementID)[0]; //<DOC> <parameter> GameWindow.canvasContext <br><br>The game's canvasContext. Use this for drawing. GameWindow.canvasContext = GameWindow.canvas.getContext('2d'); console.log("GAME: Window initialized: [" + width + ", " + height + "]"); }, redraw: function() { this.canvasContext.fillStyle = "rgb(" + this.backgroundColor.r + "," + this.backgroundColor.g + "," + this.backgroundColor.b + ")"; // sets the color to fill in the rectangle with this.canvasContext.fillRect(0, 0, this.width, this.height); for(var i = 0; i < Game.activeObjects.length; i++) { if(Game.activeObjects[i].active && Game.activeObjects[i].renderer.visible) Game.activeObjects[i].g_draw(GameWindow.canvasContext); } }}