Code edit (3 edits merged)
Please save this source code
User prompt
do //Processes other 7 node directions here.
Code edit (6 edits merged)
Please save this source code
User prompt
I want to change cell.neighbors to be 8 variables instead consisting of upLeft, up, upRight, right, downRight, down, downLeft, left
Code edit (10 edits merged)
Please save this source code
User prompt
Make cell.neighbors = []; be the cells 8 neighbors, with fixed offsets based on the direction of the neighbour
User prompt
In Grid I want cell.neighbors = []; to be filled with its neighbor cells
Code edit (1 edits merged)
Please save this source code
Code edit (8 edits merged)
Please save this source code
User prompt
Add a method to Grid that does a flood fill a* from staring from goals ending in spawn, giving each tile a score
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'data.type')' in or related to this line: 'switch (data.type) {' Line Number: 38
Code edit (3 edits merged)
Please save this source code
User prompt
the cellType check still use hardcoded variables, fix this
User prompt
Update the grid class to use gridWidth, gridHeight instead of hardcoded values
Code edit (1 edits merged)
Please save this source code
User prompt
When initializing the grid, set all tiles that exist on the edge of the grid to to be of the type wall
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
To debug cell, add a debug arrow attached to the class below numberLabel
Code edit (3 edits merged)
Please save this source code
User prompt
anchor the numberLabel centered in debugcell
User prompt
Add a number label to the debug cells
User prompt
I need to debug some A* path finding for this I need a debug cell type which shows a number + an arrow pointing in the direction of the A* grid.
/**** * 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; } } }; }); // 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 pathId = 1; if (node.upLeft && node.upLeft.pathId < pathId) { node.upLeft.score = node.score + 1.4142135624; node.upLeft.pathId = 1; } if (node.up && node.up.pathId < pathId) { node.up.score = node.score + 1; } if (node.upRight && node.upRight.pathId < pathId) { node.upRight.score = node.score + 1.4142135624; } if (node.right && node.right.pathId < pathId) { node.right.score = node.score + 1; } if (node.downRight && node.downRight.pathId < pathId) { node.downRight.score = node.score + 1.4142135624; } if (node.down && node.down.pathId < pathId) { node.down.score = node.score + 1; } if (node.downLeft && node.downLeft.pathId < pathId) { node.downLeft.score = node.score + 1.4142135624; } if (node.left && node.left.pathId < pathId) { node.left.score = node.score + 1; } }; 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
@@ -127,8 +127,9 @@
var node = toProcess[0];
var pathId = 1;
if (node.upLeft && node.upLeft.pathId < pathId) {
node.upLeft.score = node.score + 1.4142135624;
+ node.upLeft.pathId = 1;
}
if (node.up && node.up.pathId < pathId) {
node.up.score = node.score + 1;
}
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