/**** * Classes ****/ // Define a simple Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; self.update = function () { self.y += self.speed; }; }); // Define a simple Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Enemy update logic }; }); //<Assets used in the game will automatically appear here> // Define a simple Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Player update logic }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Create main menu text var mainMenuText = new Text2('Main Menu', { size: 150, fill: "#ffffff" }); mainMenuText.anchor.set(0.5, 0); LK.gui.center.addChild(mainMenuText); // Create start game button var startButton = new Text2('Start Game', { size: 100, fill: "#ffffff" }); startButton.anchor.set(0.5, 0); startButton.y = 200; LK.gui.center.addChild(startButton); // Create start game button var startButton = new Text2('Start Game', { size: 100, fill: "#ffffff" }); startButton.anchor.set(0.5, 0); startButton.y = 200; LK.gui.center.addChild(startButton); // Handle game down events game.down = function (x, y, obj) { if (startButton.intersects(obj)) { // Remove main menu elements mainMenuText.destroy(); startButton.destroy(); // Start game logic } };
/****
* Classes
****/
// Define a simple Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.y += self.speed;
};
});
// Define a simple Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Enemy update logic
};
});
//<Assets used in the game will automatically appear here>
// Define a simple Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Player update logic
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Create main menu text
var mainMenuText = new Text2('Main Menu', {
size: 150,
fill: "#ffffff"
});
mainMenuText.anchor.set(0.5, 0);
LK.gui.center.addChild(mainMenuText);
// Create start game button
var startButton = new Text2('Start Game', {
size: 100,
fill: "#ffffff"
});
startButton.anchor.set(0.5, 0);
startButton.y = 200;
LK.gui.center.addChild(startButton);
// Create start game button
var startButton = new Text2('Start Game', {
size: 100,
fill: "#ffffff"
});
startButton.anchor.set(0.5, 0);
startButton.y = 200;
LK.gui.center.addChild(startButton);
// Handle game down events
game.down = function (x, y, obj) {
if (startButton.intersects(obj)) {
// Remove main menu elements
mainMenuText.destroy();
startButton.destroy();
// Start game logic
}
};