User prompt
Has que la nave esté un poco más alante y has que cada 15 segundos los obstáculos caigan 5% más rápido y cada 50 puntos has q la nave aumente un poco más su velocidad
Code edit (1 edits merged)
Please save this source code
User prompt
Space Dodger
Initial prompt
Quiero hacer un juego el cual cuyo propósito sea q una nave espacial viaje en linea recta sin detenerse mientras van apareciendo meteoritos y basura espacial que debe ir esquivando has una barra en la parte inferior de la pantalla donde de manera táctil se pueda mover de izquierda a derecha para dirigir la nave
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Debris = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('debris', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.lastY = undefined;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Meteorite = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('meteorite', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4;
self.lastY = undefined;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Spaceship = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('spaceship', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var TouchSlider = Container.expand(function () {
var self = Container.call(this);
var sliderBar = self.attachAsset('sliderBar', {
anchorX: 0.5,
anchorY: 0.5
});
var sliderHandle = self.addChild(LK.getAsset('sliderHandle', {
anchorX: 0.5,
anchorY: 0.5
}));
self.minX = -180;
self.maxX = 180;
self.isDragging = false;
self.down = function (x, y, obj) {
self.isDragging = true;
self.updateHandle(x);
};
self.up = function (x, y, obj) {
self.isDragging = false;
};
self.updateHandle = function (x) {
var localX = x - self.x;
localX = Math.max(self.minX, Math.min(self.maxX, localX));
sliderHandle.x = localX;
};
self.getSliderValue = function () {
return sliderHandle.x / 180;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000011
});
/****
* Game Code
****/
var spaceship = game.addChild(new Spaceship());
spaceship.x = 2048 / 2;
spaceship.y = 2000;
var obstacles = [];
var obstacleSpawnTimer = 0;
var obstacleSpawnRate = 90;
var gameSpeed = 1;
var spaceshipSpeed = 1;
var survivalTime = 0;
var difficultyTimer = 0;
var lastScoreCheck = 0;
var slider = game.addChild(new TouchSlider());
slider.x = 2048 / 2;
slider.y = 2600;
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var timeTxt = new Text2('Time: 0s', {
size: 60,
fill: 0xFFFFFF
});
timeTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(timeTxt);
timeTxt.x = -20;
timeTxt.y = 100;
game.move = function (x, y, obj) {
if (slider.isDragging) {
slider.updateHandle(x);
var sliderValue = slider.getSliderValue();
spaceship.x = 2048 / 2 + sliderValue * 800 * spaceshipSpeed;
spaceship.x = Math.max(100, Math.min(1948, spaceship.x));
}
};
game.update = function () {
survivalTime++;
difficultyTimer++;
if (survivalTime % 60 === 0) {
var seconds = Math.floor(survivalTime / 60);
timeTxt.setText('Time: ' + seconds + 's');
}
// Every 15 seconds (900 ticks), increase obstacle speed by 5%
if (difficultyTimer >= 900) {
difficultyTimer = 0;
gameSpeed *= 1.05;
obstacleSpawnRate = Math.max(30, obstacleSpawnRate - 5);
}
// Every 50 points, increase spaceship speed slightly
var currentScore = LK.getScore();
if (Math.floor(currentScore / 50) > Math.floor(lastScoreCheck / 50)) {
spaceshipSpeed += 0.1;
}
lastScoreCheck = currentScore;
obstacleSpawnTimer++;
if (obstacleSpawnTimer >= obstacleSpawnRate) {
obstacleSpawnTimer = 0;
var obstacle;
if (Math.random() < 0.7) {
obstacle = new Meteorite();
} else {
obstacle = new Debris();
}
obstacle.x = Math.random() * 1800 + 124;
obstacle.y = -100;
obstacle.speed *= gameSpeed;
obstacle.lastY = obstacle.y;
obstacles.push(obstacle);
game.addChild(obstacle);
}
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
if (obstacle.lastY < 2800 && obstacle.y >= 2800) {
LK.setScore(LK.getScore() + 10);
scoreTxt.setText(LK.getScore());
}
if (obstacle.y > 2800) {
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
if (spaceship.intersects(obstacle)) {
LK.getSound('destroy').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
obstacle.lastY = obstacle.y;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -82,15 +82,17 @@
* Game Code
****/
var spaceship = game.addChild(new Spaceship());
spaceship.x = 2048 / 2;
-spaceship.y = 2300;
+spaceship.y = 2000;
var obstacles = [];
var obstacleSpawnTimer = 0;
var obstacleSpawnRate = 90;
var gameSpeed = 1;
+var spaceshipSpeed = 1;
var survivalTime = 0;
var difficultyTimer = 0;
+var lastScoreCheck = 0;
var slider = game.addChild(new TouchSlider());
slider.x = 2048 / 2;
slider.y = 2600;
var scoreTxt = new Text2('0', {
@@ -110,9 +112,9 @@
game.move = function (x, y, obj) {
if (slider.isDragging) {
slider.updateHandle(x);
var sliderValue = slider.getSliderValue();
- spaceship.x = 2048 / 2 + sliderValue * 800;
+ spaceship.x = 2048 / 2 + sliderValue * 800 * spaceshipSpeed;
spaceship.x = Math.max(100, Math.min(1948, spaceship.x));
}
};
game.update = function () {
@@ -121,13 +123,20 @@
if (survivalTime % 60 === 0) {
var seconds = Math.floor(survivalTime / 60);
timeTxt.setText('Time: ' + seconds + 's');
}
- if (difficultyTimer >= 600) {
+ // Every 15 seconds (900 ticks), increase obstacle speed by 5%
+ if (difficultyTimer >= 900) {
difficultyTimer = 0;
+ gameSpeed *= 1.05;
obstacleSpawnRate = Math.max(30, obstacleSpawnRate - 5);
- gameSpeed = Math.min(2, gameSpeed + 0.1);
}
+ // Every 50 points, increase spaceship speed slightly
+ var currentScore = LK.getScore();
+ if (Math.floor(currentScore / 50) > Math.floor(lastScoreCheck / 50)) {
+ spaceshipSpeed += 0.1;
+ }
+ lastScoreCheck = currentScore;
obstacleSpawnTimer++;
if (obstacleSpawnTimer >= obstacleSpawnRate) {
obstacleSpawnTimer = 0;
var obstacle;