User prompt
player dead after enemy bullet hit
User prompt
increase speed of enemy bullet fall
User prompt
increase enemy bullet speed fall
User prompt
enemy can shoot only one bullet
User prompt
make enemy bullet fast fall speed
User prompt
enemy bullet can destroy
User prompt
make enemy bullet can hit
User prompt
fix enemy bullet
User prompt
slow speed enemy bullet fall
User prompt
fix bullet enemy not gone after hit
User prompt
enemy bullet can hit and gone aftter hit
User prompt
enemy dead after 2x hit
User prompt
erase text space invanders
User prompt
player explosion after hit
User prompt
animate enemy red exploded ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
add background asset
User prompt
enemy dead after 3x hit
User prompt
enemy dead after 2x hit
User prompt
enemy multi direction shoot
User prompt
fix text btap to start space invanders
User prompt
make logic player shoot alien vertical upper shooter
Code edit (1 edits merged)
Please save this source code
User prompt
Platform Gunner: Alien Defense
Initial prompt
JavaScript 2D Platformer Game shooting game. player shoot enemy. enemy capable shoot. random platform. game over when enemy got hit player. touchscreen controler button for move left and right. touch controler button A for attack. touch controler S for jump
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Button = Container.expand(function (assetId, callback) { var self = Container.call(this); var buttonGraphics = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5, alpha: 0.7 }); self.width = buttonGraphics.width; self.height = buttonGraphics.height; self.callback = callback; self.down = function () { buttonGraphics.alpha = 0.9; self.isPressed = true; if (self.callback) { self.callback(); } }; self.up = function () { buttonGraphics.alpha = 0.7; self.isPressed = false; }; return self; }); var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.width = enemyGraphics.width; self.height = enemyGraphics.height; self.movementDirection = Math.random() > 0.5 ? 1 : -1; self.movementSpeed = 2 + Math.random() * 2; self.shootCooldown = 60 + Math.floor(Math.random() * 120); self.update = function () { // Move horizontally self.x += self.movementDirection * self.movementSpeed; // Change direction if at screen edge if (self.x < self.width / 2 || self.x > 2048 - self.width / 2) { self.movementDirection *= -1; } // Maybe shoot self.shootCooldown--; if (self.shootCooldown <= 0) { self.shoot(); self.shootCooldown = 60 + Math.floor(Math.random() * 120); } // Check for player collision if (self.intersects(player)) { gameOver(); } }; self.shoot = function () { var bullet = new EnemyBullet(); bullet.x = self.x; bullet.y = self.y + self.height / 2; game.addChild(bullet); enemyBullets.push(bullet); }; return self; }); var EnemyBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('enemyBullet', { anchorX: 0.5, anchorY: 0.5 }); self.width = bulletGraphics.width; self.height = bulletGraphics.height; self.speed = 6; self.update = function () { self.y += self.speed; // Remove if off screen if (self.y > 2732 + 50) { self.destroy(); var index = enemyBullets.indexOf(self); if (index > -1) { enemyBullets.splice(index, 1); } } // Check for player collision if (self.intersects(player)) { gameOver(); } }; return self; }); var Platform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.attachAsset('platform', { anchorX: 0.5, anchorY: 0.5 }); self.width = platformGraphics.width; self.height = platformGraphics.height; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.width = playerGraphics.width; self.height = playerGraphics.height; self.velocityY = 0; self.velocityX = 0; self.isJumping = false; self.facingRight = true; self.shootCooldown = 0; self.jump = function () { if (!self.isJumping) { self.velocityY = -20; self.isJumping = true; LK.getSound('jump').play(); } }; self.shoot = function () { if (self.shootCooldown <= 0) { var bullet = new PlayerBullet(); bullet.x = self.x + (self.facingRight ? 40 : -40); bullet.y = self.y; bullet.direction = self.facingRight ? 1 : -1; game.addChild(bullet); playerBullets.push(bullet); self.shootCooldown = 15; LK.getSound('shoot').play(); } }; self.update = function () { // Apply gravity self.velocityY += GRAVITY; // Apply velocities self.y += self.velocityY; self.x += self.velocityX; // Decrease shoot cooldown if (self.shootCooldown > 0) { self.shootCooldown--; } // Check for platform collisions self.checkPlatformCollisions(); // Boundary checks if (self.x < self.width / 2) { self.x = self.width / 2; } if (self.x > 2048 - self.width / 2) { self.x = 2048 - self.width / 2; } // Update facing direction based on velocity if (self.velocityX > 0) { self.facingRight = true; } else if (self.velocityX < 0) { self.facingRight = false; } // Flip player graphic based on direction if (self.facingRight) { playerGraphics.scaleX = 1; } else { playerGraphics.scaleX = -1; } }; self.checkPlatformCollisions = function () { var wasOnPlatform = false; for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; // Only check for collision if falling if (self.velocityY > 0) { var playerBottom = self.y + self.height / 2; var platformTop = platform.y - platform.height / 2; // If player's bottom is at or slightly below platform top if (Math.abs(playerBottom - platformTop) < 20) { // And player is horizontally within platform bounds if (self.x + self.width / 2 > platform.x - platform.width / 2 && self.x - self.width / 2 < platform.x + platform.width / 2) { // Land on platform self.y = platformTop - self.height / 2; self.velocityY = 0; self.isJumping = false; wasOnPlatform = true; } } } } if (!wasOnPlatform && !self.isJumping && self.velocityY === 0) { self.isJumping = true; } }; return self; }); var PlayerBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.width = bulletGraphics.width; self.height = bulletGraphics.height; self.direction = 1; // 1 for right, -1 for left self.speed = 20; self.update = function () { self.x += self.speed * self.direction; // Remove if off screen if (self.x < -50 || self.x > 2048 + 50) { self.destroy(); var index = playerBullets.indexOf(self); if (index > -1) { playerBullets.splice(index, 1); } } // Check for enemy collisions for (var i = enemies.length - 1; i >= 0; i--) { var enemy = enemies[i]; if (self.intersects(enemy)) { // Remove bullet self.destroy(); var bulletIndex = playerBullets.indexOf(self); if (bulletIndex > -1) { playerBullets.splice(bulletIndex, 1); } // Remove enemy enemy.destroy(); enemies.splice(i, 1); // Increase score LK.setScore(LK.getScore() + 10); scoreTxt.setText(LK.getScore()); // Play hit sound LK.getSound('enemyHit').play(); break; } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000033 }); /**** * Game Code ****/ // Constants var GRAVITY = 0.8; var SCREEN_WIDTH = 2048; var SCREEN_HEIGHT = 2732; var PLATFORM_COUNT = 8; var MAX_ENEMIES = 6; // Game variables var player; var platforms = []; var playerBullets = []; var enemies = []; var enemyBullets = []; var gameStarted = false; var spawnTimer = 0; var jumpButton, shootButton, moveLeftButton, moveRightButton; var scoreTxt; function initGame() { // Add score display scoreTxt = new Text2('0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(1, 0); LK.gui.topRight.addChild(scoreTxt); scoreTxt.x = -20; scoreTxt.y = 20; // Create player player = new Player(); player.x = SCREEN_WIDTH / 2; player.y = SCREEN_HEIGHT / 2; game.addChild(player); // Create initial platforms generatePlatforms(); // Create UI controls createControls(); // Start game music LK.playMusic('gameMusic'); // Set game as started gameStarted = true; } function generatePlatforms() { // Create a base platform for the player to start on var basePlatform = new Platform(); basePlatform.x = SCREEN_WIDTH / 2; basePlatform.y = SCREEN_HEIGHT / 2 + 100; platforms.push(basePlatform); game.addChild(basePlatform); // Create random platforms for (var i = 0; i < PLATFORM_COUNT - 1; i++) { var platform = new Platform(); platform.x = Math.random() * (SCREEN_WIDTH - 400) + 200; platform.y = Math.random() * (SCREEN_HEIGHT - 600) + 300; // Make sure platforms aren't too close to each other var validPosition = true; for (var j = 0; j < platforms.length; j++) { var existingPlatform = platforms[j]; var distX = Math.abs(platform.x - existingPlatform.x); var distY = Math.abs(platform.y - existingPlatform.y); if (distX < 300 && distY < 200) { validPosition = false; break; } } if (validPosition) { platforms.push(platform); game.addChild(platform); } else { i--; // Try again } } } function createControls() { // Jump button jumpButton = new Button('jumpButton', function () { player.jump(); }); jumpButton.x = SCREEN_WIDTH - 200; jumpButton.y = SCREEN_HEIGHT - 200; game.addChild(jumpButton); // Shoot button shootButton = new Button('shootButton', function () { player.shoot(); }); shootButton.x = SCREEN_WIDTH - 400; shootButton.y = SCREEN_HEIGHT - 200; game.addChild(shootButton); // Move left button moveLeftButton = new Button('moveLeftButton'); moveLeftButton.x = 200; moveLeftButton.y = SCREEN_HEIGHT - 200; game.addChild(moveLeftButton); // Move right button moveRightButton = new Button('moveRightButton'); moveRightButton.x = 400; moveRightButton.y = SCREEN_HEIGHT - 200; game.addChild(moveRightButton); } function spawnEnemy() { if (enemies.length < MAX_ENEMIES) { var enemy = new Enemy(); enemy.x = Math.random() * (SCREEN_WIDTH - 200) + 100; enemy.y = 100; game.addChild(enemy); enemies.push(enemy); } } function gameOver() { LK.getSound('playerHit').play(); LK.effects.flashScreen(0xff0000, 500); LK.showGameOver(); } function handleMove(x, y, obj) { // We don't need to handle move events for this game } function handleDown(x, y, obj) { // Start the game on first touch if not started if (!gameStarted) { initGame(); return; } } function handleUp(x, y, obj) { // We'll handle button releases in their own event handlers } // Game event handlers game.move = handleMove; game.down = handleDown; game.up = handleUp; // Main game update loop game.update = function () { if (!gameStarted) { return; } // Handle player movement from buttons if (moveLeftButton.isPressed) { player.velocityX = -6; } else if (moveRightButton.isPressed) { player.velocityX = 6; } else { player.velocityX = 0; } // Update player player.update(); // Update player bullets for (var i = playerBullets.length - 1; i >= 0; i--) { playerBullets[i].update(); } // Update enemies for (var i = 0; i < enemies.length; i++) { enemies[i].update(); } // Update enemy bullets for (var i = enemyBullets.length - 1; i >= 0; i--) { enemyBullets[i].update(); } // Spawn enemies spawnTimer++; if (spawnTimer >= 120) { // Every 2 seconds spawnEnemy(); spawnTimer = 0; } // Check if player fell out of the screen if (player.y > SCREEN_HEIGHT + 100) { gameOver(); } }; // Start screen message var startText = new Text2('Tap to Start\nPlatform Gunner: Alien Defense', { size: 70, fill: 0xFFFFFF }); startText.anchor.set(0.5, 0.5); startText.x = SCREEN_WIDTH / 2; startText.y = SCREEN_HEIGHT / 2; game.addChild(startText); // Instructions var instructionsText = new Text2('Use left/right buttons to move\nTap Jump to jump between platforms\nTap Shoot to fire at aliens', { size: 40, fill: 0xCCCCCC }); instructionsText.anchor.set(0.5, 0.5); instructionsText.x = SCREEN_WIDTH / 2; instructionsText.y = SCREEN_HEIGHT / 2 + 200; game.addChild(instructionsText);
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,437 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+var Button = Container.expand(function (assetId, callback) {
+ var self = Container.call(this);
+ var buttonGraphics = self.attachAsset(assetId, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.7
+ });
+ self.width = buttonGraphics.width;
+ self.height = buttonGraphics.height;
+ self.callback = callback;
+ self.down = function () {
+ buttonGraphics.alpha = 0.9;
+ self.isPressed = true;
+ if (self.callback) {
+ self.callback();
+ }
+ };
+ self.up = function () {
+ buttonGraphics.alpha = 0.7;
+ self.isPressed = false;
+ };
+ return self;
+});
+var Enemy = Container.expand(function () {
+ var self = Container.call(this);
+ var enemyGraphics = self.attachAsset('enemy', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = enemyGraphics.width;
+ self.height = enemyGraphics.height;
+ self.movementDirection = Math.random() > 0.5 ? 1 : -1;
+ self.movementSpeed = 2 + Math.random() * 2;
+ self.shootCooldown = 60 + Math.floor(Math.random() * 120);
+ self.update = function () {
+ // Move horizontally
+ self.x += self.movementDirection * self.movementSpeed;
+ // Change direction if at screen edge
+ if (self.x < self.width / 2 || self.x > 2048 - self.width / 2) {
+ self.movementDirection *= -1;
+ }
+ // Maybe shoot
+ self.shootCooldown--;
+ if (self.shootCooldown <= 0) {
+ self.shoot();
+ self.shootCooldown = 60 + Math.floor(Math.random() * 120);
+ }
+ // Check for player collision
+ if (self.intersects(player)) {
+ gameOver();
+ }
+ };
+ self.shoot = function () {
+ var bullet = new EnemyBullet();
+ bullet.x = self.x;
+ bullet.y = self.y + self.height / 2;
+ game.addChild(bullet);
+ enemyBullets.push(bullet);
+ };
+ return self;
+});
+var EnemyBullet = Container.expand(function () {
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('enemyBullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = bulletGraphics.width;
+ self.height = bulletGraphics.height;
+ self.speed = 6;
+ self.update = function () {
+ self.y += self.speed;
+ // Remove if off screen
+ if (self.y > 2732 + 50) {
+ self.destroy();
+ var index = enemyBullets.indexOf(self);
+ if (index > -1) {
+ enemyBullets.splice(index, 1);
+ }
+ }
+ // Check for player collision
+ if (self.intersects(player)) {
+ gameOver();
+ }
+ };
+ return self;
+});
+var Platform = Container.expand(function () {
+ var self = Container.call(this);
+ var platformGraphics = self.attachAsset('platform', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = platformGraphics.width;
+ self.height = platformGraphics.height;
+ return self;
+});
+var Player = Container.expand(function () {
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = playerGraphics.width;
+ self.height = playerGraphics.height;
+ self.velocityY = 0;
+ self.velocityX = 0;
+ self.isJumping = false;
+ self.facingRight = true;
+ self.shootCooldown = 0;
+ self.jump = function () {
+ if (!self.isJumping) {
+ self.velocityY = -20;
+ self.isJumping = true;
+ LK.getSound('jump').play();
+ }
+ };
+ self.shoot = function () {
+ if (self.shootCooldown <= 0) {
+ var bullet = new PlayerBullet();
+ bullet.x = self.x + (self.facingRight ? 40 : -40);
+ bullet.y = self.y;
+ bullet.direction = self.facingRight ? 1 : -1;
+ game.addChild(bullet);
+ playerBullets.push(bullet);
+ self.shootCooldown = 15;
+ LK.getSound('shoot').play();
+ }
+ };
+ self.update = function () {
+ // Apply gravity
+ self.velocityY += GRAVITY;
+ // Apply velocities
+ self.y += self.velocityY;
+ self.x += self.velocityX;
+ // Decrease shoot cooldown
+ if (self.shootCooldown > 0) {
+ self.shootCooldown--;
+ }
+ // Check for platform collisions
+ self.checkPlatformCollisions();
+ // Boundary checks
+ if (self.x < self.width / 2) {
+ self.x = self.width / 2;
+ }
+ if (self.x > 2048 - self.width / 2) {
+ self.x = 2048 - self.width / 2;
+ }
+ // Update facing direction based on velocity
+ if (self.velocityX > 0) {
+ self.facingRight = true;
+ } else if (self.velocityX < 0) {
+ self.facingRight = false;
+ }
+ // Flip player graphic based on direction
+ if (self.facingRight) {
+ playerGraphics.scaleX = 1;
+ } else {
+ playerGraphics.scaleX = -1;
+ }
+ };
+ self.checkPlatformCollisions = function () {
+ var wasOnPlatform = false;
+ for (var i = 0; i < platforms.length; i++) {
+ var platform = platforms[i];
+ // Only check for collision if falling
+ if (self.velocityY > 0) {
+ var playerBottom = self.y + self.height / 2;
+ var platformTop = platform.y - platform.height / 2;
+ // If player's bottom is at or slightly below platform top
+ if (Math.abs(playerBottom - platformTop) < 20) {
+ // And player is horizontally within platform bounds
+ if (self.x + self.width / 2 > platform.x - platform.width / 2 && self.x - self.width / 2 < platform.x + platform.width / 2) {
+ // Land on platform
+ self.y = platformTop - self.height / 2;
+ self.velocityY = 0;
+ self.isJumping = false;
+ wasOnPlatform = true;
+ }
+ }
+ }
+ }
+ if (!wasOnPlatform && !self.isJumping && self.velocityY === 0) {
+ self.isJumping = true;
+ }
+ };
+ return self;
+});
+var PlayerBullet = Container.expand(function () {
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = bulletGraphics.width;
+ self.height = bulletGraphics.height;
+ self.direction = 1; // 1 for right, -1 for left
+ self.speed = 20;
+ self.update = function () {
+ self.x += self.speed * self.direction;
+ // Remove if off screen
+ if (self.x < -50 || self.x > 2048 + 50) {
+ self.destroy();
+ var index = playerBullets.indexOf(self);
+ if (index > -1) {
+ playerBullets.splice(index, 1);
+ }
+ }
+ // Check for enemy collisions
+ for (var i = enemies.length - 1; i >= 0; i--) {
+ var enemy = enemies[i];
+ if (self.intersects(enemy)) {
+ // Remove bullet
+ self.destroy();
+ var bulletIndex = playerBullets.indexOf(self);
+ if (bulletIndex > -1) {
+ playerBullets.splice(bulletIndex, 1);
+ }
+ // Remove enemy
+ enemy.destroy();
+ enemies.splice(i, 1);
+ // Increase score
+ LK.setScore(LK.getScore() + 10);
+ scoreTxt.setText(LK.getScore());
+ // Play hit sound
+ LK.getSound('enemyHit').play();
+ break;
+ }
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x000033
+});
+
+/****
+* Game Code
+****/
+// Constants
+var GRAVITY = 0.8;
+var SCREEN_WIDTH = 2048;
+var SCREEN_HEIGHT = 2732;
+var PLATFORM_COUNT = 8;
+var MAX_ENEMIES = 6;
+// Game variables
+var player;
+var platforms = [];
+var playerBullets = [];
+var enemies = [];
+var enemyBullets = [];
+var gameStarted = false;
+var spawnTimer = 0;
+var jumpButton, shootButton, moveLeftButton, moveRightButton;
+var scoreTxt;
+function initGame() {
+ // Add score display
+ scoreTxt = new Text2('0', {
+ size: 80,
+ fill: 0xFFFFFF
+ });
+ scoreTxt.anchor.set(1, 0);
+ LK.gui.topRight.addChild(scoreTxt);
+ scoreTxt.x = -20;
+ scoreTxt.y = 20;
+ // Create player
+ player = new Player();
+ player.x = SCREEN_WIDTH / 2;
+ player.y = SCREEN_HEIGHT / 2;
+ game.addChild(player);
+ // Create initial platforms
+ generatePlatforms();
+ // Create UI controls
+ createControls();
+ // Start game music
+ LK.playMusic('gameMusic');
+ // Set game as started
+ gameStarted = true;
+}
+function generatePlatforms() {
+ // Create a base platform for the player to start on
+ var basePlatform = new Platform();
+ basePlatform.x = SCREEN_WIDTH / 2;
+ basePlatform.y = SCREEN_HEIGHT / 2 + 100;
+ platforms.push(basePlatform);
+ game.addChild(basePlatform);
+ // Create random platforms
+ for (var i = 0; i < PLATFORM_COUNT - 1; i++) {
+ var platform = new Platform();
+ platform.x = Math.random() * (SCREEN_WIDTH - 400) + 200;
+ platform.y = Math.random() * (SCREEN_HEIGHT - 600) + 300;
+ // Make sure platforms aren't too close to each other
+ var validPosition = true;
+ for (var j = 0; j < platforms.length; j++) {
+ var existingPlatform = platforms[j];
+ var distX = Math.abs(platform.x - existingPlatform.x);
+ var distY = Math.abs(platform.y - existingPlatform.y);
+ if (distX < 300 && distY < 200) {
+ validPosition = false;
+ break;
+ }
+ }
+ if (validPosition) {
+ platforms.push(platform);
+ game.addChild(platform);
+ } else {
+ i--; // Try again
+ }
+ }
+}
+function createControls() {
+ // Jump button
+ jumpButton = new Button('jumpButton', function () {
+ player.jump();
+ });
+ jumpButton.x = SCREEN_WIDTH - 200;
+ jumpButton.y = SCREEN_HEIGHT - 200;
+ game.addChild(jumpButton);
+ // Shoot button
+ shootButton = new Button('shootButton', function () {
+ player.shoot();
+ });
+ shootButton.x = SCREEN_WIDTH - 400;
+ shootButton.y = SCREEN_HEIGHT - 200;
+ game.addChild(shootButton);
+ // Move left button
+ moveLeftButton = new Button('moveLeftButton');
+ moveLeftButton.x = 200;
+ moveLeftButton.y = SCREEN_HEIGHT - 200;
+ game.addChild(moveLeftButton);
+ // Move right button
+ moveRightButton = new Button('moveRightButton');
+ moveRightButton.x = 400;
+ moveRightButton.y = SCREEN_HEIGHT - 200;
+ game.addChild(moveRightButton);
+}
+function spawnEnemy() {
+ if (enemies.length < MAX_ENEMIES) {
+ var enemy = new Enemy();
+ enemy.x = Math.random() * (SCREEN_WIDTH - 200) + 100;
+ enemy.y = 100;
+ game.addChild(enemy);
+ enemies.push(enemy);
+ }
+}
+function gameOver() {
+ LK.getSound('playerHit').play();
+ LK.effects.flashScreen(0xff0000, 500);
+ LK.showGameOver();
+}
+function handleMove(x, y, obj) {
+ // We don't need to handle move events for this game
+}
+function handleDown(x, y, obj) {
+ // Start the game on first touch if not started
+ if (!gameStarted) {
+ initGame();
+ return;
+ }
+}
+function handleUp(x, y, obj) {
+ // We'll handle button releases in their own event handlers
+}
+// Game event handlers
+game.move = handleMove;
+game.down = handleDown;
+game.up = handleUp;
+// Main game update loop
+game.update = function () {
+ if (!gameStarted) {
+ return;
+ }
+ // Handle player movement from buttons
+ if (moveLeftButton.isPressed) {
+ player.velocityX = -6;
+ } else if (moveRightButton.isPressed) {
+ player.velocityX = 6;
+ } else {
+ player.velocityX = 0;
+ }
+ // Update player
+ player.update();
+ // Update player bullets
+ for (var i = playerBullets.length - 1; i >= 0; i--) {
+ playerBullets[i].update();
+ }
+ // Update enemies
+ for (var i = 0; i < enemies.length; i++) {
+ enemies[i].update();
+ }
+ // Update enemy bullets
+ for (var i = enemyBullets.length - 1; i >= 0; i--) {
+ enemyBullets[i].update();
+ }
+ // Spawn enemies
+ spawnTimer++;
+ if (spawnTimer >= 120) {
+ // Every 2 seconds
+ spawnEnemy();
+ spawnTimer = 0;
+ }
+ // Check if player fell out of the screen
+ if (player.y > SCREEN_HEIGHT + 100) {
+ gameOver();
+ }
+};
+// Start screen message
+var startText = new Text2('Tap to Start\nPlatform Gunner: Alien Defense', {
+ size: 70,
+ fill: 0xFFFFFF
+});
+startText.anchor.set(0.5, 0.5);
+startText.x = SCREEN_WIDTH / 2;
+startText.y = SCREEN_HEIGHT / 2;
+game.addChild(startText);
+// Instructions
+var instructionsText = new Text2('Use left/right buttons to move\nTap Jump to jump between platforms\nTap Shoot to fire at aliens', {
+ size: 40,
+ fill: 0xCCCCCC
+});
+instructionsText.anchor.set(0.5, 0.5);
+instructionsText.x = SCREEN_WIDTH / 2;
+instructionsText.y = SCREEN_HEIGHT / 2 + 200;
+game.addChild(instructionsText);
\ No newline at end of file