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.
Code edit (1 edits merged)
Please save this source code
User prompt
✅ Add a Grid class to manage the game grid for building mazes, This class is also the render class so should inherit from Container
User prompt
Add a grid class, as we want this tower defense game to be one where you can build your own maze
Initial prompt
Tower Defense Game
/**** * 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.blendMode = 2; // 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 = 0x444444; debugArrow.visible = numberLabel.visible = false; break; } case 2: { cellGraphics.tint = 0x000088; debugArrow.visible = numberLabel.visible = false; 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 = []; for (var i = 0; i < gridWidth; i++) { self.cells[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 cellType = i === 0 || i === gridWidth - 1 || j === 0 || j === gridHeight - 1 ? 1 : 0; if (j === 0 && i > 11 - 2) { cellType = 2; } self.cells[i][j] = { type: cellType, debugCell: debugCell }; self.addChild(debugCell); debugCell.x = i * 75; debugCell.y = j * 75; } } 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]); } } }; self.update = function () { // Grid logic goes here }; }); // 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.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
@@ -26,16 +26,27 @@
numberLabel.anchor.set(.5, .5);
self.addChild(numberLabel);
self.update = function () {};
self.render = function (data) {
- if (data) {
- switch (data.type) {
- case 1:
- {
- cellGraphics.tint = 0x0;
- break;
- }
- }
+ switch (data.type) {
+ case 1:
+ {
+ cellGraphics.tint = 0x444444;
+ debugArrow.visible = numberLabel.visible = false;
+ break;
+ }
+ case 2:
+ {
+ cellGraphics.tint = 0x000088;
+ debugArrow.visible = numberLabel.visible = false;
+ break;
+ }
+ case 3:
+ {
+ cellGraphics.tint = 0x008800;
+ debugArrow.visible = numberLabel.visible = false;
+ break;
+ }
}
};
});
// Defense class
@@ -76,8 +87,11 @@
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 cellType = i === 0 || i === gridWidth - 1 || j === 0 || j === gridHeight - 1 ? 1 : 0;
+ if (j === 0 && i > 11 - 2) {
+ cellType = 2;
+ }
self.cells[i][j] = {
type: cellType,
debugCell: debugCell
};
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