User prompt
Add player health bar. When an enemy colides with the player, take 20% of the health bar. Game over at 0 health
User prompt
Make enemies move towards the player. If they touch a bullet, remove both the bullet and the enemy
User prompt
Make enemies appear at random points along the edge
User prompt
still not fixed.
User prompt
Its not fixed, they mostly come from the corners
User prompt
Enemies should only spawn at the edge of the screen, they should die after being shot once.
User prompt
Make enemies appear and approach the player. Remove them if they get hit or touch the player
Initial prompt
defense
/**** * Classes ****/ //<Assets used in the game will automatically appear here> // 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 = 10; self.update = function () { self.x += self.speed * Math.cos(self.rotation); self.y += self.speed * Math.sin(self.rotation); }; // Update enemies for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); // Check collision with player if (enemies[j].intersects(player)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Check collision with bullets for (var k = player.bullets.length - 1; k >= 0; k--) { if (enemies[j].intersects(player.bullets[k])) { enemies[j].destroy(); player.bullets[k].destroy(); enemies.splice(j, 1); player.bullets.splice(k, 1); break; } } } }); var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.update = function () { var dx = player.x - self.x; var dy = player.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; }; }); // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('character', { anchorX: 0.5, anchorY: 0.5 }); self.rotation = 0; self.bullets = []; self.shoot = function () { var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y; bullet.rotation = self.rotation; self.bullets.push(bullet); game.addChild(bullet); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize player var player = new Player(); player.x = 2048 / 2; player.y = 2732 / 2; game.addChild(player); // Initialize enemies array var enemies = []; // Spawn enemies at intervals var enemySpawnInterval = LK.setInterval(function () { var enemy = new Enemy(); var edge = Math.floor(Math.random() * 4); if (edge === 0) { // Top edge enemy.x = Math.random() * 2048; enemy.y = 0; } else if (edge === 1) { // Bottom edge enemy.x = Math.random() * 2048; enemy.y = 2732; } else if (edge === 2) { // Left edge enemy.x = 0; enemy.y = Math.random() * 2732; } else if (edge === 3) { // Right edge enemy.x = 2048; enemy.y = Math.random() * 2732; } enemies.push(enemy); game.addChild(enemy); }, 2000); // Handle mouse move to rotate player game.move = function (x, y, obj) { var localPos = game.toLocal(obj.global); var dx = localPos.x - player.x; var dy = localPos.y - player.y; player.rotation = Math.atan2(dy, dx); }; // Handle mouse down to shoot game.down = function (x, y, obj) { player.shoot(); }; // Update game state game.update = function () { for (var i = player.bullets.length - 1; i >= 0; i--) { player.bullets[i].update(); if (player.bullets[i].x < 0 || player.bullets[i].x > 2048 || player.bullets[i].y < 0 || player.bullets[i].y > 2732) { player.bullets[i].destroy(); player.bullets.splice(i, 1); } } for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); // Check collision with player if (enemies[j].intersects(player)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Check collision with bullets for (var k = player.bullets.length - 1; k >= 0; k--) { if (enemies[j].intersects(player.bullets[k])) { enemies[j].destroy(); player.bullets[k].destroy(); enemies.splice(j, 1); player.bullets.splice(k, 1); break; } } } };
===================================================================
--- original.js
+++ change.js
@@ -90,22 +90,18 @@
var enemy = new Enemy();
var edge = Math.floor(Math.random() * 4);
if (edge === 0) {
// Top edge
- var corner = Math.floor(Math.random() * 4);
- if (corner === 0) {
- enemy.x = 0;
- enemy.y = 0;
- } else if (corner === 1) {
- enemy.x = 2048;
- enemy.y = 0;
- } else if (corner === 2) {
- enemy.x = 0;
- enemy.y = 2732;
- } else if (corner === 3) {
- enemy.x = 2048;
- enemy.y = 2732;
- }
+ enemy.x = Math.random() * 2048;
+ enemy.y = 0;
+ } else if (edge === 1) {
+ // Bottom edge
+ enemy.x = Math.random() * 2048;
+ enemy.y = 2732;
+ } else if (edge === 2) {
+ // Left edge
+ enemy.x = 0;
+ enemy.y = Math.random() * 2732;
} else if (edge === 3) {
// Right edge
enemy.x = 2048;
enemy.y = Math.random() * 2732;
@@ -132,5 +128,23 @@
player.bullets[i].destroy();
player.bullets.splice(i, 1);
}
}
+ for (var j = enemies.length - 1; j >= 0; j--) {
+ enemies[j].update();
+ // Check collision with player
+ if (enemies[j].intersects(player)) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ // Check collision with bullets
+ for (var k = player.bullets.length - 1; k >= 0; k--) {
+ if (enemies[j].intersects(player.bullets[k])) {
+ enemies[j].destroy();
+ player.bullets[k].destroy();
+ enemies.splice(j, 1);
+ player.bullets.splice(k, 1);
+ break;
+ }
+ }
+ }
};
\ No newline at end of file
Fireball with angry face. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8 bit
Grinning creepy ball shaped clown face. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8 bit
Burning ball shaped creepy grinning devil. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8 bit
Creepy Jester clown with a fat circular belly, grinning and carying a trident. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8 bit
Dark night sky. Dim stars. DMT psychedelic. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8 bit