/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Phone class
var Phone = Container.expand(function () {
var self = Container.call(this);
var phoneGraphics = self.attachAsset('phone', {
anchorX: 0.5,
anchorY: 0.5
});
self.battery = 100; // Battery percentage
self.update = function () {
// Decrease battery over time
self.battery -= 0.1;
if (self.battery <= 0) {
self.battery = 0;
LK.showGameOver();
}
};
});
// Plug class
var Plug = Container.expand(function () {
var self = Container.call(this);
var plugGraphics = self.attachAsset('plug', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Plug behavior can be added here
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize phone and plug
var phone = game.addChild(new Phone());
phone.x = 1024; // Center horizontally
phone.y = 1366; // Center vertically
var plug = game.addChild(new Plug());
plug.x = Math.random() * 2048; // Random x position
plug.y = Math.random() * 2732; // Random y position
// Score display
var scoreTxt = new Text2('Battery: 100%', {
size: 100,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle move events
game.move = function (x, y, obj) {
phone.x = x;
phone.y = y;
if (phone.intersects(plug)) {
phone.battery = 100; // Recharge battery
plug.x = Math.random() * 2048; // Move plug to new random position
plug.y = Math.random() * 2732;
}
};
// Update game state
game.update = function () {
phone.update();
plug.update();
scoreTxt.setText('Battery: ' + Math.floor(phone.battery) + '%');
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Phone class
var Phone = Container.expand(function () {
var self = Container.call(this);
var phoneGraphics = self.attachAsset('phone', {
anchorX: 0.5,
anchorY: 0.5
});
self.battery = 100; // Battery percentage
self.update = function () {
// Decrease battery over time
self.battery -= 0.1;
if (self.battery <= 0) {
self.battery = 0;
LK.showGameOver();
}
};
});
// Plug class
var Plug = Container.expand(function () {
var self = Container.call(this);
var plugGraphics = self.attachAsset('plug', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Plug behavior can be added here
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize phone and plug
var phone = game.addChild(new Phone());
phone.x = 1024; // Center horizontally
phone.y = 1366; // Center vertically
var plug = game.addChild(new Plug());
plug.x = Math.random() * 2048; // Random x position
plug.y = Math.random() * 2732; // Random y position
// Score display
var scoreTxt = new Text2('Battery: 100%', {
size: 100,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle move events
game.move = function (x, y, obj) {
phone.x = x;
phone.y = y;
if (phone.intersects(plug)) {
phone.battery = 100; // Recharge battery
plug.x = Math.random() * 2048; // Move plug to new random position
plug.y = Math.random() * 2732;
}
};
// Update game state
game.update = function () {
phone.update();
plug.update();
scoreTxt.setText('Battery: ' + Math.floor(phone.battery) + '%');
};