/**** * Classes ****/ // Car class var Car = Container.expand(function () { var self = Container.call(this); var carGraphics = self.attachAsset('car', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 0; self.direction = 0; // 0: up, 1: right, 2: down, 3: left self.update = function () { if (self.direction === 0) self.y -= self.speed; if (self.direction === 1) self.x += self.speed; if (self.direction === 2) self.y += self.speed; if (self.direction === 3) self.x -= self.speed; }; self.setDirection = function (dir) { self.direction = dir; }; self.setSpeed = function (spd) { self.speed = spd; }; }); // ParkingSpot class var ParkingSpot = Container.expand(function () { var self = Container.call(this); var spotGraphics = self.attachAsset('parkingSpot', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize game elements // Assets will be automatically created and loaded by the LK engine based on their usage in the code. // For this game, we will use the following assets: // - Car: A box shape representing the player's car. // - ParkingSpot: A box shape representing the parking spot. // - Track: A box shape representing the track boundaries. var car = new Car(); car.x = 1024; // Center horizontally car.y = 2000; // Start near the bottom var parkingSpot = new ParkingSpot(); parkingSpot.x = 1024; // Center horizontally parkingSpot.y = 500; // Position near the top game.addChild(car); game.addChild(parkingSpot); // Handle touch events for car movement game.down = function (x, y, obj) { if (x < 1024) { car.setDirection(3); // Move left } else { car.setDirection(1); // Move right } car.setSpeed(5); }; game.up = function (x, y, obj) { car.setSpeed(0); }; // Update game logic game.update = function () { car.update(); // Check if car is parked if (car.intersects(parkingSpot)) { LK.effects.flashScreen(0x00FF00, 1000); // Flash green to indicate success LK.showGameOver(); // End game } };
/****
* Classes
****/
// Car class
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 0;
self.direction = 0; // 0: up, 1: right, 2: down, 3: left
self.update = function () {
if (self.direction === 0) self.y -= self.speed;
if (self.direction === 1) self.x += self.speed;
if (self.direction === 2) self.y += self.speed;
if (self.direction === 3) self.x -= self.speed;
};
self.setDirection = function (dir) {
self.direction = dir;
};
self.setSpeed = function (spd) {
self.speed = spd;
};
});
// ParkingSpot class
var ParkingSpot = Container.expand(function () {
var self = Container.call(this);
var spotGraphics = self.attachAsset('parkingSpot', {
anchorX: 0.5,
anchorY: 0.5
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize game elements
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// For this game, we will use the following assets:
// - Car: A box shape representing the player's car.
// - ParkingSpot: A box shape representing the parking spot.
// - Track: A box shape representing the track boundaries.
var car = new Car();
car.x = 1024; // Center horizontally
car.y = 2000; // Start near the bottom
var parkingSpot = new ParkingSpot();
parkingSpot.x = 1024; // Center horizontally
parkingSpot.y = 500; // Position near the top
game.addChild(car);
game.addChild(parkingSpot);
// Handle touch events for car movement
game.down = function (x, y, obj) {
if (x < 1024) {
car.setDirection(3); // Move left
} else {
car.setDirection(1); // Move right
}
car.setSpeed(5);
};
game.up = function (x, y, obj) {
car.setSpeed(0);
};
// Update game logic
game.update = function () {
car.update();
// Check if car is parked
if (car.intersects(parkingSpot)) {
LK.effects.flashScreen(0x00FF00, 1000); // Flash green to indicate success
LK.showGameOver(); // End game
}
};