User prompt
Fix Bug: 'Uncaught ReferenceError: createMenuPage is not defined' in or related to this line: 'createMenuPage(self, 'Easy', 'easy', '#00ff00');' Line Number: 159
Code edit (1 edits merged)
Please save this source code
User prompt
make text (on main menu page) saying: "easy" a button and when pressed on, it takes user to easy page
User prompt
make text (on main menu page) saying: "easy" a button and make it lead to easy page
User prompt
make "easy" button (on main menu page) lead to easy page
User prompt
make buttons darker when they are pressed on
User prompt
make "easy" button lead to "easy" page
User prompt
move the "easy" button up
User prompt
move the "hard" button down
User prompt
move the "hard" button down
User prompt
move the "hard" button up
User prompt
move the "easy" button up
User prompt
move the "easy" button up
User prompt
move the "easy" button up
User prompt
make the "easy" button (on main menu page) lead to "easy" page. make the "medium" button (on main menu page) lead to "medium" page. make the "hard" button (on main menu page) lead to "hard" page.
User prompt
why are "easy" and "hard" not buttons
User prompt
change the title name to say: "Blast through the Cosmos"
User prompt
make the colour of the title not black
User prompt
make the title look more catchy
User prompt
make the title be at the x-axis of 0
User prompt
make the title say "Blast through the Cosmos"
User prompt
add title to the top center of main menu page
User prompt
add title at the top of menu pager
User prompt
remove title on menu page
User prompt
remove the title on the home page
===================================================================
--- original.js
+++ change.js
@@ -40,9 +40,9 @@
heroBullets.push(bullet);
game.addChild(bullet);
this.bulletsInPlay++; // Increment bullets in play
this.bulletLimit--;
- bulletCountTxt.setText('Bullets: ' + this.bulletLimit); // Update bullet count display to show the amount of bullets the hero has left
+ bulletCountTxt.setText('Bullets: ' + this.bulletLimit); // Update bullet count display
this.canShoot = false; // Set shooting cooldown
LK.setTimeout(function () {
self.canShoot = true;
}, 500); // Cooldown of 500ms before next shot
@@ -178,170 +178,9 @@
/****
* Game Code
****/
-/****function initializeGame(selectedDifficulty) {
-difficulty = selectedDifficulty;
-// Initialize important asset arrays
var heroBullets = [];
-var enemies = [];
-var bulletPacks = [];
-// Create character
-var hero = game.addChild(new Hero());
-hero.x = game.width / 2;
-hero.y = game.height - 100;
-// Create score display
-var scoreTxt = new Text2('Score: 0', {
-size: 50,
-fill: "#ffffff"
-});
-var highScoreTxt = new Text2('High Score: 0 (WIP)', {
-size: 50,
-fill: "#ffffff"
-});
-scoreTxt.anchor.set(1, 0);
-highScoreTxt.anchor.set(1, 0);
-highScoreTxt.y = scoreTxt.height + 20;
-LK.gui.topRight.addChild(scoreTxt);
-LK.gui.topRight.addChild(highScoreTxt);
-// Create bullet count display
-bulletCountTxt = new Text2('Bullets: ' + hero.bulletLimit, {
-size: 100,
-fill: "#ffffff"
-});
-bulletCountTxt.anchor.set(0, 0);
-bulletCountTxt.y = scoreTxt.height + 50; // Position below the score display
-LK.gui.topLeft.addChild(bulletCountTxt);
-// Create instructions display
-var instructionsTxt = new Text2('Tap anywhere to shoot', {
-size: 50,
-fill: "#ffffff"
-});
-instructionsTxt.anchor.set(0, 0);
-LK.gui.topLeft.addChild(instructionsTxt);
-// Create a red line 3/4 down the screen
-var redLine = LK.getAsset('redLine', {});
-redLine.width = game.width;
-redLine.height = 5;
-redLine.y = game.height * 0.75;
-game.addChild(redLine);
-// Create joystick instance
-var joystick = new JoystickAsset();
-joystick.x = joystick.width / 2 + 150;
-joystick.y = game.height - joystick.height / 2 - 150;
-joystick.setMoveCallback(function (direction) {
-hero.x = Math.max(hero.width / 2, Math.min(game.width - hero.width / 2, hero.x + direction.x * 10));
-});
-game.addChild(joystick);
-// Handle hero dragging
-var dragNode = null;
-game.on('down', function (obj) {
-hero.shoot();
-});
-game.on('move', function (obj) {
-var event = obj.event;
-var pos = event.getLocalPosition(game);
-hero.x = pos.x;
-});
-// Global event listener for shooting bullets
-// Game tick event
-LK.on('tick', function () {
-// Update character
-hero.update();
-// Move and check bullets
-for (var i = heroBullets.length - 1; i >= 0; i--) {
-var bullet = heroBullets[i];
-bullet.move();
-// Check for bullet collision with enemies
-for (var j = enemies.length - 1; j >= 0; j--) {
-if (bullet.intersects(enemies[j])) {
-// Update score
-var newScore = LK.getScore() + 1;
-LK.setScore(newScore);
-scoreTxt.setText('Score: ' + newScore);
-var highScore = Math.max(newScore, Number((typeof localStorage !== 'undefined' ? localStorage.getItem('highScore') : '0') || '0'));
-highScoreTxt.setText('High Score: ' + highScore + ' (WIP)');
-if (typeof localStorage !== 'undefined' && newScore > highScore) {
-localStorage.setItem('highScore', newScore.toString());
-}
-// Increment character's bullet limit
-hero.bulletLimit++;
-bulletCountTxt.setText('Bullets: ' + hero.bulletLimit); // Update bullet count display to show the amount of bullets the hero has left
-// Destroy enemy and bullet
-enemies[j].destroy();
-enemies.splice(j, 1);
-bullet.destroy();
-heroBullets.splice(i, 1);
-hero.bulletsInPlay--; // Decrement bullets in play
-break;
-}
-}
-// Check for bullet collision with bullet packs
-for (var k = bulletPacks.length - 1; k >= 0; k--) {
-if (bullet.intersects(bulletPacks[k])) {
-// Increment character's bullet limit by 5
-hero.bulletLimit += 5;
-bulletCountTxt.setText('Bullets: ' + hero.bulletLimit); // Update bullet count display to show the amount of bullets the hero has left
-// Destroy bullet pack and bullet
-bulletPacks[k].destroy();
-bulletPacks.splice(k, 1);
-bullet.destroy();
-heroBullets.splice(i, 1);
-break;
-}
-}
-// Remove off-screen bullets and end the game if it's the last one
-if (bullet.y < 0) {
-bullet.destroy();
-heroBullets.splice(i, 1);
-if (difficulty === 'easy' && hero.bulletsInPlay === 0 && hero.bulletLimit === 0) {
-LK.showGameOver(); // End the game when no bullets remain and none are in frame in easy mode
-}
-}
-}
-// Move enemies and check if they pass the red line
-for (var k = enemies.length - 1; k >= 0; k--) {
-enemies[k].move();
-if (enemies[k].y > game.height * 0.75) {
-enemies[k].destroy();
-enemies[k] = null;
-enemies.splice(k, 1);
-}
-}
-var enemySpawnRate = difficulty === 'easy' ? 90 : difficulty === 'medium' ? 60 : 30; // Initialize enemy spawn rate based on difficulty
-// Spawn enemies and bullet packs
-if (LK.ticks % enemySpawnRate == 0) {
-var enemy = new Enemy();
-enemy.x = Math.random() * (game.width - enemy.width) + enemy.width / 2;
-enemy.y = -enemy.height;
-enemies.push(enemy);
-game.addChild(enemy);
-if (enemySpawnRate > 30) {
-enemySpawnRate -= 0.5;
-} // Decrease spawn rate over time to a minimum of 30 ticks
-}
-var bulletPackSpawnRate = difficulty === 'easy' ? 450 : difficulty === 'medium' ? 600 : 750;
-if (LK.ticks % bulletPackSpawnRate == 0) {
-// Spawn a bullet pack every 600 ticks
-var bulletPack = new BulletPack();
-bulletPack.x = Math.random() * (game.width - bulletPack.width) + bulletPack.width / 2;
-bulletPack.y = -bulletPack.height;
-bulletPacks.push(bulletPack); // Add bullet pack to bulletPacks array for collision detection
-game.addChild(bulletPack);
-}
-});
-}
-* Assets
-****/
-// Initialize the MenuPage
-function createMenuPage(menuPage, difficultyText, difficulty, buttonColor) {
- var difficultyButton = new Button(difficultyText, game.width / 2, game.height / 2 + 100, function () {
- initializeGame('easy');
- }, buttonColor);
- menuPage.addChild(difficultyButton);
-}
-var difficulty = 'easy';
-var heroBullets = [];
var bulletPacks = []; // Declare bulletPacks array in the global scope
var bulletCountTxt; // Declare bulletCountTxt in the global scope
function initializeGame() {
// Initialize important asset arrays
@@ -420,10 +259,10 @@
LK.setScore(newScore);
scoreTxt.setText('Score: ' + newScore);
var highScore = Math.max(newScore, Number((typeof localStorage !== 'undefined' ? localStorage.getItem('highScore') : '0') || '0'));
highScoreTxt.setText('High Score: ' + highScore + ' (WIP)');
- if (typeof localStorage !== 'undefined' && newScore > highScore) {
- localStorage.setItem('highScore', newScore.toString());
+ if (typeof localStorage !== 'undefined') {
+ localStorage.setItem('highScore', highScore);
}
// Increment character's bullet limit
hero.bulletLimit++;
bulletCountTxt.setText('Bullets: ' + hero.bulletLimit); // Update bullet count display
@@ -457,59 +296,82 @@
LK.showGameOver(); // End the game when the last bullet is out of frame
}
}
}
- // Move enemies and check if they pass the red line
- for (var k = enemies.length - 1; k >= 0; k--) {
- enemies[k].move();
- if (enemies[k].y > game.height * 0.75) {
- enemies[k].destroy();
- enemies[k] = null;
- enemies.splice(k, 1);
+ // Move and check enemies
+ for (var i = enemies.length - 1; i >= 0; i--) {
+ var enemy = enemies[i];
+ enemy.move();
+ // Check for collision with the hero
+ if (hero.intersects(enemy)) {
+ LK.showGameOver();
+ return; // Stop processing further updates if there's a collision with the hero
}
+ // Remove off-screen enemies
+ if (enemy.y > game.height) {
+ enemy.destroy();
+ enemies.splice(i, 1);
+ }
}
- var enemySpawnRate = difficulty === 'easy' ? 120 : difficulty === 'medium' ? 60 : 30; // Initialize enemy spawn rate based on difficulty
- // Spawn enemies and bullet packs
- if (LK.ticks % enemySpawnRate == 0) {
+ // Move and check bullet packs
+ for (var i = bulletPacks.length - 1; i >= 0; i--) {
+ var bulletPack = bulletPacks[i];
+ bulletPack.move();
+ // Remove off-screen bullet packs
+ if (bulletPack.y > game.height) {
+ bulletPack.destroy();
+ bulletPacks.splice(i, 1);
+ }
+ }
+ // Spawn enemies randomly
+ if (Math.random() < 0.02) {
var enemy = new Enemy();
- enemy.x = Math.random() * (game.width - enemy.width) + enemy.width / 2;
- enemy.y = -enemy.height;
+ enemy.x = Math.random() * game.width;
+ enemy.y = -100;
enemies.push(enemy);
game.addChild(enemy);
- if (enemySpawnRate > 30) {
- enemySpawnRate -= 0.5;
- } // Decrease spawn rate over time to a minimum of 30 ticks
}
- if (LK.ticks % 600 == 0) {
- // Spawn a bullet pack every 600 ticks
- var bulletPack = new BulletPack();
- bulletPack.x = Math.random() * (game.width - bulletPack.width) + bulletPack.width / 2;
- bulletPack.y - bulletPack.height;
- bulletPacks.push(bulletPack); // Add bullet pack to bulletPacks array for collision detection
- game.addChild(bulletPack);
- }
});
+ // Spawn bullet packs randomly
+ if (Math.random() < 0.01) {
+ var bulletPack = new BulletPack();
+ bulletPack.x = Math.random() * game.width;
+ bulletPack.y = -100;
+ bulletPacks.push(bulletPack);
+ game.addChild(bulletPack);
+ }
+ // End of 'tick' event listener
+ // End of initializeGame function
+ function createMenuPage(container, difficultyText, difficultyLevel, color) {
+ // ... (previous code)
+ }
+ // Create title text
+ var titleText = new Text2('Select Difficulty', {
+ size: 100,
+ fill: "#ffffff"
+ });
+ titleText.anchor.set(0.5, 0);
+ container.addChild(titleText);
+ // Create difficulty button
+ var difficultyButton = new Button(difficultyText, container.width / 2, titleText.height + 50, function () {
+ // Set difficulty and start the game
+ difficulty = difficultyLevel;
+ game.clearChildren();
+ initializeGame();
+ LK.hideMenuPage(container);
+ });
+ difficultyButton.anchor.set(0.5, 0);
+ container.addChild(difficultyButton);
+ // Set background color
+ container.backgroundColor = color;
+ // Hide the page initially
+ LK.hideMenuPage(container);
}
-var easyButton = new Button('Easy', game.width / 2, game.height / 2 - 200, function () {
- initializeGame('easy');
-});
-LK.gui.center.addChild(easyButton);
-var mediumMenuPage = game.addChild(new MediumMenuPage());
-mediumMenuPage.y = 0;
-var hardMenuPage = game.addChild(new HardMenuPage());
-hardMenuPage.y = 600;
-// Add title to the top center of the main menu page
-var menuTitle = new Text2('Blast through the Cosmos', {
- size: 120,
- fill: ['#1e3bff', '#c132ff'],
- stroke: '#ffffff',
- strokeThickness: 6,
- dropShadow: true,
- dropShadowColor: '#5e5e5e',
- dropShadowBlur: 4,
- dropShadowAngle: Math.PI / 6,
- dropShadowDistance: 6
-});
-menuTitle.anchor.set(0.5, 0);
-menuTitle.x = 0;
-menuTitle.y = 50;
-LK.gui.top.addChild(menuTitle);
\ No newline at end of file
+// Initial setup
+var difficulty = null;
+// Show menu pages
+var easyMenuPage = new EasyMenuPage();
+var mediumMenuPage = new MediumMenuPage();
+var hardMenuPage = new HardMenuPage();
+LK.showMenuPage(easyMenuPage);
+// Hide loader
+LK.hideLoader();
\ No newline at end of file
android. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
letter X png. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
space background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
galaxy background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
galaxy background. High quality
space background.. High contrast