diff --git a/client/assets/img/scoreTexts/scoreTextAsset.png b/client/assets/img/scoreTexts/scoreTextAsset.png new file mode 100644 index 0000000..4bbbc41 Binary files /dev/null and b/client/assets/img/scoreTexts/scoreTextAsset.png differ diff --git a/client/assets/img/scoreTexts/textNum0.png b/client/assets/img/scoreTexts/textNum0.png new file mode 100644 index 0000000..61e5c4b Binary files /dev/null and b/client/assets/img/scoreTexts/textNum0.png differ diff --git a/client/assets/img/scoreTexts/textNum1.png b/client/assets/img/scoreTexts/textNum1.png new file mode 100644 index 0000000..11b0b83 Binary files /dev/null and b/client/assets/img/scoreTexts/textNum1.png differ diff --git a/client/assets/img/scoreTexts/textNum2.png b/client/assets/img/scoreTexts/textNum2.png new file mode 100644 index 0000000..158d91e Binary files /dev/null and b/client/assets/img/scoreTexts/textNum2.png differ diff --git a/client/assets/img/scoreTexts/textNum3.png b/client/assets/img/scoreTexts/textNum3.png new file mode 100644 index 0000000..bc68a40 Binary files /dev/null and b/client/assets/img/scoreTexts/textNum3.png differ diff --git a/client/assets/img/scoreTexts/textNum4.png b/client/assets/img/scoreTexts/textNum4.png new file mode 100644 index 0000000..8fe6b95 Binary files /dev/null and b/client/assets/img/scoreTexts/textNum4.png differ diff --git a/client/assets/img/scoreTexts/textNum5.png b/client/assets/img/scoreTexts/textNum5.png new file mode 100644 index 0000000..bc7e0ca Binary files /dev/null and b/client/assets/img/scoreTexts/textNum5.png differ diff --git a/client/assets/img/scoreTexts/textNum6.png b/client/assets/img/scoreTexts/textNum6.png new file mode 100644 index 0000000..cb5b86d Binary files /dev/null and b/client/assets/img/scoreTexts/textNum6.png differ diff --git a/client/assets/img/scoreTexts/textNum7.png b/client/assets/img/scoreTexts/textNum7.png new file mode 100644 index 0000000..d6e9736 Binary files /dev/null and b/client/assets/img/scoreTexts/textNum7.png differ diff --git a/client/assets/img/scoreTexts/textNum8.png b/client/assets/img/scoreTexts/textNum8.png new file mode 100644 index 0000000..77ee5d4 Binary files /dev/null and b/client/assets/img/scoreTexts/textNum8.png differ diff --git a/client/assets/img/scoreTexts/textNum9.png b/client/assets/img/scoreTexts/textNum9.png new file mode 100644 index 0000000..a68d0df Binary files /dev/null and b/client/assets/img/scoreTexts/textNum9.png differ diff --git a/client/config/config.js b/client/config/config.js index 07d4b89..488750a 100644 --- a/client/config/config.js +++ b/client/config/config.js @@ -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 = { @@ -306,3 +361,4 @@ config.default.mapUtilities = { config.default.gameInformation = { title: "PathLight" }; + diff --git a/client/index.html b/client/index.html index d7773bb..8b848ba 100644 --- a/client/index.html +++ b/client/index.html @@ -22,6 +22,7 @@ + diff --git a/client/js/gameLoop.js b/client/js/gameLoop.js index 8a3b7c2..8784b63 100644 --- a/client/js/gameLoop.js +++ b/client/js/gameLoop.js @@ -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; }; @@ -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); diff --git a/client/js/gameLoopTools/mapController.js b/client/js/gameLoopTools/mapController.js index 5cb96c0..ba06469 100644 --- a/client/js/gameLoopTools/mapController.js +++ b/client/js/gameLoopTools/mapController.js @@ -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); + } } } }; diff --git a/client/js/gameLoopTools/neutralMap.js b/client/js/gameLoopTools/neutralMap.js index 10bc096..14ccbfb 100644 --- a/client/js/gameLoopTools/neutralMap.js +++ b/client/js/gameLoopTools/neutralMap.js @@ -1,5 +1,7 @@ const neutralMap = {}; +neutralMap.mapSprites = []; + neutralMap.init = (data) => { data = typeof data === "undefined" ? {} : data; neutralMap.mapData = data.neutralMap || config.neutralMap; @@ -7,11 +9,9 @@ neutralMap.init = (data) => { neutralMap.height = data.height || config.init.screenHeight; neutralMap.graphicCenter = [0.5, 0.5]; - }; neutralMap.createMaps = () => { - let nextMapSpriteBottom = neutralMap.height; let latestMapSprite; do { @@ -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 diff --git a/client/js/gameLoopTools/scoreUtilities.js b/client/js/gameLoopTools/scoreUtilities.js new file mode 100644 index 0000000..d28bf1f --- /dev/null +++ b/client/js/gameLoopTools/scoreUtilities.js @@ -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; +}; diff --git a/client/js/load.js b/client/js/load.js index e5c86c2..906edff 100644 --- a/client/js/load.js +++ b/client/js/load.js @@ -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); }, /** @@ -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();