User prompt
star should have the same y moments downwards like the obstacles
User prompt
dot should spawn in the bottom of the screen
User prompt
star should spawn in the center of the screen
User prompt
add start asset. stars will spawn in the center of the screen every 2000 pixels y
User prompt
obstacles should have random speed but never slower than the current speed
User prompt
obstacles should spawn randmonly from either side of the screen and moveon the opposite side direction
User prompt
obstacles should only move when dot y is smaller than 1400
User prompt
obstacles should have different widths and different speeds and oscilations randmonly
User prompt
every new spawned or repositioned obstacle should be 1000 pixels higher thanthe higher obstacle
User prompt
obstacles should increse and decrease their width constantly
User prompt
when an obstacle is repositiones it should also have 1000 pixels y distance from others
User prompt
obstacles should have 1000 pixles y from each other as space
Code edit (1 edits merged)
Please save this source code
User prompt
obstacles should only move down when dot y is smaller than 1400. they should always move sideways
User prompt
obstacles should only move when dot y is smaller than 1400
User prompt
when dot moves up on the top part of the screen, the obstacle should move down the same distancethe dot does
User prompt
obstacle vertical speed should increase if dotsspeed incresase
User prompt
when the dot bounces and its bouncing on the top half of thescreen then obstacle should move downwards generating a sense of screen scrolling upwards
User prompt
when the dot reaches the center of the screen, the obstacles should movedownwards
User prompt
when dot reaches 1400 y height, then the obstacles should move downwards generating an effect that the dot is moving up and the obstacles are going down
User prompt
make movement more fluid when obstacles move down
User prompt
when dot reaches center of the screen then obstacles should move downwards generating a sense that the dot is moving upwards and the obstacles are being left begind
User prompt
when dot passes 1400 pixels y platforms should move downwards the same amount of pixelss dot is moving up
User prompt
when dot reaches 1400 pixels platforms should move downwards the same distance dot moves over 1400 pixels.
User prompt
add a new platform every time there are 1000 pixels space between the topmost platform and the top of the screen
/**** * 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 () { 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.move = function () { self.x += self.speed; 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 stars = []; var createStars = function createStars() { var lastStarY = stars.length > 0 ? stars[stars.length - 1].y : 0; if (2732 - lastStarY >= 2000) { var star = game.addChild(new Star()); star.x = 2048 / 2; star.y = 2732 / 2; stars.push(star); } }; 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() * (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 () { createStars(); dot.update(); for (var i = 0; i < obstacles.length; i++) { obstacles[i].move(); if (dot.y < 1800 && dot.movedDistance < 0) { // If the dot moved up and its y position is less than 1800 obstacles[i].moveDown(-dot.movedDistance); stars.forEach(function (star) { star.moveDown(-dot.movedDistance); }); } 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
@@ -51,8 +51,14 @@
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
@@ -100,10 +106,13 @@
dot.update();
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].move();
if (dot.y < 1800 && dot.movedDistance < 0) {
- // If the dot moved up and its y position is less than 1400
+ // If the dot moved up and its y position is less than 1800
obstacles[i].moveDown(-dot.movedDistance);
+ stars.forEach(function (star) {
+ star.moveDown(-dot.movedDistance);
+ });
}
if (dot.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();