/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocity = {
x: 0,
y: 0
};
self.angle = 0;
self.speed = 0;
self.maxSpeed = 10;
self.acceleration = 0.25;
self.friction = 0.95;
self.driftFriction = 0.92;
self.turnSpeed = 0.08;
self.isDrifting = false;
self.driftTime = 0;
self.driftAngle = 0;
self.update = function () {
// Apply acceleration/braking based on button input
if (isAccelerating) {
self.speed += self.acceleration;
self.speed = Math.min(self.speed, self.maxSpeed);
} else if (isBraking) {
self.speed -= 0.3;
self.speed = Math.max(self.speed, -2);
}
// Apply standard friction (no drift)
self.speed *= self.friction;
// Apply direct steering based on button input
if (steerDirection !== 0 && Math.abs(self.speed) > 0.1) {
// Direct turning without drift
self.angle += steerDirection * self.turnSpeed * 1.5; // Increased turn rate for better control
}
// Update velocity based on angle (direct movement)
self.velocity.x = Math.cos(self.angle) * self.speed;
self.velocity.y = Math.sin(self.angle) * self.speed;
// Update position
self.x += self.velocity.x;
self.y += self.velocity.y;
// Update rotation to match angle
self.rotation = self.angle;
// Always set drift to false
self.isDrifting = false;
self.driftTime = 0;
self.driftAngle = 0;
};
return self;
});
var Track = Container.expand(function () {
var self = Container.call(this);
// Create track walls array
self.walls = [];
// Create outer track walls
var wallThickness = 120;
var trackWidth = 1800;
var trackHeight = 2400;
var innerWidth = 1000;
var innerHeight = 1600;
// Track surface first (so it appears behind walls)
var trackSurface = self.addChild(LK.getAsset('track', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0
}));
// Create oval track with proper racing circuit layout
// Outer walls - top straight
var topWall = self.addChild(LK.getAsset('wall', {
width: trackWidth - 400,
height: wallThickness,
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: -trackHeight / 2 + wallThickness / 2
}));
self.walls.push(topWall);
// Outer walls - bottom straight
var bottomWall = self.addChild(LK.getAsset('wall', {
width: trackWidth - 400,
height: wallThickness,
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: trackHeight / 2 - wallThickness / 2
}));
self.walls.push(bottomWall);
// Outer walls - left straight
var leftWall = self.addChild(LK.getAsset('wall', {
width: wallThickness,
height: trackHeight - 600,
anchorX: 0.5,
anchorY: 0.5,
x: -trackWidth / 2 + wallThickness / 2,
y: 0
}));
self.walls.push(leftWall);
// Outer walls - right straight
var rightWall = self.addChild(LK.getAsset('wall', {
width: wallThickness,
height: trackHeight - 600,
anchorX: 0.5,
anchorY: 0.5,
x: trackWidth / 2 - wallThickness / 2,
y: 0
}));
self.walls.push(rightWall);
// Create corner walls for proper oval shape
// Top-left corner walls
var cornerTL1 = self.addChild(LK.getAsset('wall', {
width: 250,
height: 250,
anchorX: 0.5,
anchorY: 0.5,
x: -600,
y: -900
}));
self.walls.push(cornerTL1);
var cornerTL2 = self.addChild(LK.getAsset('wall', {
width: 200,
height: 200,
anchorX: 0.5,
anchorY: 0.5,
x: -750,
y: -700
}));
self.walls.push(cornerTL2);
// Top-right corner walls
var cornerTR1 = self.addChild(LK.getAsset('wall', {
width: 250,
height: 250,
anchorX: 0.5,
anchorY: 0.5,
x: 600,
y: -900
}));
self.walls.push(cornerTR1);
var cornerTR2 = self.addChild(LK.getAsset('wall', {
width: 200,
height: 200,
anchorX: 0.5,
anchorY: 0.5,
x: 750,
y: -700
}));
self.walls.push(cornerTR2);
// Bottom-left corner walls
var cornerBL1 = self.addChild(LK.getAsset('wall', {
width: 250,
height: 250,
anchorX: 0.5,
anchorY: 0.5,
x: -600,
y: 900
}));
self.walls.push(cornerBL1);
var cornerBL2 = self.addChild(LK.getAsset('wall', {
width: 200,
height: 200,
anchorX: 0.5,
anchorY: 0.5,
x: -750,
y: 700
}));
self.walls.push(cornerBL2);
// Bottom-right corner walls
var cornerBR1 = self.addChild(LK.getAsset('wall', {
width: 250,
height: 250,
anchorX: 0.5,
anchorY: 0.5,
x: 600,
y: 900
}));
self.walls.push(cornerBR1);
var cornerBR2 = self.addChild(LK.getAsset('wall', {
width: 200,
height: 200,
anchorX: 0.5,
anchorY: 0.5,
x: 750,
y: 700
}));
self.walls.push(cornerBR2);
// Inner walls - create oval inner track
// Inner top straight
var innerTopWall = self.addChild(LK.getAsset('wall', {
width: innerWidth,
height: wallThickness,
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: -innerHeight / 2 + wallThickness / 2
}));
self.walls.push(innerTopWall);
// Inner bottom straight
var innerBottomWall = self.addChild(LK.getAsset('wall', {
width: innerWidth,
height: wallThickness,
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: innerHeight / 2 - wallThickness / 2
}));
self.walls.push(innerBottomWall);
// Inner left straight
var innerLeftWall = self.addChild(LK.getAsset('wall', {
width: wallThickness,
height: innerHeight - 300,
anchorX: 0.5,
anchorY: 0.5,
x: -innerWidth / 2 + wallThickness / 2,
y: 0
}));
self.walls.push(innerLeftWall);
// Inner right straight
var innerRightWall = self.addChild(LK.getAsset('wall', {
width: wallThickness,
height: innerHeight - 300,
anchorX: 0.5,
anchorY: 0.5,
x: innerWidth / 2 - wallThickness / 2,
y: 0
}));
self.walls.push(innerRightWall);
// Inner corner walls
// Inner top-left corner
var innerCornerTL = self.addChild(LK.getAsset('wall', {
width: 150,
height: 150,
anchorX: 0.5,
anchorY: 0.5,
x: -400,
y: -650
}));
self.walls.push(innerCornerTL);
// Inner top-right corner
var innerCornerTR = self.addChild(LK.getAsset('wall', {
width: 150,
height: 150,
anchorX: 0.5,
anchorY: 0.5,
x: 400,
y: -650
}));
self.walls.push(innerCornerTR);
// Inner bottom-left corner
var innerCornerBL = self.addChild(LK.getAsset('wall', {
width: 150,
height: 150,
anchorX: 0.5,
anchorY: 0.5,
x: -400,
y: 650
}));
self.walls.push(innerCornerBL);
// Inner bottom-right corner
var innerCornerBR = self.addChild(LK.getAsset('wall', {
width: 150,
height: 150,
anchorX: 0.5,
anchorY: 0.5,
x: 400,
y: 650
}));
self.walls.push(innerCornerBR);
// Add start/finish line visual
var startLine = self.addChild(LK.getAsset('wall', {
width: 400,
height: 20,
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 1000,
color: 0xFFFFFF
}));
self.checkCollision = function (carObj) {
// Check collision with all walls
for (var i = 0; i < self.walls.length; i++) {
if (carObj.intersects(self.walls[i])) {
return true;
}
}
return false;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x222222
});
/****
* Game Code
****/
// Game variables
var car;
var track;
var score = 0;
var multiplier = 1;
var driftScore = 0;
var bestDrift = 0;
var laps = 0;
var maxLaps = 3;
var checkpointPassed = false;
var lastDriftSound = 0;
// UI Elements
var scoreText = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var multiplierText = new Text2('x1', {
size: 60,
fill: 0xFFFF00
});
multiplierText.anchor.set(0.5, 0);
multiplierText.y = 90;
LK.gui.top.addChild(multiplierText);
var driftText = new Text2('', {
size: 100,
fill: 0x00FF00
});
driftText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(driftText);
var lapText = new Text2('Lap 1/3', {
size: 70,
fill: 0xFFFFFF
});
lapText.anchor.set(1, 0);
LK.gui.topRight.addChild(lapText);
// Create track
track = game.addChild(new Track());
track.x = 1024;
track.y = 1366;
// Create car at starting position
car = game.addChild(new Car());
car.x = 1024;
car.y = 2300;
car.angle = -Math.PI / 2;
// Create checkpoint at start/finish line
var checkpoint = game.addChild(LK.getAsset('checkpoint', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2366,
alpha: 0.3
}));
// Create control buttons container
var controlsContainer = new Container();
LK.gui.bottom.addChild(controlsContainer);
controlsContainer.y = -300;
// Gas button
var gasButton = controlsContainer.addChild(LK.getAsset('button', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'ellipse',
anchorX: 0.5,
anchorY: 0.5,
x: 300,
y: 0
}));
// Brake button
var brakeButton = controlsContainer.addChild(LK.getAsset('button', {
width: 200,
height: 200,
color: 0xff0000,
shape: 'ellipse',
anchorX: 0.5,
anchorY: 0.5,
x: -300,
y: 0
}));
// Left steer button
var leftButton = controlsContainer.addChild(LK.getAsset('button', {
width: 150,
height: 150,
color: 0x0088ff,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5,
x: -450,
y: -150
}));
// Right steer button
var rightButton = controlsContainer.addChild(LK.getAsset('button', {
width: 150,
height: 150,
color: 0x0088ff,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5,
x: 450,
y: -150
}));
// Add gas pedal indicator
var gasPedal = controlsContainer.addChild(LK.getAsset('button', {
width: 80,
height: 200,
color: 0x888888,
shape: 'box',
anchorX: 0.5,
anchorY: 1,
x: 150,
y: 50
}));
var gasPedalIndicator = gasPedal.addChild(LK.getAsset('button', {
width: 70,
height: 0,
color: 0x00ff00,
shape: 'box',
anchorX: 0.5,
anchorY: 1,
x: 0,
y: 0
}));
var gasPedalText = new Text2('PEDAL', {
size: 30,
fill: 0xffffff
});
gasPedalText.anchor.set(0.5, 0.5);
gasPedalText.y = -220;
gasPedal.addChild(gasPedalText);
// Add button labels
var gasText = new Text2('GAS', {
size: 50,
fill: 0xffffff
});
gasText.anchor.set(0.5, 0.5);
gasButton.addChild(gasText);
var brakeText = new Text2('BRAKE', {
size: 40,
fill: 0xffffff
});
brakeText.anchor.set(0.5, 0.5);
brakeButton.addChild(brakeText);
var leftText = new Text2('←', {
size: 80,
fill: 0xffffff
});
leftText.anchor.set(0.5, 0.5);
leftButton.addChild(leftText);
var rightText = new Text2('→', {
size: 80,
fill: 0xffffff
});
rightText.anchor.set(0.5, 0.5);
rightButton.addChild(rightText);
// Control variables
var isAccelerating = false;
var isBraking = false;
var steerDirection = 0; // -1 for left, 0 for neutral, 1 for right
// Button controls
gasButton.down = function () {
isAccelerating = true;
gasButton.alpha = 0.7;
};
gasButton.up = function () {
isAccelerating = false;
gasButton.alpha = 1;
};
brakeButton.down = function () {
isBraking = true;
brakeButton.alpha = 0.7;
};
brakeButton.up = function () {
isBraking = false;
brakeButton.alpha = 1;
};
leftButton.down = function () {
steerDirection = -1;
leftButton.alpha = 0.7;
};
leftButton.up = function () {
if (steerDirection === -1) steerDirection = 0;
leftButton.alpha = 1;
};
rightButton.down = function () {
steerDirection = 1;
rightButton.alpha = 0.7;
};
rightButton.up = function () {
if (steerDirection === 1) steerDirection = 0;
rightButton.alpha = 1;
};
// Global up to handle button releases when finger moves off button
game.up = function () {
isAccelerating = false;
isBraking = false;
steerDirection = 0;
gasButton.alpha = 1;
brakeButton.alpha = 1;
leftButton.alpha = 1;
rightButton.alpha = 1;
};
// Update drifting score display
function updateDriftDisplay() {
// No drift scoring - hide drift text
if (driftText.alpha > 0) {
driftText.alpha = 0;
}
}
// Check checkpoint crossing
function checkCheckpoint() {
var carY = car.y;
var checkY = checkpoint.y;
// Check if car crosses start/finish line (moving up towards finish)
if (carY > checkY - 50 && carY < checkY + 50 && car.x > 824 && car.x < 1224) {
if (!checkpointPassed && car.velocity.y > 0) {
checkpointPassed = true;
laps++;
// Award points for completing a lap
score += 1000;
scoreText.setText('Score: ' + score);
lapText.setText('Lap ' + Math.min(laps, maxLaps) + '/' + maxLaps);
// Flash checkpoint
tween(checkpoint, {
alpha: 0.8
}, {
duration: 200,
onFinish: function onFinish() {
tween(checkpoint, {
alpha: 0.3
}, {
duration: 200
});
}
});
// Check win condition
if (laps >= maxLaps) {
LK.setScore(score);
LK.showYouWin();
}
}
} else if (Math.abs(carY - checkY) > 100) {
checkpointPassed = false;
}
}
// Main game update
game.update = function () {
// Check track collision
if (track.checkCollision(car)) {
// Crash effect
LK.getSound('crash').play();
LK.effects.flashObject(car, 0xff0000, 500);
// Bounce car back
car.speed *= -0.5;
car.x += car.velocity.x * -5;
car.y += car.velocity.y * -5;
}
// No drift multiplier - keep at x1
multiplierText.setText('x1');
// Update gas pedal indicator
if (isAccelerating) {
gasPedalIndicator.height = Math.min(180, gasPedalIndicator.height + 10);
gasPedalIndicator.alpha = 1;
} else {
gasPedalIndicator.height = Math.max(0, gasPedalIndicator.height - 5);
gasPedalIndicator.alpha = 0.7;
}
// Update displays
updateDriftDisplay();
checkCheckpoint();
// Keep car on screen
car.x = Math.max(100, Math.min(1948, car.x));
car.y = Math.max(100, Math.min(2632, car.y));
};
// Start background music
LK.playMusic('race'); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocity = {
x: 0,
y: 0
};
self.angle = 0;
self.speed = 0;
self.maxSpeed = 10;
self.acceleration = 0.25;
self.friction = 0.95;
self.driftFriction = 0.92;
self.turnSpeed = 0.08;
self.isDrifting = false;
self.driftTime = 0;
self.driftAngle = 0;
self.update = function () {
// Apply acceleration/braking based on button input
if (isAccelerating) {
self.speed += self.acceleration;
self.speed = Math.min(self.speed, self.maxSpeed);
} else if (isBraking) {
self.speed -= 0.3;
self.speed = Math.max(self.speed, -2);
}
// Apply standard friction (no drift)
self.speed *= self.friction;
// Apply direct steering based on button input
if (steerDirection !== 0 && Math.abs(self.speed) > 0.1) {
// Direct turning without drift
self.angle += steerDirection * self.turnSpeed * 1.5; // Increased turn rate for better control
}
// Update velocity based on angle (direct movement)
self.velocity.x = Math.cos(self.angle) * self.speed;
self.velocity.y = Math.sin(self.angle) * self.speed;
// Update position
self.x += self.velocity.x;
self.y += self.velocity.y;
// Update rotation to match angle
self.rotation = self.angle;
// Always set drift to false
self.isDrifting = false;
self.driftTime = 0;
self.driftAngle = 0;
};
return self;
});
var Track = Container.expand(function () {
var self = Container.call(this);
// Create track walls array
self.walls = [];
// Create outer track walls
var wallThickness = 120;
var trackWidth = 1800;
var trackHeight = 2400;
var innerWidth = 1000;
var innerHeight = 1600;
// Track surface first (so it appears behind walls)
var trackSurface = self.addChild(LK.getAsset('track', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0
}));
// Create oval track with proper racing circuit layout
// Outer walls - top straight
var topWall = self.addChild(LK.getAsset('wall', {
width: trackWidth - 400,
height: wallThickness,
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: -trackHeight / 2 + wallThickness / 2
}));
self.walls.push(topWall);
// Outer walls - bottom straight
var bottomWall = self.addChild(LK.getAsset('wall', {
width: trackWidth - 400,
height: wallThickness,
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: trackHeight / 2 - wallThickness / 2
}));
self.walls.push(bottomWall);
// Outer walls - left straight
var leftWall = self.addChild(LK.getAsset('wall', {
width: wallThickness,
height: trackHeight - 600,
anchorX: 0.5,
anchorY: 0.5,
x: -trackWidth / 2 + wallThickness / 2,
y: 0
}));
self.walls.push(leftWall);
// Outer walls - right straight
var rightWall = self.addChild(LK.getAsset('wall', {
width: wallThickness,
height: trackHeight - 600,
anchorX: 0.5,
anchorY: 0.5,
x: trackWidth / 2 - wallThickness / 2,
y: 0
}));
self.walls.push(rightWall);
// Create corner walls for proper oval shape
// Top-left corner walls
var cornerTL1 = self.addChild(LK.getAsset('wall', {
width: 250,
height: 250,
anchorX: 0.5,
anchorY: 0.5,
x: -600,
y: -900
}));
self.walls.push(cornerTL1);
var cornerTL2 = self.addChild(LK.getAsset('wall', {
width: 200,
height: 200,
anchorX: 0.5,
anchorY: 0.5,
x: -750,
y: -700
}));
self.walls.push(cornerTL2);
// Top-right corner walls
var cornerTR1 = self.addChild(LK.getAsset('wall', {
width: 250,
height: 250,
anchorX: 0.5,
anchorY: 0.5,
x: 600,
y: -900
}));
self.walls.push(cornerTR1);
var cornerTR2 = self.addChild(LK.getAsset('wall', {
width: 200,
height: 200,
anchorX: 0.5,
anchorY: 0.5,
x: 750,
y: -700
}));
self.walls.push(cornerTR2);
// Bottom-left corner walls
var cornerBL1 = self.addChild(LK.getAsset('wall', {
width: 250,
height: 250,
anchorX: 0.5,
anchorY: 0.5,
x: -600,
y: 900
}));
self.walls.push(cornerBL1);
var cornerBL2 = self.addChild(LK.getAsset('wall', {
width: 200,
height: 200,
anchorX: 0.5,
anchorY: 0.5,
x: -750,
y: 700
}));
self.walls.push(cornerBL2);
// Bottom-right corner walls
var cornerBR1 = self.addChild(LK.getAsset('wall', {
width: 250,
height: 250,
anchorX: 0.5,
anchorY: 0.5,
x: 600,
y: 900
}));
self.walls.push(cornerBR1);
var cornerBR2 = self.addChild(LK.getAsset('wall', {
width: 200,
height: 200,
anchorX: 0.5,
anchorY: 0.5,
x: 750,
y: 700
}));
self.walls.push(cornerBR2);
// Inner walls - create oval inner track
// Inner top straight
var innerTopWall = self.addChild(LK.getAsset('wall', {
width: innerWidth,
height: wallThickness,
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: -innerHeight / 2 + wallThickness / 2
}));
self.walls.push(innerTopWall);
// Inner bottom straight
var innerBottomWall = self.addChild(LK.getAsset('wall', {
width: innerWidth,
height: wallThickness,
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: innerHeight / 2 - wallThickness / 2
}));
self.walls.push(innerBottomWall);
// Inner left straight
var innerLeftWall = self.addChild(LK.getAsset('wall', {
width: wallThickness,
height: innerHeight - 300,
anchorX: 0.5,
anchorY: 0.5,
x: -innerWidth / 2 + wallThickness / 2,
y: 0
}));
self.walls.push(innerLeftWall);
// Inner right straight
var innerRightWall = self.addChild(LK.getAsset('wall', {
width: wallThickness,
height: innerHeight - 300,
anchorX: 0.5,
anchorY: 0.5,
x: innerWidth / 2 - wallThickness / 2,
y: 0
}));
self.walls.push(innerRightWall);
// Inner corner walls
// Inner top-left corner
var innerCornerTL = self.addChild(LK.getAsset('wall', {
width: 150,
height: 150,
anchorX: 0.5,
anchorY: 0.5,
x: -400,
y: -650
}));
self.walls.push(innerCornerTL);
// Inner top-right corner
var innerCornerTR = self.addChild(LK.getAsset('wall', {
width: 150,
height: 150,
anchorX: 0.5,
anchorY: 0.5,
x: 400,
y: -650
}));
self.walls.push(innerCornerTR);
// Inner bottom-left corner
var innerCornerBL = self.addChild(LK.getAsset('wall', {
width: 150,
height: 150,
anchorX: 0.5,
anchorY: 0.5,
x: -400,
y: 650
}));
self.walls.push(innerCornerBL);
// Inner bottom-right corner
var innerCornerBR = self.addChild(LK.getAsset('wall', {
width: 150,
height: 150,
anchorX: 0.5,
anchorY: 0.5,
x: 400,
y: 650
}));
self.walls.push(innerCornerBR);
// Add start/finish line visual
var startLine = self.addChild(LK.getAsset('wall', {
width: 400,
height: 20,
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 1000,
color: 0xFFFFFF
}));
self.checkCollision = function (carObj) {
// Check collision with all walls
for (var i = 0; i < self.walls.length; i++) {
if (carObj.intersects(self.walls[i])) {
return true;
}
}
return false;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x222222
});
/****
* Game Code
****/
// Game variables
var car;
var track;
var score = 0;
var multiplier = 1;
var driftScore = 0;
var bestDrift = 0;
var laps = 0;
var maxLaps = 3;
var checkpointPassed = false;
var lastDriftSound = 0;
// UI Elements
var scoreText = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var multiplierText = new Text2('x1', {
size: 60,
fill: 0xFFFF00
});
multiplierText.anchor.set(0.5, 0);
multiplierText.y = 90;
LK.gui.top.addChild(multiplierText);
var driftText = new Text2('', {
size: 100,
fill: 0x00FF00
});
driftText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(driftText);
var lapText = new Text2('Lap 1/3', {
size: 70,
fill: 0xFFFFFF
});
lapText.anchor.set(1, 0);
LK.gui.topRight.addChild(lapText);
// Create track
track = game.addChild(new Track());
track.x = 1024;
track.y = 1366;
// Create car at starting position
car = game.addChild(new Car());
car.x = 1024;
car.y = 2300;
car.angle = -Math.PI / 2;
// Create checkpoint at start/finish line
var checkpoint = game.addChild(LK.getAsset('checkpoint', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2366,
alpha: 0.3
}));
// Create control buttons container
var controlsContainer = new Container();
LK.gui.bottom.addChild(controlsContainer);
controlsContainer.y = -300;
// Gas button
var gasButton = controlsContainer.addChild(LK.getAsset('button', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'ellipse',
anchorX: 0.5,
anchorY: 0.5,
x: 300,
y: 0
}));
// Brake button
var brakeButton = controlsContainer.addChild(LK.getAsset('button', {
width: 200,
height: 200,
color: 0xff0000,
shape: 'ellipse',
anchorX: 0.5,
anchorY: 0.5,
x: -300,
y: 0
}));
// Left steer button
var leftButton = controlsContainer.addChild(LK.getAsset('button', {
width: 150,
height: 150,
color: 0x0088ff,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5,
x: -450,
y: -150
}));
// Right steer button
var rightButton = controlsContainer.addChild(LK.getAsset('button', {
width: 150,
height: 150,
color: 0x0088ff,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5,
x: 450,
y: -150
}));
// Add gas pedal indicator
var gasPedal = controlsContainer.addChild(LK.getAsset('button', {
width: 80,
height: 200,
color: 0x888888,
shape: 'box',
anchorX: 0.5,
anchorY: 1,
x: 150,
y: 50
}));
var gasPedalIndicator = gasPedal.addChild(LK.getAsset('button', {
width: 70,
height: 0,
color: 0x00ff00,
shape: 'box',
anchorX: 0.5,
anchorY: 1,
x: 0,
y: 0
}));
var gasPedalText = new Text2('PEDAL', {
size: 30,
fill: 0xffffff
});
gasPedalText.anchor.set(0.5, 0.5);
gasPedalText.y = -220;
gasPedal.addChild(gasPedalText);
// Add button labels
var gasText = new Text2('GAS', {
size: 50,
fill: 0xffffff
});
gasText.anchor.set(0.5, 0.5);
gasButton.addChild(gasText);
var brakeText = new Text2('BRAKE', {
size: 40,
fill: 0xffffff
});
brakeText.anchor.set(0.5, 0.5);
brakeButton.addChild(brakeText);
var leftText = new Text2('←', {
size: 80,
fill: 0xffffff
});
leftText.anchor.set(0.5, 0.5);
leftButton.addChild(leftText);
var rightText = new Text2('→', {
size: 80,
fill: 0xffffff
});
rightText.anchor.set(0.5, 0.5);
rightButton.addChild(rightText);
// Control variables
var isAccelerating = false;
var isBraking = false;
var steerDirection = 0; // -1 for left, 0 for neutral, 1 for right
// Button controls
gasButton.down = function () {
isAccelerating = true;
gasButton.alpha = 0.7;
};
gasButton.up = function () {
isAccelerating = false;
gasButton.alpha = 1;
};
brakeButton.down = function () {
isBraking = true;
brakeButton.alpha = 0.7;
};
brakeButton.up = function () {
isBraking = false;
brakeButton.alpha = 1;
};
leftButton.down = function () {
steerDirection = -1;
leftButton.alpha = 0.7;
};
leftButton.up = function () {
if (steerDirection === -1) steerDirection = 0;
leftButton.alpha = 1;
};
rightButton.down = function () {
steerDirection = 1;
rightButton.alpha = 0.7;
};
rightButton.up = function () {
if (steerDirection === 1) steerDirection = 0;
rightButton.alpha = 1;
};
// Global up to handle button releases when finger moves off button
game.up = function () {
isAccelerating = false;
isBraking = false;
steerDirection = 0;
gasButton.alpha = 1;
brakeButton.alpha = 1;
leftButton.alpha = 1;
rightButton.alpha = 1;
};
// Update drifting score display
function updateDriftDisplay() {
// No drift scoring - hide drift text
if (driftText.alpha > 0) {
driftText.alpha = 0;
}
}
// Check checkpoint crossing
function checkCheckpoint() {
var carY = car.y;
var checkY = checkpoint.y;
// Check if car crosses start/finish line (moving up towards finish)
if (carY > checkY - 50 && carY < checkY + 50 && car.x > 824 && car.x < 1224) {
if (!checkpointPassed && car.velocity.y > 0) {
checkpointPassed = true;
laps++;
// Award points for completing a lap
score += 1000;
scoreText.setText('Score: ' + score);
lapText.setText('Lap ' + Math.min(laps, maxLaps) + '/' + maxLaps);
// Flash checkpoint
tween(checkpoint, {
alpha: 0.8
}, {
duration: 200,
onFinish: function onFinish() {
tween(checkpoint, {
alpha: 0.3
}, {
duration: 200
});
}
});
// Check win condition
if (laps >= maxLaps) {
LK.setScore(score);
LK.showYouWin();
}
}
} else if (Math.abs(carY - checkY) > 100) {
checkpointPassed = false;
}
}
// Main game update
game.update = function () {
// Check track collision
if (track.checkCollision(car)) {
// Crash effect
LK.getSound('crash').play();
LK.effects.flashObject(car, 0xff0000, 500);
// Bounce car back
car.speed *= -0.5;
car.x += car.velocity.x * -5;
car.y += car.velocity.y * -5;
}
// No drift multiplier - keep at x1
multiplierText.setText('x1');
// Update gas pedal indicator
if (isAccelerating) {
gasPedalIndicator.height = Math.min(180, gasPedalIndicator.height + 10);
gasPedalIndicator.alpha = 1;
} else {
gasPedalIndicator.height = Math.max(0, gasPedalIndicator.height - 5);
gasPedalIndicator.alpha = 0.7;
}
// Update displays
updateDriftDisplay();
checkCheckpoint();
// Keep car on screen
car.x = Math.max(100, Math.min(1948, car.x));
car.y = Math.max(100, Math.min(2632, car.y));
};
// Start background music
LK.playMusic('race');
Car seen from above. In-Game asset. 2d. High contrast. No shadows
Cyrcle. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Button . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
WAY. In-Game asset. 2d. High contrast. No shadows