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); }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); }); // 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); // 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 // Initialize enemies array var enemies = []; game.update = function () { // Create enemies at random points along the edge if (LK.ticks % 60 == 0) { var enemy = new Enemy(); var side = Math.floor(Math.random() * 4); switch (side) { case 0: // top enemy.x = Math.random() * 2048; enemy.y = 0; break; case 1: // right enemy.x = 2048; enemy.y = Math.random() * 2732; break; case 2: // bottom enemy.x = Math.random() * 2048; enemy.y = 2732; break; case 3: // left enemy.x = 0; enemy.y = Math.random() * 2732; break; } enemies.push(enemy); game.addChild(enemy); } 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); } } };
===================================================================
--- original.js
+++ change.js
@@ -13,42 +13,16 @@
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;
- }
- }
- }
});
+// Enemy class
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);
@@ -82,34 +56,8 @@
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;
@@ -120,31 +68,44 @@
game.down = function (x, y, obj) {
player.shoot();
};
// Update game state
+// Initialize enemies array
+var enemies = [];
game.update = function () {
+ // Create enemies at random points along the edge
+ if (LK.ticks % 60 == 0) {
+ var enemy = new Enemy();
+ var side = Math.floor(Math.random() * 4);
+ switch (side) {
+ case 0:
+ // top
+ enemy.x = Math.random() * 2048;
+ enemy.y = 0;
+ break;
+ case 1:
+ // right
+ enemy.x = 2048;
+ enemy.y = Math.random() * 2732;
+ break;
+ case 2:
+ // bottom
+ enemy.x = Math.random() * 2048;
+ enemy.y = 2732;
+ break;
+ case 3:
+ // left
+ enemy.x = 0;
+ enemy.y = Math.random() * 2732;
+ break;
+ }
+ enemies.push(enemy);
+ game.addChild(enemy);
+ }
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;
- }
- }
- }
};
\ 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