Initial prompt
Dot Bounce
User prompt
When dot passes the center of the screen, obstacles should move downwards the same distance dot is moving upwarda
User prompt
Obstacles should only start moving downwards when dot's y is less than 1000
Code edit (3 edits merged)
Please save this source code
User prompt
Obstacles should be 1000 pixels in y appart from each other
User prompt
Obstacles always have to be 1000 y pixels away from each other
Code edit (1 edits merged)
Please save this source code
User prompt
When a obstacle is repositioned it should be 1000 pixela y from the previous one
User prompt
Obstacle y will be 1000 time more than the rpevious obstacle
User prompt
Obstacles y will always be less than 1400
User prompt
Remove random y from obstacle initial position
User prompt
Firs obstacle y shoild be 1400
User prompt
Dot should spawn in y = 1800
User prompt
Obstacles should have 1000 pixela y of separation amongst each other
User prompt
Obstacles reposition shoild always be 1000 y pixels from the previous and next obstacle
User prompt
When dot collides with obstacle just stop dot in that position
User prompt
Obstacles should spawn forming a stair
User prompt
First obstacle should spawn in y = 2800
Code edit (2 edits merged)
Please save this source code
User prompt
First obstacle should spawn in the bottom of the screen and next ones should always have a stair patter even when repositioned
User prompt
Obstacles shouls spawn one at a time
User prompt
If ball interects with top of a obstacle is should roll on top of it
Code edit (1 edits merged)
Please save this source code
User prompt
Obstacles should spawn and be repositioned always over y = 1400
User prompt
Dot should spawn at y = 2000
===================================================================
--- original.js
+++ change.js
@@ -31,13 +31,14 @@
self.move = function (offsetY) {
self.x += self.speed;
if (self.x < -self.width / 2) {
self.x = 2048 + self.width / 2;
- if (self === obstacles[0]) {
- self.y = 2732 - self.height / 2;
- } else {
- var previousObstacleIndex = obstacles.indexOf(self) - 1;
- self.y = obstacles[previousObstacleIndex].y - self.height - 100; // 100 is the gap between obstacles
+ self.y = Math.random() * (2732 - self.height) + self.height / 2;
+ if (obstacles.indexOf(self) === obstacles.length - 1) {
+ var newObstacle = game.addChild(new Obstacle());
+ newObstacle.x = 2048 + self.width / 2;
+ newObstacle.y = Math.random() * (2732 - newObstacle.height) + newObstacle.height / 2;
+ obstacles.push(newObstacle);
}
}
if (offsetY) {
self.y += offsetY;
@@ -58,14 +59,12 @@
var dot = game.addChild(new Dot());
dot.x = 2048 / 2;
dot.y = 2732 / 2;
var obstacles = [];
-for (var i = 0; i < 5; i++) {
- var obstacle = game.addChild(new Obstacle());
- obstacle.x = 2048 / 2 + i * 450;
- obstacle.y = i === 0 ? 2732 - obstacle.height / 2 : Math.random() * (2732 - obstacle.height) + obstacle.height / 2;
- obstacles.push(obstacle);
-}
+var obstacle = game.addChild(new Obstacle());
+obstacle.x = 2048 / 2;
+obstacle.y = 2732 - obstacle.height / 2;
+obstacles.push(obstacle);
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});