User prompt
Upper case the F in flap and float in the tutorial text
User prompt
Make gravity when mouse is down be /3
User prompt
Don't set scale on that.
User prompt
Please increment the particles.
Code edit (1 edits merged)
Please save this source code
User prompt
Okay, please fix that.
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'wefwef.wefwefwe.wef;' Line Number: 87
User prompt
add javadocs to all classes
User prompt
Migrate to the latest version of LK
User prompt
Update the game, to use the new event format where possible
User prompt
Add sound when bird flaps
User prompt
add sound when bird bounces
User prompt
add game over jingle before calling LK.gameOver
===================================================================
--- original.js
+++ change.js
@@ -1,11 +1,7 @@
/****
* Classes
****/
-/**
-* Bird class represents the main character in the game.
-* It has properties for speed, gravity, lift and methods for flapping, updating and flipping.
-*/
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
@@ -14,19 +10,12 @@
self.xSpeed = 10.9375;
self.ySpeed = -20;
self.gravity = 1;
self.lift = -15;
- birdGraphics.alpha = 1;
- /**
- * Flap method increases the bird's ySpeed by the lift amount.
- */
self.flap = function () {
self.ySpeed = self.lift * 1.5;
};
- /**
- * Update method updates the bird's position and rotation based on its speed and gravity.
- */
- self.update = function () {
+ self._update_migrated = function () {
if (game.isMouseDown) {
self.ySpeed += self.gravity / 3;
} else {
self.ySpeed += self.gravity;
@@ -38,19 +27,12 @@
}
var targetRotation = Math.atan2(self.ySpeed, self.xSpeed * self.scale.x) / 2;
birdGraphics.rotation += (targetRotation - birdGraphics.rotation) / 10;
};
- /**
- * Flip method flips the bird's direction by multiplying its scale by -1.
- */
self.flip = function () {
self.scale.x *= -1;
};
});
-/**
-* Obstacle class represents the obstacles in the game.
-* It has properties for speed and a method for moving.
-*/
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleShadow = self.attachAsset('obstacleShadow', {
anchorX: 0.5,
@@ -68,18 +50,12 @@
anchorY: 0.5
});
obstacleGraphics.rotation = Math.PI / 4;
self.speed = 5;
- /**
- * Move method updates the obstacle's position based on the given speed.
- */
- self.move = function (speed) {
+ self._move_migrated = function (speed) {
self.y += speed;
};
});
-/**
-* Wall class represents the walls in the game.
-*/
var Wall = Container.expand(function () {
var self = Container.call(this);
var wallGraphics = self.attachAsset('wall', {
anchorX: 0.5,
@@ -125,9 +101,9 @@
game.obstacleSpeed = 5;
game.obstacleSpeedIncrease = 0.005;
game.checkObstacleCollision = function (obstacles) {
for (var i = 0; i < obstacles.length; i++) {
- obstacles[i].move();
+ obstacles[i]._move_migrated();
var dist = Math.sqrt(Math.pow(bird.x - obstacles[i].x, 2) + Math.pow(bird.y - obstacles[i].y, 2));
if (dist < 280) {
LK.setScore(game.score);
LK.showGameOver();
@@ -173,17 +149,17 @@
var rightObstacleSpawnTime = Math.floor(Math.random() * obstacleSpawnRandomness) + obstacleSpawnRandomness;
bird.x = 1024;
bird.y = 1366;
game.isMouseDown = false;
-game.on('down', function (obj) {
+game.on('down', function (x, y, obj) {
bird.flap();
game.isMouseDown = true;
});
-game.on('up', function (obj) {
+game.on('up', function (x, y, obj) {
game.isMouseDown = false;
});
LK.on('tick', function () {
- bird.update();
+ bird._update_migrated();
if (game.score > 2) {
tutorialText.y += 5;
tutorialTextWhite.y += 5;
}
@@ -214,16 +190,16 @@
game.score++;
LK.setScore(game.score);
}
for (var i = leftObstacles.length - 1; i >= 0; i--) {
- leftObstacles[i].move(game.obstacleSpeed);
+ leftObstacles[i]._move_migrated(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);
+ rightObstacles[i]._move_migrated(game.obstacleSpeed);
if (rightObstacles[i].y > 3232) {
rightObstacles[i].destroy();
rightObstacles.splice(i, 1);
}