/****
* 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;
}
};
});
// 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
****/
// 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 = 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
for (var i = 0; i < sheepArray.length; i++) {
var sheep = sheepArray[i];
sheep.move();
sheep.avoidWalls();
sheep.avoidDog(shepherdDog);
}
});
// 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
}); /****
* 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;
}
};
});
// 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
****/
// 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 = 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
for (var i = 0; i < sheepArray.length; i++) {
var sheep = sheepArray[i];
sheep.move();
sheep.avoidWalls();
sheep.avoidDog(shepherdDog);
}
});
// 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
});
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