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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions js/audioHandler.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
"use strict"
"use strict";

// if app exists use the existing copy
// else create a new empty object literal
var app = app || {};
const app = window.app || {};
window.app = app;

app.audioHandler = {


Sounds: {
//Flight by Test Shot Starfish
//https://soundcloud.com/testshotstarfish/flight?in=testshotstarfish/sets/music-for-space
FLIGHT: { path:"media\\music\\TestShotStarfish_Flight.wav" , buffer: undefined , nodes:[]},
FLIGHT: { path: "media\\music\\TestShotStarfish_Flight.wav", buffer: undefined, nodes: [] },
//Delta IV: Launch by NASA is licensed under a Creative Commons License.
//https://soundcloud.com/nasa/delta-iv-launch?in=nasa/sets/rocket-engine-sounds
ENGINE: { path:"media\\music\\DeltaIVAudio.wav", buffer: undefined , nodes:[]}
ENGINE: { path: "media\\music\\DeltaIVAudio.wav", buffer: undefined, nodes: [] }
},

audioCTX: undefined, //initialized by init()
Expand All @@ -23,66 +24,65 @@ app.audioHandler = {
this.audioCTX = new AudioContext();

//for each path, load the sound asynchronously and add sound;
for( var sound in this.Sounds) {
if(!this.Sounds.hasOwnProperty(sound)) continue;
for (const sound in this.Sounds) {
if (!this.Sounds.hasOwnProperty(sound)) continue;

//load from path, save buffer to SOUNDS
this.loadSound(this.Sounds[sound]);
console.log("loaded " + this.Sounds[sound].path + " to " + this.Sounds[sound].buffer);
console.log(`loaded ${this.Sounds[sound].path} to ${this.Sounds[sound].buffer}`);
}
},

loadSound: function(sound) {
var request = new XMLHttpRequest();
const request = new XMLHttpRequest();
request.open('GET', sound.path, true);
request.responseType = 'arraybuffer';

request.onload = function() {

app.audioHandler.audioCTX.decodeAudioData(request.response, function(buffer) {
request.onload = () => {
app.audioHandler.audioCTX.decodeAudioData(request.response, (buffer) => {
sound.buffer = buffer;
});
}
};
request.send();
},

playSound: function (sound) {
if(sound.nodes.length==0) {
var source = this.audioCTX.createBufferSource();
if (sound.nodes.length === 0) {
const source = this.audioCTX.createBufferSource();
source.buffer = sound.buffer;
source.connect(this.audioCTX.destination);
sound.nodes.push(source);
}
for(var i = 0; i < sound.nodes.length; i++) {
for (let i = 0; i < sound.nodes.length; i++) {
sound.nodes[i].start(0);
}
},

playLoop: function (sound, startTime = 0, duration = 0) {

if(sound.nodes.length == 0) {
var source = this.audioCTX.createBufferSource();
if (sound.nodes.length === 0) {
const source = this.audioCTX.createBufferSource();
source.buffer = sound.buffer;
source.loop = true;
source.connect(this.audioCTX.destination);
sound.nodes.push(source);
}

if(duration<=0) {
for(var i = 0; i < sound.nodes.length; i++) {
if (duration <= 0) {
for (let i = 0; i < sound.nodes.length; i++) {
sound.nodes[i].start(0, startTime);
}
}
else {
for(var i = 0; i < sound.nodes.length; i++) {
for (let i = 0; i < sound.nodes.length; i++) {
sound.nodes[i].start(0, startTime, duration);
}
}
},

stopSound: function (sound) {
if(sound.nodes.length!=0) {
for(var i = 0; i < sound.nodes.length; i++) {
if (sound.nodes.length !== 0) {
for (let i = 0; i < sound.nodes.length; i++) {
sound.nodes[i].stop();
sound.nodes.pop();
}
Expand Down
41 changes: 20 additions & 21 deletions js/emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// last modified: 10/7/2015

"use strict";
var app = app || {};
const app = window.app || {};
window.app = app;

app.Emitter=function(){
app.Emitter = (function() {

function Emitter(){
// public
Expand All @@ -19,7 +20,7 @@ app.Emitter=function(){
this.minYspeed = 2;
this.maxYspeed = 4;
this.startRadius = 4;
this.expansionRate = 0.3
this.expansionRate = 0.3;
this.decayRate = 2.5;
this.lifetime = 100;
this.red = 0;
Expand All @@ -28,20 +29,20 @@ app.Emitter=function(){

// private
this._particles = undefined;
};
}


// "public" methods
var p=Emitter.prototype;
const p = Emitter.prototype;

p.createParticles = function(emitterPoint){
// initialize particle array
this._particles = [];

// create exhaust particles
for(var i=0; i< this.numParticles; i++){
for (let i = 0; i < this.numParticles; i++) {
// create a particle object and add to array
var p = {};
const p = {};
this._particles.push(_initParticle(this, p, emitterPoint, new Victor(0,0)));
}

Expand All @@ -56,8 +57,8 @@ app.Emitter=function(){
// make it bigger, and fade it out
// increase its age so we know when to recycle it

for(var i=0;i<this._particles.length;i++){
var p = this._particles[i];
for (let i = 0; i < this._particles.length; i++) {
const p = this._particles[i];

p.age += this.decayRate;
p.r += this.expansionRate;
Expand All @@ -66,35 +67,33 @@ app.Emitter=function(){
p.x += p.xSpeed;
p.y += p.ySpeed;

var alpha = 1 - p.age/this.lifetime;
const alpha = 1 - p.age/this.lifetime;

// if the particle is too old, recycle it
if(p.age >= this.lifetime){
if (p.age >= this.lifetime) {
_initParticle(this, p, emitterPoint, currentSpeed);
}

}
}

p.draw = function(ctx){
for(var i=0;i<this._particles.length;i++){
var p = this._particles[i];
var alpha = 1 - p.age/this.lifetime;
for (let i = 0; i < this._particles.length; i++) {
const p = this._particles[i];
const alpha = 1 - p.age/this.lifetime;
ctx.save();
if(this.useSquares){


// fill a rectangle
ctx.fillStyle = "rgba(" + this.red + "," + this.green + "," +
this.blue + "," + alpha + ")";
ctx.fillStyle = `rgba(${this.red},${this.green},${this.blue},${alpha})`;
ctx.fillRect(p.x, p.y, p.r, p.r);
// note: this code is easily modified to draw images
}

if(this.useCircles){
// fill a circle
ctx.fillStyle = "rgba(" + this.red + "," + this.green + "," +
this.blue + "," + alpha + ")";
ctx.fillStyle = `rgba(${this.red},${this.green},${this.blue},${alpha})`;

ctx.beginPath();
ctx.arc(p.x, p.y, p.r, Math.PI * 2, false);
Expand All @@ -108,7 +107,7 @@ app.Emitter=function(){
function _initParticle(obj, p, emitterPoint, initialSpeed){

// give it a random age when first created
p.age = getRandom(0,obj.lifetime);
p.age = getRandom(0, obj.lifetime);

p.x = emitterPoint.x + getRandom(-obj.xRange, obj.xRange);
p.y = emitterPoint.y + getRandom(0, obj.yRange);
Expand All @@ -118,8 +117,8 @@ app.Emitter=function(){
// p.xSpeed = -initialSpeed.x / 10;
p.ySpeed = -initialSpeed.y / 5;
return p;
};
}


return Emitter;
}();
})();
14 changes: 7 additions & 7 deletions js/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"use strict";

var myKeys = {};
const myKeys = {};

myKeys.KEYBOARD = Object.freeze({
"KEY_LEFT": 37,
Expand All @@ -30,18 +30,18 @@ myKeys.keydown = [];


// event listeners
window.addEventListener("keydown",function(e){
console.log("keydown=" + e.keyCode);
window.addEventListener("keydown", (e) => {
console.log(`keydown=${e.keyCode}`);
myKeys.keydown[e.keyCode] = true;
});

window.addEventListener("keyup",function(e){
console.log("keyup=" + e.keyCode);
window.addEventListener("keyup", (e) => {
console.log(`keyup=${e.keyCode}`);
myKeys.keydown[e.keyCode] = false;

// pausing and resuming
var char = String.fromCharCode(e.keyCode);
if (char == "p" || char == "P"){
const char = String.fromCharCode(e.keyCode);
if (char === "p" || char === "P") {
if (app.main.paused){
app.main.resumeGame();
} else {
Expand Down
29 changes: 14 additions & 15 deletions js/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ the game will be properties of app.

// if app exists use the existing copy
// else create a new empty object literal
var app = app || {};
const app = window.app || {};
window.app = app;


window.onload = function(){
window.onload = () => {
console.log("window.onload called");
//debugger;
var sources = {
const sources = {
deployed: "media/images/f9FirstStageLegsFins298x1254.png",
stowed: "media/images/f9FirstStageNoDeploy100x1198.png"
};
var buttonSources = {
};
const buttonSources = {
sea: "media/images/SeaButton.png",
mountain: "media/images/MountainButton.png"
};
Expand All @@ -37,18 +38,16 @@ window.onload = function(){

//load images function from html5 canvas tutorials
//http://www.html5canvastutorials.com/tutorials/html5-canvas-image-loader/
function loadImages(sources, callback){
var images = {};
var loadedImages = 0;
var numImages = 0;
function loadImages(sources, callback) {
const images = {};
let loadedImages = 0;
const numImages = Object.keys(sources).length;
//get num of sources
for(var src in sources) {
numImages++;
}
for(var src in sources){
for (const src in sources) {
images[src] = new Image();
images[src].onload = function(){
if(++loadedImages >= numImages){
images[src].onload = () => {
loadedImages += 1;
if (loadedImages >= numImages) {
console.log("images loaded");
callback(images);

Expand Down
Loading