User prompt
add more obstacles as score increases
Code edit (3 edits merged)
Please save this source code
User prompt
decresase obstacle speed in half
Code edit (7 edits merged)
Please save this source code
User prompt
add increaase and decrease size animation to star
User prompt
when dot is destroyed bounce should be disabled
User prompt
change dot particle effect to be a circular explosion where all the dots have the same distance between each other and the same speed
Code edit (1 edits merged)
Please save this source code
User prompt
dot partcicles should take 1 whole second to dissapear
User prompt
After the player has 6 points, start adding 100 pixles more for the next star y spawn position. This will be cumulative
Code edit (2 edits merged)
Please save this source code
User prompt
When obstacles are 2000 y offscreen destrpy them to increease performance
User prompt
When a obstacle is created, draw a dotted line of the onstacles orbit
User prompt
Add a very small dotted line marking the orbit of each new obstacle
User prompt
Fix Bug: 'TypeError: obstacles[i].move is not a function' in or related to this line: 'obstacles[i].move();' Line Number: 235
User prompt
When a star is destoyed show a text for 1 second where the star was that says "+1"
User prompt
When star is destroyed show a +1 message where the star was
User prompt
To display the "+1" text properly, the `ScorePopup` class should instantiate a `Text2` object and then add it to the container using the `addChild` method, which is the standard way to add display objects to containers in many game engines, including LK.
Code edit (1 edits merged)
Please save this source code
User prompt
Center scorepop with star considering anchors
Code edit (2 edits merged)
Please save this source code
User prompt
reduce obtacle speed in 30%
User prompt
add effect to scoretxt when it updates
User prompt
add transition effect for scoretxt when its updated
User prompt
when transition effect is done to scoretxt make sure scoretxt always keeps the original y position
/****
* Classes
****/
var ParticleEffect = Container.expand(function (x, y) {
var self = Container.call(this);
self.x = x;
self.y = y;
var particles = [];
for (var i = 0; i < 20; i++) {
var particle = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5
});
particle.scaleX = particle.scaleY = Math.random() * 0.5 + 0.5;
particle.alpha = 0.7;
particle.vx = (Math.random() - 0.5) * 10;
particle.vy = (Math.random() - 0.5) * 10;
particles.push(particle);
}
self.update = function () {
for (var i = particles.length - 1; i >= 0; i--) {
particles[i].x += particles[i].vx;
particles[i].y += particles[i].vy;
particles[i].alpha -= 0.02;
if (particles[i].alpha <= 0) {
particles[i].destroy();
particles.splice(i, 1);
}
}
if (particles.length === 0) {
self.destroy();
}
};
game.addChild(self);
});
var DotParticleEffect = Container.expand(function (x, y) {
var self = Container.call(this);
self.x = x;
self.y = y;
var particles = [];
for (var i = 0; i < 20; i++) {
var particle = self.attachAsset('dot', {
anchorX: 0.5,
anchorY: 0.5
});
particle.scaleX = particle.scaleY = Math.random() * 0.5 + 0.5;
particle.alpha = 1;
particle.vx = (Math.random() - 0.5) * 20;
particle.vy = (Math.random() - 0.5) * 20;
particles.push(particle);
}
self.update = function () {
for (var i = particles.length - 1; i >= 0; i--) {
particles[i].x += particles[i].vx;
particles[i].y += particles[i].vy;
particles[i].alpha -= 0.05;
if (particles[i].alpha <= 0) {
particles[i].destroy();
particles.splice(i, 1);
}
}
if (particles.length === 0) {
self.destroy();
}
};
game.addChild(self);
});
var Dot = Container.expand(function () {
var self = Container.call(this);
var dotGraphics = self.attachAsset('dot', {
anchorX: 0.5,
anchorY: 0.5
});
self.destroyed = false;
self.velocityY = 0;
self.gravity = 0.5 + LK.getScore() * 0.01;
self.bounce = -15 - LK.getScore() * 0.2;
self.update = function () {
var previousY = self.y;
self.velocityY += self.gravity;
self.y += self.velocityY;
if (self.y > 2732 - self.height / 2) {
self.velocityY = self.bounce;
}
self.movedDistance = self.y - previousY;
};
self.bounceUp = function () {
self.velocityY = self.bounce;
};
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = Math.random() < 0.5 ? -1 : 1;
self.speed = (Math.random() * 3 + 5 + LK.getScore() * 0.1) * self.direction;
self.rotationSpeed = 0.05 + LK.getScore() * 0.001;
self.rotation = 0;
self.move = function () {
self.x += self.speed;
self.rotation += self.rotationSpeed;
obstacleGraphics.rotation = self.rotation;
if (self.direction === 1 && self.x > 2048 + self.width / 2 || self.direction === -1 && self.x < -self.width / 2) {
self.direction *= -1;
self.speed *= -1;
self.y = Math.random() * (2732 - self.height) + self.height / 2;
}
};
self.moveDown = function (distance) {
self.y += distance;
if (self.y > 2732 - self.height / 2) {
self.y = -self.height / 2;
}
};
});
var Star = Container.expand(function () {
var self = Container.call(this);
var starGraphics = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5
});
self.moveDown = function (distance) {
self.y += distance;
if (self.y > 2732 - self.height / 2) {
self.y = -self.height / 2;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
function createParticleEffect(x, y) {
var effect = new ParticleEffect(x, y);
LK.on('tick', function () {
effect.update();
});
}
function createDotParticleEffect(x, y) {
var effect = new DotParticleEffect(x, y);
LK.on('tick', function () {
effect.update();
});
}
var dot = game.addChild(new Dot());
dot.x = 2048 / 2;
dot.y = 2732 - dot.height / 2;
var obstacles = [];
function updateObstacles() {
var obstacleCount = 5 + Math.floor(LK.getScore() / 10);
while (obstacles.length < obstacleCount) {
var obstacle = game.addChild(new Obstacle());
obstacle.x = obstacle.direction === 1 ? -obstacle.width / 2 : 2048 + obstacle.width / 2;
obstacle.y = Math.random() * (2732 - obstacle.height) + obstacle.height / 2;
obstacles.push(obstacle);
}
}
updateObstacles();
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.x = 500;
LK.gui.top.addChild(scoreTxt);
LK.gui.top.addChild(scoreTxt);
game.on('down', function (obj) {
if (dot) {
dot.bounceUp();
}
});
var stars = [];
var star = game.addChild(new Star());
star.x = 2048 / 2;
star.y = 2732 / 2;
stars.push(star);
LK.on('tick', function () {
dot.update();
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].move();
if (dot.y < 1800 && dot.movedDistance < 0) {
obstacles[i].moveDown(-dot.movedDistance);
}
if (dot.intersects(obstacles[i])) {
if (!dot.destroyed) {
createDotParticleEffect(dot.x, dot.y);
dot.destroyed = true;
}
dot.destroy();
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
}
}
for (var j = stars.length - 1; j >= 0; j--) {
if (dot.intersects(stars[j])) {
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore().toString());
var oldStarY = stars[j].y;
createParticleEffect(stars[j].x, stars[j].y);
stars[j].destroy();
stars.splice(j, 1);
var newStar = game.addChild(new Star());
newStar.x = 2048 / 2;
newStar.y = oldStarY - 1500;
stars.push(newStar);
} else if (dot.y < 1800 && dot.movedDistance < 0) {
stars[j].moveDown(-dot.movedDistance);
}
}
});