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 ****/ // 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 }; }); // 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 ****/ // Grid class // Initialize game variables var Grid = function Grid(rows, cols, cellSize) { this.rows = rows; this.cols = cols; this.cellSize = cellSize; this.grid = []; // Initialize the grid with empty cells for (var i = 0; i < rows; i++) { this.grid[i] = []; for (var j = 0; j < cols; j++) { this.grid[i][j] = null; } } // Method to add an object to the grid this.addObject = function (obj, row, col) { if (this.isValidCell(row, col)) { this.grid[row][col] = obj; obj.x = col * this.cellSize + this.cellSize / 2; obj.y = row * this.cellSize + this.cellSize / 2; } }; // Method to remove an object from the grid this.removeObject = function (row, col) { if (this.isValidCell(row, col)) { this.grid[row][col] = null; } }; // Check if a cell is within the grid bounds this.isValidCell = function (row, col) { return row >= 0 && row < this.rows && col >= 0 && col < this.cols; }; }; var tower = game.addChild(new Tower()); tower.x = 2048 / 2; tower.y = 2732 / 2; var enemies = []; var defenses = []; game.update = function () { // Game logic goes here // Spawn enemies, update defenses, check for collisions, etc. };
===================================================================
--- original.js
+++ change.js
@@ -1,58 +1,90 @@
-/****
+/****
* Classes
-****/
+****/
// 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
- };
+ 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
- };
+ var self = Container.call(this);
+ var enemyGraphics = self.attachAsset('enemy', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Enemy 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
- };
+ 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
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
+// Grid class
// Initialize game variables
+var Grid = function Grid(rows, cols, cellSize) {
+ this.rows = rows;
+ this.cols = cols;
+ this.cellSize = cellSize;
+ this.grid = [];
+ // Initialize the grid with empty cells
+ for (var i = 0; i < rows; i++) {
+ this.grid[i] = [];
+ for (var j = 0; j < cols; j++) {
+ this.grid[i][j] = null;
+ }
+ }
+ // Method to add an object to the grid
+ this.addObject = function (obj, row, col) {
+ if (this.isValidCell(row, col)) {
+ this.grid[row][col] = obj;
+ obj.x = col * this.cellSize + this.cellSize / 2;
+ obj.y = row * this.cellSize + this.cellSize / 2;
+ }
+ };
+ // Method to remove an object from the grid
+ this.removeObject = function (row, col) {
+ if (this.isValidCell(row, col)) {
+ this.grid[row][col] = null;
+ }
+ };
+ // Check if a cell is within the grid bounds
+ this.isValidCell = function (row, col) {
+ return row >= 0 && row < this.rows && col >= 0 && col < this.cols;
+ };
+};
var tower = game.addChild(new Tower());
tower.x = 2048 / 2;
tower.y = 2732 / 2;
var enemies = [];
var defenses = [];
game.update = function () {
- // Game logic goes here
- // Spawn enemies, update defenses, check for collisions, etc.
+ // Game logic goes here
+ // Spawn enemies, update defenses, check for collisions, etc.
};
\ No newline at end of file
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