Skip to content

Commit

Permalink
Issue #98 Fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
hal255 committed Dec 1, 2018
2 parents 2e1283a + f24aab2 commit 8a4a575
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 44 deletions.
Binary file added client/assets/img/scoreTexts/scoreTextAsset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/img/scoreTexts/textNum0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/img/scoreTexts/textNum1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/img/scoreTexts/textNum2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/img/scoreTexts/textNum3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/img/scoreTexts/textNum4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/img/scoreTexts/textNum5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/img/scoreTexts/textNum6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/img/scoreTexts/textNum7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/img/scoreTexts/textNum8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/img/scoreTexts/textNum9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 64 additions & 8 deletions client/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,71 @@ config.default.blocks = {
}

config.default.score = {
style : {
font: "bold 30px Courier",
fill: "#fff",
},
interface: {},
amount: 0,
bonus1: 1,
bonus: 1,
text: "SCORE:",
x: 0,
y: 5
x: config.default.settings.tileWidth,
y: 5,
numOffsetX: 17, // score value, number of spaces
sprites:{
scoreText:{
src: "assets/img/scoreTexts/scoreTextAsset.png",
key: "scoreText"
},
textNum0:{
src: "assets/img/scoreTexts/textNum0.png",
key: "textNum0"
},
textNum1:{
src: "assets/img/scoreTexts/textNum1.png",
key: "textNum1"
},
textNum2:{
src: "assets/img/scoreTexts/textNum2.png",
key: "textNum2"
},
textNum3:{
src: "assets/img/scoreTexts/textNum3.png",
key: "textNum3"
},
textNum4:{
src: "assets/img/scoreTexts/textNum4.png",
key: "textNum4"
},
textNum5:{
src: "assets/img/scoreTexts/textNum5.png",
key: "textNum5"
},
textNum6:{
src: "assets/img/scoreTexts/textNum6.png",
key: "textNum6"
},
textNum7:{
src: "assets/img/scoreTexts/textNum7.png",
key: "textNum7"
},
textNum8:{
src: "assets/img/scoreTexts/textNum8.png",
key: "textNum8"
},
textNum9:{
src: "assets/img/scoreTexts/textNum9.png",
key: "textNum9"
}
},
};

config.default.score.spriteMap = {
"0": config.default.score.sprites.textNum0.key,
"1": config.default.score.sprites.textNum1.key,
"2": config.default.score.sprites.textNum2.key,
"3": config.default.score.sprites.textNum3.key,
"4": config.default.score.sprites.textNum4.key,
"5": config.default.score.sprites.textNum5.key,
"6": config.default.score.sprites.textNum6.key,
"7": config.default.score.sprites.textNum7.key,
"8": config.default.score.sprites.textNum8.key,
"9": config.default.score.sprites.textNum9.key
};

config.default.debug = {
Expand Down Expand Up @@ -306,3 +361,4 @@ config.default.mapUtilities = {
config.default.gameInformation = {
title: "PathLight"
};

1 change: 1 addition & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<script type="text/javascript" src="js/gameLoopTools/playerUtilities.js"></script>
<script type="text/javascript" src="js/gameLoopTools/blockUtilities.js"></script>
<script type="text/javascript" src="js/gameLoopTools/darknessUtilities.js"></script>
<script type="text/javascript" src="js/gameLoopTools/scoreUtilities.js"></script>
<script type="text/javascript" src="js/gameLoop.js"></script>
<script type="text/javascript" src="js/gameOverState.js"></script>
<script type="text/javascript" src="js/stateManager.js"></script>
Expand Down
15 changes: 4 additions & 11 deletions client/js/gameLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,8 @@ gameLoop = {
game.input.onDown.add(() => { gameLoop.player.controlType = config.default.controls.mouse; });

//setup score UI
let gameScoreData = [
gameLoop.score.x,
gameLoop.score.y,
gameLoop.score.text,
gameLoop.score.style
];
gameLoop.score.interface = game.add.text(...gameScoreData);
scoreUtilities.create(gameLoop.score);

if (gameLoop.debugMode === true) {
gameLoop.debug.controls = game.input.keyboard;
};
Expand All @@ -61,10 +56,8 @@ gameLoop = {
mapController.update();
playerUtilities.update(gameLoop.player);

//gameLoop.score.amount += gameLoop.score.bonus1;

// update score and text
gameLoop.score.interface.setText(gameLoop.score.text + gameLoop.score.amount);
// update score
scoreUtilities.setText(gameLoop.score, gameLoop.score.amount + gameLoop.score.bonus);

if(gameLoop.debugMode){
//let upScrollCheat = gameLoop.debug.controls.isDown(Phaser.KeyCode.OPEN_BRACKET);
Expand Down
21 changes: 14 additions & 7 deletions client/js/gameLoopTools/mapController.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,26 @@ mapController.update = () => {
if (object.fullyOnMap === false) {
if (mapController.top <= objectTop) {
if (typeof (object.onFullyOnMap) === "function") {
// Since the top of the object might be past y=0 when this is detected, the position of the object top is passed
// as an argument to use for spawning the next object at the correct position
object.onFullyOnMap(transformUtilities.getTopPosition(object.y, object.height, object.anchor.y));
}
}
object.fullyOnMap = true;
}
}
else {
if (mapController.top > objectTop)
object.fullyOnMap = false;
}

if (mapController.bottom <= objectTop) {
if (typeof (object.onFullyLeftMap) === "function")
object.onFullyLeftMap();
//if (typeof (object.destroy) === "function") // this should be used if there's some custom destruction method attached to .onFullyLeftMap
// object.destroy();
object.destroy();
mapController.mapObjects.splice(i, 1);
if (typeof (object.onFullyLeftMap) === "function") {
object.onFullyLeftMap(); // This delegate acts as an override to the default auto-destroy behavior
}
else {
object.destroy();
mapController.mapObjects.splice(i, 1);
}
}
}
};
Expand Down
28 changes: 10 additions & 18 deletions client/js/gameLoopTools/neutralMap.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const neutralMap = {};

neutralMap.mapSprites = [];

neutralMap.init = (data) => {
data = typeof data === "undefined" ? {} : data;
neutralMap.mapData = data.neutralMap || config.neutralMap;
neutralMap.width = data.width || config.init.screenWidth;
neutralMap.height = data.height || config.init.screenHeight;

neutralMap.graphicCenter = [0.5, 0.5];

};

neutralMap.createMaps = () => {

let nextMapSpriteBottom = neutralMap.height;
let latestMapSprite;
do {
Expand All @@ -26,29 +26,21 @@ neutralMap.createMaps = () => {
transformUtilities.getScaleValueToEnvelopeRect(latestMapSprite.width, latestMapSprite.height, neutralMap.width, neutralMap.height);
latestMapSprite.y = nextMapSpriteBottom - latestMapSprite.height * (1 - latestMapSprite.anchor.y);

latestMapSprite.onFullyOnMap = neutralMap.generateNewMap;
latestMapSprite.onFullyOnMap = neutralMap.reorderBottomSpriteToTop;
latestMapSprite.onFullyLeftMap = () => { }; // this acts as an override to the default auto-destroy functionality

nextMapSpriteBottom = transformUtilities.getTopPosition(latestMapSprite.y, latestMapSprite.height, latestMapSprite.anchor.y); // next map sprite bottom is latest map sprite top

neutralMap.mapSprites.push(latestMapSprite);
mapController.addToMap(latestMapSprite);
} while (nextMapSpriteBottom >= 0);
};

neutralMap.generateNewMap = (topPosition) => {
let mapSpriteData = [
neutralMap.width * neutralMap.mapData.xRegion,
0, // this will be changed
neutralMap.mapData.imgKey
];
let mapSprite = game.add.sprite(...mapSpriteData);
mapSprite.anchor.setTo(...neutralMap.graphicCenter);
mapSprite.scale.x = mapSprite.scale.y =
transformUtilities.getScaleValueToEnvelopeRect(mapSprite.width, mapSprite.height, neutralMap.width, neutralMap.height);
mapSprite.y = topPosition - mapSprite.height * (1 - mapSprite.anchor.y);

mapSprite.onFullyOnMap = neutralMap.generateNewMap;

mapController.addToMap(mapSprite);
// This reorder function does visually break if an integer number of sprites do not take up the entire screen height, in which case the do-while loop above just needs to run 1 more time
neutralMap.reorderBottomSpriteToTop = (topPosition) => {
let bottomSprite = neutralMap.mapSprites.shift();
bottomSprite.y = topPosition - bottomSprite.height * (1 - bottomSprite.anchor.y);
neutralMap.mapSprites.push(bottomSprite);
};

// setup neutral map
Expand Down
30 changes: 30 additions & 0 deletions client/js/gameLoopTools/scoreUtilities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const scoreUtilities = {};
scoreUtilities.create = (score) => {
score.sprite = game.add.sprite(score.x, score.y, score.sprites.scoreText.key);
game.physics.enable(score.sprite, Phaser.Physics.ARCADE);
score.spriteMap = config.default.score.spriteMap;
};

scoreUtilities.setText = (score, newScore) => {
if (newScore != null){
score.amount++;
}
else{
score.amount = newScore;
}
// kill all the children (that sounds... wrong)
if (score.sprite.children.length > 0){
score.sprite.removeChildren();
}

// create children based on score amount
let amountStr = score.amount.toString();
let offSetX = score.numOffsetX;
let length = amountStr.length;

for(var i = 0; i < length; i++){
score.sprite.addChild(game.make.sprite(offSetX+score.sprite.width, score.y, score.spriteMap[amountStr[i]]));
offSetX += score.numOffsetX;
}
return score.amount;
};
16 changes: 16 additions & 0 deletions client/js/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ loadState = {

// Game over loads
game.load.image(config.gameOverState.restartButton.key, config.gameOverState.restartButton.src);

// score texts
game.load.image(config.default.score.sprites.scoreText.key, config.default.score.sprites.scoreText.src);
game.load.image(config.default.score.sprites.textNum0.key, config.default.score.sprites.textNum0.src);
game.load.image(config.default.score.sprites.textNum1.key, config.default.score.sprites.textNum1.src);
game.load.image(config.default.score.sprites.textNum2.key, config.default.score.sprites.textNum2.src);
game.load.image(config.default.score.sprites.textNum3.key, config.default.score.sprites.textNum3.src);
game.load.image(config.default.score.sprites.textNum4.key, config.default.score.sprites.textNum4.src);
game.load.image(config.default.score.sprites.textNum5.key, config.default.score.sprites.textNum5.src);
game.load.image(config.default.score.sprites.textNum6.key, config.default.score.sprites.textNum6.src);
game.load.image(config.default.score.sprites.textNum7.key, config.default.score.sprites.textNum7.src);
game.load.image(config.default.score.sprites.textNum8.key, config.default.score.sprites.textNum8.src);
game.load.image(config.default.score.sprites.textNum9.key, config.default.score.sprites.textNum9.src);
},

/**
Expand All @@ -155,6 +168,9 @@ loadState = {
create: () => {
// setup screen image
game.stage.backgroundColor = loadState.background;

loadState.changeState(); // skip all this fake loading screen stuff lol

//loadState.getMapSpeed();
loadState.createScreenImg();

Expand Down

0 comments on commit 8a4a575

Please sign in to comment.