User prompt
Fix Bug: 'TypeError: sheep.avoidDog is not a function' in or related to this line: 'sheep.avoidDog(shepherdDog);' Line Number: 97
User prompt
the sheep and the dog must be mutually repulsive.
User prompt
the sheep and the dog must be mutually repulsive.
User prompt
Fix Bug: 'TypeError: shepherdDog.move is not a function' in or related to this line: 'shepherdDog.move(pos);' Line Number: 120
User prompt
optimise dog movements using Particle Swarm Optimisation so that there are no collisions between sheep and dog
User prompt
optimise sheep and dog movements using Particle Swarm Optimisation so that there are no collisions between sheep and dog
User prompt
do a sheep-dog collision.
User prompt
introduce collisions for dog
User prompt
make the sheep's speed 250 percent faster
User prompt
make the sheep's speed 50 per cent faster
User prompt
make the sheep's speed 25 per cent faster
User prompt
dogs and sheep must be mutually repulsive
User prompt
when pushing the sheep away from the dog, they should change their trajectory to the opposite one
User prompt
when pushing the sheep away from the dog, they should change their trajectory to the opposite one
User prompt
when a sheep is pushed away from a dog, they increase their running speed by 2 per cent
User prompt
sheep increase their speed by 25 per cent when pushing off
User prompt
dogs and sheep must be mutually repulsive.
User prompt
dogs and sheep must be mutually repulsive
User prompt
do a dog-sheep collision
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'style')' in or related to this line: 'game.canvas.style.cursor = 'none'; // Hide the cursor' Line Number: 94
User prompt
hide the mouse cursor when controlling the dog
User prompt
Fix Bug: 'TypeError: sheep.avoidSheep is not a function' in or related to this line: 'sheep.avoidSheep(sheepArray);' Line Number: 133
User prompt
gather the sheep into a flock, the distance between the sheep must not exceed 100 pixels.
User prompt
gather the sheep into a flock, the distance between the sheep must not exceed 100 pixels.
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'style')' in or related to this line: 'game.view.style.cursor = 'none';' Line Number: 75
/**** * Classes ****/ // Sheep class var Sheep = Container.expand(function () { var self = Container.call(this); var sheepGraphics = self.attachAsset('sheep', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1; self.direction = Math.random() * Math.PI * 2; self.move = function () { self.x += Math.cos(self.direction) * self.speed; self.y += Math.sin(self.direction) * self.speed; }; self.avoidWalls = function () { if (self.x < 50 || self.x > 1998 || self.y < 50 || self.y > 2682) { self.direction += Math.PI; } }; self.avoidDog = function (dog) { if (self.intersects(dog)) { self.direction += Math.PI / 2; } }; self.avoidSheep = function (sheepArray) { var personalSpace = 150; // Define a personal space radius for each sheep for (var i = 0; i < sheepArray.length; i++) { var otherSheep = sheepArray[i]; if (self !== otherSheep) { var dx = otherSheep.x - self.x; var dy = otherSheep.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < personalSpace) { var avoidanceForce = personalSpace - distance; var avoidanceAngle = Math.atan2(dy, dx) + Math.PI; // Opposite direction self.direction += (avoidanceAngle - self.direction) * avoidanceForce / personalSpace; } } } }; }); // Shepherd dog class var Dog = Container.expand(function () { var self = Container.call(this); var dogGraphics = self.attachAsset('dog', { anchorX: 0.5, anchorY: 0.5 }); self.move = function (pos) { self.x = pos.x; self.y = pos.y; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x90EE90 // Light green background }); /**** * Game Code ****/ // Shepherd dog asset // Sheep asset // Initialize sheep array var sheepArray = []; // Create 20 sheep and add them to the game and sheepArray for (var i = 0; i < 20; i++) { var sheep = new Sheep(); sheep.x = Math.random() * 2048; sheep.y = Math.random() * 2732; game.addChild(sheep); sheepArray.push(sheep); } // Create shepherd dog and add it to the game var shepherdDog = new Dog(); shepherdDog.x = 1024; // Start in the middle of the game area shepherdDog.y = 1366; game.addChild(shepherdDog); // Event listener for touch move to move the shepherd dog and hide the cursor game.on('move', function (obj) { var pos = obj.event.getLocalPosition(game); shepherdDog.move(pos); if (game.canvas) { game.canvas.style.cursor = 'none'; // Hide the cursor } }); // Main game tick event LK.on('tick', function () { // Move each sheep and handle collisions for (var i = 0; i < sheepArray.length; i++) { var sheep = sheepArray[i]; sheep.move(); sheep.avoidWalls(); sheep.avoidDog(shepherdDog); sheep.avoidSheep(sheepArray); } }); // Ensure the game is touchscreen compatible and show the cursor when touching down game.on('down', function (obj) { var pos = obj.event.getLocalPosition(game); shepherdDog.move(pos); game.canvas.style.cursor = 'auto'; // Show the cursor }); game.on('up', function (obj) { // Show the mouse cursor when touch is released game.on('up', function (obj) { game.canvas.style.cursor = 'auto'; // Show the cursor }); });
===================================================================
--- original.js
+++ change.js
@@ -84,9 +84,11 @@
// Event listener for touch move to move the shepherd dog and hide the cursor
game.on('move', function (obj) {
var pos = obj.event.getLocalPosition(game);
shepherdDog.move(pos);
- game.canvas.style.cursor = 'none'; // Hide the cursor
+ if (game.canvas) {
+ game.canvas.style.cursor = 'none'; // Hide the cursor
+ }
});
// Main game tick event
LK.on('tick', function () {
// Move each sheep and handle collisions
sheep, top view, cartoon style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
sheep, top view, cartoon style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Collie shepherd dog, top view, cartoon style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a white text bubble that says "baa," comic book style.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
double-sided blue arrow in the form of a semicircle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
computer mouse top view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
angry big bear, lying down and sleeping, top view, cartoon style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
erase