/****
* Classes
****/
// Building class representing the buildings
var Building = Container.expand(function () {
var self = Container.call(this);
var buildingGraphics = self.attachAsset('building', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -buildingGraphics.height;
}
};
});
// Button class representing the control buttons
var Button = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Button logic will be handled in the game code
};
});
// Button class representing the control buttons
var ButtonRight = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('buttonRight', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Button logic will be handled in the game code
};
});
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Car class representing the obstacles
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -carGraphics.height;
var lane = Math.floor(Math.random() * lanesNum);
self.speed = lanes[lane].speed;
self.x = lane * laneWidth + laneWidth / 2 + padding;
}
};
});
// Pizza class representing the player
var DeliveryBoy = Container.expand(function () {
var self = Container.call(this);
var deliveryBoyGraphics = self.attachAsset('pizza', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Player movement logic will be handled in the game code
};
});
// Lane class representing the lanes
var Lane = Container.expand(function () {
var self = Container.call(this);
var laneGraphics = self.attachAsset('lane', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 5 + 3; // Random speed between 1 and 6
});
// PizzaBox class representing the pizza boxes
var PizzaBox = Container.expand(function () {
var self = Container.call(this);
var pizzaBoxGraphics = self.attachAsset('pizzaBox', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
self.rotation += 0.1; // Add rotation to the pizza box
if (self.y > 2732 || self.x < 0 || self.x > 2048) {
self.destroy();
} else {
for (var i = 0; i < cars.length; i++) {
if (self.intersects(cars[i])) {
LK.setScore(LK.getScore() + 1);
self.destroy();
}
}
}
};
});
// Button class representing the throw buttons
var ThrowLeft = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('throwLeft', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Button logic will be handled in the game code
};
});
var ThrowRight = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('throwRight', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Button logic will be handled in the game code
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize game variables
var cars = [];
var lanes = [];
var buildings = [];
var lanesNum = 4;
var padding = 300; // Define padding
// Define the width of a lane
var laneWidth = (2048 - 2 * padding) / lanesNum;
// Initialize lanes and buildings
for (var i = 0; i < lanesNum; i++) {
var lane = game.addChild(new Lane());
lane.x = i * laneWidth + laneWidth / 2 + padding; // Add padding to the lane position
lane.y = 2732 / 2;
lanes.push(lane);
// Add buildings on the left and right side of the lanes
var buildingLeft = game.addChild(new Building());
var buildingRight = game.addChild(new Building());
buildingLeft.x = buildingLeft.width / 2;
buildingLeft.y = 2732 / 2;
buildingRight.x = 2048 - buildingRight.width / 2;
buildingRight.y = 2732 / 2;
}
// Create multiple cars
for (var i = 0; i < 5; i++) {
(function (i) {
LK.setTimeout(function () {
var car = new Car();
var lane = Math.floor(Math.random() * lanesNum);
car.x = padding + lane * laneWidth + laneWidth / 2;
car.y = Math.random() * -2732;
car.speed = lanes[lane].speed; // Set the car's speed to the speed of the lane
cars.push(car);
game.addChild(car);
}, i * 1000); // Add a delay of i seconds to each car spawn
})(i);
}
var deliveryBoy = game.addChild(new DeliveryBoy());
deliveryBoy.x = lanes[1].x;
deliveryBoy.y = 2732 - 500;
// Initialize the control buttons
var buttonLeft = game.addChild(new Button());
buttonLeft.x = padding / 2;
buttonLeft.y = 2732 - 200;
var buttonRight = game.addChild(new ButtonRight());
buttonRight.x = 2048 - padding / 2;
buttonRight.y = 2732 - 200;
// Initialize the throw buttons
var throwLeft = game.addChild(new ThrowLeft());
throwLeft.x = padding / 2;
throwLeft.y = buttonLeft.y - buttonLeft.height;
var throwRight = game.addChild(new ThrowRight());
throwRight.x = 2048 - padding / 2;
throwRight.y = buttonRight.y - buttonRight.height;
// Initialize the score text
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle touch events for player movement
buttonRight.down = function (x, y, obj) {
if (deliveryBoy.x < (lanesNum - 1) * laneWidth + padding) {
deliveryBoy.x += laneWidth;
}
};
buttonLeft.down = function (x, y, obj) {
if (deliveryBoy.x > laneWidth + padding) {
deliveryBoy.x -= laneWidth;
}
};
throwLeft.down = function (x, y, obj) {
var pizzaBox = new PizzaBox();
pizzaBox.x = deliveryBoy.x;
pizzaBox.y = deliveryBoy.y;
pizzaBox.speedX = -15;
pizzaBox.speedY = -10;
game.addChild(pizzaBox);
};
throwRight.down = function (x, y, obj) {
var pizzaBox = new PizzaBox();
pizzaBox.x = deliveryBoy.x;
pizzaBox.y = deliveryBoy.y;
pizzaBox.speedX = 15;
pizzaBox.speedY = -10;
game.addChild(pizzaBox);
};
// Update game logic
game.update = function () {
// Update all cars and buildings
for (var i = 0; i < cars.length; i++) {
cars[i].update();
if (deliveryBoy.intersects(cars[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Update the buildings
if (buildings[i]) {
buildings[i].update();
}
}
// Check if a pizza intersects with a building and increase the score
for (var i = 0; i < buildings.length; i++) {
for (var j = 0; j < pizzaBoxes.length; j++) {
if (pizzaBoxes[j].intersects(buildings[i])) {
LK.setScore(LK.getScore() + 1);
pizzaBoxes[j].destroy();
pizzaBoxes.splice(j, 1);
}
}
}
// Update the score text
scoreTxt.setText(LK.getScore());
}; /****
* Classes
****/
// Building class representing the buildings
var Building = Container.expand(function () {
var self = Container.call(this);
var buildingGraphics = self.attachAsset('building', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -buildingGraphics.height;
}
};
});
// Button class representing the control buttons
var Button = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Button logic will be handled in the game code
};
});
// Button class representing the control buttons
var ButtonRight = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('buttonRight', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Button logic will be handled in the game code
};
});
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Car class representing the obstacles
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -carGraphics.height;
var lane = Math.floor(Math.random() * lanesNum);
self.speed = lanes[lane].speed;
self.x = lane * laneWidth + laneWidth / 2 + padding;
}
};
});
// Pizza class representing the player
var DeliveryBoy = Container.expand(function () {
var self = Container.call(this);
var deliveryBoyGraphics = self.attachAsset('pizza', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Player movement logic will be handled in the game code
};
});
// Lane class representing the lanes
var Lane = Container.expand(function () {
var self = Container.call(this);
var laneGraphics = self.attachAsset('lane', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 5 + 3; // Random speed between 1 and 6
});
// PizzaBox class representing the pizza boxes
var PizzaBox = Container.expand(function () {
var self = Container.call(this);
var pizzaBoxGraphics = self.attachAsset('pizzaBox', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
self.rotation += 0.1; // Add rotation to the pizza box
if (self.y > 2732 || self.x < 0 || self.x > 2048) {
self.destroy();
} else {
for (var i = 0; i < cars.length; i++) {
if (self.intersects(cars[i])) {
LK.setScore(LK.getScore() + 1);
self.destroy();
}
}
}
};
});
// Button class representing the throw buttons
var ThrowLeft = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('throwLeft', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Button logic will be handled in the game code
};
});
var ThrowRight = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('throwRight', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Button logic will be handled in the game code
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize game variables
var cars = [];
var lanes = [];
var buildings = [];
var lanesNum = 4;
var padding = 300; // Define padding
// Define the width of a lane
var laneWidth = (2048 - 2 * padding) / lanesNum;
// Initialize lanes and buildings
for (var i = 0; i < lanesNum; i++) {
var lane = game.addChild(new Lane());
lane.x = i * laneWidth + laneWidth / 2 + padding; // Add padding to the lane position
lane.y = 2732 / 2;
lanes.push(lane);
// Add buildings on the left and right side of the lanes
var buildingLeft = game.addChild(new Building());
var buildingRight = game.addChild(new Building());
buildingLeft.x = buildingLeft.width / 2;
buildingLeft.y = 2732 / 2;
buildingRight.x = 2048 - buildingRight.width / 2;
buildingRight.y = 2732 / 2;
}
// Create multiple cars
for (var i = 0; i < 5; i++) {
(function (i) {
LK.setTimeout(function () {
var car = new Car();
var lane = Math.floor(Math.random() * lanesNum);
car.x = padding + lane * laneWidth + laneWidth / 2;
car.y = Math.random() * -2732;
car.speed = lanes[lane].speed; // Set the car's speed to the speed of the lane
cars.push(car);
game.addChild(car);
}, i * 1000); // Add a delay of i seconds to each car spawn
})(i);
}
var deliveryBoy = game.addChild(new DeliveryBoy());
deliveryBoy.x = lanes[1].x;
deliveryBoy.y = 2732 - 500;
// Initialize the control buttons
var buttonLeft = game.addChild(new Button());
buttonLeft.x = padding / 2;
buttonLeft.y = 2732 - 200;
var buttonRight = game.addChild(new ButtonRight());
buttonRight.x = 2048 - padding / 2;
buttonRight.y = 2732 - 200;
// Initialize the throw buttons
var throwLeft = game.addChild(new ThrowLeft());
throwLeft.x = padding / 2;
throwLeft.y = buttonLeft.y - buttonLeft.height;
var throwRight = game.addChild(new ThrowRight());
throwRight.x = 2048 - padding / 2;
throwRight.y = buttonRight.y - buttonRight.height;
// Initialize the score text
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle touch events for player movement
buttonRight.down = function (x, y, obj) {
if (deliveryBoy.x < (lanesNum - 1) * laneWidth + padding) {
deliveryBoy.x += laneWidth;
}
};
buttonLeft.down = function (x, y, obj) {
if (deliveryBoy.x > laneWidth + padding) {
deliveryBoy.x -= laneWidth;
}
};
throwLeft.down = function (x, y, obj) {
var pizzaBox = new PizzaBox();
pizzaBox.x = deliveryBoy.x;
pizzaBox.y = deliveryBoy.y;
pizzaBox.speedX = -15;
pizzaBox.speedY = -10;
game.addChild(pizzaBox);
};
throwRight.down = function (x, y, obj) {
var pizzaBox = new PizzaBox();
pizzaBox.x = deliveryBoy.x;
pizzaBox.y = deliveryBoy.y;
pizzaBox.speedX = 15;
pizzaBox.speedY = -10;
game.addChild(pizzaBox);
};
// Update game logic
game.update = function () {
// Update all cars and buildings
for (var i = 0; i < cars.length; i++) {
cars[i].update();
if (deliveryBoy.intersects(cars[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Update the buildings
if (buildings[i]) {
buildings[i].update();
}
}
// Check if a pizza intersects with a building and increase the score
for (var i = 0; i < buildings.length; i++) {
for (var j = 0; j < pizzaBoxes.length; j++) {
if (pizzaBoxes[j].intersects(buildings[i])) {
LK.setScore(LK.getScore() + 1);
pizzaBoxes[j].destroy();
pizzaBoxes.splice(j, 1);
}
}
}
// Update the score text
scoreTxt.setText(LK.getScore());
};
car from above, top view, from above, 8bit pixelart,. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
house from above, top down, pixel art, 8 bit style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
button with an arrow, 8bit pixelart. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.