User prompt
Obstacles should spawn forming a stair
User prompt
When dot collides with obstacle just stop dot in that position
User prompt
Obstacles reposition shoild always be 1000 y pixels from the previous and next obstacle
User prompt
Obstacles should have 1000 pixela y of separation amongst each other
User prompt
Dot should spawn in y = 1800
User prompt
Firs obstacle y shoild be 1400
User prompt
Remove random y from obstacle initial position
User prompt
Obstacles y will always be less than 1400
User prompt
Obstacle y will be 1000 time more than the rpevious obstacle
User prompt
When a obstacle is repositioned it should be 1000 pixela y from the previous one
Code edit (3 edits merged)
Please save this source code
User prompt
Obstacles always have to be 1000 y pixels away from each other
User prompt
Obstacles should be 1000 pixels in y appart from each other
Code edit (1 edits merged)
Please save this source code
User prompt
Obstacles should only start moving downwards when dot's y is less than 1000
User prompt
When dot passes the center of the screen, obstacles should move downwards the same distance dot is moving upwarda
Initial prompt
Dot Bounce
/**** * Classes ****/ 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 () { self.velocityY += self.gravity; self.y += self.velocityY; if (self.y > 2732 - self.height / 2) { self.velocityY = self.bounce; } }; 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.speed = -5; self.move = function (offsetY) { self.x += self.speed; if (self.x < -self.width / 2) { self.x = 2048 + self.width / 2; var lastObstacleY = obstacles.length > 0 ? obstacles[obstacles.length - 1].y : 0; self.y = lastObstacleY + 1000; if (self.y > 2732 - self.height / 2) { self.y = self.height / 2; } } if (offsetY) { self.y += offsetY; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ 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 = Math.random() * (2732 - 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 () { var previousY = dot.y; dot.update(); var offsetY = previousY - dot.y; for (var i = 0; i < obstacles.length; i++) { obstacles[i].move(dot.y < 1400 && offsetY > 0 ? offsetY : 0); if (dot.intersects(obstacles[i])) { LK.effects.flashScreen(0xff0000, 1000); 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()); });
===================================================================
--- original.js
+++ change.js
@@ -31,9 +31,13 @@
self.move = function (offsetY) {
self.x += self.speed;
if (self.x < -self.width / 2) {
self.x = 2048 + self.width / 2;
- self.y = Math.random() * (2732 - self.height) + self.height / 2;
+ var lastObstacleY = obstacles.length > 0 ? obstacles[obstacles.length - 1].y : 0;
+ self.y = lastObstacleY + 1000;
+ if (self.y > 2732 - self.height / 2) {
+ self.y = self.height / 2;
+ }
}
if (offsetY) {
self.y += offsetY;
}