Commit 3d5e52e2 authored by Matthew Odle's avatar Matthew Odle

reorganize data structure for images; fix bug where all creatures of the same...

reorganize data structure for images; fix bug where all creatures of the same type were sharing an image due to the image inits in knobsAndLevers
parent 4c61505b
......@@ -50,30 +50,27 @@ var knobsAndLevers = {
animationInterval : 50,
hitPoints : 1,
type : 'centipede',
sprites : {
objects : {
up : {activeIndex : 0, files : ['centipede-head-1-up.png', 'centipede-head-2-up.png'], images : []},
down : {activeIndex : 0, files : ['centipede-head-1-down.png', 'centipede-head-2-down.png'], images : []},
left : {activeIndex : 0, files : ['centipede-head-1-left.png', 'centipede-head-2-left.png'], images : []},
right : {activeIndex : 0, files : ['centipede-head-1-right.png', 'centipede-head-2-right.png'], images : []},
},
getKey : function(obj) {
let direction = '';
if (obj.moveVertically) {
direction = obj.directionY > 0 ? 'down' : 'up';
} else {
direction = obj.directionX > 0 ? 'right' : 'left';
};
return direction;
},
},
},
sprites : {
up : {activeIndex : 0, files : ['centipede-head-1-up.png', 'centipede-head-2-up.png'], images : []},
down : {activeIndex : 0, files : ['centipede-head-1-down.png', 'centipede-head-2-down.png'], images : []},
left : {activeIndex : 0, files : ['centipede-head-1-left.png', 'centipede-head-2-left.png'], images : []},
right : {activeIndex : 0, files : ['centipede-head-1-right.png', 'centipede-head-2-right.png'], images : []},
},
getSpriteKey : function(obj) {
let direction = '';
if (obj.moveVertically) {
direction = obj.directionY > 0 ? 'down' : 'up';
} else {
direction = obj.directionX > 0 ? 'right' : 'left';
};
return direction;
},
},
init : function(configs) {
this.args.width = configs.general.gridSquareSideLength;
this.args.height = configs.general.gridSquareSideLength;
this.args.x = configs.canvas.width / 2;
images.init(this.args.extraArgs.sprites);
console.log('centipede defaults initialized');
},
},
......@@ -94,14 +91,12 @@ var knobsAndLevers = {
hitPoints : 2,
type : 'fly',
speed : {x : 0, y : 2},
sprites : {
objects : {
one : {activeIndex : 0, files : ['flea-1.png', 'flea-2.png'], images : []},
},
getKey : function(obj) {
return 'one';
},
},
},
sprites : {
one : {activeIndex : 0, files : ['flea-1.png', 'flea-2.png'], images : []},
},
getSpriteKey : function(obj) {
return 'one';
},
constructorFunctions : {
setX : function(fly) { fly.x = supporting.getRandom(0, knobsAndLevers.canvas.width) },
......@@ -113,12 +108,11 @@ var knobsAndLevers = {
this.args.height = configs.general.gridSquareSideLength * 0.75;
this.args.y = -configs.canvas.height / 10;
this.interval = supporting.clone(configs.game.interval);
images.init(this.args.extraArgs.sprites);
console.log('flies defaults initialized');
},
},
game : {
playerCollisionsEnabled : true,
playerCollisionsEnabled : false,
interval : {
min : 0,
max : 0,
......@@ -139,7 +133,7 @@ var knobsAndLevers = {
startLevel : 0,
maxMushrooms : 50,
tier : {
incrementScore : 10000,
incrementScore : 2000,
current: 1,
max : 5,
isMaxed : false,
......@@ -197,28 +191,25 @@ var knobsAndLevers = {
extraArgs : {
hitPoints : 4,
type : 'mushroom',
sprites : {
objects : {
normal1 : {files : ['mushroom-1.png'], images : []},
normal2 : {files : ['mushroom-2.png'], images : []},
normal3 : {files : ['mushroom-3.png'], images : []},
normal4 : {files : ['mushroom-4.png'], images : []},
poisoned1 : {files : ['mushroom-poisoned-1.png'], images : []},
poisoned2 : {files : ['mushroom-poisoned-2.png'], images : []},
poisoned3 : {files : ['mushroom-poisoned-3.png'], images : []},
poisoned4 : {files : ['mushroom-poisoned-4.png'], images : []},
},
getKey : function(obj) {
return (obj.poisoned ? 'poisoned' : 'normal') + obj.hitPoints;
},
},
},
sprites : {
normal1 : {files : ['mushroom-1.png'], images : []},
normal2 : {files : ['mushroom-2.png'], images : []},
normal3 : {files : ['mushroom-3.png'], images : []},
normal4 : {files : ['mushroom-4.png'], images : []},
poisoned1 : {files : ['mushroom-poisoned-1.png'], images : []},
poisoned2 : {files : ['mushroom-poisoned-2.png'], images : []},
poisoned3 : {files : ['mushroom-poisoned-3.png'], images : []},
poisoned4 : {files : ['mushroom-poisoned-4.png'], images : []},
},
getSpriteKey : function(obj) {
return (obj.poisoned ? 'poisoned' : 'normal') + obj.hitPoints;
},
},
init : function(configs) {
this.scaleFactor = configs.general.gridSquareSideLength * 0.1;
this.args.width = configs.general.gridSquareSideLength * 0.8;
this.args.height = configs.general.gridSquareSideLength * 0.8;
images.init(this.args.extraArgs.sprites);
console.log('mushroom defaults initialized');
},
},
......@@ -231,18 +222,18 @@ var knobsAndLevers = {
extraArgs : {
type : 'player',
speed : {x : 0, y : 0},
sprites : {
objects : {
player1 : {files : ['player1.png'], images : []},
player2 : {files : ['player2.png'], images : []},
},
getKey : function(obj) {
return obj.name ? obj.name : 'player1';
},
},
},
sprites : {
player1 : {files : ["player1.png"], images : []},
player2 : {files : ["player2.png"], images : []},
},
getSpriteKey : function(obj) {
return obj.name ? obj.name : 'player1';
},
constructorFunctions : {
setX : function(player) {
console.log(player);
console.log(players.player);
player.x = knobsAndLevers.player.startX[Object.keys(players.players).length];
},
},
......@@ -268,7 +259,6 @@ var knobsAndLevers = {
],
this.startY = configs.canvas.height - this.dimensions.height - 1;
this.args.y = this.startY;
images.init(this.args.extraArgs.sprites);
},
resetCheats : function() {
knobsAndLevers.resetParameter(this.speed);
......@@ -291,14 +281,12 @@ var knobsAndLevers = {
hitPoints : 1,
type : 'spider',
speed : {x : 1, y : 1},
sprites : {
objects : {
one : {activeIndex : 0, files : ['spider-1.png', 'spider-2.png'], images : []},
},
getKey : function(obj) {
return 'one';
},
},
},
sprites : {
one : {activeIndex : 0, files : ['spider-1.png', 'spider-2.png'], images : []},
},
getSpriteKey : function(obj) {
return 'one';
},
},
speedLimits : {
......@@ -311,7 +299,6 @@ var knobsAndLevers = {
this.args.height = configs.general.gridSquareSideLength * 0.5;
this.args.x = 1;
this.interval = supporting.clone(configs.game.interval);
images.init(this.args.extraArgs.sprites);
console.log('spider defaults initialized');
},
},
......@@ -349,17 +336,15 @@ var knobsAndLevers = {
hitPoints : 1,
type : 'worm',
speed : {x : 0.5, y : 0},
sprites : {
objects : {
leftcrazy : {activeIndex : 0, files : ['worm-1-left-crazy.png'], images : []},
rightcrazy : {activeIndex : 0, files : ['worm-1-right-crazy.png'], images : []},
leftnormal : {activeIndex : 0, files : ['worm-1-left-normal.png', 'worm-2-left-normal.png'], images : []},
rightnormal : {activeIndex : 0, files : ['worm-1-right-normal.png', 'worm-2-right-normal.png'], images : []},
},
getKey : function(obj) {
return (obj.speedX > 0 ? 'right' : 'left') + obj.imageType;
},
},
},
sprites : {
leftcrazy : {activeIndex : 0, files : ['worm-1-left-crazy.png'], images : []},
rightcrazy : {activeIndex : 0, files : ['worm-1-right-crazy.png'], images : []},
leftnormal : {activeIndex : 0, files : ['worm-1-left-normal.png', 'worm-2-left-normal.png'], images : []},
rightnormal : {activeIndex : 0, files : ['worm-1-right-normal.png', 'worm-2-right-normal.png'], images : []},
},
getSpriteKey : function(obj) {
return (obj.speedX > 0 ? 'right' : 'left') + obj.imageType;
},
constructorFunctions : {
setImageType : function(worm) {
......@@ -395,7 +380,6 @@ var knobsAndLevers = {
this.args.height = configs.general.gridSquareSideLength;
this.args.defaultHeight = this.args.height;
this.interval = supporting.clone(configs.game.interval);
images.init(this.args.extraArgs.sprites);
console.log('worm defaults initialized');
},
},
......
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