/****
* Classes
****/
// Sheep class
var Sheep = Container.expand(function () {
var self = Container.call(this);
self.avoidOtherSheep = function (sheepArray) {
var separationDistance = 120;
sheepArray.forEach(function (otherSheep) {
if (otherSheep !== self && self.intersects(otherSheep)) {
var dx = self.x - otherSheep.x;
var dy = self.y - otherSheep.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < separationDistance) {
var angle = Math.atan2(dy, dx);
self.direction += angle;
}
}
});
};
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;
}
};
});
// 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: 0x87CEEB // Light blue background to represent the sky
});
/****
* 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
game.on('move', function (obj) {
var pos = obj.event.getLocalPosition(game);
shepherdDog.move(pos);
});
// Main game tick event
LK.on('tick', function () {
// Move each sheep and avoid other sheep
for (var i = 0; i < sheepArray.length; i++) {
var sheep = sheepArray[i];
sheep.move();
sheep.avoidWalls();
sheep.avoidDog(shepherdDog);
sheep.avoidOtherSheep(sheepArray);
}
});
// Ensure the game is touchscreen compatible
game.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
shepherdDog.move(pos);
});
game.on('up', function (obj) {
// This can be used for future features where the dog stops moving on touch up
}); ===================================================================
--- original.js
+++ change.js
@@ -1,90 +1,105 @@
-/****
+/****
* 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;
- }
- };
+ var self = Container.call(this);
+ self.avoidOtherSheep = function (sheepArray) {
+ var separationDistance = 120;
+ sheepArray.forEach(function (otherSheep) {
+ if (otherSheep !== self && self.intersects(otherSheep)) {
+ var dx = self.x - otherSheep.x;
+ var dy = self.y - otherSheep.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance < separationDistance) {
+ var angle = Math.atan2(dy, dx);
+ self.direction += angle;
+ }
+ }
+ });
+ };
+ 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;
+ }
+ };
});
// 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;
- };
+ 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: 0x87CEEB // Light blue background to represent the sky
+ backgroundColor: 0x87CEEB // Light blue background to represent the sky
});
-/****
+/****
* Game Code
****/
-// Initialize sheep array
-// Sheep asset
// 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);
+ 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
game.on('move', function (obj) {
- var pos = obj.event.getLocalPosition(game);
- shepherdDog.move(pos);
+ var pos = obj.event.getLocalPosition(game);
+ shepherdDog.move(pos);
});
// Main game tick event
LK.on('tick', function () {
- // Move each sheep
- for (var i = 0; i < sheepArray.length; i++) {
- var sheep = sheepArray[i];
- sheep.move();
- sheep.avoidWalls();
- sheep.avoidDog(shepherdDog);
- }
+ // Move each sheep and avoid other sheep
+ for (var i = 0; i < sheepArray.length; i++) {
+ var sheep = sheepArray[i];
+ sheep.move();
+ sheep.avoidWalls();
+ sheep.avoidDog(shepherdDog);
+ sheep.avoidOtherSheep(sheepArray);
+ }
});
// Ensure the game is touchscreen compatible
game.on('down', function (obj) {
- var pos = obj.event.getLocalPosition(game);
- shepherdDog.move(pos);
+ var pos = obj.event.getLocalPosition(game);
+ shepherdDog.move(pos);
});
game.on('up', function (obj) {
- // This can be used for future features where the dog stops moving on touch up
+ // This can be used for future features where the dog stops moving on touch up
});
\ No newline at end of file
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