Commit 74069a03 authored by Matthew Odle's avatar Matthew Odle

move metrics and texts to canvas-libs

parent 26692d9d
var metrics = {
floatingPoints : [],
floatingPointCycleDuration : 50,
lives : {player1 : 0, player2 : 0},
extraLivesGained : 0,
currentLevel : {},
score : {player1 : 0, player2 : 0},
lastScore : 0,
init : function() {
this.currentLevel = knobsAndLevers.game.startLevel;
this.lives.player1 = knobsAndLevers.player.defaultLives;
this.livesMarker = Object.assign({}, templates.marker);
console.log("metrics initialized");
},
manageScore : function(change) {
this.changeScore(change);
this.manageTier();
},
changeScore : function(change) {
this.score.player1 += change;
this.score.player1 = this.score.player1 < 0 ? 0 : this.score.player1;
},
manageTier : function() {
this.setTier();
this.manageLives();
},
setTier : function() {
let newTier = Math.floor((this.score.player1 + 1) / knobsAndLevers.game.tier.incrementScore) + 1;
if (!newTier) {
throw('problem calculating tier');
};
knobsAndLevers.game.tier.update(newTier);
},
manageLives : function() {
if (this.extraLivesGained < knobsAndLevers.game.tier.current - 1) {
this.lives.player1 += 1;
this.extraLivesGained += 1;
sounds.playTierChangeSound();
};
},
addNewFloatingPoint : function(x, y, points, action) {
let newPoint = this.getNewPoint(x, y);
newPoint.color = action == 'lose' ? 'red' : 'black';
newPoint.text = (action == 'lose' ? '-' : '+') + points;
newPoint.cycleNumber = 0;
this.floatingPoints.push(newPoint);
},
getNewPoint : function(x, y) {
let args = {
fontSize : "15px",
color : "black",
x : x,
y : y,
extraArgs : {type : "text"},
};
return new Component(args);
},
manage : function() {
for (i = 0; i < this.floatingPoints.length; i += 1) {
this.floatingPoints[i].cycleNumber += 1;
this.floatingPoints[i].y -= 1;
this.floatingPoints[i].update();
if (this.floatingPoints[i].cycleNumber > this.floatingPointCycleDuration) {
this.floatingPoints.splice(i, 1);
};
};
},
reset : function() {
this.lives.player1 = knobsAndLevers.player.defaultLives;
this.lives.player2 = knobsAndLevers.player.defaultLives;
this.currentLevel = 1;
this.lastScore = this.score.player1;
this.score.player1 = 0;
},
};
var texts = {
textParams : {},
init : function() {
this.setTextParams();
this.buildBackgrounds(this.textParams);
this.createElements();
console.log("texts initialized");
},
setTextParams : function() {
this.textParams = {
level : Object.assign(this.getDefaults(), {
x : knobsAndLevers.canvas.width * 0.6,
y : this.getDefaults().gameInfoHeight,
}),
lives : Object.assign(this.getDefaults(), {
x : 720,
y : this.getDefaults().gameInfoHeight,
}),
score : Object.assign(this.getDefaults(), {
x : 100,
y : this.getDefaults().gameInfoHeight,
}),
died : Object.assign(this.getDefaults(), {
fontSize : (knobsAndLevers.general.gridSquareSideLength * 1.5) + "px",
y : knobsAndLevers.canvas.height * 0.75,
backgroundMultipliers : {
y : 1.01,
height : 1.8,
},
}),
paused : Object.assign(this.getDefaults(), {
y : knobsAndLevers.canvas.height * 0.9,
backgroundMultipliers : {
y : 1.01,
height : 1,
},
}),
gameOver : Object.assign(this.getDefaults(), {
fontSize : '50px',
y : knobsAndLevers.canvas.height * 0.5,
backgroundMultipliers : {
y : 1.05,
height : 3,
},
}),
};
},
getDefaults : function() {
return supporting.clone(knobsAndLevers.text.baseParams);
},
buildBackgrounds : function(params) {
Object.keys(params).forEach(key => {
let multipliers = params[key].backgroundMultipliers;
if (!multipliers) {
return;
};
let defaults = supporting.clone(knobsAndLevers.text.baseBackgroundParams);
defaults.height *= multipliers.height;
defaults.y = (params[key].y - defaults.height) * multipliers.y;
params[key].background = new Component(defaults);
});
},
createElements : function() {
this.lives = new Component(this.textParams.lives);
this.score = new Component(this.textParams.score);
this.level = new Component(this.textParams.level);
this.pausedMessage = new Component(this.textParams.paused);
this.diedText = new Component(this.textParams.died);
this.gameOver = new Component(this.textParams.gameOver);
},
};
......@@ -29,9 +29,11 @@ var libs = [
'menus/initials.js',
'menus/main-menu.js',
'menus.js',
'metrics.js',
'playerBase.js',
'sound.js',
'templates.js',
'texts.js',
];
var scripts = [
......@@ -39,10 +41,8 @@ var scripts = [
'components/centipedes.js',
'components/game-objects.js',
'components/lasers.js',
'components/metrics.js',
'components/mushrooms.js',
'components/players.js',
'components/texts.js',
'game.js',
'init/init.js',
'knobs-and-levers.js',
......
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