/****
* Classes
****/
// App class
var App = Container.expand(function () {
var self = Container.call(this);
var appGraphics = self.attachAsset('app', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// App update logic
};
});
//<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.update = function () {
// Phone update logic
};
self.down = function (x, y, obj) {
// Handle phone touch down
};
self.up = function (x, y, obj) {
// Handle phone touch up
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize variables
var phone;
var apps = [];
var level = 1;
var maxLevels = 100;
var scoreTxt;
// Initialize game elements
function initGame() {
// Create phone
phone = game.addChild(new Phone());
phone.x = 2048 / 2;
phone.y = 2732 - 200;
// Create apps
for (var i = 0; i < level; i++) {
var app = new App();
app.x = Math.random() * 2048;
app.y = Math.random() * (2732 - 400);
apps.push(app);
game.addChild(app);
}
// Create score text
scoreTxt = new Text2('Level: ' + level, {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
}
// Update game elements
game.update = function () {
// Check for collisions between phone and apps
for (var i = apps.length - 1; i >= 0; i--) {
if (phone.intersects(apps[i])) {
apps[i].destroy();
apps.splice(i, 1);
}
}
// Check if all apps are eaten
if (apps.length === 0) {
level++;
if (level > maxLevels) {
LK.showGameOver();
} else {
initGame();
}
}
// Update score text
scoreTxt.setText('Level: ' + level);
};
// Handle touch events
game.down = function (x, y, obj) {
phone.x = x;
phone.y = y;
};
game.move = function (x, y, obj) {
phone.x = x;
phone.y = y;
};
game.up = function (x, y, obj) {
// Handle touch up
};
// Initialize the game
initGame(); /****
* Classes
****/
// App class
var App = Container.expand(function () {
var self = Container.call(this);
var appGraphics = self.attachAsset('app', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// App update logic
};
});
//<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.update = function () {
// Phone update logic
};
self.down = function (x, y, obj) {
// Handle phone touch down
};
self.up = function (x, y, obj) {
// Handle phone touch up
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize variables
var phone;
var apps = [];
var level = 1;
var maxLevels = 100;
var scoreTxt;
// Initialize game elements
function initGame() {
// Create phone
phone = game.addChild(new Phone());
phone.x = 2048 / 2;
phone.y = 2732 - 200;
// Create apps
for (var i = 0; i < level; i++) {
var app = new App();
app.x = Math.random() * 2048;
app.y = Math.random() * (2732 - 400);
apps.push(app);
game.addChild(app);
}
// Create score text
scoreTxt = new Text2('Level: ' + level, {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
}
// Update game elements
game.update = function () {
// Check for collisions between phone and apps
for (var i = apps.length - 1; i >= 0; i--) {
if (phone.intersects(apps[i])) {
apps[i].destroy();
apps.splice(i, 1);
}
}
// Check if all apps are eaten
if (apps.length === 0) {
level++;
if (level > maxLevels) {
LK.showGameOver();
} else {
initGame();
}
}
// Update score text
scoreTxt.setText('Level: ' + level);
};
// Handle touch events
game.down = function (x, y, obj) {
phone.x = x;
phone.y = y;
};
game.move = function (x, y, obj) {
phone.x = x;
phone.y = y;
};
game.up = function (x, y, obj) {
// Handle touch up
};
// Initialize the game
initGame();