User prompt
add obstacles at z index 0
User prompt
Add a 222a9a drop shadow to the highscore
User prompt
set dropShadowAngle to 0 and dropShadowDistance to 10
User prompt
set obstacleShadow.y to 15
User prompt
det stop shadow distance to 7
User prompt
Set highscore drop shadow distance to 7
User prompt
Increase the obstacle threshold to 300
User prompt
Increase the obstacle threshold to 280
User prompt
Add a second shadow to obstacles
User prompt
use a separate asset id for the second obstacle
User prompt
set obstacle 2 y to -3
User prompt
set obstacle 2 y to -5
User prompt
Set obstacleShadow2 y to -7
User prompt
Remove the code that sets the obstacle shadow y
User prompt
Don't set y on the first obstacle shadow
User prompt
Set the floor for obstacleSpawnRandomness to 20
User prompt
half obstacleSpawnRandomnessDecrease
User prompt
Add a second score label that renders below the current one. Make this one white
User prompt
Remove the drop shadow on score text 2
User prompt
Attach score text after score text 2
User prompt
Update both score text and score text 2 when updating scores
User prompt
set scoretext2 x to -3 and scoretext2 y to -5
User prompt
set scoreText2.x to -4
User prompt
Use the build in system to report scores to the system
User prompt
make obstacleSpawnRandomnessDecrease 2/3 as impactful
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleShadow = self.createAsset('obstacleShadow', 'Obstacle Shadow', .5, .5);
obstacleShadow.rotation = Math.PI / 4;
obstacleShadow.y += 40;
var obstacleGraphics = self.createAsset('obstacle', 'Obstacle', .5, .5);
obstacleGraphics.rotation = Math.PI / 4;
self.speed = 5;
self.move = function (speed) {
self.y += speed;
};
});
var Wall = Container.expand(function () {
var self = Container.call(this);
var wallGraphics = self.createAsset('wall', 'Wall', .5, .5);
});
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.createAsset('bird', 'Bird character', .5, .5);
birdGraphics.scale.x = 1;
self.xSpeed = 10.9375;
self.ySpeed = -20;
self.gravity = 1;
self.lift = -15;
self.flap = function () {
self.ySpeed = self.lift * 1.5;
};
self.update = function () {
self.ySpeed += self.gravity;
self.y += self.ySpeed;
self.x += self.xSpeed;
if (self.y <= 0 || self.y >= 2732) {
self.speed = -self.speed;
}
var targetRotation = Math.atan2(self.ySpeed, self.xSpeed * self.scale.x) / 2;
birdGraphics.rotation += (targetRotation - birdGraphics.rotation) / 10;
};
self.flip = function () {
self.scale.x *= -1;
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
self.score = 0;
self.obstacleSpeed = 5;
self.obstacleSpeedIncrease = 0.005;
self.checkObstacleCollision = function (obstacles) {
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].move();
var dist = Math.sqrt(Math.pow(bird.x - obstacles[i].x, 2) + Math.pow(bird.y - obstacles[i].y, 2));
if (dist < 250) {
LK.showGameOver();
}
}
};
LK.stageContainer.setBackgroundColor(0xadd8e6);
var scoreText = new Text2('0', {
size: 150,
fill: '#3a84f7',
font: 'Impact'
});
scoreText.anchor.set(.5, 0);
LK.gui.topCenter.addChild(scoreText);
var bird = self.addChild(new Bird());
var leftWall = self.addChild(new Wall());
leftWall.x = 0;
leftWall.y = 1366;
var rightWall = self.addChild(new Wall());
rightWall.x = 2048;
rightWall.y = 1366;
var leftObstacles = [], rightObstacles = [];
var obstacleSpawnRandomness = 120;
var obstacleSpawnRandomnessDecrease = 0.05;
var obstacleSpawnY = -500;
var leftObstacleSpawnTime = Math.floor(Math.random() * obstacleSpawnRandomness) + obstacleSpawnRandomness;
var rightObstacleSpawnTime = Math.floor(Math.random() * obstacleSpawnRandomness) + obstacleSpawnRandomness;
bird.x = 1024;
bird.y = 1366;
stage.on('down', function (obj) {
bird.flap();
});
LK.on('tick', function () {
bird.update();
scoreText.setText(self.score);
self.obstacleSpeed += self.obstacleSpeedIncrease;
obstacleSpawnRandomness -= obstacleSpawnRandomnessDecrease;
if (obstacleSpawnRandomness < 60) {
obstacleSpawnRandomness = 60;
}
if (LK.ticks >= leftObstacleSpawnTime) {
var newObstacle = self.addChildAt(new Obstacle(), 0);
newObstacle.x = 0;
newObstacle.y = obstacleSpawnY;
leftObstacles.push(newObstacle);
leftObstacleSpawnTime += Math.floor(Math.random() * obstacleSpawnRandomness) + obstacleSpawnRandomness;
}
if (LK.ticks >= rightObstacleSpawnTime) {
var newObstacle = self.addChildAt(new Obstacle(), 0);
newObstacle.x = 2048;
newObstacle.y = -newObstacle.height;
rightObstacles.push(newObstacle);
rightObstacleSpawnTime += Math.floor(Math.random() * obstacleSpawnRandomness) + obstacleSpawnRandomness;
}
if (bird.intersects(leftWall) && bird.xSpeed < 0 || bird.intersects(rightWall) && bird.xSpeed > 0) {
bird.xSpeed = -bird.xSpeed;
bird.flip();
self.score++;
}
for (var i = leftObstacles.length - 1; i >= 0; i--) {
leftObstacles[i].move(self.obstacleSpeed);
if (leftObstacles[i].y > 3232) {
leftObstacles[i].destroy();
leftObstacles.splice(i, 1);
}
}
for (var i = rightObstacles.length - 1; i >= 0; i--) {
rightObstacles[i].move(self.obstacleSpeed);
if (rightObstacles[i].y > 3232) {
rightObstacles[i].destroy();
rightObstacles.splice(i, 1);
}
}
self.checkObstacleCollision(leftObstacles);
self.checkObstacleCollision(rightObstacles);
if (bird.y < 0 || bird.y > 2732) {
LK.showGameOver();
}
});
});