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; } } } }; }); // Baa class var Baa = Container.expand(function () { var self = Container.call(this); var baaGraphics = self.attachAsset('baa', { anchorX: 0.5, anchorY: 0.5 }); self.visible = false; self.currentSheep = null; self.show = function (sheep) { self.currentSheep = sheep; self.visible = true; LK.setTimeout(function () { self.visible = false; self.currentSheep = null; }, 1000); }; self.tick = function () { if (self.visible && self.currentSheep) { self.x = self.currentSheep.x; self.y = self.currentSheep.y - self.currentSheep.height / 2 - self.height / 2; } }; }); // 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; 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; }; }); // Grass class var Grass = Container.expand(function () { var self = Container.call(this); var grassGraphics = self.attachAsset('grass', { anchorX: 0.5, anchorY: 0.5 }); self.resetPosition = function () { self.x = Math.random() * 2048; self.y = -self.height; }; self.move = function () { self.y += 2; // Move down at a constant speed if (self.y > 2732) { // If grass is below the screen self.resetPosition(); // Reset to the top } }; self.resetPosition(); // Initialize position }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x90EE90 // Light green background }); /**** * Game Code ****/ var grassInstances = []; LK.setInterval(function () { var grass = new Grass(); game.addChild(grass); grassInstances.push(grass); }, 1000); // Create a new grass instance every second // Initialize sheep array // Sheep asset // Shepherd dog asset 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 var baaInstance = game.addChild(new Baa()); LK.setInterval(function () { var randomSheepIndex = Math.floor(Math.random() * sheepArray.length); var randomSheep = sheepArray[randomSheepIndex]; baaInstance.show(randomSheep); }, 3000); LK.on('tick', function () { // Move each sheep, handle collisions, update Baa position, and move grass instances baaInstance.tick(); for (var j = 0; j < grassInstances.length; j++) { grassInstances[j].move(); } 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
@@ -104,29 +104,26 @@
self.targetPosition = pos;
};
});
// Grass class
-var MovingGrass = Container.expand(function () {
+var Grass = Container.expand(function () {
var self = Container.call(this);
var grassGraphics = self.attachAsset('grass', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 0.5; // Speed at which the grass moves down
self.resetPosition = function () {
- // Set position to a random location on the screen
- self.x = Math.random() * (2048 - self.width) + self.width / 2;
- self.y = Math.random() * (2732 - self.height) + self.height / 2;
+ self.x = Math.random() * 2048;
+ self.y = -self.height;
};
- self.moveDown = function () {
- // Move the grass down and reset if it goes off the bottom of the screen
- self.y += self.speed;
+ self.move = function () {
+ self.y += 2; // Move down at a constant speed
if (self.y > 2732) {
- self.resetPosition();
+ // If grass is below the screen
+ self.resetPosition(); // Reset to the top
}
};
- // Initialize with a position reset
- self.resetPosition();
+ self.resetPosition(); // Initialize position
});
/****
* Initialize Game
@@ -137,13 +134,14 @@
/****
* Game Code
****/
-// Initialize and place seven moving grasses in random positions
-for (var i = 0; i < 7; i++) {
- var movingGrass = new MovingGrass();
- game.addChild(movingGrass);
-}
+var grassInstances = [];
+LK.setInterval(function () {
+ var grass = new Grass();
+ game.addChild(grass);
+ grassInstances.push(grass);
+}, 1000); // Create a new grass instance every second
// Initialize sheep array
// Sheep asset
// Shepherd dog asset
var sheepArray = [];
@@ -173,23 +171,20 @@
var randomSheep = sheepArray[randomSheepIndex];
baaInstance.show(randomSheep);
}, 3000);
LK.on('tick', function () {
- // Move each sheep, handle collisions, and update Baa position
+ // Move each sheep, handle collisions, update Baa position, and move grass instances
baaInstance.tick();
+ for (var j = 0; j < grassInstances.length; j++) {
+ grassInstances[j].move();
+ }
for (var i = 0; i < sheepArray.length; i++) {
var sheep = sheepArray[i];
sheep.move();
sheep.avoidWalls();
sheep.avoidDog(shepherdDog, shepherdDog.targetPosition);
sheep.avoidSheep(sheepArray);
}
- // Move each MovingGrass instance down
- game.children.forEach(function (child) {
- if (child instanceof MovingGrass) {
- child.moveDown();
- }
- });
});
// Ensure the game is touchscreen compatible
game.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
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