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
===================================================================
--- original.js
+++ change.js
@@ -1,71 +1,72 @@
-/****
+/****
* 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 = -15;
- 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;
- }
- }
- };
+ 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 = -15;
+ 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);
- self.speed = 3;
- self.move = function () {
- self.x -= self.speed;
- if (self.x < -obstacleGraphics.width) {
- self.destroy();
- }
- };
+ var self = Container.call(this);
+ var obstacleGraphics = self.createAsset('obstacle', 'Obstacle', 0.5, 1);
+ obstacleGraphics.scale.set(0.8);
+ self.speed = 3;
+ self.move = function () {
+ self.x -= self.speed;
+ if (self.x < -obstacleGraphics.width) {
+ self.destroy();
+ }
+ };
});
-/****
+/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+/****
* Game Code
****/
// Initialize player
var player = game.addChild(new Player());
@@ -74,37 +75,37 @@
// 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])) {
- LK.effects.flashScreen(0xff0000, 500);
- LK.showGameOver();
- }
- }
- // Spawn obstacles
- if (LK.ticks % 120 === 0) {
- var obstacle = new Obstacle();
- obstacle.x = game.width;
- obstacle.y = game.height - 100;
- obstacles.push(obstacle);
- game.addChild(obstacle);
- }
+ 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])) {
+ LK.effects.flashScreen(0xff0000, 500);
+ LK.showGameOver();
+ }
+ }
+ // Spawn obstacles
+ if (LK.ticks % 120 === 0) {
+ var obstacle = new Obstacle();
+ obstacle.x = game.width;
+ obstacle.y = game.height - 100;
+ obstacles.push(obstacle);
+ game.addChild(obstacle);
+ }
});
// Touch event listeners
game.on('down', function (obj) {
- player.jump();
+ player.jump();
});
game.on('move', function (obj) {
- var pos = obj.event.getLocalPosition(game);
- if (pos.x > game.width / 2) {
- player.dash();
- } else {
- player.flip();
- }
+ 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
+ // Up event not used in this game
});
\ No newline at end of file