Code edit (2 edits merged)
Please save this source code
User prompt
Migrate to the latest version of LK
Code edit (12 edits merged)
Please save this source code
User prompt
Add a simulated y position that increases by game.obstacleSpeed every tick. The score should be this divided by 10.
User prompt
Add 1 score every 10 ticks instead of based on y position
User prompt
Remove the tutorial text
User prompt
Please fix the bug: 'ReferenceError: tutorialText is not defined' in or related to this line: 'tutorialText.y += 5;' Line Number: 200
User prompt
Add 1 score every '10 y' that we travel up
Code edit (1 edits merged)
Please save this source code
User prompt
Spawn the shadows with the same flip / scale x as the bird
User prompt
Make the shadow graphics tint a bright fuschia
Code edit (1 edits merged)
Please save this source code
User prompt
Ensure the z index of the shadow graphics are behind the cat
User prompt
Ensure the shadow graphics are behind the cat
User prompt
Ensure the shadow graphics scale x matches the cats at the time it's spawned.
Code edit (3 edits merged)
Please save this source code
User prompt
They should be at full alpha for the 200ms, and only then do they start fading out
User prompt
Don't fade out the shadow immediately, they should stick around for 200ms or so
User prompt
Spawn the shadows every few frames, while the cat is in the air
User prompt
There should be up to 15 shadow particles at a time, spawned while the bird is in the air
User prompt
Add a 'shadow' particle effect, in the style of street fighter powerups, where every few frames there is a clone of our cat. You only need to add them during a jump. They should be fully tinted to an opaque colour.
User prompt
Make isInAir a counter, we want to allow 2 jumps before landing.
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: isUpEventTriggered is not defined' in or related to this line: 'if (game.isMouseDown && isUpEventTriggered) {' Line Number: 179
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ var Bird = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird', { anchorX: 0.5, anchorY: 0.5 }); self.graphics = birdGraphics; self.xSpeed = 10.9375; self.ySpeed = -20; self.gravity = 1; self.lift = -15; self.isInAir = false; self.flap = function () { if (self.isInAir < 2) { self.ySpeed = self.lift * 1.5; self.isInAir += 1; var shadow = game.addChild(new Shadow()); // Add a shadow particle shadow.x = self.x; // Position the shadow at the bird's current position shadow.y = self.y; shadow.scale.x = self.scale.x; // Ensure the shadow graphics scale x matches the cats at the time it's spawned } if (bird.intersects(leftWall)) { bird.xSpeed = 30; // Add positive x speed when bird jumps from the left wall } else if (bird.intersects(rightWall)) { bird.xSpeed = -30; // Add negative x speed when bird jumps from the right wall } }; self.update = function () { if (game.isMouseDown) { self.ySpeed += self.gravity / 3; } else { self.ySpeed += self.gravity; } self.y += self.ySpeed; self.x += self.xSpeed; if (self.y <= 0 || self.y >= 2732) { self.speed = -self.speed; } if (self.xSpeed === 0) { birdGraphics.scale.x = bird.intersects(leftWall) ? -1 : 1; } else { birdGraphics.scale.x = self.xSpeed > 0 ? -1 : 1; } // Bird rotation removed }; }); var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.move = function (speed) { self.y += speed; }; }); var Shadow = Container.expand(function () { var self = Container.call(this); var shadowGraphics = self.attachAsset('bird', { anchorX: 0.5, anchorY: 0.5 }); self.graphics = shadowGraphics; shadowGraphics.tint = 0x280924; // Tint the shadow to bright fuschia shadowGraphics.alpha = 1; // Make the shadow semi-transparent self.fadeOut = function () { // Delay the start of the fade out by 200ms LK.setTimeout(function () { if (shadowGraphics.alpha > 0) { shadowGraphics.alpha -= 0.05; // Gradually decrease the alpha to create a fade out effect } else { self.destroy(); // Destroy the shadow when it's fully transparent } }, 200); }; }); 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: 0x111111 }); /**** * Game Code ****/ 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.setScore(game.score); LK.showGameOver(); } } }; var background = game.addChild(LK.getAsset('background', { anchorX: 0.5, anchorY: 1, x: 1024, y: 2732 })); var scoreText = new Text2('0', { size: 150, fill: '#ffffff', 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 * (2 / 3); 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.isMouseDown = false; game.isUpEventTriggered = true; game.isUpEventTriggered = true; game.on('down', function (obj) { if (game.isUpEventTriggered) { bird.flap(); game.isMouseDown = true; game.isUpEventTriggered = false; } }); game.on('up', function (obj) { game.isMouseDown = false; game.isUpEventTriggered = true; }); LK.on('tick', function () { bird.update(); // Update the shadow particles var shadowCount = 0; for (var i = game.children.length - 1; i >= 0; i--) { if (game.children[i] instanceof Shadow) { game.children[i].fadeOut(); shadowCount++; } // If there are more than 15 shadow particles, remove the oldest one if (shadowCount > 12) { game.children[i].destroy(); } } // Spawn the shadows every few frames, while the cat is in the air if (bird.isInAir && LK.ticks % 4 == 0) { var shadow = game.addChildAt(new Shadow(), game.getChildIndex(bird)); // Add a shadow particle behind the bird shadow.x = bird.x; // Position the shadow at the bird's current position shadow.y = bird.y; shadow.graphics.scale.x = bird.graphics.scale.x; // Ensure the shadow graphics scale x matches the bird at the time it's spawned } if (game.score > 2) { tutorialText.y += 5; tutorialTextWhite.y += 5; } 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.addChild(new Obstacle()); newObstacle.x = -10 + newObstacle.width * 0.5; newObstacle.y = obstacleSpawnY; leftObstacles.push(newObstacle); leftObstacleSpawnTime += Math.floor(Math.random() * obstacleSpawnRandomness) + obstacleSpawnRandomness; } if (LK.ticks >= rightObstacleSpawnTime) { var newObstacle = game.addChild(new Obstacle()); newObstacle.x = 2048 + 10 - newObstacle.width * 0.5; newObstacle.y = -newObstacle.height; newObstacle.scale.x *= -1; // Flip the obstacle horizontally rightObstacles.push(newObstacle); rightObstacleSpawnTime += Math.floor(Math.random() * obstacleSpawnRandomness) + obstacleSpawnRandomness; } if (bird.intersects(leftWall) || bird.intersects(rightWall)) { bird.ySpeed = game.obstacleSpeed; bird.xSpeed = 0; bird.isInAir = 0; } 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.setScore(game.score); LK.showGameOver(); } else if (bird.ySpeed < 0) { game.score += Math.floor(Math.abs(bird.ySpeed) / 10); } });
===================================================================
--- original.js
+++ change.js
@@ -6,8 +6,9 @@
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
+ self.graphics = birdGraphics;
self.xSpeed = 10.9375;
self.ySpeed = -20;
self.gravity = 1;
self.lift = -15;
@@ -48,10 +49,10 @@
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
- anchorX: 0,
- anchorY: 0
+ anchorX: 0.5,
+ anchorY: 0.5
});
self.speed = 5;
self.move = function (speed) {
self.y += speed;
@@ -62,9 +63,10 @@
var shadowGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
- shadowGraphics.tint = 0xFF00FF; // Tint the shadow to bright fuschia
+ self.graphics = shadowGraphics;
+ shadowGraphics.tint = 0x280924; // Tint the shadow to bright fuschia
shadowGraphics.alpha = 1; // Make the shadow semi-transparent
self.fadeOut = function () {
// Delay the start of the fade out by 200ms
LK.setTimeout(function () {
@@ -183,9 +185,9 @@
if (bird.isInAir && LK.ticks % 4 == 0) {
var shadow = game.addChildAt(new Shadow(), game.getChildIndex(bird)); // Add a shadow particle behind the bird
shadow.x = bird.x; // Position the shadow at the bird's current position
shadow.y = bird.y;
- shadow.scale.x = bird.birdGraphics.scale.x; // Ensure the shadow graphics scale x matches the bird at the time it's spawned
+ shadow.graphics.scale.x = bird.graphics.scale.x; // Ensure the shadow graphics scale x matches the bird at the time it's spawned
}
if (game.score > 2) {
tutorialText.y += 5;
tutorialTextWhite.y += 5;
@@ -198,16 +200,16 @@
obstacleSpawnRandomness = 20;
}
if (LK.ticks >= leftObstacleSpawnTime) {
var newObstacle = game.addChild(new Obstacle());
- newObstacle.x = 0;
+ newObstacle.x = -10 + newObstacle.width * 0.5;
newObstacle.y = obstacleSpawnY;
leftObstacles.push(newObstacle);
leftObstacleSpawnTime += Math.floor(Math.random() * obstacleSpawnRandomness) + obstacleSpawnRandomness;
}
if (LK.ticks >= rightObstacleSpawnTime) {
var newObstacle = game.addChild(new Obstacle());
- newObstacle.x = 2048;
+ newObstacle.x = 2048 + 10 - newObstacle.width * 0.5;
newObstacle.y = -newObstacle.height;
newObstacle.scale.x *= -1; // Flip the obstacle horizontally
rightObstacles.push(newObstacle);
rightObstacleSpawnTime += Math.floor(Math.random() * obstacleSpawnRandomness) + obstacleSpawnRandomness;
@@ -235,6 +237,8 @@
game.checkObstacleCollision(rightObstacles);
if (bird.y < 0 || bird.y > 2732) {
LK.setScore(game.score);
LK.showGameOver();
+ } else if (bird.ySpeed < 0) {
+ game.score += Math.floor(Math.abs(bird.ySpeed) / 10);
}
});
\ No newline at end of file