Commit 6ff96ac0 authored by Matthew Odle's avatar Matthew Odle

update image loading; add runner.js to handle init executions

parent a4378de7
var customComponents = {
// TODO move drawComponent to canvas-libs
drawComponent : function(ctx, obj) {
let key = this.imageKeys[obj.type](obj);
if (!obj.images) {
throw 'no images; images is ' + obj.images;
};
if (!obj.images[key]) {
throw 'no key match; images is ' + obj.images;
};
ctx.drawImage(obj.images[key].image, obj.x, obj.y, obj.width, obj.height);
},
imageKeys : {
'centipede' : function(obj) {return customComponents.getCentipedeDirection(obj);},
'fly' : function(obj) {return 'one';},
'mushroom' : function(obj) {return (obj.poisoned ? 'poisoned' : 'normal') + obj.hitPoints;},
'player' : function(obj) {return obj.name ? obj.name : 'player1';},
'spider' : function(obj) {return 'one';},
'mushroom' : function(obj) {return (obj.poisoned ? 'poisoned' : 'normal') + obj.hitPoints;},
'worm' : function(obj) {return obj.speedX > 0 ? 'two' : 'one';},
'fly' : function(obj) {return 'one';},
},
getCentipedeDirection : function(obj) {
let direction = '';
......
var init = {
run : function() {
console.log('init the things, yo');
console.log('start centipede init');
knobsAndLevers.init();
......@@ -33,5 +33,3 @@ var init = {
console.log("game reset");
},
};
init.run();
/*
* This script is unable to access functions defined in the files being loaded
* i.e. init.run(); results in Uncaught ReferenceError: init is not defined
* even after the init function has been loaded.
* Suspect that window object is not defined at this point (it logs as undefined).
* Therefore, need to execute those objects during script load
* init/runner.js accomplishes this.
*/
var libsPath = '../canvas-libs/app/scripts/';
// var libsPath = 'https://glcdn.githack.com/taciturn-pachyderm/canvas-libs/raw/v2.2.0/app/scripts/';
......@@ -14,6 +23,7 @@ var libs = [
'game-area.js',
'hud.js',
'images.js',
'init/init.js',
'leaderboard.js',
'mainBase.js',
'menus/initials.js',
......@@ -36,18 +46,15 @@ var scripts = [
'components/texts.js',
'components/spiders.js',
'game.js',
'init/init.js',
'knobs-and-levers.js',
'main.js',
'properties/menus-props.js',
'sound.js',
];
var initLibs = [
'init/init.js',
];
var initScripts = [
'init/init.js',
var runners = [
'init/runner.js',
];
var targetDomObject = 'head';
......@@ -60,7 +67,6 @@ function loadScript (path, file) {
libs.forEach(file => loadScript(libsPath, file));
scripts.forEach(file => loadScript(scriptsPath, file));
initLibs.forEach(file => loadScript(libsPath, file));
initScripts.forEach(file => loadScript(scriptsPath, file));
runners.forEach(file => loadScript(scriptsPath, file));
console.log(document[targetDomObject]);
libsInit.run();
init.run();
......@@ -49,10 +49,13 @@ var knobsAndLevers = {
extraArgs : {
type : "centipede",
images : {
up : {filename : 'centipede-head-1-up.png'},
down : {filename : 'centipede-head-1-down.png'},
left : {filename : 'centipede-head-1-left.png'},
right : {filename : 'centipede-head-1-right.png'},
objects : {
up : {filename : 'centipede-head-1-up.png'},
down : {filename : 'centipede-head-1-down.png'},
left : {filename : 'centipede-head-1-left.png'},
right : {filename : 'centipede-head-1-right.png'},
},
select : function(obj) {return customComponents.getCentipedeDirection(obj);},
},
},
},
......@@ -81,8 +84,11 @@ var knobsAndLevers = {
type : 'fly',
speed : {x : 0, y : 2},
images : {
one : {filename : 'flea-1.png'},
two : {filename : 'flea-2.png'},
objects : {
one : {filename : 'flea-1.png'},
two : {filename : 'flea-2.png'},
},
select : function(obj) {return 'one';},
},
},
constructorFunctions : {
......@@ -179,14 +185,17 @@ var knobsAndLevers = {
extraArgs : {
type : 'mushroom',
images : {
normal1 : {filename : 'mushroom-1.png'},
normal2 : {filename : 'mushroom-2.png'},
normal3 : {filename : 'mushroom-3.png'},
normal4 : {filename : 'mushroom-4.png'},
poisoned1 : {filename : 'mushroom-poisoned-1.png'},
poisoned2 : {filename : 'mushroom-poisoned-2.png'},
poisoned3 : {filename : 'mushroom-poisoned-3.png'},
poisoned4 : {filename : 'mushroom-poisoned-4.png'},
objects : {
normal1 : {filename : 'mushroom-1.png'},
normal2 : {filename : 'mushroom-2.png'},
normal3 : {filename : 'mushroom-3.png'},
normal4 : {filename : 'mushroom-4.png'},
poisoned1 : {filename : 'mushroom-poisoned-1.png'},
poisoned2 : {filename : 'mushroom-poisoned-2.png'},
poisoned3 : {filename : 'mushroom-poisoned-3.png'},
poisoned4 : {filename : 'mushroom-poisoned-4.png'},
},
select : function(obj) {return (obj.poisoned ? 'poisoned' : 'normal') + obj.hitPoints;},
},
},
},
......@@ -208,8 +217,11 @@ var knobsAndLevers = {
type : 'player',
speed : {x : 0, y : 0},
images : {
player1 : {filename : 'player1.png'},
player2 : {filename : 'player2.png'},
objects : {
player1 : {filename : 'player1.png'},
player2 : {filename : 'player2.png'},
},
select : function(obj) {return obj.name ? obj.name : 'player1';},
},
},
constructorFunctions : {
......@@ -263,8 +275,11 @@ var knobsAndLevers = {
type : "spider",
speed : {x : 1, y : 1},
images : {
one : {filename : 'spider-1.png'},
two : {filename : 'spider-2.png'},
objects : {
one : {filename : 'spider-1.png'},
two : {filename : 'spider-2.png'},
},
select : function(obj) {return 'one';},
},
},
},
......@@ -315,8 +330,11 @@ var knobsAndLevers = {
type : "worm",
speed : {x : 0.5, y : 0},
images : {
one : {filename : 'worm-1.png'},
two : {filename : 'worm-2.png'},
objects : {
one : {filename : 'worm-1.png'},
two : {filename : 'worm-2.png'},
},
select : function(obj) {return obj.speedX > 0 ? 'two' : 'one';},
},
},
constructorFunctions : {
......
......@@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" type="text/css" media="screen" href="app/static/css/style.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<script src="app/scripts/load.js"></script>
<script src="app/scripts/init/load.js"></script>
</head>
<body onload="game.start()">
<div id="canvas-wrapper"></div>
......
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