/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Kite class representing each kite in the game var Kite = Container.expand(function () { var self = Container.call(this); var kiteGraphics = self.attachAsset('kite', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.direction = Math.random() * Math.PI * 2; // Random initial direction // Update function to move the kite self.update = function () { self.x += Math.cos(self.direction) * self.speed; self.y += Math.sin(self.direction) * self.speed; // Keep kites within bounds if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) { self.direction += Math.PI; // Reverse direction } }; // Function to change direction when cutting another kite self.changeDirection = function () { self.direction += Math.PI / 2; // Change direction by 90 degrees }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Init game with sky blue background }); /**** * Game Code ****/ // Initialize kites array var kites = []; // Create and add kites to the game for (var i = 0; i < 5; i++) { var kite = new Kite(); kite.x = Math.random() * 2048; kite.y = Math.random() * 2732; kites.push(kite); game.addChild(kite); } // Function to handle kite interactions function handleKiteInteractions() { for (var i = 0; i < kites.length; i++) { for (var j = i + 1; j < kites.length; j++) { if (kites[i].intersects(kites[j])) { kites[i].changeDirection(); kites[j].changeDirection(); } } } } // Game update function game.update = function () { for (var i = 0; i < kites.length; i++) { kites[i].update(); } handleKiteInteractions(); }; // Event listener for dragging kites var dragKite = null; game.down = function (x, y, obj) { for (var i = 0; i < kites.length; i++) { if (kites[i].intersects({ x: x, y: y, width: 1, height: 1 })) { dragKite = kites[i]; break; } } }; game.move = function (x, y, obj) { if (dragKite) { dragKite.x = x; dragKite.y = y; } }; game.up = function (x, y, obj) { dragKite = null; };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Kite class representing each kite in the game
var Kite = Container.expand(function () {
var self = Container.call(this);
var kiteGraphics = self.attachAsset('kite', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.direction = Math.random() * Math.PI * 2; // Random initial direction
// Update function to move the kite
self.update = function () {
self.x += Math.cos(self.direction) * self.speed;
self.y += Math.sin(self.direction) * self.speed;
// Keep kites within bounds
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
self.direction += Math.PI; // Reverse direction
}
};
// Function to change direction when cutting another kite
self.changeDirection = function () {
self.direction += Math.PI / 2; // Change direction by 90 degrees
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Init game with sky blue background
});
/****
* Game Code
****/
// Initialize kites array
var kites = [];
// Create and add kites to the game
for (var i = 0; i < 5; i++) {
var kite = new Kite();
kite.x = Math.random() * 2048;
kite.y = Math.random() * 2732;
kites.push(kite);
game.addChild(kite);
}
// Function to handle kite interactions
function handleKiteInteractions() {
for (var i = 0; i < kites.length; i++) {
for (var j = i + 1; j < kites.length; j++) {
if (kites[i].intersects(kites[j])) {
kites[i].changeDirection();
kites[j].changeDirection();
}
}
}
}
// Game update function
game.update = function () {
for (var i = 0; i < kites.length; i++) {
kites[i].update();
}
handleKiteInteractions();
};
// Event listener for dragging kites
var dragKite = null;
game.down = function (x, y, obj) {
for (var i = 0; i < kites.length; i++) {
if (kites[i].intersects({
x: x,
y: y,
width: 1,
height: 1
})) {
dragKite = kites[i];
break;
}
}
};
game.move = function (x, y, obj) {
if (dragKite) {
dragKite.x = x;
dragKite.y = y;
}
};
game.up = function (x, y, obj) {
dragKite = null;
};