/**** * Classes ****/ // Define the Character class var Character = Container.expand(function () { var self = Container.call(this); var characterGraphics = self.attachAsset('character', { anchorX: 0.5, anchorY: 0.5 }); self.gun = null; self.setGun = function (gunType) { if (self.gun) { self.gun.destroy(); } self.gun = new Gun(gunType); self.gun.x = self.x; self.gun.y = self.y - 50; // Position the gun above the character game.addChild(self.gun); }; return self; }); // Assets will be automatically created and loaded based on their usage in the code. // Define the Gun class var Gun = Container.expand(function (type) { var self = Container.call(this); var gunGraphics = self.attachAsset(type, { anchorX: 0.5, anchorY: 0.5 }); self.type = type; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize variables var character; var guns = ['gun1', 'gun2', 'gun3']; // Example gun types var gunButtons = []; // Function to create gun selection buttons function createGunButtons() { for (var i = 0; i < guns.length; i++) { var gunButton = new Text2(guns[i], { size: 50, fill: "#ffffff" }); gunButton.x = 100 + i * 200; gunButton.y = 100; gunButton.gunType = guns[i]; gunButton.interactive = true; gunButton.buttonMode = true; gunButton.on('pointerdown', function (event) { character.setGun(event.target.gunType); }); game.addChild(gunButton); gunButtons.push(gunButton); } } // Function to start the game function startGame() { // Remove start button startButton.destroy(); // Create character character = new Character(); character.x = 2048 / 2; character.y = 2732 - 200; game.addChild(character); // Create gun selection buttons createGunButtons(); } // Create start button var startButton = new Text2('Start', { size: 100, fill: "#ffffff" }); startButton.x = 2048 / 2; startButton.y = 2732 / 2; startButton.anchor.set(0.5, 0.5); startButton.interactive = true; startButton.buttonMode = true; startButton.on('pointerdown', startGame); game.addChild(startButton);
/****
* Classes
****/
// Define the Character class
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
self.gun = null;
self.setGun = function (gunType) {
if (self.gun) {
self.gun.destroy();
}
self.gun = new Gun(gunType);
self.gun.x = self.x;
self.gun.y = self.y - 50; // Position the gun above the character
game.addChild(self.gun);
};
return self;
});
// Assets will be automatically created and loaded based on their usage in the code.
// Define the Gun class
var Gun = Container.expand(function (type) {
var self = Container.call(this);
var gunGraphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
self.type = type;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize variables
var character;
var guns = ['gun1', 'gun2', 'gun3']; // Example gun types
var gunButtons = [];
// Function to create gun selection buttons
function createGunButtons() {
for (var i = 0; i < guns.length; i++) {
var gunButton = new Text2(guns[i], {
size: 50,
fill: "#ffffff"
});
gunButton.x = 100 + i * 200;
gunButton.y = 100;
gunButton.gunType = guns[i];
gunButton.interactive = true;
gunButton.buttonMode = true;
gunButton.on('pointerdown', function (event) {
character.setGun(event.target.gunType);
});
game.addChild(gunButton);
gunButtons.push(gunButton);
}
}
// Function to start the game
function startGame() {
// Remove start button
startButton.destroy();
// Create character
character = new Character();
character.x = 2048 / 2;
character.y = 2732 - 200;
game.addChild(character);
// Create gun selection buttons
createGunButtons();
}
// Create start button
var startButton = new Text2('Start', {
size: 100,
fill: "#ffffff"
});
startButton.x = 2048 / 2;
startButton.y = 2732 / 2;
startButton.anchor.set(0.5, 0.5);
startButton.interactive = true;
startButton.buttonMode = true;
startButton.on('pointerdown', startGame);
game.addChild(startButton);