User prompt
Now create a new class for the player's ammunition. the player only has a limited amount of bullets that can be fired. start this from 10 bullets. when a bullet is fired from the player, deduct one bullet. when an Ammo item is collected from the screen, refill 1 ammo. The amount of ammo needs to be displayed in the UI inside the foreground container. place one Ammo item to the right of the other. when deducting ammo after firing a bullet, start deducting from the right and deduct them to the left. when refilling, add them to the right. when there's 0 ammo bullets left, the player can no longer shoot, so each of these elements represents the ampount of bullets the player has
User prompt
place all the existing elements like the player, ammon, bullet and enemy in the midground container
User prompt
create a BackgroundContainer, MidgroundContainer and ForegroundContainer
User prompt
when a bullet hits an enemy, destroy both the enemy and the bullet
User prompt
the bullet should be fired towards the closest enemy near the player
User prompt
when firing a bullet, fire it towards the closest enemy. once fired, the bullet maintains it's initial trajectory, it shouldnt follow the enemy
User prompt
now create a new class for the enemy spawner. enemies can be spawned from all 4 edges of the screen not just the top. also add an interval at which an enemy spawns. the spawned enemy has to follow the player wherever he goes
User prompt
the ammo should not be time based. remove that functionality. spawn an Ammo item, wait for it to be collected, and once collected spawn a new one
User prompt
only spawn a new ammo after the existing one has been collected. there can only be 1 ammo item on the screen at a time
User prompt
increase the player speed
User prompt
create a new class for the Ammo collectible. spawn a new Ammo item at a random location of the screen. he player automatically moves towards it to collect it. upon collection, spawn a new ammo at another point and have the player move towards it again. repeat this process indefinitely
Initial prompt
Tap to fire
===================================================================
--- original.js
+++ change.js
@@ -1,118 +1,153 @@
-/****
+/****
* Classes
-****/
+****/
+// Ammo class
+var Ammo = Container.expand(function () {
+ var self = Container.call(this);
+ var ammoGraphics = self.attachAsset('ammo', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+});
//<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.y += self.speed;
- };
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -10;
+ self.update = function () {
+ self.y += self.speed;
+ };
});
// Obstacle class
var Obstacle = Container.expand(function () {
- var self = Container.call(this);
- var obstacleGraphics = self.attachAsset('obstacle', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 5;
- self.update = function () {
- self.y += self.speed;
- };
+ var self = Container.call(this);
+ var obstacleGraphics = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.update = function () {
+ self.y += self.speed;
+ };
});
// Player class
var Player = Container.expand(function () {
- var self = Container.call(this);
- var playerGraphics = self.attachAsset('player', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.shoot = function () {
- var newBullet = new Bullet();
- newBullet.x = self.x;
- newBullet.y = self.y;
- bullets.push(newBullet);
- game.addChild(newBullet);
- };
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.shoot = function () {
+ var newBullet = new Bullet();
+ newBullet.x = self.x;
+ newBullet.y = self.y;
+ bullets.push(newBullet);
+ game.addChild(newBullet);
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize arrays and variables
var bullets = [];
var obstacles = [];
+var ammos = [];
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 200;
var scoreTxt = new Text2('0', {
- size: 150,
- fill: "#ffffff"
+ size: 150,
+ fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle touch down event
game.down = function (x, y, obj) {
- player.shoot();
+ player.shoot();
};
// Update game state
game.update = function () {
- // Update bullets
- for (var i = bullets.length - 1; i >= 0; i--) {
- bullets[i].update();
- if (bullets[i].y < -50) {
- bullets[i].destroy();
- bullets.splice(i, 1);
- }
- }
- // Update obstacles
- for (var j = obstacles.length - 1; j >= 0; j--) {
- obstacles[j].update();
- if (obstacles[j].y > 2732 + 50) {
- obstacles[j].destroy();
- obstacles.splice(j, 1);
- }
- }
- // Check for collisions
- for (var k = bullets.length - 1; k >= 0; k--) {
- for (var l = obstacles.length - 1; l >= 0; l--) {
- if (bullets[k].intersects(obstacles[l])) {
- bullets[k].destroy();
- obstacles[l].destroy();
- bullets.splice(k, 1);
- obstacles.splice(l, 1);
- LK.setScore(LK.getScore() + 1);
- scoreTxt.setText(LK.getScore());
- break;
- }
- }
- }
- // Spawn new obstacles
- if (LK.ticks % 60 == 0) {
- var newObstacle = new Obstacle();
- newObstacle.x = Math.random() * 2048;
- newObstacle.y = -50;
- obstacles.push(newObstacle);
- game.addChild(newObstacle);
- }
- // Check for game over
- for (var m = obstacles.length - 1; m >= 0; m--) {
- if (obstacles[m].intersects(player)) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
- }
+ // Player moves towards the Ammo
+ if (ammos.length > 0) {
+ var dx = ammos[0].x - player.x;
+ var dy = ammos[0].y - player.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ var speed = 5;
+ if (distance > speed) {
+ player.x += dx * speed / distance;
+ player.y += dy * speed / distance;
+ }
+ }
+ // Update bullets
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ bullets[i].update();
+ if (bullets[i].y < -50) {
+ bullets[i].destroy();
+ bullets.splice(i, 1);
+ }
+ }
+ // Update obstacles
+ for (var j = obstacles.length - 1; j >= 0; j--) {
+ obstacles[j].update();
+ if (obstacles[j].y > 2732 + 50) {
+ obstacles[j].destroy();
+ obstacles.splice(j, 1);
+ }
+ }
+ // Check for collisions
+ for (var k = bullets.length - 1; k >= 0; k--) {
+ for (var l = obstacles.length - 1; l >= 0; l--) {
+ if (bullets[k].intersects(obstacles[l])) {
+ bullets[k].destroy();
+ obstacles[l].destroy();
+ bullets.splice(k, 1);
+ obstacles.splice(l, 1);
+ LK.setScore(LK.getScore() + 1);
+ scoreTxt.setText(LK.getScore());
+ break;
+ }
+ }
+ }
+ // Spawn new obstacles
+ if (LK.ticks % 60 == 0) {
+ var newObstacle = new Obstacle();
+ newObstacle.x = Math.random() * 2048;
+ newObstacle.y = -50;
+ obstacles.push(newObstacle);
+ game.addChild(newObstacle);
+ }
+ // Spawn new Ammo
+ if (LK.ticks % 120 == 0) {
+ var newAmmo = new Ammo();
+ newAmmo.x = Math.random() * 2048;
+ newAmmo.y = Math.random() * 2732;
+ ammos.push(newAmmo);
+ game.addChild(newAmmo);
+ }
+ // Check for game over
+ for (var m = obstacles.length - 1; m >= 0; m--) {
+ if (obstacles[m].intersects(player)) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ }
+ // Check for Ammo collection
+ for (var n = ammos.length - 1; n >= 0; n--) {
+ if (ammos[n].intersects(player)) {
+ ammos[n].destroy();
+ ammos.splice(n, 1);
+ }
+ }
};
\ No newline at end of file
8-bit pixelated isometric cute watermelon with a rotor above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit pixelated radial watermelon red juice explosion splash. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit pixelated isometric blueberry-shaped UFO with a cute fruit inside. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit pixelated isometric blueberry projectile. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit pixelated isometric blueberry projectile icon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create a minimal and stylized 8-bit pixelated background of an alien village made of pineapple-shaped huts, viewed from a distance so the buildings appear small and occupy a small lower part of the background. The sky should be light blue and occupy the majority of the image, with the huts constructed from various fruits and having primitive shapes. Use a softer color palette to ensure the background does not distract from the main game elements, capturing the essence of classic 8-bit era video games. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.