User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'visible')' in this line: 'if (self.activeMagicCount < self.maxMagicAllowed && LK.gui.topCenter.children[0].visible && self.activeBadElves > 0) {' Line Number: 297
User prompt
in this code line, avoid instancing any magic unless the score is visible and a badelf exists self.maxMagicAllowed = 3; if (self.activeMagicCount < self.maxMagicAllowed) { var magicInstance = new Magic(this.magicSpawnX, this.magicSpawnY, self); self.addChild(magicInstance); self.activeMagicCount++;
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'activeMagicCount')' in this line: 'self.activeMagicCount = self.activeMagicCount || 0;' Line Number: 266
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'activeMagicCount')' in this line: 'if (self.activeMagicCount < self.maxMagicAllowed) {' Line Number: 266
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'activeMagicCount')' in this line: 'if (self.activeMagicCount < self.maxMagicAllowed) {' Line Number: 266
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'activeMagicCount')' in this line: 'if (self.activeMagicCount < self.maxMagicAllowed) {' Line Number: 266
Code edit (14 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'maxMagicAllowed')' in this line: 'self.maxMagicAllowed = 3;' Line Number: 265
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'getLocalPosition')' in this line: 'var pos = event.getLocalPosition(self.parent);' Line Number: 229
User prompt
Fix Bug: 'ReferenceError: obj is not defined' in this line: 'var pos = obj.event.getLocalPosition(self.parent);' Line Number: 229
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'getLocalPosition')' in this line: 'var pos = event.getLocalPosition(self.parent);' Line Number: 229
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'getLocalPosition')' in this line: 'var pos = event.getLocalPosition(self.parent);' Line Number: 229
User prompt
Fix Bug: 'TypeError: child.move is not a function' in this line: 'child.move();' Line Number: 526
User prompt
Fix Bug: 'TypeError: child.move is not a function' in this line: 'child.move();' Line Number: 530
User prompt
Fix Bug: 'TypeError: child.move is not a function' in this line: 'child.move();' Line Number: 530
Code edit (1 edits merged)
Please save this source code
User prompt
when left click is pressed, move the crosshair to that location
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'activeMagicCount')' in this line: 'self.gameInstance.activeMagicCount++;' Line Number: 528
User prompt
Fix Bug: 'Cannot read properties of undefined (reading 'activeMagicCount')' in this line: 'self.gameInstance.activeMagicCount++;' Line Number: 528
User prompt
Make sure that instances of Magic are being correctly created and added to the game. For instance, when a BadElf shoots magic, it should instantiate a Magic object and add it to the game.
User prompt
Ensure that (LK.on('tick', function() {...})) is actively running and calling the move function for each Magic instance.
User prompt
// Inside the Magic move function console.log("Distance: " + distance + ", Threshold: " + hitThreshold);
User prompt
// Inside the Magic move function console.log("Santa X: " + santa.x + ", Y: " + santa.y); console.log("Distance: " + distance + ", Threshold: " + hitThreshold);
===================================================================
--- original.js
+++ change.js
@@ -81,10 +81,60 @@
self.parent.randomTextActive = false;
}, 3000);
};
});
+var BadElf = Container.expand(function (spawnX, spawnY, gameInstance) {
+ var self = Container.call(this);
+ self.gameInstance = gameInstance;
+ self.spawnedMagicCount = 1;
+ self.magicShootingInterval = LK.setInterval(function () {
+ if (self.visible && self.gameInstance && self.gameInstance.activeMagicCount < self.gameInstance.maxMagicAllowed) {
+ var magic = new Magic(self.x + 125, self.y, self.gameInstance);
+ self.gameInstance.addChild(magic);
+ self.gameInstance.activeMagicCount++;
+ self.spawnedMagicCount++;
+ if (self.spawnedMagicCount >= 2) {
+ self.alpha = 1;
+ var fadeOutInterval;
+ var fadeOut = function () {
+ if (self.alpha > 0) {
+ self.alpha -= 0.05;
+ } else {
+ LK.clearInterval(fadeOutInterval);
+ self.gameInstance.activeBadElves--;
+ self.destroy();
+ LK.setTimeout(function () {
+ self.gameInstance.spawnBadElf();
+ }, 2000);
+ }
+ };
+ LK.clearInterval(self.magicShootingInterval);
+ fadeOutInterval = LK.setInterval(fadeOut, 60);
+ self.magicShootingInterval = null;
+ }
+ }
+ }, Math.random() * (6000 - 2000) + 2000);
+ var badElfGraphics = self.createAsset('badElf', 'Mischievous Elf', 0.5, 0.5);
+ self.x = spawnX;
+ self.y = spawnY;
+ self.on('down', function (obj) {
+ LK.setScore(LK.getScore() + 3);
+ LK.gui.topCenter.children[0].setText(LK.getScore().toString());
+ this.gameInstance.activeBadElves--;
+ var obstacleBox = new ObstacleBox(this.x, this.y, this.gameInstance);
+ obstacleBox.x = this.x;
+ obstacleBox.y = this.y;
+ this.parent.addChild(obstacleBox);
+ LK.setTimeout(function () {
+ obstacleBox.destroy();
+ }, 1000);
+ LK.clearInterval(this.magicShootingInterval);
+ this.destroy();
+ });
+});
var Magic = Container.expand(function (x, y, gameInstance) {
var self = Container.call(this);
+ console.log("magic creation triggered");
self.gameInstance = gameInstance;
self.moveEnabled = true;
self.rotation = 0;
var magicGraphics = self.createAsset('magic', 'Magic effect', 0.5, 0.5);
@@ -109,9 +159,9 @@
self.x += normX * speed;
self.y += normY * speed;
}
console.log("distance = " + distance);
- if (distance <= 150) {
+ if (distance <= 100) {
console.log('Hit threshold met. Game over triggered.');
self.gameInstance.triggerGameOver();
}
if (self.gameInstance.santa) {} else if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
@@ -138,57 +188,8 @@
this.gameInstance.activeMagicCount--;
this.destroy();
});
});
-var BadElf = Container.expand(function (spawnX, spawnY, gameInstance) {
- var self = Container.call(this);
- self.gameInstance = gameInstance;
- self.spawnedMagicCount = 1;
- self.magicShootingInterval = LK.setInterval(function () {
- if (self.visible && self.gameInstance && self.gameInstance.activeMagicCount < self.gameInstance.maxMagicAllowed) {
- var magic = new Magic(self.x + 125, self.y, self.gameInstance);
- self.gameInstance.addChild(magic);
- self.gameInstance.activeMagicCount++;
- self.spawnedMagicCount++;
- if (self.spawnedMagicCount >= 2) {
- self.alpha = 1;
- var fadeOutInterval;
- var fadeOut = function () {
- if (self.alpha > 0) {
- self.alpha -= 0.05;
- } else {
- LK.clearInterval(fadeOutInterval);
- self.gameInstance.activeBadElves--;
- self.destroy();
- LK.setTimeout(function () {
- self.gameInstance.spawnBadElf();
- }, 2000);
- }
- };
- LK.clearInterval(self.magicShootingInterval);
- fadeOutInterval = LK.setInterval(fadeOut, 60);
- self.magicShootingInterval = null;
- }
- }
- }, Math.random() * (6000 - 2000) + 2000);
- var badElfGraphics = self.createAsset('badElf', 'Mischievous Elf', 0.5, 0.5);
- self.x = spawnX;
- self.y = spawnY;
- self.on('down', function (obj) {
- LK.setScore(LK.getScore() + 3);
- LK.gui.topCenter.children[0].setText(LK.getScore().toString());
- this.gameInstance.activeBadElves--;
- var obstacleBox = new ObstacleBox(this.x, this.y, this.gameInstance);
- obstacleBox.x = this.x;
- obstacleBox.y = this.y;
- this.parent.addChild(obstacleBox);
- LK.setTimeout(function () {
- obstacleBox.destroy();
- }, 1000);
- LK.clearInterval(this.magicShootingInterval);
- this.destroy();
- });
-});
var Mistletoe = Container.expand(function (gameInstance) {
var self = Container.call(this);
self.gameInstance = gameInstance;
var mistletoeGraphics = self.createAsset('mistletoe', 'Mistletoe', 0.5, 0.5);
@@ -260,10 +261,17 @@
};
var crosshairGraphics = self.createAsset('crosshair', 'Crosshair', .5, .5);
self.y = -crosshairGraphics.height / 2;
});
+self.maxMagicAllowed = 3;
+if (self.activeMagicCount < self.maxMagicAllowed) {
+ var magicInstance = new Magic(this.magicSpawnX, this.magicSpawnY, self);
+ self.addChild(magicInstance);
+ self.activeMagicCount++;
+}
var Game = Container.expand(function () {
var self = Container.call(this);
+ self.maxMagicAllowed = 3;
this.triggerGameOver = function () {
this.isGameOver = true;
LK.showGameOver();
LK.on('tick', function () {
@@ -291,14 +299,8 @@
this.triggerGameOver = function () {
this.isGameOver = true;
LK.showGameOver();
};
- self.maxMagicAllowed = 3;
- if (self.activeMagicCount < self.maxMagicAllowed) {
- var magicInstance = new Magic(this.magicSpawnX, this.magicSpawnY, self);
- self.addChild(magicInstance);
- self.activeMagicCount++;
- }
self.respawnReindeer = function (reindeer) {
LK.setTimeout(function () {
var newReindeer = new Reindeer(self);
var spawnLeftSide = Math.random() < 0.5;
@@ -517,12 +519,9 @@
var badElf = new BadElf(location.x, location.y, self);
var scaleModifier = Math.random() * 0.25 + 0.75;
badElf.scale.set(scaleModifier, scaleModifier);
self.addChildAt(badElf, self.getChildIndex(room1Background) + 1);
- var magic = new Magic(badElf.x + badElf.width / 2, badElf.y, self);
self.activeBadElves++;
- self.addChildAt(magic, self.getChildIndex(santa));
- var bulletStartY = badElf.y - badElf.height;
}
};
var muzzleFlash = new MuzzleFlash();
muzzleFlash.x = santa.x - santa.santaGraphics.width + 400;
over the shoulder santa firing a revolver Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d transparent christmas crosshair Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d 3rd person front view of a christmas town square with a starry sky Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Christmas sparkles png Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
circular christmas golden star pattern transparent png Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d christmas brick wall Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d opened christmas crate Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d diagonal christmas car or truck in snow Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas poster showcasing miss santa clause Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a single white snowflake Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d stacked christmas winter tire Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d stacked christmas winter tire Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d christmas magical mistletoe Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d christmas 357 Magnum bullets Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d silhouette of a flying reindeer with a red glowy nose Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d christmas dark sparkles Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d christmas evil robot elf with a gun Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d pile of gray and red nuts and bolts Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
transparent snow sphere. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
snd_pistol
Sound effect
snd_enemyshot
Sound effect
snd_obstacle
Sound effect
snd_messages
Sound effect
snd_ricochet
Sound effect
snd_reindeer
Sound effect
snd_mistletoe
Sound effect
snd_reindeershot
Sound effect
snd_mistletoeshot
Sound effect
snd_christmasmusic
Music
snd_reload
Sound effect
snd_blastwave
Sound effect