User prompt
update score in 100 points when enemy dies
User prompt
create a scoreboard and increase score when enemy dies
Code edit (1 edits merged)
Please save this source code
User prompt
new bullet class does not affect the enemy
User prompt
make the enemy shoot new bullet class towards the player when appearing on the screen
User prompt
make the enemy shoot new bullet class towards the player
User prompt
make the enemy shoot new bullet class
User prompt
create a new bullet class and assign it to enemy
User prompt
make enemy class shoot bullets
User prompt
create another asset same as enemy class
User prompt
create another type of same enemy class
User prompt
destroy the blast effect after hitting the enemy
User prompt
change the blasting effect as a asset
User prompt
add a blasting effect when the enemy destroys
User prompt
Please fix the bug: 'TypeError: game.getChildrenByType is not a function' in or related to this line: 'var enemies = game.getChildrenByType(Enemy);' Line Number: 25
User prompt
Please fix the bug: 'TypeError: game.getChildrenByClass is not a function' in or related to this line: 'var enemies = game.getChildrenByClass(Enemy);' Line Number: 25
User prompt
when the bullet hits the enemy class the enemy should destroy
User prompt
add damage to bullet
User prompt
remove the player movement only on x axis
User prompt
create enemies like in space fighter game
User prompt
remove asteroids and its class
User prompt
spawn asteroids infront of the player
User prompt
move player only on x axis
User prompt
when i click the left mouse button the player character shoots a bullet
User prompt
create asteroids which are spawn randomly on the game
/**** 
* Classes
****/ 
// Bullet class
var Bullet = Container.expand(function () {
	var self = Container.call(this);
	// Attach bullet asset
	var bulletGraphics = self.attachAsset('bullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Set bullet speed
	self.speed = -5;
	// Update function called every game tick
	self.update = function () {
		self.y += self.speed;
		// Check for collision with enemy
		var enemies = game.children.filter(function (child) {
			return child instanceof Enemy;
		});
		for (var i = 0; i < enemies.length; i++) {
			var enemy = enemies[i];
			if (self.intersects(enemy)) {
				// Destroy enemy and bullet on collision
				enemy.destroy();
				self.destroy();
				// Increase score by 100 points when enemy dies
				LK.setScore(LK.getScore() + 100);
				// Add a blasting effect
				var blast = self.attachAsset('blast', {
					anchorX: 0.5,
					anchorY: 0.5
				});
				blast.x = self.x;
				blast.y = self.y;
				game.addChild(blast);
				// Destroy the blast effect after a short delay
				LK.setTimeout(function () {
					blast.destroy();
				}, 500);
				break;
			}
		}
	};
});
// Enemy class
var Enemy = Container.expand(function () {
	var self = Container.call(this);
	// Attach enemy asset
	var enemyGraphics = self.attachAsset('enemy', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Set enemy speed
	self.speed = 5;
	// Update function called every game tick
	self.update = function () {
		// Move enemy based on speed
		self.y += self.speed;
		// Enemy fires a bullet every 60 ticks
		if (LK.ticks % 60 == 0) {
			var enemyBullet = game.addChild(new EnemyBullet());
			// Set bullet initial position to enemy's position
			enemyBullet.x = self.x;
			enemyBullet.y = self.y;
			// Set bullet speed to move downwards
			enemyBullet.speed = 7;
		}
	};
});
// EnemyBullet class
var EnemyBullet = Container.expand(function () {
	var self = Container.call(this);
	// Attach bullet asset
	var bulletGraphics = self.attachAsset('bullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Set bullet speed
	self.speed = 5;
	// Update function called every game tick
	self.update = function () {
		self.y += self.speed;
	};
});
// Player class
var Player = Container.expand(function () {
	var self = Container.call(this);
	// Attach player asset
	var playerGraphics = self.attachAsset('player', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Set player speed
	self.speed = 5;
	// Update function called every game tick
	self.update = function () {
		// Player movement is handled in game.move event
	};
});
/**** 
* Initialize Game
****/ 
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
var game = new LK.Game({
	backgroundColor: 0x000000
});
/**** 
* Game Code
****/ 
// Create a scoreboard and display it on the screen
var scoreTxt = new Text2('0', {
	size: 150,
	fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
game.update = function () {
	// Spawn an enemy every 60 ticks
	if (LK.ticks % 60 == 0) {
		var enemy = game.addChild(new Enemy());
		// Set enemy initial position
		enemy.x = Math.random() * 2048;
		enemy.y = 0;
	}
};
var player = game.addChild(new Player());
// Set player initial position
player.x = 1024;
player.y = 2732 - player.height / 2 - 100;
// Add mouse move event to the game
game.move = function (x, y, obj) {
	// Move player only on x axis
	player.x = x;
};
game.down = function (x, y, obj) {
	// Create a bullet instance
	var bullet = game.addChild(new Bullet());
	// Set bullet initial position to player's position
	bullet.x = player.x;
	bullet.y = player.y;
};
// Update the scoreboard every game tick
scoreTxt.setText(LK.getScore()); ===================================================================
--- original.js
+++ change.js
@@ -23,10 +23,10 @@
 			if (self.intersects(enemy)) {
 				// Destroy enemy and bullet on collision
 				enemy.destroy();
 				self.destroy();
-				// Increase score when enemy dies
-				LK.setScore(LK.getScore() + 1);
+				// Increase score by 100 points when enemy dies
+				LK.setScore(LK.getScore() + 100);
 				// Add a blasting effect
 				var blast = self.attachAsset('blast', {
 					anchorX: 0.5,
 					anchorY: 0.5
:quality(85)/https://cdn.frvr.ai/67bd57e4efe262753dfd6dfb.png%3F3) 
 Space craft in facing forward. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/67bd65e6b3c92d3f541dbe1d.png%3F3) 
 spacecraft in 4k
:quality(85)/https://cdn.frvr.ai/67bd6df50b7dc080adb82b08.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/67bd6ef5b3c92d3f541dbebe.png%3F3) 
 fire blast. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/67bd755cb3c92d3f541dbf00.png%3F3) 
 asteroid. Single Game Texture. In-Game asset. 2d. No shadows
:quality(85)/https://cdn.frvr.ai/67bd7b3cb3c92d3f541dbf68.png%3F3) 
 dark nebula galaxy 4k. Single Game Texture. In-Game asset. 2d. Blank background. No shadows