User prompt
Create a new class for StartParticles. This new class will be used to show particles explode in a circular way when a star is destpryes
User prompt
Stars should increase and decrease their size constantly
User prompt
Start should increase and decrease their size
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'y')' in or related to this line: 'newStar.y = stars[j].y - 1000;' Line Number: 139
User prompt
When a star is destroyed a new one should appear 1000 pixels higher. Should be in the center of the x axis
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'y')' in or related to this line: 'newStar.y = stars[j].y - 2000;' Line Number: 139
User prompt
When a star is destroyed a new one should appear 2000 pixels higher
User prompt
On game start dor should be on the bottom.of the screen
User prompt
Spawn on 1 start on game start in the center of the screen
User prompt
Stars y position should update in relation to dot like obstacles do
User prompt
Stars should spawn in the center of x
User prompt
Add stars class. When dot intersects with star, add 1 point and destroy star
User prompt
Obstacles should rotate on their axis
User prompt
create a new shapedobstacle that will have the same behaviour as obstacles with dot. shapedobstcale will be a shape made of many small assets.
User prompt
make sure bigobstacle has not collision points in the black and transparent area
User prompt
add multiple colission points on the big obstacle to delimit the image boundries.
User prompt
if dot is over transparent obstacle then no game over
User prompt
while dot is in on top of black background there is no game ove
User prompt
Fix Bug: 'TypeError: dot.intersectsPixelPerfect is not a function' in or related to this line: 'if (dot.intersectsPixelPerfect(obstacles[i])) {' Line Number: 113
User prompt
dot intersection with obstacles should be based on pixels and not asset area
User prompt
Fix Bug: 'TypeError: dot.intersectsPixel is not a function' in or related to this line: 'if (obstacles[i] instanceof BigObstacle && dot.intersectsPixel(obstacles[i])) {' Line Number: 113
User prompt
dot interection with big obstacle should be based on pixels and not on asset surface
User prompt
Fix Bug: 'TypeError: dot.intersectsPixel is not a function' in or related to this line: 'if (obstacles[i] instanceof BigObstacle ? dot.intersectsPixel(obstacles[i]) : dot.intersects(obstacles[i])) {' Line Number: 113
User prompt
dot interection with big obstacle should be based on pixels and not on asset surface
/**** * Classes ****/ var StarParticles = Container.expand(function () { var self = Container.call(this); self.particles = []; for (var i = 0; i < 100; i++) { var particle = self.attachAsset('dot', { anchorX: 0.5, anchorY: 0.5 }); particle.x = 0; particle.y = 0; var angle = Math.random() * Math.PI * 2; var speed = Math.random() * 5 + 2; particle.velocityX = Math.cos(angle) * speed; particle.velocityY = Math.sin(angle) * speed; self.particles.push(particle); } self.update = function () { for (var i = 0; i < self.particles.length; i++) { var particle = self.particles[i]; particle.x += particle.velocityX; particle.y += particle.velocityY; particle.alpha -= 0.01; if (particle.alpha <= 0) { self.removeChild(particle); self.particles.splice(i, 1); i--; } } if (self.particles.length === 0) { self.destroy(); } }; }); var Dot = Container.expand(function () { var self = Container.call(this); var dotGraphics = self.attachAsset('dot', { anchorX: 0.5, anchorY: 0.5 }); self.velocityY = 0; self.gravity = 0.5; self.bounce = -15; 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) * self.direction; self.rotationSpeed = 0.05; 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 ****/ var dot = game.addChild(new Dot()); dot.x = 2048 / 2; dot.y = 2732 - dot.height / 2; var obstacles = []; for (var i = 0; i < 5; i++) { var obstacle = game.addChild(new Obstacle()); obstacle.x = obstacle.direction === 1 ? -obstacle.width / 2 : 2048 + obstacle.width / 2; obstacle.y = Math.random() * (1366 - obstacle.height) + obstacle.height / 2; obstacles.push(obstacle); } var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); scoreTxt.x = 2048 / 2; scoreTxt.y = 50; LK.gui.top.addChild(scoreTxt); game.on('down', function (obj) { dot.bounceUp(); }); LK.on('tick', function () { dot.update(); for (var i = 0; i < obstacles.length; i++) { obstacles[i].move(); if (dot.y < 1200 && dot.movedDistance < 0) { // If the dot moved up and its y position is less than 1400 obstacles[i].moveDown(-dot.movedDistance); } if (dot.intersects(obstacles[i])) { LK.showGameOver(); } } // Update score based on the dot's survival time var currentScore = Math.floor(LK.ticks / 60); LK.setScore(currentScore); scoreTxt.setText(LK.getScore().toString()); }); 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 < 1200 && dot.movedDistance < 0) { obstacles[i].moveDown(-dot.movedDistance); } if (dot.intersects(obstacles[i])) { LK.showGameOver(); } } 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; 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 < 1200 && dot.movedDistance < 0) { stars[j].moveDown(-dot.movedDistance); } } var currentScore = Math.floor(LK.ticks / 60); LK.setScore(currentScore); scoreTxt.setText(LK.getScore().toString()); });
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,40 @@
/****
* Classes
****/
+var StarParticles = Container.expand(function () {
+ var self = Container.call(this);
+ self.particles = [];
+ for (var i = 0; i < 100; i++) {
+ var particle = self.attachAsset('dot', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ particle.x = 0;
+ particle.y = 0;
+ var angle = Math.random() * Math.PI * 2;
+ var speed = Math.random() * 5 + 2;
+ particle.velocityX = Math.cos(angle) * speed;
+ particle.velocityY = Math.sin(angle) * speed;
+ self.particles.push(particle);
+ }
+ self.update = function () {
+ for (var i = 0; i < self.particles.length; i++) {
+ var particle = self.particles[i];
+ particle.x += particle.velocityX;
+ particle.y += particle.velocityY;
+ particle.alpha -= 0.01;
+ if (particle.alpha <= 0) {
+ self.removeChild(particle);
+ self.particles.splice(i, 1);
+ i--;
+ }
+ }
+ if (self.particles.length === 0) {
+ self.destroy();
+ }
+ };
+});
var Dot = Container.expand(function () {
var self = Container.call(this);
var dotGraphics = self.attachAsset('dot', {
anchorX: 0.5,
@@ -55,23 +88,14 @@
var starGraphics = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5
});
- self.scale = 1;
- self.scaleDirection = 1;
self.moveDown = function (distance) {
self.y += distance;
if (self.y > 2732 - self.height / 2) {
self.y = -self.height / 2;
}
};
- self.update = function () {
- self.scale += 0.01 * self.scaleDirection;
- if (self.scale > 1.2 || self.scale < 0.8) {
- self.scaleDirection *= -1;
- }
- starGraphics.scale.set(self.scale);
- };
});
/****
* Initialize Game
@@ -137,9 +161,8 @@
LK.showGameOver();
}
}
for (var j = stars.length - 1; j >= 0; j--) {
- stars[j].update();
if (dot.intersects(stars[j])) {
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore().toString());
var oldStarY = stars[j].y;