User prompt
Move the game title to the left
User prompt
Add design to the game title
User prompt
Add design to the game title with "Car Racing" theme
User prompt
Flip sideward of left arrow asset
User prompt
Finish line asset have white and black tiles
User prompt
Background ID asset input
User prompt
Whe game over spawns, a Pixel art trophy shows under it
User prompt
Fix finish line turning black
User prompt
Fix finish line when turning black
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.createAsset('player', 'Player Graphics', .5, .5);
playerGraphics.scale.set(2);
playerGraphics.scale.x *= -1;
self.speed = 5;
self.move = function (direction) {
if (direction === 'left') {
self.x -= self.speed;
} else if (direction === 'right') {
self.x += self.speed;
}
};
});
var CPU1 = Container.expand(function () {
var self = Container.call(this);
var cpuGraphics = self.createAsset('cpu1', 'CPU1 Graphics', .5, .5);
cpuGraphics.scale.set(2);
cpuGraphics.scale.x *= -1;
self.speed = 3;
self.move = function () {
self.x += self.speed;
};
});
var CPU2 = Container.expand(function () {
var self = Container.call(this);
var cpuGraphics = self.createAsset('cpu2', 'CPU2 Graphics', .5, .5);
cpuGraphics.scale.set(2);
cpuGraphics.scale.x *= -1;
self.speed = 2;
self.move = function () {
self.x += self.speed;
};
});
var CPU3 = Container.expand(function () {
var self = Container.call(this);
var cpuGraphics = self.createAsset('cpu3', 'CPU3 Graphics', .5, .5);
cpuGraphics.scale.set(2);
cpuGraphics.scale.x *= -1;
self.speed = 3;
self.move = function () {
self.x += self.speed;
};
});
var FinishLine = Container.expand(function () {
var self = Container.call(this);
var finishLineGraphics = self.createAsset('finishLine', 'Finish Line Graphics', .5, 1);
finishLineGraphics.scale.set(5);
});
var Game = Container.expand(function () {
var self = Container.call(this);
LK.stageContainer.setBackgroundColor(0x00008B);
var gameTitle = new Text2('Car Champions!', {
size: 150,
fill: '#ffffff'
});
gameTitle.x = 100;
gameTitle.y = 150;
self.addChild(gameTitle);
var player = self.addChild(new Player());
player.x = 200;
player.y = 2732 / 2;
var cpu1 = self.addChild(new CPU1());
cpu1.x = 200;
cpu1.y = 2732 / 2 - 100;
var cpu2 = self.addChild(new CPU2());
cpu2.x = 200;
cpu2.y = 2732 / 2 - 200;
var cpu3 = self.addChild(new CPU3());
cpu3.x = 200;
cpu3.y = 2732 / 2 - 300;
var finishLine = self.addChild(new FinishLine());
finishLine.x = 2048 - 200;
finishLine.y = 2732 / 2;
var countdown = 3;
var countdownText = new Text2(countdown.toString(), {
size: 150,
fill: '#ffffff'
});
countdownText.x = 2048 / 2;
countdownText.y = 2732 / 2;
self.addChild(countdownText);
var countdownInterval = LK.setInterval(function () {
countdown--;
countdownText.setText(countdown.toString());
if (countdown === 0) {
LK.clearInterval(countdownInterval);
countdownText.destroy();
}
}, 1000);
var leftArrow = self.createAsset('leftArrow', 'Left Arrow', .5, .5);
leftArrow.scale.set(2);
leftArrow.x = 100;
leftArrow.y = 2732 - 100;
var leftArrowPressed = false;
leftArrow.on('down', function () {
leftArrowPressed = true;
});
leftArrow.on('up', function () {
leftArrowPressed = false;
});
var rightArrow = self.createAsset('rightArrow', 'Right Arrow', .5, .5);
rightArrow.scale.set(2);
rightArrow.x = 2048 - 100;
rightArrow.y = 2732 - 100;
var rightArrowPressed = false;
rightArrow.on('down', function () {
rightArrowPressed = true;
});
rightArrow.on('up', function () {
rightArrowPressed = false;
});
var isGameOver = false;
LK.on('tick', function () {
if (countdown === 0) {
cpu1.move();
cpu2.move();
cpu3.move();
if (leftArrowPressed) {
player.move('left');
}
if (rightArrowPressed) {
player.move('right');
}
}
if (player.intersects(finishLine)) {
isGameOver = true;
console.log("Player Wins!");
}
if (cpu1.intersects(finishLine) || cpu2.intersects(finishLine) || cpu3.intersects(finishLine)) {
isGameOver = true;
console.log("CPU Wins!");
}
if (isGameOver) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
});
});