Remix started
Copy Flip & Flap
User prompt
Add Cartoons Forest Background
User prompt
Add background asset to the game.
User prompt
Make the background full screen.
User prompt
Overlay the obstacle asset
User prompt
Make the background full screen.
User prompt
Put a nature design font on the score
User prompt
Change the score font to green and the shadow to yellow green
===================================================================
--- original.js
+++ change.js
@@ -1,25 +1,13 @@
-var Obstacle = Container.expand(function () {
- var self = Container.call(this);
- var obstacleShadow = self.createAsset('obstacleShadow', 'Obstacle Shadow', .5, .5);
- obstacleShadow.rotation = Math.PI / 4;
- var obstacleShadow2 = self.createAsset('obstacleShadow2', 'Obstacle Shadow 2', .5, .5);
- obstacleShadow2.rotation = Math.PI / 4;
- obstacleShadow2.y = -7;
- 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);
-});
+/****
+* Classes
+****/
var Bird = Container.expand(function () {
var self = Container.call(this);
- var birdGraphics = self.createAsset('bird', 'Bird character', .5, .5);
+ var birdGraphics = self.attachAsset('bird', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
birdGraphics.scale.x = 1;
self.xSpeed = 10.9375;
self.ySpeed = -20;
self.gravity = 1;
@@ -40,108 +28,153 @@
self.flip = function () {
self.scale.x *= -1;
};
});
-var Game = Container.expand(function () {
+var Obstacle = 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 < 280) {
- LK.showGameOver();
- }
- }
- };
- LK.stageContainer.setBackgroundColor(0xadd8e6);
- var scoreText = new Text2('0', {
- size: 150,
- fill: '#3a84f7',
- font: 'Impact',
- dropShadow: true,
- dropShadowColor: '#222a9a',
- dropShadowBlur: 5,
- dropShadowDistance: 7,
- dropShadowAngle: 0
+ var obstacleShadow = self.attachAsset('obstacleShadow', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
- scoreText.anchor.set(.5, 0);
- LK.gui.topCenter.addChild(scoreText);
- var scoreText2 = new Text2('0', {
- size: 150,
- fill: '#ffffff',
- font: 'Impact'
+ obstacleShadow.rotation = Math.PI / 4;
+ var obstacleShadow2 = self.attachAsset('obstacleShadow2', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
- scoreText2.anchor.set(.5, 0);
- scoreText2.x = -4;
- scoreText2.y = -5;
- LK.gui.topCenter.addChild(scoreText2);
- 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.025;
- 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();
+ obstacleShadow2.rotation = Math.PI / 4;
+ obstacleShadow2.y = -7;
+ var obstacleGraphics = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
- LK.on('tick', function () {
- bird.update();
- scoreText.setText(self.score);
- scoreText2.setText(self.score);
- self.obstacleSpeed += self.obstacleSpeedIncrease;
- obstacleSpawnRandomness -= obstacleSpawnRandomnessDecrease;
- if (obstacleSpawnRandomness < 20) {
- obstacleSpawnRandomness = 20;
- }
- 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) {
+ 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.attachAsset('wall', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+});
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+var background = game.addChild(LK.getAsset('background', {
+ anchorX: 0.5,
+ anchorY: 0.5
+}));
+background.x = 1024;
+background.y = 1366;
+game.score = 0;
+game.obstacleSpeed = 5;
+game.obstacleSpeedIncrease = 0.005;
+game.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 < 280) {
LK.showGameOver();
}
- });
+ }
+};
+game.setBackgroundColor(0xadd8e6);
+var scoreText = new Text2('0', {
+ size: 150,
+ fill: '#3a84f7',
+ font: 'Impact',
+ dropShadow: true,
+ dropShadowColor: '#222a9a',
+ dropShadowBlur: 5,
+ dropShadowDistance: 7,
+ dropShadowAngle: 0
});
+scoreText.anchor.set(.5, 0);
+LK.gui.top.addChild(scoreText);
+var scoreText2 = new Text2('0', {
+ size: 150,
+ fill: '#ffffff',
+ font: 'Impact'
+});
+scoreText2.anchor.set(.5, 0);
+scoreText2.x = -4;
+scoreText2.y = -5;
+LK.gui.top.addChild(scoreText2);
+LK.gui.top.addChild(scoreText);
+var bird = game.addChild(new Bird());
+var leftWall = game.addChild(new Wall());
+leftWall.x = 0;
+leftWall.y = 1366;
+var rightWall = game.addChild(new Wall());
+rightWall.x = 2048;
+rightWall.y = 1366;
+var leftObstacles = [],
+ rightObstacles = [];
+var obstacleSpawnRandomness = 120;
+var obstacleSpawnRandomnessDecrease = 0.025;
+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;
+game.on('down', function (obj) {
+ bird.flap();
+});
+LK.on('tick', function () {
+ bird.update();
+ scoreText.setText(game.score);
+ scoreText2.setText(game.score);
+ game.obstacleSpeed += game.obstacleSpeedIncrease;
+ obstacleSpawnRandomness -= obstacleSpawnRandomnessDecrease;
+ if (obstacleSpawnRandomness < 20) {
+ obstacleSpawnRandomness = 20;
+ }
+ if (LK.ticks >= leftObstacleSpawnTime) {
+ var newObstacle = game.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 = game.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();
+ game.score++;
+ }
+ for (var i = leftObstacles.length - 1; i >= 0; i--) {
+ leftObstacles[i].move(game.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(game.obstacleSpeed);
+ if (rightObstacles[i].y > 3232) {
+ rightObstacles[i].destroy();
+ rightObstacles.splice(i, 1);
+ }
+ }
+ game.checkObstacleCollision(leftObstacles);
+ game.checkObstacleCollision(rightObstacles);
+ if (bird.y < 0 || bird.y > 2732) {
+ LK.showGameOver();
+ }
+});
\ No newline at end of file