/**** * Classes ****/ // Assets will be automatically created based on usage in the code. // Flea class var Flea = Container.expand(function () { var self = Container.call(this); var fleaGraphics = self.attachAsset('flea', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.move = function () { self.x += self.speed; }; }); // Wall class var Wall = Container.expand(function () { var self = Container.call(this); var wallGraphics = self.attachAsset('wall', { anchorX: 0.5, anchorY: 0.5 }); self.health = 3; self.hit = function () { self.health -= 1; if (self.health <= 0) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var fleas = []; var walls = []; // Create walls for (var i = 0; i < 5; i++) { var wall = new Wall(); wall.x = 500 + i * 300; wall.y = game.height / 2; game.addChild(wall); walls.push(wall); } // Flea button var fleaButton = LK.getAsset('fleaButton', { anchorX: 0.5, anchorY: 0.5, x: 100, y: game.height - 100 }); game.addChild(fleaButton); fleaButton.on('down', function () { var flea = new Flea(); flea.x = 100; flea.y = game.height - 200; game.addChild(flea); fleas.push(flea); }); // Handle game logic on tick LK.on('tick', function () { // Move fleas for (var i = fleas.length - 1; i >= 0; i--) { fleas[i].move(); // Check collision with walls for (var j = walls.length - 1; j >= 0; j--) { if (fleas[i].intersects(walls[j])) { walls[j].hit(); fleas[i].destroy(); fleas.splice(i, 1); break; } } // Remove off-screen fleas if (fleas[i] && fleas[i].x > game.width + 50) { fleas[i].destroy(); fleas.splice(i, 1); } } }); // Note: The game automatically handles game over, pause, and other system events.
/****
* Classes
****/
// Assets will be automatically created based on usage in the code.
// Flea class
var Flea = Container.expand(function () {
var self = Container.call(this);
var fleaGraphics = self.attachAsset('flea', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.move = function () {
self.x += self.speed;
};
});
// Wall class
var Wall = Container.expand(function () {
var self = Container.call(this);
var wallGraphics = self.attachAsset('wall', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 3;
self.hit = function () {
self.health -= 1;
if (self.health <= 0) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
var fleas = [];
var walls = [];
// Create walls
for (var i = 0; i < 5; i++) {
var wall = new Wall();
wall.x = 500 + i * 300;
wall.y = game.height / 2;
game.addChild(wall);
walls.push(wall);
}
// Flea button
var fleaButton = LK.getAsset('fleaButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 100,
y: game.height - 100
});
game.addChild(fleaButton);
fleaButton.on('down', function () {
var flea = new Flea();
flea.x = 100;
flea.y = game.height - 200;
game.addChild(flea);
fleas.push(flea);
});
// Handle game logic on tick
LK.on('tick', function () {
// Move fleas
for (var i = fleas.length - 1; i >= 0; i--) {
fleas[i].move();
// Check collision with walls
for (var j = walls.length - 1; j >= 0; j--) {
if (fleas[i].intersects(walls[j])) {
walls[j].hit();
fleas[i].destroy();
fleas.splice(i, 1);
break;
}
}
// Remove off-screen fleas
if (fleas[i] && fleas[i].x > game.width + 50) {
fleas[i].destroy();
fleas.splice(i, 1);
}
}
});
// Note: The game automatically handles game over, pause, and other system events.
a flea. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a castle made out of fleas. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a concrete wall. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.