/**** * Classes ****/ // Bomb class representing a weapon var Bomb = Container.expand(function () { var self = Container.call(this); var bombGraphics = self.attachAsset('bomb', { anchorX: 0.5, anchorY: 0.5 }); self.explode = function () { // Logic to slow down nearby sperms for (var i = 0; i < sperms.length; i++) { if (Math.abs(sperms[i].x - self.x) < 100) { sperms[i].speed *= 0.5; // Slow down sperm } } self.destroy(); }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Sperm class representing each racer var Sperm = Container.expand(function () { var self = Container.call(this); var spermGraphics = self.attachAsset('sperm', { anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 2 + 1; // Random speed for each sperm self.update = function () { self.x += self.speed; if (self.x > 2048) { // If sperm reaches the end, declare winner LK.showGameOver(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize sperms var sperms = []; for (var i = 0; i < 5; i++) { var sperm = new Sperm(); sperm.x = 100; sperm.y = 200 + i * 100; sperms.push(sperm); game.addChild(sperm); } // Initialize bombs var bombs = []; function dropBomb(x, y) { var bomb = new Bomb(); bomb.x = x; bomb.y = y; bombs.push(bomb); game.addChild(bomb); LK.setTimeout(function () { bomb.explode(); }, 2000); // Bomb explodes after 2 seconds } // Handle touch events to drop bombs game.down = function (x, y, obj) { dropBomb(x, y); }; // Update game logic game.update = function () { for (var i = 0; i < sperms.length; i++) { sperms[i].update(); } for (var j = bombs.length - 1; j >= 0; j--) { if (bombs[j].destroyed) { bombs.splice(j, 1); } } };
/****
* Classes
****/
// Bomb class representing a weapon
var Bomb = Container.expand(function () {
var self = Container.call(this);
var bombGraphics = self.attachAsset('bomb', {
anchorX: 0.5,
anchorY: 0.5
});
self.explode = function () {
// Logic to slow down nearby sperms
for (var i = 0; i < sperms.length; i++) {
if (Math.abs(sperms[i].x - self.x) < 100) {
sperms[i].speed *= 0.5; // Slow down sperm
}
}
self.destroy();
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Sperm class representing each racer
var Sperm = Container.expand(function () {
var self = Container.call(this);
var spermGraphics = self.attachAsset('sperm', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 2 + 1; // Random speed for each sperm
self.update = function () {
self.x += self.speed;
if (self.x > 2048) {
// If sperm reaches the end, declare winner
LK.showGameOver();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize sperms
var sperms = [];
for (var i = 0; i < 5; i++) {
var sperm = new Sperm();
sperm.x = 100;
sperm.y = 200 + i * 100;
sperms.push(sperm);
game.addChild(sperm);
}
// Initialize bombs
var bombs = [];
function dropBomb(x, y) {
var bomb = new Bomb();
bomb.x = x;
bomb.y = y;
bombs.push(bomb);
game.addChild(bomb);
LK.setTimeout(function () {
bomb.explode();
}, 2000); // Bomb explodes after 2 seconds
}
// Handle touch events to drop bombs
game.down = function (x, y, obj) {
dropBomb(x, y);
};
// Update game logic
game.update = function () {
for (var i = 0; i < sperms.length; i++) {
sperms[i].update();
}
for (var j = bombs.length - 1; j >= 0; j--) {
if (bombs[j].destroyed) {
bombs.splice(j, 1);
}
}
};