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 ****/ // Cat class var Cat = Container.expand(function () { var self = Container.call(this); var catGraphics = self.attachAsset('cat', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.direction = 'left'; self.patrol = function () { if (self.direction === 'left') { self.x -= self.speed; if (self.x < 0) { self.direction = 'right'; } } if (self.direction === 'right') { self.x += self.speed; if (self.x > 2048) { self.direction = 'left'; } } }; }); // Cheese class var Cheese = Container.expand(function () { var self = Container.call(this); var cheeseGraphics = self.attachAsset('cheese', { anchorX: 0.5, anchorY: 0.5 }); }); // 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) { if (direction === 'left') { self.x -= self.speed; } if (direction === 'right') { self.x += self.speed; } if (direction === 'up') { self.y -= self.speed; } if (direction === 'down') { self.y += self.speed; } }; }); // Wall class var Wall = Container.expand(function () { var self = Container.call(this); var wallGraphics = self.attachAsset('wall', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xF4D03F // Init game with a cheese-like background color }); /**** * Game Code ****/ var mouse = game.addChild(new Mouse()); mouse.x = 100; mouse.y = 2732 / 2; var cheese = game.addChild(new Cheese()); cheese.x = 2048 / 2; cheese.y = 2732 / 2; var hole = game.addChild(new Hole()); hole.x = 2048 - 100; hole.y = 2732 / 2; var cat = game.addChild(new Cat()); cat.x = 2048 / 2; cat.y = 2732 / 2; // Add walls to the game var walls = []; for (var i = 0; i < 10; i++) { var wall = game.addChild(new Wall()); wall.x = i * 200; wall.y = 2732 / 2; walls.push(wall); } var dragNode = null; function handleMove(obj) { var event = obj.event; var pos = event.getLocalPosition(game); if (dragNode) { var dx = pos.x - dragNode.x; var dy = pos.y - dragNode.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 1) { dragNode.x += dx * 0.05; dragNode.y += dy * 0.05; } else { 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) { var event = obj.event; var pos = event.getLocalPosition(game); mouse.x = pos.x; mouse.y = pos.y; dragNode = null; }); LK.on('tick', function () { // Game logic to be executed each tick cat.patrol(); if (mouse.intersects(cat)) { // Cat caught the mouse, show game over LK.effects.flashScreen(0xFF0000, 1000); LK.showGameOver(); } // Check for collision with walls for (var i = 0; i < walls.length; i++) { if (mouse.intersects(walls[i])) { // Mouse hit a wall, stop movement dragNode = null; } } });
===================================================================
--- original.js
+++ change.js
@@ -64,8 +64,16 @@
self.y += self.speed;
}
};
});
+// Wall class
+var Wall = Container.expand(function () {
+ var self = Container.call(this);
+ var wallGraphics = self.attachAsset('wall', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+});
/****
* Initialize Game
****/
@@ -87,8 +95,16 @@
hole.y = 2732 / 2;
var cat = game.addChild(new Cat());
cat.x = 2048 / 2;
cat.y = 2732 / 2;
+// Add walls to the game
+var walls = [];
+for (var i = 0; i < 10; i++) {
+ var wall = game.addChild(new Wall());
+ wall.x = i * 200;
+ wall.y = 2732 / 2;
+ walls.push(wall);
+}
var dragNode = null;
function handleMove(obj) {
var event = obj.event;
var pos = event.getLocalPosition(game);
@@ -134,5 +150,12 @@
// Cat caught the mouse, show game over
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
}
+ // Check for collision with walls
+ for (var i = 0; i < walls.length; i++) {
+ if (mouse.intersects(walls[i])) {
+ // Mouse hit a wall, stop movement
+ dragNode = null;
+ }
+ }
});
\ No newline at end of file
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.