Code edit (1 edits merged)
Please save this source code
User prompt
scoreChange.fill = score - oldScore > 0 ? 0x00FF00 : 0xFF0000; This is always black, fix it
Code edit (1 edits merged)
Please save this source code
User prompt
You forgot to initialize scoreChange
User prompt
I don't see the scoreChange text for some reason
User prompt
Position scoreChange text just below the scoreText element. So top-center, but below the score text
User prompt
When the score changes, show below it the increase or decrease (eg. "+1" or "-4"). If it's a negative number, color it red. If it's a positive number, color it green. After 3s, remove it from the screen
User prompt
The game is over if the score drops below 1
Code edit (4 edits merged)
Please save this source code
User prompt
When an enemy reaches the bottom of the screen, reduce the score by the amount of 'damage' property defined in the enemy class
Code edit (3 edits merged)
Please save this source code
User prompt
When spawing enemies, have randomness weights for the types: small = 50% medium = 30% large = 20%
Code edit (1 edits merged)
Please save this source code
User prompt
When checking for collisions, reduce HP from the enemy, instead of just destroying it. One bullet is 40 damage
User prompt
Change line 148 to spawn random enemies from the three types previously defined
User prompt
Please fix the bug: 'Timeout.tick error: Enemy is not defined' in or related to this line: 'var enemy = new Enemy();' Line Number: 135
User prompt
Use assets 'enemyShipSmall', 'enemyShipMedium', 'enemyShipLarge' to create a variation in enemy types and visuals. Small ship: HP 100 Medium ship: HP 200 Large ship: HP 400
User prompt
Show a counter of enemies killed, place it on the top-center of the screen
User prompt
Create a scrolling background full of stars to simulate traveling through space
Initial prompt
Star Ship
/**** * Classes ****/ // Define the 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 = -15; self.update = function () { self.y += self.speed; }; }); // Define the Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemyShipSmall', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 4; self.hp = 200; self.damage = 1; self.update = function () { self.y += self.speed; }; }); // Define the LargeEnemy class var LargeEnemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemyShipLarge', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1; self.hp = 600; self.damage = 4; self.update = function () { self.y += self.speed; }; }); // Define the MediumEnemy class var MediumEnemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemyShipMedium', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.hp = 400; self.damage = 2; self.update = function () { self.y += self.speed; }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Define the Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('playerShip', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Player update logic can be added here }; }); // Define the SmallEnemy class var SmallEnemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemyShipSmall', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.hp = 100; self.update = function () { self.y += self.speed; }; }); // Define the StarBackground class var StarBackground = Container.expand(function () { var self = Container.call(this); var starBackgroundGraphics = self.attachAsset('starBackground', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1; self.update = function () { self.y += self.speed; if (self.y >= 2732) { self.y = 0; } }; }); // Define the ScoreChange class var ScoreChange = Text2.expand(function () { var self = Text2.call(this, '', { size: 100 }); self.anchor.set(0.5, 0); self.alpha = 1; self.update = function () { if (self.alpha > 0) { self.alpha -= 0.01; } else { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x888888 //Init game with black background }); /**** * Game Code ****/ // Initialize score counter var score = 0; var scoreText = new Text2(score.toString(), { size: 100, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); // Initialize player // Initialize star background var starBackground1 = game.addChild(new StarBackground()); starBackground1.x = 2048 / 2; starBackground1.y = 2732 / 2; var starBackground2 = game.addChild(new StarBackground()); starBackground2.x = 2048 / 2; starBackground2.y = -2732 / 2; var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 200; // Arrays to keep track of bullets and enemies var bullets = []; var enemies = []; // Handle player movement game.move = function (x, y, obj) { player.x = x; player.y = y; }; // Spawn enemies at intervals var enemySpawnInterval = LK.setInterval(function () { var enemyTypes = [Enemy, Enemy, Enemy, Enemy, Enemy, Enemy, MediumEnemy, MediumEnemy, MediumEnemy, LargeEnemy]; var randomEnemy = enemyTypes[Math.floor(Math.random() * enemyTypes.length)]; var enemy = new randomEnemy(); enemy.x = Math.random() * 2048; enemy.y = -50; enemies.push(enemy); game.addChild(enemy); }, Math.floor(Math.random() * 2000) + 1000); // Fire bullets at intervals var bulletFireInterval = LK.setInterval(function () { var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y; bullets.push(bullet); game.addChild(bullet); }, 300); // Update game state game.update = function () { // Update star backgrounds starBackground1.update(); starBackground2.update(); // Update bullets for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; bullet.update(); if (bullet.y < -50) { bullet.destroy(); bullets.splice(i, 1); } } // Update enemies for (var j = enemies.length - 1; j >= 0; j--) { var enemy = enemies[j]; enemy.update(); if (enemy.y > 2732 + 50) { var oldScore = score; score -= enemy.damage; // Reduce score by enemy's damage scoreText.setText(score.toString()); // Update score text var scoreChange = new ScoreChange(); scoreChange.setText((score - oldScore).toString()); scoreChange.x = scoreText.x; scoreChange.y = scoreText.y + scoreText.height + 10; scoreChange.fill = score - oldScore > 0 ? '#00FF00' : '#FF0000'; LK.gui.top.addChild(scoreChange); if (score < 1) { LK.showGameOver(); } enemy.destroy(); enemies.splice(j, 1); } } // Check for collisions for (var k = bullets.length - 1; k >= 0; k--) { var bullet = bullets[k]; for (var l = enemies.length - 1; l >= 0; l--) { var enemy = enemies[l]; if (bullet.intersects(enemy)) { bullet.destroy(); bullets.splice(k, 1); enemy.hp -= 100; // Reduce enemy HP by 40 if (enemy.hp <= 0) { // If enemy HP is 0 or less, destroy it enemy.destroy(); enemies.splice(l, 1); // Increase score and update score text var oldScore = score; score++; scoreText.setText(score.toString()); var scoreChange = new ScoreChange(); scoreChange.setText((score - oldScore).toString()); scoreChange.x = scoreText.x; scoreChange.y = scoreText.y + scoreText.height + 10; scoreChange.fill = score - oldScore > 0 ? 0x00FF00 : 0xFF0000; LK.gui.top.addChild(scoreChange); } break; } } } };
===================================================================
--- original.js
+++ change.js
@@ -116,9 +116,9 @@
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x888888 //Init game with black background
});
/****
* Game Code
alien space ship. top-down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a missile with the trail. the missile is pointing to the top, and the trail goes down. no background, top-down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
top-down view, spaceship in the shape of a fighter jet. pointed upwards. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
explosion VFX, transparent. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows