Code edit (2 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
make textline15 below textline14 and make it say: This game is no longer updated.
Code edit (1 edits merged)
Please save this source code
User prompt
remove highscoretxt
User prompt
Fix Bug: 'ReferenceError: highScoreTxt is not defined' in or related to this line: 'highScoreTxt.setText('High Score: ' + highScore + ' (WIP)');' Line Number: 702
User prompt
Fix Bug: 'Uncaught ReferenceError: ScoreTxt is not defined' in or related to this line: 'cosmicCreditsTxt.y = ScoreTxt.y + ScoreTxt.height + 20; // Position below the high score display' Line Number: 578
Code edit (3 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught ReferenceError: highScoreTxt is not defined' in or related to this line: 'highScoreTxt.anchor.set(1, 0);' Line Number: 577
Code edit (1 edits merged)
Please save this source code
User prompt
change versiontxt to: v0.2.2 BETA
User prompt
change "Tap anywhere to shoot" to: "Double tap anywhere to shoot"
User prompt
make it so the user has to double tap to shoot bullet
User prompt
change versiontxt to be v0.21 BETA
User prompt
the bulletpack bounce off the walls then move the other way. Make it more unpredictable and that they don't have to hit the walls to move the other way
User prompt
the enemies bounce off the walls then move the other way. Make it more unpredictable and that they don't have to hit the walls to move the other way
User prompt
make bullet pack rarity 1/5 of enemy rarity
User prompt
the bulletpack asset does not show up when it is meant to
User prompt
why are there no bulletpacks appearing?
User prompt
the bulletpack bounces off the walls then move the other way. Make it more unpredictable and that they don't have to hit the walls to move the other way
User prompt
the enemies bounce off the walls then move the other way. Make it more unpredictable and that they don't have to hit the walls to move the other way
User prompt
save this
===================================================================
--- original.js
+++ change.js
@@ -1,20 +1,254 @@
/****
* Classes
****/
+var HelpMenuBackground = Container.expand(function (positionX, positionY) {
+ var self = Container.call(this);
+ var backgroundGraphics = self.attachAsset('helpMenuBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Create and add welcome text to the HelpMenuBackground
+ var textline1 = new Text2('Welcome to Blast through the Cosmos - Your Ultimate Space Adventure!', {
+ size: 60,
+ fill: "#ffffff",
+ font: "Game Over",
+ align: 'center',
+ wordWrap: true,
+ wordWrapWidth: game.width * 0.8
+ });
+ textline1.anchor.set(0.5);
+ textline1.x = 0;
+ textline1.y = -800; // Position the text at 0,0
+ self.addChild(textline1);
+ // Create and add controls text to the HelpMenuBackground
+ var textline2 = new Text2('Controls:', {
+ size: 50,
+ fill: "#ffffff",
+ font: "Game Over",
+ align: 'center'
+ });
+ textline2.anchor.set(0.5);
+ textline2.x = 0;
+ textline2.y = -650; // Position the text below textline1
+ self.addChild(textline2);
+ self.x = positionX;
+ var textline3 = new Text2('Move your spaceship: For mouse, the spaceship will follow your cursor. For phone, tap where you want your ship to go.', {
+ size: 70,
+ fill: "#ffffff",
+ font: "Game Over",
+ align: 'center',
+ wordWrap: true,
+ wordWrapWidth: game.width * 0.8
+ });
+ textline3.anchor.set(0.5);
+ textline3.x = 0;
+ textline3.y = -500; // Position the text below textline2
+ self.addChild(textline3);
+ var textline4 = new Text2('Fire bullets: Double Tap anywhere on the screen.', {
+ size: 70,
+ fill: "#ffffff",
+ font: "Game Over",
+ align: 'center',
+ wordWrap: true,
+ wordWrapWidth: game.width * 0.8
+ });
+ textline4.anchor.set(0.5);
+ textline4.x = 0;
+ textline4.y = -350; // Position the text below textline3
+ self.addChild(textline4);
+ var textline5 = new Text2('Objective:', {
+ size: 50,
+ fill: "#ffffff",
+ font: "Game Over",
+ align: 'center',
+ wordWrap: true,
+ wordWrapWidth: game.width * 0.8
+ });
+ textline5.anchor.set(0.5);
+ textline5.x = 0;
+ textline5.y = -200; // Position the text below textline4
+ self.addChild(textline5);
+ var textline6 = new Text2('Destroy the robotic android enemies to increase your score, Cosmic Credits, and replenish your bullets.', {
+ size: 70,
+ fill: "#ffffff",
+ font: "Game Over",
+ align: 'center',
+ wordWrap: true,
+ wordWrapWidth: game.width * 0.8
+ });
+ textline6.anchor.set(0.5);
+ textline6.x = 0;
+ textline6.y = -100; // Position the text below textline5
+ self.addChild(textline6);
+ var textline7 = new Text2('Running out of bullets results in defeat, so keep an eye on your ammo!', {
+ size: 70,
+ fill: "#ffffff",
+ font: "Game Over",
+ align: 'center',
+ wordWrap: true,
+ wordWrapWidth: game.width * 0.8
+ });
+ textline7.anchor.set(0.5);
+ textline7.x = 0;
+ textline7.y = 0 + 50; // Position the text below textline6
+ self.addChild(textline7);
+ var textline8 = new Text2('Game Elements:', {
+ size: 50,
+ fill: "#ffffff",
+ font: "Game Over",
+ align: 'center',
+ wordWrap: true,
+ wordWrapWidth: game.width * 0.8
+ });
+ textline8.anchor.set(0.5);
+ textline8.x = 0;
+ textline8.y = textline7.y + 150; // Position the text below textline7
+ self.addChild(textline8);
+ var textline9 = new Text2('Bullets: Start with 3 bullets. Shoot enemies to gain Cosmic Credits and earn back your bullets. Collect bullet packs to add 5 bullets instantly.', {
+ size: 70,
+ fill: "#ffffff",
+ font: "Game Over",
+ align: 'center',
+ wordWrap: true,
+ wordWrapWidth: game.width * 0.8
+ });
+ textline9.anchor.set(0.5);
+ textline9.x = 0;
+ textline9.y = textline8.y + 150; // Position the text below textline8
+ self.addChild(textline9);
+ var textline10 = new Text2('Cosmic Credits (CC): Use CC to purchase bullets. Spend wisely to survive longer and achieve higher scores.', {
+ size: 70,
+ fill: "#ffffff",
+ font: "Game Over",
+ align: 'center',
+ wordWrap: true,
+ wordWrapWidth: game.width * 0.8
+ });
+ textline10.anchor.set(0.5);
+ textline10.x = 0;
+ textline10.y = textline9.y + 200; // Position the text below textline9
+ self.addChild(textline10);
+ var textline11 = new Text2('Tips for Success:', {
+ size: 50,
+ fill: "#ffffff",
+ font: "Game Over",
+ align: 'center',
+ wordWrap: true,
+ wordWrapWidth: game.width * 0.8
+ });
+ textline11.anchor.set(0.5);
+ textline11.x = 0;
+ textline11.y = textline10.y + 150; // Position the text below textline10
+ self.addChild(textline11);
+ var textline12 = new Text2('Prioritize enemies strategically to maximize your score and rewards.', {
+ size: 70,
+ fill: "#ffffff",
+ font: "Game Over",
+ align: 'center',
+ wordWrap: true,
+ wordWrapWidth: game.width * 0.8
+ });
+ textline12.anchor.set(0.5);
+ textline12.x = 0;
+ textline12.y = textline11.y + 100; // Position the text below textline11
+ self.addChild(textline12);
+ var textline13 = new Text2('Master your spaceship\'s movements to navigate through challenging obstacles.', {
+ size: 70,
+ fill: "#ffffff",
+ font: "Game Over",
+ align: 'center',
+ wordWrap: true,
+ wordWrapWidth: game.width * 0.8
+ });
+ textline13.anchor.set(0.5);
+ textline13.x = 0;
+ textline13.y = textline12.y + 150; // Position the text below textline12
+ self.addChild(textline13);
+ var textline14 = new Text2('Save up Cosmic Credits for crucial upgrades as you progress.', {
+ size: 70,
+ fill: "#ffffff",
+ font: "Game Over",
+ align: 'center',
+ wordWrap: true,
+ wordWrapWidth: game.width * 0.8
+ });
+ textline14.anchor.set(0.5);
+ textline14.x = 0;
+ textline14.y = textline13.y + 150; // Position the text below textline13
+ self.addChild(textline14);
+ self.y = positionY;
+});
+var RestartButton = Container.expand(function (positionX, positionY) {
+ var self = Container.call(this);
+ var buttonGraphics = self.attachAsset('restartButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var restartText = new Text2('Restart', {
+ size: 150,
+ fill: "#ffffff",
+ font: "Game Over"
+ });
+ restartText.anchor.set(0.5);
+ self.addChild(restartText);
+ self.x = positionX;
+ self.y = positionY;
+ self.interactive = true;
+ self.on('down', function (obj) {
+ self.alpha = 0.5;
+ });
+ self.on('up', function (obj) {
+ self.alpha = 1.0;
+ LK.showGameOver();
+ });
+});
+var ResumeButton = Container.expand(function (positionX, positionY) {
+ var self = Container.call(this);
+ var buttonGraphics = self.attachAsset('resume', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Create and add the resume text to the button
+ var resumeText = new Text2('Resume', {
+ size: 150,
+ fill: "#ffffff",
+ font: "Game Over"
+ });
+ resumeText.anchor.set(0.5);
+ self.addChild(resumeText);
+ self.x = positionX;
+ self.y = positionY;
+ self.interactive = true;
+ self.on('down', function (obj) {
+ self.alpha = 0.5;
+ });
+ self.on('up', function (obj) {
+ self.alpha = 1.0;
+ isGamePaused = false;
+ bulletAddedOnPause = false;
+ pauseButton.interactive = true; // Re-enable the pause button
+ self.destroy();
+ pauseMenuBackground.destroy();
+ restartButton.destroy();
+ settingsButton.destroy();
+ });
+});
var PurchaseButtonWithText = Container.expand(function (buttonAssetId, buttonText, buttonSubText, positionX, positionY, onClickCallback) {
var self = Container.call(this);
var button = self.attachAsset('purchase1', {
anchorX: 0.5,
anchorY: 0.5
});
var text = new Text2(buttonText, {
size: 45,
- fill: "#ffffff"
+ fill: "#ffffff",
+ font: "Game Over"
});
var subText = new Text2(buttonSubText, {
size: 45,
- fill: "#ffffff"
+ fill: "#ffffff",
+ font: "Game Over"
});
text.anchor.set(0.5, 1);
subText.anchor.set(0.5, 0);
text.y = -button.height / 2 - 10;
@@ -71,19 +305,10 @@
self.canShoot = true; // Allow shooting initially
self.update = function () {
// Hero update logic
};
- self.tapCount = 0;
- self.lastTapTime = 0;
self.shoot = function () {
- var currentTime = Date.now();
- if (currentTime - self.lastTapTime < 300) {
- self.tapCount++;
- } else {
- self.tapCount = 1;
- }
- self.lastTapTime = currentTime;
- if (self.tapCount >= 2 && this.bulletLimit > 0 && this.canShoot) {
+ if (this.bulletLimit > 0 && this.canShoot && !isGamePaused) {
var bullet = new Bullet();
bullet.x = this.x;
bullet.y = this.y - this.height / 2;
heroBullets.push(bullet);
@@ -92,9 +317,8 @@
bulletCountTxt.setText('Bullets: ' + this.bulletLimit); // Update bullet count display
this.canShoot = false; // Set shooting cooldown
LK.setTimeout(function () {
self.canShoot = true;
- self.tapCount = 0;
}, 500); // Cooldown of 500ms before next shot
}
};
});
@@ -206,21 +430,89 @@
self.containsPoint = function (point) {
return point.x >= self.x - self.width / 2 && point.x <= self.x + self.width / 2 && point.y >= self.y - self.height / 2 && point.y <= self.y + self.height / 2;
};
});
+var SettingsButton = Container.expand(function (positionX, positionY) {
+ var self = Container.call(this);
+ var buttonGraphics = self.attachAsset('help', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Create and add the settings text to the button
+ var settingsText = new Text2('Help', {
+ size: 150,
+ fill: "#ffffff",
+ font: "Game Over"
+ });
+ settingsText.anchor.set(0.5);
+ self.addChild(settingsText);
+ self.x = positionX;
+ self.y = positionY;
+ self.interactive = true;
+ self.on('down', function (obj) {
+ self.alpha = 0.5;
+ });
+ self.on('up', function (obj) {
+ self.alpha = 1.0;
+ var settingsMenuOpen = false;
+ var helpMenuBackground = game.addChild(new HelpMenuBackground(game.width / 2, game.height / 2));
+ settingsMenuOpen = true;
+ // Add 'exit' asset to the settings menu
+ var exitButton = helpMenuBackground.addChild(LK.getAsset('exit', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: game.width / 2 - 1000,
+ // Move 100 pixels to the left
+ y: -1250
+ }));
+ exitButton.interactive = true;
+ exitButton.on('down', function () {
+ exitButton.alpha = 0.5;
+ });
+ exitButton.on('up', function () {
+ exitButton.alpha = 1.0;
+ helpMenuBackground.destroy(); // Close help menu
+ settingsMenuOpen = false;
+ });
+ });
+});
/****
* Initialize Game
****/
-// Create left movement button
var game = new LK.Game({
- title: 'gameplaypage',
- backgroundColor: 0x000000 // Init game with black background
+ title: 'gameplaypage'
});
/****
* Game Code
****/
+var backgrounds = ['gameBackground', 'gamebackground2', 'gamebackground3', 'gamebackground4', 'gamebackground5', 'gamebackground6', 'gamebackground7', 'gamebackground8', 'gamebackground9', 'gamebackground10'];
+var selectedBackground = backgrounds[Math.floor(Math.random() * backgrounds.length)];
+var background = game.addChild(LK.getAsset(selectedBackground, {
+ width: game.width,
+ height: game.height,
+ x: game.width / 2,
+ y: game.height / 2,
+ anchorX: 0.5,
+ anchorY: 0.5
+}));
+var pauseMenuBackground, resumeButton, restartButton, settingsButton;
+function showPauseMenu() {
+ if (isGamePaused) {
+ pauseMenuBackground = game.addChild(LK.getAsset('pauseMenuBackground', {
+ width: game.width,
+ height: game.height,
+ color: 0x000000,
+ alpha: 0.5
+ }));
+ resumeButton = game.addChild(new ResumeButton(game.width / 2, game.height / 2 - 750));
+ restartButton = game.addChild(new RestartButton(game.width / 2, game.height / 2 + 250));
+ settingsButton = game.addChild(new SettingsButton(game.width / 2, game.height / 2 - 250));
+ }
+}
+var isGamePaused = false,
+ settingsMenuOpen = false; // Global variables to track the pause state of the game and settings menu state
var Purchase1 = game.addChild(new PurchaseButtonWithText('purchase1', '10 Bullets for:', '50 Cosmic Credits', 200, game.height - 200, function () {
if (cosmicCredits >= 50) {
cosmicCredits -= 50;
hero.bulletLimit += 10;
@@ -272,17 +564,20 @@
var cosmicCredits = 0; // Initialize cosmic credits
// Create score display
var scoreTxt = new Text2('Score: 0', {
size: 50,
- fill: "#ffffff"
+ fill: "#ffffff",
+ font: "Game Over"
});
var highScoreTxt = new Text2('High Score: 0 (WIP)', {
size: 50,
- fill: "#ffffff"
+ fill: "#ffffff",
+ font: "Game Over"
});
var cosmicCreditsTxt = new Text2('Cosmic Credits: 0', {
size: 50,
- fill: "#ffffff"
+ fill: "#ffffff",
+ font: "Game Over"
}); // New currency display
scoreTxt.anchor.set(1, 0);
highScoreTxt.anchor.set(1, 0);
cosmicCreditsTxt.anchor.set(1, 0);
@@ -291,30 +586,60 @@
LK.gui.topRight.addChild(scoreTxt);
LK.gui.topRight.addChild(highScoreTxt);
LK.gui.topRight.addChild(cosmicCreditsTxt); // Add the cosmic credits display to the GUI
// Create version display
-var versionTxt = new Text2('v0.2.2 BETA', {
+var versionTxt = new Text2('v0.3.0 BETA', {
size: 50,
- fill: "#ffffff"
+ fill: "#ffffff",
+ font: "Game Over"
});
versionTxt.anchor.set(1, 0);
versionTxt.y = cosmicCreditsTxt.y + cosmicCreditsTxt.height + 20; // Position below the cosmic credits display
LK.gui.topRight.addChild(versionTxt); // Add the version display to the GUI
// Create bullet count display
var bulletCountTxt = new Text2('Bullets: 3', {
size: 100,
- fill: "#ffffff"
+ fill: "#ffffff",
+ font: "Game Over"
});
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('Double tap anywhere to shoot', {
size: 50,
- fill: "#ffffff"
+ fill: "#ffffff",
+ font: "Game Over"
});
instructionsTxt.anchor.set(0, 0);
LK.gui.topLeft.addChild(instructionsTxt);
+// Pause button event listener
+var pauseButton = game.addChild(LK.getAsset('pause', {
+ x: 1000
+}));
+pauseButton.interactive = true;
+var bulletAddedOnPause = false;
+pauseButton.on('down', function () {
+ if (!isGamePaused && !settingsMenuOpen) {
+ isGamePaused = true;
+ pauseButton.interactive = false; // Disable the pause button
+ // Make the bullet closest to the hero null
+ var closestBullet = null;
+ var closestDistance = Infinity;
+ heroBullets.forEach(function (bullet) {
+ var distance = hero.y - bullet.y;
+ if (distance >= 0 && distance < closestDistance) {
+ closestDistance = distance;
+ closestBullet = bullet;
+ }
+ });
+ if (closestBullet) {
+ closestBullet.destroy();
+ heroBullets.splice(heroBullets.indexOf(closestBullet), 1);
+ }
+ showPauseMenu();
+ }
+});
// Create a red line 3/4 down the screen
var redLine = LK.getAsset('redLine', {});
redLine.width = game.width;
redLine.height = 5;
@@ -329,30 +654,38 @@
});
game.addChild(joystick);
// Handle tap on the game stage to shoot bullets, excluding buttons
var dragNode = null;
+var lastTapTime = 0;
game.on('down', function (obj) {
+ var currentTime = Date.now();
var event = obj.event;
var pos = event.getLocalPosition(game);
- // Check if the tap is not on any button
+ // Check if the tap is not on any button or the pause button
var purchaseButtonBoundsLeft = Purchase1.getBounds();
var purchaseButtonBoundsRight = purchase2.getBounds();
- if (!(pos.x >= purchaseButtonBoundsLeft.x && pos.x <= purchaseButtonBoundsLeft.x + purchaseButtonBoundsLeft.width && pos.y >= purchaseButtonBoundsLeft.y && pos.y <= purchaseButtonBoundsLeft.y + purchaseButtonBoundsLeft.height || pos.x >= purchaseButtonBoundsRight.x && pos.x <= purchaseButtonBoundsRight.x + purchaseButtonBoundsRight.width && pos.y >= purchaseButtonBoundsRight.y && pos.y <= purchaseButtonBoundsRight.y + purchaseButtonBoundsRight.height) && !joystick.containsPoint(pos)) {
- hero.tapCount++;
- hero.lastTapTime = Date.now();
- if (hero.tapCount >= 2) {
+ var pauseButtonBounds = pauseButton.getBounds();
+ if (!(pos.x >= purchaseButtonBoundsLeft.x && pos.x <= purchaseButtonBoundsLeft.x + purchaseButtonBoundsLeft.width && pos.y >= purchaseButtonBoundsLeft.y && pos.y <= purchaseButtonBoundsLeft.y + purchaseButtonBoundsLeft.height || pos.x >= purchaseButtonBoundsRight.x && pos.x <= purchaseButtonBoundsRight.x + purchaseButtonBoundsRight.width && pos.y >= purchaseButtonBoundsRight.y && pos.y <= purchaseButtonBoundsRight.y + purchaseButtonBoundsRight.height || pos.x >= pauseButtonBounds.x && pos.x <= pauseButtonBounds.x + pauseButtonBounds.width && pos.y >= pauseButtonBounds.y && pos.y <= pauseButtonBounds.y + pauseButtonBounds.height) && !joystick.containsPoint(pos)) {
+ if (currentTime - lastTapTime < 300) {
hero.shoot();
}
+ lastTapTime = currentTime;
}
});
game.on('move', function (obj) {
+ if (isGamePaused) {
+ return;
+ }
var event = obj.event;
var pos = event.getLocalPosition(game);
hero.x = pos.x;
// hero.y = pos.y; // Removed the line that sets the hero's y position
});
// Game tick event
LK.on('tick', function () {
+ if (isGamePaused || settingsMenuOpen) {
+ return;
+ } // Stop updating if game is paused or settings menu is open
// Update character
hero.update();
// Move and check bullets
for (var i = heroBullets.length - 1; i >= 0; i--) {
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