User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'anchor')' in or related to this line: 'self.anchor.set(0.5, 0);' Line Number: 54
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'anchor')' in or related to this line: 'scoreDisplay.anchor.set(0.5, 0);' Line Number: 55
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'anchor')' in or related to this line: 'self.anchor.set(0.5, 0);' Line Number: 54
User prompt
Show the score at the top. It is a timer based on how long you last. For each hunter that passes you add one point
User prompt
Increase the number of hunters over time and add a score.
User prompt
Add trees and other obstacles
Initial prompt
Varga
/**** * Classes ****/ // Hunter class representing the enemies var Hunter = Container.expand(function () { var self = Container.call(this); var hunterGraphics = self.attachAsset('hunter', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = -100; // Reset position to top self.x = Math.random() * 2048; // Randomize x position } }; }); // Tree class representing the obstacles var Tree = Container.expand(function () { var self = Container.call(this); var treeGraphics = self.attachAsset('tree', { anchorX: 0.5, anchorY: 0.5 }); }); //<Assets used in the game will automatically appear here> // Wolf class representing the player character var Wolf = Container.expand(function () { var self = Container.call(this); var wolfGraphics = self.attachAsset('wolf', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Wolf movement logic can be added here }; }); // Score class to display the score var Score = Text2.expand(function () { var self = Text2.call(this); var scoreDisplay = Text2.call(this, '0', { size: 150, fill: "#ffffff" }); scoreDisplay.anchor.set(0.5, 0); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x228B22 // Init game with forest green background }); /**** * Game Code ****/ // Initialize game variables var score = 0; var wolf = game.addChild(new Wolf()); wolf.x = 2048 / 2; wolf.y = 2732 - 150; // Initialize and add the score to the GUI overlay var scoreDisplay = new Score(); LK.gui.top.addChild(scoreDisplay); var hunters = []; for (var i = 0; i < 5; i++) { var hunter = new Hunter(); hunter.x = Math.random() * 2048; hunter.y = Math.random() * -2732; hunters.push(hunter); game.addChild(hunter); } var trees = []; for (var i = 0; i < 10; i++) { var tree = new Tree(); tree.x = Math.random() * 2048; tree.y = Math.random() * 2732; trees.push(tree); game.addChild(tree); } // Handle touch/mouse movement game.move = function (x, y, obj) { wolf.x = x; wolf.y = y; }; // Update game state game.update = function () { for (var i = 0; i < hunters.length; i++) { hunters[i].update(); if (wolf.intersects(hunters[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } if (hunters[i].y > 2732) { score += 1; scoreDisplay.setText(score.toString()); var newHunter = new Hunter(); newHunter.x = Math.random() * 2048; newHunter.y = Math.random() * -2732; hunters.push(newHunter); game.addChild(newHunter); } } };
===================================================================
--- original.js
+++ change.js
@@ -39,13 +39,14 @@
};
});
// Score class to display the score
var Score = Text2.expand(function () {
- var self = Text2.call(this, '0', {
+ var self = Text2.call(this);
+ var scoreDisplay = Text2.call(this, '0', {
size: 150,
fill: "#ffffff"
});
- self.anchor.set(0.5, 0);
+ scoreDisplay.anchor.set(0.5, 0);
});
/****
* Initialize Game
Wolf puppy 8-bit character cute and adorable. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit character that is a hunter. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit pine tree. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.