User prompt
also add blocks they hurt you but if you jump on them they do nothing
User prompt
when you lose reset speed to normal
User prompt
every 25 secounds make obsticle get 10 times faster
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'addEventListener')' in this line: 'document.addEventListener('keydown', function (event) {' Line Number: 106
User prompt
if you press any hotkey make the player jump
User prompt
after you get 8 secounds into the game make the obsticles get faster everyeight seccounds
User prompt
make player jump a little farther
User prompt
spread obsitcles apart
User prompt
make hero jump a little higher
User prompt
make obsticle a little smaller
Initial prompt
geometry dash Z
/**** * Classes ****/ // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.createAsset('player', 'Player character', 0.5, 1); self.speed = 5; self.isJumping = false; self.isFlipping = false; self.isDashing = false; self.jumpHeight = -22; self.gravity = 0.5; self.velocityY = 0; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.velocityY = self.jumpHeight; } }; self.flip = function () { if (self.isJumping && !self.isFlipping) { self.isFlipping = true; playerGraphics.rotation += Math.PI; } }; self.dash = function () { if (self.isJumping && !self.isDashing) { self.isDashing = true; self.x += 50; } }; self.update = function () { if (self.isJumping) { self.y += self.velocityY; self.velocityY += self.gravity; if (self.y > game.height - playerGraphics.height) { self.y = game.height - playerGraphics.height; self.isJumping = false; self.isFlipping = false; self.isDashing = false; playerGraphics.rotation = 0; } } }; }); // Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.createAsset('obstacle', 'Obstacle', 0.5, 1); obstacleGraphics.scale.set(0.8); self.speed = Obstacle.baseSpeed; self.move = function () { self.x -= self.speed; if (self.x < -obstacleGraphics.width) { self.destroy(); } }; }); // Block class var Block = Container.expand(function () { var self = Container.call(this); var blockGraphics = self.createAsset('block', 'Harmful block', 0.5, 1); blockGraphics.scale.set(0.8); self.speed = Obstacle.baseSpeed; self.move = function () { self.x -= self.speed; if (self.x < -blockGraphics.width) { self.destroy(); } }; self.isHarmful = function () { // Check if the player's bottom is above the top of the block, which means the player is jumping on it var playerBottom = player.y + player.height; var blockTop = self.y - blockGraphics.height / 2; return playerBottom < blockTop; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize player Obstacle.baseSpeed = 3; Obstacle.increaseSpeed = function () { Obstacle.baseSpeed += 1; }; var player = game.addChild(new Player()); player.x = game.width / 4; player.y = game.height - 150; // Initialize obstacles array var obstacles = []; // Game tick event LK.on('tick', function () { player.update(); // Move each obstacle and check for collisions for (var i = obstacles.length - 1; i >= 0; i--) { obstacles[i].move(); if (player.intersects(obstacles[i]) && !(obstacles[i] instanceof Block && !obstacles[i].isHarmful())) { LK.effects.flashScreen(0xff0000, 500); LK.showGameOver(); } } // Increase obstacle speed every 25 seconds and make it 10 times faster if (LK.ticks % 1500 === 0) { Obstacle.baseSpeed = 3; } // Spawn obstacles and blocks if (LK.ticks % 180 === 0) { var obstacleType = Math.random() < 0.5 ? Obstacle : Block; var obstacle = new obstacleType(); obstacle.x = game.width; obstacle.y = game.height - 100; obstacles.push(obstacle); game.addChild(obstacle); } }); // Keyboard event listener to make the player jump game.on('down', function (obj) { player.jump(); }); game.on('move', function (obj) { var pos = obj.event.getLocalPosition(game); if (pos.x > game.width / 2) { player.dash(); } else { player.flip(); } }); game.on('up', function (obj) { // Up event not used in this game });
===================================================================
--- original.js
+++ change.js
@@ -56,8 +56,27 @@
self.destroy();
}
};
});
+// Block class
+var Block = Container.expand(function () {
+ var self = Container.call(this);
+ var blockGraphics = self.createAsset('block', 'Harmful block', 0.5, 1);
+ blockGraphics.scale.set(0.8);
+ self.speed = Obstacle.baseSpeed;
+ self.move = function () {
+ self.x -= self.speed;
+ if (self.x < -blockGraphics.width) {
+ self.destroy();
+ }
+ };
+ self.isHarmful = function () {
+ // Check if the player's bottom is above the top of the block, which means the player is jumping on it
+ var playerBottom = player.y + player.height;
+ var blockTop = self.y - blockGraphics.height / 2;
+ return playerBottom < blockTop;
+ };
+});
/****
* Initialize Game
****/
@@ -83,20 +102,21 @@
player.update();
// Move each obstacle and check for collisions
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].move();
- if (player.intersects(obstacles[i])) {
+ if (player.intersects(obstacles[i]) && !(obstacles[i] instanceof Block && !obstacles[i].isHarmful())) {
LK.effects.flashScreen(0xff0000, 500);
LK.showGameOver();
}
}
// Increase obstacle speed every 25 seconds and make it 10 times faster
if (LK.ticks % 1500 === 0) {
Obstacle.baseSpeed = 3;
}
- // Spawn obstacles
+ // Spawn obstacles and blocks
if (LK.ticks % 180 === 0) {
- var obstacle = new Obstacle();
+ var obstacleType = Math.random() < 0.5 ? Obstacle : Block;
+ var obstacle = new obstacleType();
obstacle.x = game.width;
obstacle.y = game.height - 100;
obstacles.push(obstacle);
game.addChild(obstacle);