Code edit (7 edits merged)
Please save this source code
User prompt
trees should always appear behind player
Code edit (3 edits merged)
Please save this source code
User prompt
spawn trees randomly, base of tree should be above ground level, trees can scale from .5 to 1.5 of normal size
User prompt
trees are closer to the player so should move faster
User prompt
spawn clouds periodically, limit to a max of 3 clouds at any time
User prompt
randomize cloud scaling and placement, limit placement to upper 1/3 of screen, scale up to 2x
User prompt
clouds are further away from the player and should appear to move slower
User prompt
anchor the sky at the top of the screen
User prompt
add a moving background to the game with a sky, trees and clouds
Code edit (1 edits merged)
Please save this source code
User prompt
lower the spawn height of player and enemies by 10
User prompt
the power ups and treasure should be higher in teh sky so the player has to jump up to get them
User prompt
the bullets are still killing multiple enemies, can you fix that
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'destroy')' in or related to this line: 'game.children[j].destroy();' Line Number: 297
User prompt
the bullet should travel 10 times faster
User prompt
bullets kill enemies
Code edit (1 edits merged)
Please save this source code
User prompt
powerup2 gives the player a gun for 10 shots, when pushing the button the player fires a bullet instead of jumping.
User prompt
at the top of the screen an an indicator for each power up that shows how much time remains on them
User prompt
move the power up bar to the top of the screen
User prompt
add a bar at the bottom of the screen to show how much time is left on the power ups
Code edit (1 edits merged)
Please save this source code
User prompt
powerUp3 should make the player immune to death for 3 seconds
User prompt
if the one of the enemies and the player collide on the ground, the player dies, if the player collides with the enemy when he is coming down from a jump the enemy dies
/**** * Classes ****/ // Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 50; self.update = function () { self.x += self.speed; if (self.x > 2048 + 50) { self.destroy(); } }; }); // Clouds class var Clouds = Container.expand(function () { var self = Container.call(this); var cloudsGraphics = self.attachAsset('clouds', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -0.5; self.scale.set(1 + Math.random()); // Randomize scale up to 2x self.y = Math.random() * (2732 / 3); // Limit placement to upper 1/3 of screen self.update = function () { self.x += self.speed; if (self.x < -self.width) { self.x = 2048 + self.width; self.scale.set(1 + Math.random()); // Randomize scale again when repositioned self.y = Math.random() * (2732 / 3); // Randomize y position again when repositioned } }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyType = Math.floor(Math.random() * 3); if (enemyType == 0) { var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; } else if (enemyType == 1) { var enemyGraphics = self.attachAsset('enemy2', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -7; } else { var enemyGraphics = self.attachAsset('enemy3', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -10; } self.update = function () { self.x += self.speed; if (self.x < -50) { self.destroy(); } }; }); //<Assets used in the game will automatically appear here> // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.jumpPower = -20; self.isJumping = false; self.isFalling = false; // Track if the hero is coming down from a jump self.isImmune = false; // Track if the hero is immune self.hasGun = false; // Track if the hero has a gun self.bullets = 0; // Track the number of bullets the hero has self.update = function () { if (self.isJumping) { self.y += self.jumpPower; self.jumpPower += 0.4; // Adjust gravity effect if (self.y >= 2732 * 2 / 3 - self.height) { // Ground level self.y = 2732 * 2 / 3 - self.height; self.isJumping = false; self.isFalling = false; // The hero is no longer falling self.jumpPower = -20; // Adjust jump power } else if (self.jumpPower > 0) { self.isFalling = true; // The hero is falling } } }; self.jump = function () { if (!self.isJumping) { self.isJumping = true; } }; self.makeImmune = function () { self.isImmune = true; LK.setTimeout(function () { self.isImmune = false; }, 3000); // Make the hero immune for 3 seconds }; self.giveGun = function () { self.hasGun = true; self.bullets = 10; }; }); // Pothole class var Pothole = Container.expand(function () { var self = Container.call(this); var potholeGraphics = self.attachAsset('pothole', { anchorX: 0.5, anchorY: 0.5, color: 0x8B4513 // Brown color }); self.update = function () { self.x -= 3; if (self.x < -50) { self.destroy(); } }; }); // PowerUp class var PowerUp = Container.expand(function () { var self = Container.call(this); var powerUpType = Math.floor(Math.random() * 3); if (powerUpType == 0) { var powerUpGraphics = self.attachAsset('powerUp', { anchorX: 0.5, anchorY: 0.5 }); self.value = 50; } else if (powerUpType == 1) { var powerUpGraphics = self.attachAsset('powerUp2', { anchorX: 0.5, anchorY: 0.5 }); self.value = 100; } else { var powerUpGraphics = self.attachAsset('powerUp3', { anchorX: 0.5, anchorY: 0.5 }); self.value = 150; } self.update = function () { self.x -= 5; if (self.x < -50) { self.destroy(); } }; }); // PowerUpTimer class var PowerUpTimer = Container.expand(function () { var self = Container.call(this); var timerBarGraphics = self.attachAsset('timerBar', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { if (self.width > 0) { self.width -= 1; } else { self.destroy(); } }; }); // Sky class var Sky = Container.expand(function () { var self = Container.call(this); var skyGraphics = self.attachAsset('sky', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Sky movement logic (if any) }; }); // Treasure class var Treasure = Container.expand(function () { var self = Container.call(this); var treasureType = Math.floor(Math.random() * 3); if (treasureType == 0) { var treasureGraphics = self.attachAsset('treasure', { anchorX: 0.5, anchorY: 0.5 }); self.value = 10; } else if (treasureType == 1) { var treasureGraphics = self.attachAsset('treasure2', { anchorX: 0.5, anchorY: 0.5 }); self.value = 20; } else { var treasureGraphics = self.attachAsset('treasure3', { anchorX: 0.5, anchorY: 0.5 }); self.value = 30; } self.update = function () { self.x -= 5; if (self.x < -50) { self.destroy(); } }; }); // Trees class var Trees = Container.expand(function () { var self = Container.call(this); var treesGraphics = self.attachAsset('trees', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; self.update = function () { self.x += self.speed; if (self.x < -self.width) { self.x = 2048 + self.width; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ function spawnCloud() { if (game.children.filter(function (child) { return child instanceof Clouds; }).length < 3) { var cloud = new Clouds(); cloud.x = 2048 + cloud.width; game.addChild(cloud); } } var sky = game.addChild(new Sky()); sky.x = 2048 / 2; sky.y = 2732 / 2; var trees = game.addChild(new Trees()); trees.x = 2048 / 2; trees.y = 2732 * 2 / 3; var clouds = game.addChild(new Clouds()); clouds.x = 2048 / 2; clouds.y = 2732 / 4; var ground = game.addChild(LK.getAsset('ground', { x: 0, y: 2732 * 2 / 3 - 120 })); var hero = game.addChild(new Hero()); hero.x = 200; hero.y = 2732 * 2 / 3 - hero.height - 10; var enemies = []; var potholes = []; var treasures = []; var powerUps = []; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var score = 0; function spawnEnemy() { var enemy = new Enemy(); enemy.x = 2048; enemy.y = 2732 * 2 / 3 - enemy.height - 10; enemies.push(enemy); game.addChild(enemy); } function spawnPothole() { var pothole = new Pothole(); pothole.x = 2048; pothole.y = 2732 * 2 / 3 - pothole.height; // Move the potholes up to the grassline potholes.push(pothole); game.addChild(pothole); } function spawnTreasure() { var treasure = new Treasure(); treasure.x = 2048; treasure.y = 2732 * 2 / 3 - treasure.height - 350; // Increase the spawn height of treasures treasures.push(treasure); game.addChild(treasure); } function spawnPowerUp() { var powerUp = new PowerUp(); powerUp.x = 2048; powerUp.y = 2732 * 2 / 3 - powerUp.height - 300; // Increase the spawn height of power-ups powerUps.push(powerUp); game.addChild(powerUp); } game.down = function (x, y, obj) { if (hero.hasGun && hero.bullets > 0) { // Fire a bullet var bullet = new Bullet(); bullet.x = hero.x; bullet.y = hero.y; game.addChild(bullet); hero.bullets--; if (hero.bullets == 0) { hero.hasGun = false; } } else { hero.jump(); } }; game.update = function () { hero.update(); sky.update(); trees.update(); clouds.update(); for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].update(); if (hero.intersects(enemies[i])) { if (hero.isFalling) { // The hero kills the enemy if it is falling enemies[i].destroy(); enemies.splice(i, 1); } else if (!hero.isImmune) { // The hero dies if it is not falling and not immune LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Check for bullet collision with enemies for (var j = game.children.length - 1; j >= 0; j--) { if (game.children[j] instanceof Bullet) { if (enemies[i].intersects(game.children[j])) { // Destroy the enemy and the bullet enemies[i].destroy(); enemies.splice(i, 1); if (game.children[j]) { game.children[j].destroy(); } break; } } break; // Ensure only one enemy is killed per bullet } } for (var i = game.children.length - 1; i >= 0; i--) { if (game.children[i] instanceof Pothole) { game.children[i].update(); if (hero.intersects(game.children[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } } for (var i = treasures.length - 1; i >= 0; i--) { treasures[i].update(); if (hero.intersects(treasures[i])) { score += 10; scoreTxt.setText(score); treasures[i].destroy(); treasures.splice(i, 1); } } for (var i = powerUps.length - 1; i >= 0; i--) { powerUps[i].update(); if (hero.intersects(powerUps[i])) { var powerUpTimer = new PowerUpTimer(); powerUpTimer.x = 2048 * (i + 1) / (powerUps.length + 1); powerUpTimer.y = 50; game.addChild(powerUpTimer); if (powerUps[i].value == 150) { // If the power up is powerUp3, make the hero immune hero.makeImmune(); } else if (powerUps[i].value == 100) { // If the power up is powerUp2, give the hero a gun hero.giveGun(); } else { score += 50; scoreTxt.setText(score); } powerUps[i].destroy(); powerUps.splice(i, 1); } } if (LK.ticks % 60 == 0) { spawnEnemy(); } if (LK.ticks % 120 == 0) { var pothole = new Pothole(); pothole.x = 2048; pothole.y = 2732 - pothole.height; game.addChild(pothole); } if (LK.ticks % 180 == 0) { spawnTreasure(); } if (LK.ticks % 240 == 0) { spawnPowerUp(); } if (LK.ticks % 300 == 0) { spawnCloud(); } };
===================================================================
--- original.js
+++ change.js
@@ -218,9 +218,9 @@
var treesGraphics = self.attachAsset('trees', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = -2;
+ self.speed = -5;
self.update = function () {
self.x += self.speed;
if (self.x < -self.width) {
self.x = 2048 + self.width;
toy gun. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cartoon bullet, sideways, flying right, with empty background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
suit of armour, no background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
gold coin. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cartoon bomb, no shadow, no background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
gold bar. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
treasure chest. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cloud in bright blue sky.
bright blue sky over a grassy meadow.
dark green tree, plain background. Single Game Texture. In-Game asset. 2d. Blank background. No shadows.
a tall thin bunch of grass. Single Game Texture. In-Game asset. 2d. Blank background. No shadows.