Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'cell.targets')' in or related to this line: 'enemy.currentTarget = cell.targets[cell.targets.length * Math.random() >> 0];' Line Number: 225
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'cell.targets')' in or related to this line: 'enemy.currentTarget = cell.targets[cell.targets * Math.random() >> 0];' Line Number: 225
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'cell.targets')' in or related to this line: 'enemy.currentTarget = cell.targets[cell.targets * Math.random() >> 0];' Line Number: 225
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'cell.targets')' in or related to this line: 'enemy.currentTarget = cell.targets[cell.targets * Math.random() >> 0];' Line Number: 225
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'cell.currentTarget.targets')' in or related to this line: 'enemy.currentTarget = cell.currentTarget.targets[cell.targets * Math.random() >> 0];' Line Number: 232
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'cell.currentTarget.targets')' in or related to this line: 'enemy.currentTarget = cell.currentTarget.targets[cell.targets * Math.random() >> 0];' Line Number: 232
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'cell.currentTarget.targets')' in or related to this line: 'enemy.currentTarget = cell.currentTarget.targets[cell.targets * Math.random() >> 0];' Line Number: 232
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (17 edits merged)
Please save this source code
User prompt
when creating cells, after creating all the neighbors also pop them into an array
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
for each nodetype updated in pathfinder, push them to toProcess
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ // DebugCell class var DebugCell = Container.expand(function () { var self = Container.call(this); var cellGraphics = self.attachAsset('cell', { anchorX: 0.5, anchorY: 0.5 }); cellGraphics.tint = Math.random() * 0xffffff; // Add a debug arrow to the debug cells var debugArrow = self.attachAsset('arrow', { anchorX: 0.5, anchorY: 0.5 }); debugArrow.rotation = Math.random() * Math.PI * 2; self.addChild(debugArrow); debugArrow.alpha = .4; // Add a number label to the debug cells var numberLabel = new Text2('0', { size: 30, fill: "#ffffff", weight: 800 }); numberLabel.anchor.set(.5, .5); self.addChild(numberLabel); self.update = function () {}; self.render = function (data) { switch (data.type) { case 1: { cellGraphics.tint = 0xaaaaaa; debugArrow.visible = numberLabel.visible = false; break; } case 2: { cellGraphics.tint = 0x000088; break; } case 3: { cellGraphics.tint = 0x008800; debugArrow.visible = numberLabel.visible = false; break; } } numberLabel.setText(Math.ceil(data.score)); }; }); // Defense class var Defense = Container.expand(function () { var self = Container.call(this); var defenseGraphics = self.attachAsset('defense', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Defense logic goes here }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Enemy logic goes here }; }); // Grid class /* Types: 0: Ground 1: Wall 2: Spawn 3: Target */ var Grid = Container.expand(function (gridWidth, gridHeight) { var self = Container.call(this); self.cells = []; self.spawns = []; self.goals = []; for (var i = 0; i < gridWidth; i++) { self.cells[i] = []; for (var j = 0; j < gridHeight; j++) { self.cells[i][j] = { score: 0, pathId: 0 }; } } for (var i = 0; i < gridWidth; i++) { for (var j = 0; j < gridHeight; j++) { var debugCell = new DebugCell(); // Set the type to 1 (wall) if the cell is on the edge of the grid, otherwise set it to 0 (ground) var cell = self.cells[i][j]; var cellType = i === 0 || i === gridWidth - 1 || j === 0 || j === gridHeight - 1 ? 1 : 0; if (i > 11 - 3 && i <= 11 + 3) { if (j === 0) { cellType = 2; self.spawns.push(cell); } else if (j === gridHeight - 1) { cellType = 3; self.goals.push(cell); } } cell.type = cellType, cell.debugCell = debugCell, cell.x = i, cell.y = j; //Cache neighbours for speed cell.upLeft = self.cells[i - 1] && self.cells[i - 1][j - 1]; cell.up = self.cells[i - 1] && self.cells[i - 1][j]; cell.upRight = self.cells[i - 1] && self.cells[i - 1][j + 1]; cell.left = self.cells[i][j - 1]; cell.right = self.cells[i][j + 1]; cell.downLeft = self.cells[i + 1] && self.cells[i + 1][j - 1]; cell.down = self.cells[i + 1] && self.cells[i + 1][j]; cell.downRight = self.cells[i + 1] && self.cells[i + 1][j + 1]; self.addChild(debugCell); debugCell.x = i * 75; debugCell.y = j * 75; } } self.pathFind = function () { var toProcess = self.goals.concat([]); var node = toProcess[0]; var newNodes = []; var pathId = 1; if (node.upLeft && node.upLeft.pathId < pathId) { node.upLeft.score = node.score + 1.4142135624; newNodes.push(node.upLeft); } if (node.upRight && node.upRight.pathId < pathId) { node.upRight.score = node.score + 1.4142135624; newNodes.push(node.upRight); } if (node.downRight && node.downRight.pathId < pathId) { node.downRight.score = node.score + 1.4142135624; newNodes.push(node.downRight); } if (node.downLeft && node.downLeft.pathId < pathId) { node.downLeft.score = node.score + 1.4142135624; newNodes.push(node.downLeft); } if (node.up && node.up.pathId < pathId) { node.up.score = node.score + 1; newNodes.push(node.up); } if (node.right && node.right.pathId < pathId) { node.right.score = node.score + 1; newNodes.push(node.right); } if (node.down && node.down.pathId < pathId) { node.down.score = node.score + 1; newNodes.push(node.down); } if (node.left && node.left.pathId < pathId) { node.left.score = node.score + 1; newNodes.push(node.left); } }; self.renderDebug = function () { for (var i = 0; i < gridWidth; i++) { for (var j = 0; j < gridHeight; j++) { var debugCell = self.cells[i][j].debugCell; debugCell.render(self.cells[i][j]); } } }; }); // Assets will be automatically created and loaded by the LK engine // Tower class var Tower = Container.expand(function () { var self = Container.call(this); var towerGraphics = self.attachAsset('tower', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Tower logic goes here }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ /* Types: 0: Ground 1: Wall 2: Spawn 3: Target */ // Grid class // Initialize game variables var tower = game.addChild(new Tower()); tower.x = 2048 / 2; tower.y = 2732 / 2; var enemies = []; var defenses = []; var grid = new Grid(24, 28); grid.pathFind(); grid.x = 150; grid.y = 150; grid.renderDebug(); game.addChild(grid); game.update = function () { // Game logic goes here // Spawn enemies, update defenses, check for collisions, etc. };
===================================================================
--- original.js
+++ change.js
@@ -125,40 +125,41 @@
}
self.pathFind = function () {
var toProcess = self.goals.concat([]);
var node = toProcess[0];
+ var newNodes = [];
var pathId = 1;
if (node.upLeft && node.upLeft.pathId < pathId) {
node.upLeft.score = node.score + 1.4142135624;
- toProcess.push(node.upLeft);
+ newNodes.push(node.upLeft);
}
- if (node.up && node.up.pathId < pathId) {
- node.up.score = node.score + 1;
- toProcess.push(node.up);
- }
if (node.upRight && node.upRight.pathId < pathId) {
node.upRight.score = node.score + 1.4142135624;
- toProcess.push(node.upRight);
+ newNodes.push(node.upRight);
}
- if (node.right && node.right.pathId < pathId) {
- node.right.score = node.score + 1;
- toProcess.push(node.right);
- }
if (node.downRight && node.downRight.pathId < pathId) {
node.downRight.score = node.score + 1.4142135624;
- toProcess.push(node.downRight);
+ newNodes.push(node.downRight);
}
- if (node.down && node.down.pathId < pathId) {
- node.down.score = node.score + 1;
- toProcess.push(node.down);
- }
if (node.downLeft && node.downLeft.pathId < pathId) {
node.downLeft.score = node.score + 1.4142135624;
- toProcess.push(node.downLeft);
+ newNodes.push(node.downLeft);
}
+ if (node.up && node.up.pathId < pathId) {
+ node.up.score = node.score + 1;
+ newNodes.push(node.up);
+ }
+ if (node.right && node.right.pathId < pathId) {
+ node.right.score = node.score + 1;
+ newNodes.push(node.right);
+ }
+ if (node.down && node.down.pathId < pathId) {
+ node.down.score = node.score + 1;
+ newNodes.push(node.down);
+ }
if (node.left && node.left.pathId < pathId) {
node.left.score = node.score + 1;
- toProcess.push(node.left);
+ newNodes.push(node.left);
}
};
self.renderDebug = function () {
for (var i = 0; i < gridWidth; i++) {
White circle with two eyes, seen from above.. In-Game asset. 2d. High contrast. No shadows
White simple circular enemy seen from above, black outline. Black eyes, with a single shield in-font of it. Black and white only. Blue background.
White circle with black outline. Blue background.. In-Game asset. 2d. High contrast. No shadows