User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting '13.66')' in or related to this line: 'self.grid[x][y] = obj;' Line Number: 37
User prompt
add a grid and discrete movement for the mouse
User prompt
Add a maze and collision
User prompt
Lerp mouse position to input position
User prompt
Pero mouse position to touch position when input is detected
User prompt
Mouse moves to touch position only when touch input is detracted
User prompt
Make it a stealth game, add patrolling cats
Initial prompt
Cheese chase
/**** * Classes ****/ // Cheese class var Cheese = Container.expand(function () { var self = Container.call(this); var cheeseGraphics = self.attachAsset('cheese', { anchorX: 0.5, anchorY: 0.5 }); }); // Grid class var Grid = Container.expand(function () { var self = Container.call(this); self.grid = []; self.gridSize = 100; self.gridWidth = Math.floor(2048 / self.gridSize); self.gridHeight = Math.floor(2732 / self.gridSize); // Initialize the grid with empty cells for (var i = 0; i < self.gridWidth; i++) { self.grid[i] = []; for (var j = 0; j < self.gridHeight; j++) { self.grid[i][j] = null; } } // Method to add an object to the grid self.addObject = function (obj, x, y) { self.grid[x][y] = obj; obj.x = x * self.gridSize; obj.y = y * self.gridSize; }; // Method to move an object in the grid self.moveObject = function (obj, oldX, oldY, newX, newY) { self.grid[oldX][oldY] = null; self.addObject(obj, newX, newY); }; }); // Hole class var Hole = Container.expand(function () { var self = Container.call(this); var holeGraphics = self.attachAsset('hole', { anchorX: 0.5, anchorY: 0.5 }); }); // Assets will be automatically created based on usage in the code. // Mouse class var Mouse = Container.expand(function () { var self = Container.call(this); var mouseGraphics = self.attachAsset('mouse', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.move = function (direction) { var oldX = self.x / grid.gridSize; var oldY = self.y / grid.gridSize; var newX = oldX; var newY = oldY; if (direction === 'left') { newX--; } if (direction === 'right') { newX++; } if (direction === 'up') { newY--; } if (direction === 'down') { newY++; } // Check if the new position is within the grid and not occupied if (newX >= 0 && newX < grid.gridWidth && newY >= 0 && newY < grid.gridHeight && grid.grid[newX][newY] === null) { grid.moveObject(self, oldX, oldY, newX, newY); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xF4D03F // Init game with a cheese-like background color }); /**** * Game Code ****/ var grid = game.addChild(new Grid()); var mouse = new Mouse(); grid.addObject(mouse, 1, grid.gridHeight / 2); var cheese = new Cheese(); grid.addObject(cheese, grid.gridWidth / 2, grid.gridHeight / 2); var hole = new Hole(); grid.addObject(hole, grid.gridWidth - 1, grid.gridHeight / 2); var dragNode = null; function handleMove(obj) { var event = obj.event; var pos = event.getLocalPosition(game); if (dragNode) { dragNode.x = pos.x; dragNode.y = pos.y; } if (mouse.intersects(cheese)) { // Mouse got the cheese, move cheese to mouse position cheese.x = mouse.x; cheese.y = mouse.y; } if (cheese.intersects(hole)) { // Cheese delivered to the hole, show game win LK.effects.flashScreen(0x00FF00, 1000); LK.showGameOver(); } } game.on('down', function (obj) { dragNode = mouse; handleMove(obj); }); game.on('move', handleMove); game.on('up', function (obj) { dragNode = null; }); LK.on('tick', function () { // Game logic to be executed each tick });
===================================================================
--- original.js
+++ change.js
@@ -13,10 +13,10 @@
var Grid = Container.expand(function () {
var self = Container.call(this);
self.grid = [];
self.gridSize = 100;
- self.gridWidth = 2048 / self.gridSize;
- self.gridHeight = 2732 / self.gridSize;
+ self.gridWidth = Math.floor(2048 / self.gridSize);
+ self.gridHeight = Math.floor(2732 / self.gridSize);
// Initialize the grid with empty cells
for (var i = 0; i < self.gridWidth; i++) {
self.grid[i] = [];
for (var j = 0; j < self.gridHeight; j++) {
grey square, black border. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
simple light yellow button front view game console, clean, rounded edges, high resolution, graphic. Single Game Texture. In-Game asset. 2d. Blank background. High contrast.
Worn out sticker for a video game, 90s style, cheese, simple, vintage. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
wall view from top-down, game asset videogame, black color, simple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. worn out sticker. 90's style. vintage. simple. top-down view. poster. sticker
top-down view, videogame character enemy, roomba, 90s style sticker, flat, no perspective, silhouette, black and white, cartoon, fun, simple, from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
top-down view, videogame heart, 90s style sticker, flat, no perspective, silhouette, white, cartoon, fun, simple, from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Black square with white outline. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.