Commit 6099b18f authored by Matthew Odle's avatar Matthew Odle

move image loading to its own script; call during knobsAndLevers init

parent 2e8150a2
...@@ -49,10 +49,10 @@ var knobsAndLevers = { ...@@ -49,10 +49,10 @@ var knobsAndLevers = {
extraArgs : { extraArgs : {
type : "centipede", type : "centipede",
images : { images : {
up : { filename : 'centipede-head-1-up.png', image : new Image() }, up : {filename : 'centipede-head-1-up.png'},
down : { filename : 'centipede-head-1-down.png', image : new Image() }, down : {filename : 'centipede-head-1-down.png'},
left : { filename : 'centipede-head-1-left.png', image : new Image() }, left : {filename : 'centipede-head-1-left.png'},
right : { filename : 'centipede-head-1-right.png', image : new Image() }, right : {filename : 'centipede-head-1-right.png'},
}, },
}, },
}, },
...@@ -60,6 +60,7 @@ var knobsAndLevers = { ...@@ -60,6 +60,7 @@ var knobsAndLevers = {
this.args.width = configs.general.gridSquareSideLength; this.args.width = configs.general.gridSquareSideLength;
this.args.height = configs.general.gridSquareSideLength; this.args.height = configs.general.gridSquareSideLength;
this.args.x = configs.canvas.width / 2; this.args.x = configs.canvas.width / 2;
images.init(this.args.extraArgs.images);
}, },
}, },
components : { components : {
...@@ -80,8 +81,8 @@ var knobsAndLevers = { ...@@ -80,8 +81,8 @@ var knobsAndLevers = {
type : 'fly', type : 'fly',
speed : {x : 0, y : 2}, speed : {x : 0, y : 2},
images : { images : {
one : { filename : 'flea-1.png', image : new Image() }, one : {filename : 'flea-1.png'},
two : { filename : 'flea-2.png', image : new Image() }, two : {filename : 'flea-2.png'},
}, },
}, },
constructorFunctions : { constructorFunctions : {
...@@ -94,6 +95,7 @@ var knobsAndLevers = { ...@@ -94,6 +95,7 @@ var knobsAndLevers = {
this.args.height = configs.general.gridSquareSideLength * 0.75; this.args.height = configs.general.gridSquareSideLength * 0.75;
this.args.y = -configs.canvas.height / 10; this.args.y = -configs.canvas.height / 10;
this.interval = supporting.clone(configs.game.interval); this.interval = supporting.clone(configs.game.interval);
images.init(this.args.extraArgs.images);
}, },
}, },
game : { game : {
...@@ -177,14 +179,14 @@ var knobsAndLevers = { ...@@ -177,14 +179,14 @@ var knobsAndLevers = {
extraArgs : { extraArgs : {
type : 'mushroom', type : 'mushroom',
images : { images : {
normal1 : { filename : 'mushroom-1.png', image : new Image() }, normal1 : {filename : 'mushroom-1.png'},
normal2 : { filename : 'mushroom-2.png', image : new Image() }, normal2 : {filename : 'mushroom-2.png'},
normal3 : { filename : 'mushroom-3.png', image : new Image() }, normal3 : {filename : 'mushroom-3.png'},
normal4 : { filename : 'mushroom-4.png', image : new Image() }, normal4 : {filename : 'mushroom-4.png'},
poisoned1 : { filename : 'mushroom-poisoned-1.png', image : new Image() }, poisoned1 : {filename : 'mushroom-poisoned-1.png'},
poisoned2 : { filename : 'mushroom-poisoned-2.png', image : new Image() }, poisoned2 : {filename : 'mushroom-poisoned-2.png'},
poisoned3 : { filename : 'mushroom-poisoned-3.png', image : new Image() }, poisoned3 : {filename : 'mushroom-poisoned-3.png'},
poisoned4 : { filename : 'mushroom-poisoned-4.png', image : new Image() }, poisoned4 : {filename : 'mushroom-poisoned-4.png'},
}, },
}, },
}, },
...@@ -192,6 +194,7 @@ var knobsAndLevers = { ...@@ -192,6 +194,7 @@ var knobsAndLevers = {
this.scaleFactor = configs.general.gridSquareSideLength * 0.1; this.scaleFactor = configs.general.gridSquareSideLength * 0.1;
this.args.width = configs.general.gridSquareSideLength * 0.8; this.args.width = configs.general.gridSquareSideLength * 0.8;
this.args.height = configs.general.gridSquareSideLength * 0.8; this.args.height = configs.general.gridSquareSideLength * 0.8;
images.init(this.args.extraArgs.images);
}, },
}, },
player : { player : {
...@@ -205,8 +208,8 @@ var knobsAndLevers = { ...@@ -205,8 +208,8 @@ var knobsAndLevers = {
type : 'player', type : 'player',
speed : {x : 0, y : 0}, speed : {x : 0, y : 0},
images : { images : {
player1 : { filename : 'player1.png', image : new Image() }, player1 : {filename : 'player1.png'},
player2 : { filename : 'player2.png', image : new Image() }, player2 : {filename : 'player2.png'},
}, },
}, },
constructorFunctions : { constructorFunctions : {
...@@ -224,6 +227,7 @@ var knobsAndLevers = { ...@@ -224,6 +227,7 @@ var knobsAndLevers = {
], ],
this.startY = configs.canvas.height - this.dimensions.height - 1; this.startY = configs.canvas.height - this.dimensions.height - 1;
this.args.y = this.startY; this.args.y = this.startY;
images.init(this.args.extraArgs.images);
}, },
speed : { speed : {
value : 2, value : 2,
...@@ -259,8 +263,8 @@ var knobsAndLevers = { ...@@ -259,8 +263,8 @@ var knobsAndLevers = {
type : "spider", type : "spider",
speed : {x : 1, y : 1}, speed : {x : 1, y : 1},
images : { images : {
one : { filename : 'spider-1.png', image : new Image() }, one : {filename : 'spider-1.png'},
two : { filename : 'spider-2.png', image : new Image() }, two : {filename : 'spider-2.png'},
}, },
}, },
}, },
...@@ -274,6 +278,7 @@ var knobsAndLevers = { ...@@ -274,6 +278,7 @@ var knobsAndLevers = {
this.args.height = configs.general.gridSquareSideLength * 0.5; this.args.height = configs.general.gridSquareSideLength * 0.5;
this.args.x = 1; this.args.x = 1;
this.interval = supporting.clone(configs.game.interval); this.interval = supporting.clone(configs.game.interval);
images.init(this.args.extraArgs.images);
}, },
}, },
text : { text : {
...@@ -310,8 +315,8 @@ var knobsAndLevers = { ...@@ -310,8 +315,8 @@ var knobsAndLevers = {
type : "worm", type : "worm",
speed : {x : 0.5, y : 0}, speed : {x : 0.5, y : 0},
images : { images : {
one : { filename : 'worm-1.png', image : new Image() }, one : {filename : 'worm-1.png'},
two : { filename : 'worm-2.png', image : new Image() }, two : {filename : 'worm-2.png'},
}, },
}, },
constructorFunctions : { constructorFunctions : {
...@@ -334,6 +339,7 @@ var knobsAndLevers = { ...@@ -334,6 +339,7 @@ var knobsAndLevers = {
this.args.width = configs.general.gridSquareSideLength * 1.5; this.args.width = configs.general.gridSquareSideLength * 1.5;
this.args.height = configs.general.gridSquareSideLength; this.args.height = configs.general.gridSquareSideLength;
this.interval = supporting.clone(configs.game.interval); this.interval = supporting.clone(configs.game.interval);
images.init(this.args.extraArgs.images);
}, },
}, },
}; };
var canvasPath = '../canvas-libs/app/scripts/'; var libsPath = '../canvas-libs/app/scripts/';
// var canvasPath = 'https://glcdn.githack.com/taciturn-pachyderm/canvas-libs/raw/v2.2.0/app/scripts/'; // var libsPath = 'https://glcdn.githack.com/taciturn-pachyderm/canvas-libs/raw/v2.2.0/app/scripts/';
var mainPath = 'app/scripts/'; var scriptsPath = 'app/scripts/';
var canvasFiles = [ var libs = [
'supporting.js', 'supporting.js',
'component.js', 'component.js',
'controls/gamepad.js', 'controls/gamepad.js',
...@@ -13,6 +13,7 @@ var canvasFiles = [ ...@@ -13,6 +13,7 @@ var canvasFiles = [
'gameBase.js', 'gameBase.js',
'game-area.js', 'game-area.js',
'hud.js', 'hud.js',
'images.js',
'leaderboard.js', 'leaderboard.js',
'mainBase.js', 'mainBase.js',
'menus/initials.js', 'menus/initials.js',
...@@ -23,7 +24,7 @@ var canvasFiles = [ ...@@ -23,7 +24,7 @@ var canvasFiles = [
'templates.js', 'templates.js',
]; ];
var mainFiles = [ var scripts = [
'collisions.js', 'collisions.js',
'component.js', 'component.js',
'components/centipedes.js', 'components/centipedes.js',
...@@ -41,11 +42,11 @@ var mainFiles = [ ...@@ -41,11 +42,11 @@ var mainFiles = [
'sound.js', 'sound.js',
]; ];
var canvasInitFiles = [ var initLibs = [
'init/init.js', 'init/init.js',
]; ];
var mainInitFiles = [ var initScripts = [
'init/init.js', 'init/init.js',
]; ];
...@@ -57,9 +58,9 @@ function loadScript (path, file) { ...@@ -57,9 +58,9 @@ function loadScript (path, file) {
console.log(script.src, 'added to', targetDomObject); console.log(script.src, 'added to', targetDomObject);
}; };
canvasFiles.forEach(file => loadScript(canvasPath, file)); libs.forEach(file => loadScript(libsPath, file));
mainFiles.forEach(file => loadScript(mainPath, file)); scripts.forEach(file => loadScript(scriptsPath, file));
canvasInitFiles.forEach(file => loadScript(canvasPath, file)); initLibs.forEach(file => loadScript(libsPath, file));
mainInitFiles.forEach(file => loadScript(mainPath, file)); initScripts.forEach(file => loadScript(scriptsPath, file));
console.log(document[targetDomObject]); console.log(document[targetDomObject]);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment