User prompt
Whenever a player completes a square, increment the corresponding player's score variable by 1
Code edit (1 edits merged)
Please save this source code
User prompt
aligns score vertically with players icons
User prompt
make the scores twice bigger
User prompt
move the score text of P1 at right of P1 icon, and the score text of P2 at left of P2 icon
User prompt
3. Create two Text2 objects, which will be used to display the scores on the screen. These text objects should be added to the 'Game' class as well, and we can call them `player1ScoreText` and `player2ScoreText`.
User prompt
2. Initialize these score variables to zero at the start of the game, as both players start with no points.
User prompt
1. Define two variables within the 'Game' class to keep track of the scores for each player. Let's call them `player1Score` and `player2Score`.
User prompt
fix "gameInstance.currentPlayer" because it doesn't exist, use the global currentPlayer
User prompt
fix currentPlayer variable to only use the one from the global scope
User prompt
fix currentPlayer not changing
User prompt
move activateLine function at the same level as updatePlayerIcons function
User prompt
move function activateLine out from VerticalLine to global scope
User prompt
factorise activateLine by creating a global function with all required parameters to ensure it respects functional programming
User prompt
continue the factorisation process where it is suitable
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'player1Icon')' in this line: 'updatePlayerIcons(currentPlayer, self.gameInstance.player1Icon, self.gameInstance.player2Icon);' Line Number: 16
User prompt
use updatePlayerIcons in VerticalLine like in HorizontalLine, adapt the signatures
User prompt
update this.updatePlayerIcons to be global independant function not 'this' , update the corresponding calls
User prompt
Fix Bug: 'TypeError: self.gameInstance.updatePlayerIcons is not a function' in this line: 'self.gameInstance.updatePlayerIcons(currentPlayer, self.gameInstance.player1Icon, self.gameInstance.player2Icon);' Line Number: 34
User prompt
updatePlayerIcons doesn't work because in the caller funciton self is refering to the HorizontalLine not the game. fix this
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'scale')' in this line: 'player1Icon.scale.set(currentPlayer === 1 ? 1.2 : 0.8);' Line Number: 57
User prompt
update updatePlayerIcons to make it dependency free
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'scale')' in this line: 'gameInstance.player1Icon.scale.set(currentPlayer === 1 ? 1.2 : 0.8);' Line Number: 58
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'scale')' in this line: 'gameInstance.player1Icon.scale.set(currentPlayer === 1 ? 1.2 : 0.8);' Line Number: 58
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'scale')' in this line: 'gameInstance.player1Icon.scale.set(currentPlayer === 1 ? 1.2 : 0.8);' Line Number: 58
var VerticalLine = Container.expand(function (playerNumber, gameInstance) { var self = Container.call(this); var lineGraphics = self.createAsset('lineVertical', 'Vertical Line Graphics', 0.5, 0); lineGraphics.alpha = 0.3; self.playerNumber = null; self.gameInstance = gameInstance; self.setLength = function (length) { lineGraphics.height = length; }; self.on('down', function () { activateLine(self, currentPlayer, lineGraphics, self.gameInstance); }); return self; }); var HorizontalLine = Container.expand(function (playerNumber, gameInstance) { var self = Container.call(this); var lineGraphics = self.createAsset('lineHorizontal', 'Horizontal Line Graphics', 0, 0.5); lineGraphics.alpha = 0.3; self.playerNumber = null; self.gameInstance = gameInstance; self.setLength = function (length) { lineGraphics.width = length; }; self.on('down', function () { activateLine(self, currentPlayer, lineGraphics, self.gameInstance); }); return self; }); var Dot = Container.expand(function () { var self = Container.call(this); var dotGraphics = self.createAsset('dot', 'Dot Graphics', .5, .5); self.connect = function () {}; }); var Square = Container.expand(function () { var self = Container.call(this); var squareGraphics = self.createAsset('square', 'Square Graphics', .5, .5); self.collectGift = function () {}; }); var PlayerIcon = Container.expand(function (playerNumber) { var self = Container.call(this); var iconAsset = playerNumber === 1 ? 'player1Icon' : 'player2Icon'; var playerIconGraphics = self.createAsset(iconAsset, 'Player ' + playerNumber + ' Icon', 0.5, 0.5); playerIconGraphics.tint = playerNumber === 2 ? 0x00FF00 : playerIconGraphics.tint; playerIconGraphics.tint = playerNumber === 1 ? 0xFF0000 : playerIconGraphics.tint; return self; }); function updatePlayerIcons(currentPlayer, player1Icon, player2Icon) { if (player1Icon && player2Icon) { player1Icon.scale.set(currentPlayer === 1 ? 1.2 : 0.8); player2Icon.scale.set(currentPlayer === 2 ? 1.2 : 0.8); } } function activateLine(line, playerNumber, lineGraphics, gameInstance) { if (line.playerNumber === null) { line.playerNumber = playerNumber; lineGraphics.alpha = 1; lineGraphics.tint = playerNumber === 1 ? 0xFF0000 : 0x00FF00; currentPlayer = currentPlayer === 1 ? 2 : 1; updatePlayerIcons(playerNumber, gameInstance.player1Icon, gameInstance.player2Icon); } } var currentPlayer = 1; var player2Score = 0; var player1Score = 0; var Game = Container.expand(function () { var self = Container.call(this); self.player1Icon = self.addChild(new PlayerIcon(1)); self.player1Icon.x = 2048 * 0.25; self.player1Icon.y = 250; self.player1Icon.scale.set(1.2); self.player2Icon = self.addChild(new PlayerIcon(2)); self.player2Icon.x = 2048 * 0.75; self.player2Icon.y = 250; self.player2Icon.scale.set(1); player1Icon = self.player1Icon; player2Icon = self.player2Icon; var dots = []; var squares = []; var gifts = 0; var player1Icon, player2Icon; var boardSize = 6 * 300; var offsetX = (2048 - boardSize) / 2; var offsetY = (2732 - boardSize) / 2 + 150; for (var i = 0; i < 7; i++) { for (var j = 0; j < 7; j++) { var dot = new Dot(); dot.x = offsetX + i * 300; dot.y = offsetY + j * 300; dots.push(dot); if (i < 6) { var hLine = new HorizontalLine(currentPlayer, self); hLine.x = dot.x; hLine.y = dot.y; hLine.setLength(300); self.addChild(hLine); } if (j < 6) { var vLine = new VerticalLine(currentPlayer, self); vLine.x = dot.x; vLine.y = dot.y; vLine.setLength(300); self.addChild(vLine); } self.addChild(dot); } } dots.forEach(function (dot) { dot.on('down', function (obj) { var event = obj.event; var pos = event.getLocalPosition(self); }); }); LK.on('tick', function () { squares.forEach(function (square) { if (square.isComplete()) { gifts++; square.collectGift(); } }); }); });
===================================================================
--- original.js
+++ change.js
@@ -59,8 +59,10 @@
updatePlayerIcons(playerNumber, gameInstance.player1Icon, gameInstance.player2Icon);
}
}
var currentPlayer = 1;
+var player2Score = 0;
+var player1Score = 0;
var Game = Container.expand(function () {
var self = Container.call(this);
self.player1Icon = self.addChild(new PlayerIcon(1));
self.player1Icon.x = 2048 * 0.25;
a b&w grinch icon Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
b&w smiling Santa Clauss' head icon Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a white christmas star. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
top face of a white gift. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.