User prompt
there should be a gap of at least 10 pixels between the grass
User prompt
the amount of emerging grass should be equal on average
User prompt
there must be spaces between the grass
User prompt
there must be spaces between the grass
User prompt
put the grass on a layer below the sheep and the dog.
User prompt
grass should appear randomly from the top edge of the screen all the time
User prompt
grass should appear in random places
User prompt
the grass should slowly go down and hide behind the bottom edge of the screen, new grass should appear from the top edge of the screen.
User prompt
place the seven grasses in random places in the frame
User prompt
to the right of the dog show woof, to the left of dog2 show woof for 1 second, woof must move with the dogs while visible
User prompt
align baa to the top edge of the sheep
User prompt
once every three seconds next to a random sheep show the baa for 1 second, when the baa is visible it should move with the sheep
User prompt
when the dog appears on the screen show woof for 0.5 seconds to his right, while woof is visible he should move with the dog
User prompt
show woof for 0.5 seconds next to the dog whenever the dog changes direction, if the dog moves left show woof on the left, if the dog moves right show woof on the right.
User prompt
a dog must never overlap a sheep
User prompt
the sheep must never overlap.
User prompt
the sheep must never overlap.
User prompt
sheep should not be born closer than 300 pixels to the edges of the screen and should not be closer than 300 pixels to the edges of the screen
User prompt
the herding process needs to happen faster.
User prompt
the process must be faster
User prompt
sheep should not be born closer than 300 pixels to the edges of the screen and should not be closer than 300 pixels to the edges of the screen
User prompt
make this effect twice as strong
User prompt
make that effect stronger.
User prompt
make it so the dog can herd the sheep.
User prompt
double the sheep speed with Particle Swarm Optimisation, the sheep should not overlap each other.
/**** * 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 < 300 || self.x > 1748 || self.y < 300 || self.y > 2432) { self.direction += Math.PI; } }; self.avoidDog = function (dog, targetPosition) { if (self.intersects(dog)) { var dx = targetPosition.x - self.x; var dy = targetPosition.y - self.y; self.direction = Math.atan2(dy, dx); } }; 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 = 1; var avoidanceAngle = Math.atan2(dy, dx) + Math.PI; // Opposite direction self.direction = avoidanceAngle; self.x += Math.cos(self.direction) * self.speed * avoidanceForce; self.y += Math.sin(self.direction) * self.speed * avoidanceForce; } } } }; }); // Woof class to display 'woof' image next to the dog var Woof = Container.expand(function () { var self = Container.call(this); var woofGraphics = self.attachAsset('woof', { anchorX: 0.5, anchorY: 0.5 }); self.visible = false; // Initially hide the woof // Function to show woof next to the dog self.showNextToDog = function (dog) { self.x = dog.x + dog.width / 2 + self.width / 2; self.y = dog.y; self.visible = true; // Hide woof after 0.5 seconds LK.setTimeout(function () { self.visible = false; }, 500); }; }); // Shepherd dog class with two states var Dog = Container.expand(function () { var self = Container.call(this); var dogGraphics = self.attachAsset('dog', { anchorX: 0.5, anchorY: 0.5 }); var dog2Graphics = self.attachAsset('dog2', { anchorX: 0.5, anchorY: 0.5 }); dog2Graphics.visible = false; // Initially hide the dog2 self.targetPosition = { x: 1024, y: 1366 }; // Default target position in the middle self.move = function (pos, lastPos) { self.x = pos.x; self.y = pos.y; // Show and move the woof image with the dog if (!self.woofInstance) { self.woofInstance = new Woof(); game.addChild(self.woofInstance); } self.woofInstance.showNextToDog(self); if (pos.x > lastPos.x) { dogGraphics.visible = true; dog2Graphics.visible = false; } else if (pos.x < lastPos.x) { dogGraphics.visible = false; dog2Graphics.visible = true; } }; self.lastPos = { x: self.x, y: self.y }; // Store the last position self.setTargetPosition = function (pos) { self.targetPosition = pos; }; }); /**** * 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 = 300 + Math.random() * (2048 - 600); sheep.y = 300 + Math.random() * (2732 - 600); 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 handle direction game.on('move', function (obj) { var pos = obj.event.getLocalPosition(game); shepherdDog.move(pos, shepherdDog.lastPos); shepherdDog.lastPos = pos; // Update the last position }); // 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, shepherdDog.targetPosition); sheep.avoidSheep(sheepArray); } }); // Ensure the game is touchscreen compatible game.on('down', function (obj) { var pos = obj.event.getLocalPosition(game); shepherdDog.setTargetPosition(pos); shepherdDog.move(pos, shepherdDog.lastPos); shepherdDog.lastPos = pos; // Update the last position }); game.on('up', function (obj) { var pos = obj.event.getLocalPosition(game); shepherdDog.setTargetPosition(pos); });
===================================================================
--- original.js
+++ change.js
@@ -44,8 +44,27 @@
}
}
};
});
+// Woof class to display 'woof' image next to the dog
+var Woof = Container.expand(function () {
+ var self = Container.call(this);
+ var woofGraphics = self.attachAsset('woof', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.visible = false; // Initially hide the woof
+ // Function to show woof next to the dog
+ self.showNextToDog = function (dog) {
+ self.x = dog.x + dog.width / 2 + self.width / 2;
+ self.y = dog.y;
+ self.visible = true;
+ // Hide woof after 0.5 seconds
+ LK.setTimeout(function () {
+ self.visible = false;
+ }, 500);
+ };
+});
// Shepherd dog class with two states
var Dog = Container.expand(function () {
var self = Container.call(this);
var dogGraphics = self.attachAsset('dog', {
@@ -63,30 +82,20 @@
}; // Default target position in the middle
self.move = function (pos, lastPos) {
self.x = pos.x;
self.y = pos.y;
- var woofAsset = LK.getAsset('woof', {
- anchorX: 0.5,
- anchorY: 0.5
- });
+ // Show and move the woof image with the dog
+ if (!self.woofInstance) {
+ self.woofInstance = new Woof();
+ game.addChild(self.woofInstance);
+ }
+ self.woofInstance.showNextToDog(self);
if (pos.x > lastPos.x) {
dogGraphics.visible = true;
dog2Graphics.visible = false;
- woofAsset.x = self.x - dogGraphics.width / 2 - woofAsset.width / 2;
- woofAsset.y = self.y;
- game.addChild(woofAsset);
- LK.setTimeout(function () {
- woofAsset.destroy();
- }, 500);
} else if (pos.x < lastPos.x) {
dogGraphics.visible = false;
dog2Graphics.visible = true;
- woofAsset.x = self.x + dog2Graphics.width / 2 + woofAsset.width / 2;
- woofAsset.y = self.y;
- game.addChild(woofAsset);
- LK.setTimeout(function () {
- woofAsset.destroy();
- }, 500);
}
};
self.lastPos = {
x: self.x,
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