/**** * Classes ****/ // Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); //var bulletGraphics = self.attachAsset('bullet', { // anchorX: 0.5, // anchorY: 0.5 //}); self.direction = 0; self.speed_y = -10; self.speed_x = 0; self.power = 2; self.update = function () { self.x += self.speed_x; self.y += self.speed_y; }; }); // EnemyBullet class var EnemyBullet = Container.expand(function () { var self = Container.call(this); self.speed_y = 5; // Default speed for enemy bullets going down self.update = function () { self.y += self.speed_y; if (self.y < 0 || self.y > 2732) { self.destroy(); } }; }); // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); // Add a collision detection object self.collisionObject = LK.getAsset('playerc', { anchorX: 0.5, anchorY: 0.5, width: playerGraphics.width * 0.6, // Slightly smaller for collision detection height: playerGraphics.height * 0.6, alpha: 0 }); self.addChild(self.collisionObject); self.shoot = function () { LK.getSound('Player_shoot').play(); if (powerup_between(0, 5)) { split_shot(); //forward_split_lazer(); //side_plazma(); } else if (powerup_between(5, 15)) { split_shot(); split_shot(); } else if (powerup_between(15, 20)) { split_shot(); forward_lazer(); } else if (powerup_between(20, 30)) { split_shot(); split_shot(); forward_lazer(); } else if (powerup_between(30, 40)) { split_shot(); split_shot(); forward_plazma(); } else if (powerup_between(40, 50)) { split_shot(); split_shot(); forward_plazma(); forward_split_lazer(); } else if (powerup_between(50, 60)) { //split_shot(); //split_shot(); forward_plazma(); forward_split_lazer(); forward_split_lazer(); } else if (powerup_between(60, 70)) { //split_shot(); //split_shot(); forward_plazma(); forward_split_lazer(); forward_split_lazer(); side_plazma(); } else if (powerup_between(70, 80)) { //split_shot(); //split_shot(); forward_plazma(); forward_split_lazer(); forward_split_lazer(); side_plazma(); side_plazma(); } }; }); // PowerUp class var PowerUp = Container.expand(function () { var self = Container.call(this); var powerUpGraphics = self.attachAsset('powerUp', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y += 1; self.rotation += Math.PI / 40; }; }); var Star = Container.expand(function () { var self = Container.call(this); var starType = Math.random() > 0.5 ? 'depth_1' : 'depth_2'; var starGraphics = self.attachAsset(starType, { anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 2 + 1; // Random speed for each star self.alpha = Math.random() * 0.1; // Random opacity between 0.5 and 1.0 self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = -50; // Reset star to top self.x = Math.random() * 2048; // Randomize x position } }; }); // Function to spawn power-ups //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // enemy_1 class var enemy_1 = Container.expand(function () { var self = Container.call(this); self.n = 0; self.xpos = 0.0; self.lives = 1; self.maxLives = self.lives; // Store the maximum lives for percentage calculation self.healthBarForeground = LK.getAsset('healthBarForeground', { anchorX: 0.5, anchorY: 0.5, width: 100, height: 10, y: -60 }); //self.addChild(self.healthBarForeground); var enemy_1Graphics = self.attachAsset('enemy_1', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3 + LK.getScore() / 5000; self.update = function () { self.y += self.speed; movement = Math.sin(self.y / 100); self.rotation = -movement / 2; self.x = self.xpos + movement * enemy_1_movemwnt_amplitude; // Make enemy_1 move in a sine wave self.r; //self.x = self.xpos + Math.floor(self.y); }; }); // enemy_2 class var enemy_2 = Container.expand(function () { var self = Container.call(this); self.n = 0; self.xpos = 0.0; self.lives = 5; self.maxLives = self.lives; // Store the maximum lives for percentage calculation self.healthBarForeground = LK.getAsset('healthBarForeground', { anchorX: 0.5, anchorY: 0.5, width: 100, height: 10, y: -60 }); //self.addChild(self.healthBarForeground); var enemy_2Graphics = self.attachAsset('enemy_2', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3 + LK.getScore() / 5000; ; self.update = function () { self.y += self.speed; self.x = self.xpos + Math.sin(self.y / 100) * enemy_2_movemwnt_amplitude; // Make enemy_2 move in a sine wave }; }); // enemy_3 class var enemy_3 = Container.expand(function () { var self = Container.call(this); self.n = 0; self.xpos = 0.0; self.lives = 10; self.maxLives = self.lives; // Store the maximum lives for percentage calculation self.healthBarForeground = LK.getAsset('healthBarForeground', { anchorX: 0.5, anchorY: 0.5, width: 100, height: 10, y: -60 }); //self.addChild(self.healthBarForeground); self.odd = 0; var enemy_3Graphics = self.attachAsset('enemy_3', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 4 + LK.getScore() / 5000; ; self.update = function () { self.y += self.speed; self.x = self.xpos + self.odd * Math.sin(self.y / 200) * enemy_1_movemwnt_amplitude; // Make enemy_3 move in a sine wave }; }); // enemy_4 class var enemy_4 = Container.expand(function () { var self = Container.call(this); var enemy_4Graphics = self.attachAsset('enemy_4', { anchorX: 0.5, anchorY: 0.5 }); self.lives = 8; self.maxLives = self.lives; // Store the maximum lives for percentage calculation self.healthBarForeground = LK.getAsset('healthBarForeground', { anchorX: 0.5, anchorY: 0.5, width: 100, height: 10, y: -60 }); //self.addChild(self.healthBarForeground); self.speed = Math.random() > 0.5 ? 5 : -5; // Randomize direction self.update = function () { self.x += self.speed; // Randomly shoot bullets up or down if (Math.random() < 0.01) { // 1% chance to shoot each frame var bullet = new EnemyBullet(); bullet.x = self.x; bullet.y = self.y; bullet.speed_y = Math.random() > 0.5 ? 5 : -5; // Randomize bullet direction bullet.attachAsset('bullet_2', { anchorX: 0.5, anchorY: 0.5 }); game.addChild(bullet); // Ensure bullets are deleted when they come off the screen bullet.update = function () { bullet.y += bullet.speed_y; if (bullet.y < 0 || bullet.y > 2732) { bullet.destroy(); } }; // Limit the number of bullets on screen to reduce lag if (game.children.filter(function (child) { return child instanceof EnemyBullet; }).length > 10) { bullet.destroy(); } } // Check if enemy_4 has moved off the screen if (self.speed > 0 && self.x > 2048 || self.speed < 0 && self.x < 0) { self.destroy(); } }; }); // enemy_5 class var enemy_5 = Container.expand(function () { var self = Container.call(this); var enemy_5Graphics = self.attachAsset('enemy_5', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = (Math.random() - 0.5) * 10; // Random horizontal speed self.speedY = (Math.random() - 0.5) * 10; // Random vertical speed // Random initial position if (Math.random() > 0.5) { self.x = Math.random() * 2048; self.y = Math.random() > 0.5 ? -50 : 2732 + 50; } else { self.x = Math.random() > 0.5 ? -50 : 2048 + 50; self.y = Math.random() * 2732; } self.lives = 50; // Initialize lives for enemy_5 self.maxLives = self.lives; // Store the maximum lives for percentage calculation self.healthBarForeground = LK.getAsset('healthBarForeground', { anchorX: 0.5, anchorY: 0.5, width: 100, height: 10, y: -60 }); //self.addChild(self.healthBarForeground); self.update = function () { self.x += self.speedX; self.y += self.speedY; // Check if enemy_5 has moved off the screen if (self.x < -50 || self.x > 2048 + 50 || self.y < -50 || self.y > 2732 + 50) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ LK.getSound('select_powerup').play(); function powerup_between(a, b) { return poweruplevel >= a && poweruplevel < b; } function createExplosion(x, y) { var explosion = LK.getAsset('explosion', { anchorX: 0.5, anchorY: 0.5, x: x, y: y }); game.addChild(explosion); LK.effects.flashObject(explosion, 0xFFFFFF, 100); LK.setTimeout(function () { explosion.destroy(); }, 100); } function split_shot() { var bullet1 = new Bullet(); bullet1.x = player.x + 80 * shotside; bullet1.y = player.y - 50; bullet1.power = 1; bullet1.speed_x = 0.9 * shotside; bullet1.attachAsset('bullet2', { anchorX: 0.5, anchorY: 0.5 }); bullets.push(bullet1); game.addChild(bullet1); shotside *= -1; } function forward_lazer() { var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y - 50; bullet.power = 2; bullet.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); bullets.push(bullet); game.addChild(bullet); } function forward_split_lazer() { var bullet1 = new Bullet(); bullet1.x = player.x + 100 * shotside; bullet1.y = player.y - 200; bullet1.power = 2; bullet1.speed_x = 2 * shotside; bullet1.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); bullet1.rotation = .24 * shotside; bullets.push(bullet1); game.addChild(bullet1); shotside *= -1; } function forward_plazma() { var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y - 50; bullet.speedY = -18; bullet.power = 4; bullet.attachAsset('plazma', { anchorX: 0.5, anchorY: 0.5 }); bullets.push(bullet); game.addChild(bullet); } function side_plazma() { var bullet1 = new Bullet(); bullet1.x = player.x + 100 * shotside; bullet1.y = player.y; bullet1.power = 4; bullet1.speed_x = 8 * shotside; bullet1.speed_y = 0; bullet1.attachAsset('plazma', { anchorX: 0.5, anchorY: 0.5 }); bullet1.rotation = Math.PI / 2; bullet1.width /= 2; bullet1.height /= 2; bullets.push(bullet1); game.addChild(bullet1); shotside *= -1; } var background = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(background); var stars = []; for (var i = 0; i < 10; i++) { // Create 100 stars var star = new Star(); star.x = Math.random() * 2048; // Random x position star.y = Math.random() * 2732; // Random y position stars.push(star); game.addChild(star); } LK.getSound('instruction').play(); LK.playMusic('background_music', { loop: true }); function spawnPowerUp() { var powerUp = new PowerUp(); powerUp.x = Math.random() * 2048; powerUp.y = -50; powerUps.push(powerUp); game.addChild(powerUp); } // Function to spawn enemy_1s function spawnEnemy_1() { if (enemy_1s.length > 1 * enemy_1_wave_length) { return; } var groupX = Math.random() * (2048 - enemy_1_movemwnt_amplitude * 2) + enemy_1_movemwnt_amplitude; // Generate a random x position for the group for (var i = 0.0; i < enemy_1_wave_length; i++) { var enemy = new enemy_1(); enemy.n = i; enemy.y = -50 - i * 110; // Assign a slightly different y position to each enemy enemy.xpos = groupX; // Assign the group x position to the enemy enemy.group = enemy_1GroupCount; // Assign the group number to the enemy enemy_1s.push(enemy); game.addChild(enemy); } // Increment enemy_1 group counter enemy_1GroupCount += 1; } // Function to spawn enemy_2s function spawnEnemy_2() { if (enemy_2s.length > 2 * enemy_2_wave_length) { return; } if (LK.getScore() > 200) { var groupX = Math.random() * (2048 - enemy_2_movemwnt_amplitude * 2) + enemy_2_movemwnt_amplitude; // Generate a random x position for the group for (var i = 0.0; i < enemy_2_wave_length; i++) { var groupX = Math.random() * (2048 - enemy_2_movemwnt_amplitude * 2) + enemy_2_movemwnt_amplitude; // Generate a random x position var enemy = new enemy_2(); enemy.n = i; enemy.y = -50 - i * 110; // Assign a slightly different y position to each enemy enemy.xpos = groupX; // Assign the group x position to the enemy enemy.group = enemy_2GroupCount; // Assign the group number to the enemy enemy_2s.push(enemy); game.addChild(enemy); } } // Increment enemy_1 group counter enemy_2GroupCount += 1; } // Function to spawn enemy_3s function spawnEnemy_3() { if (enemy_3s.length > 2 * enemy_3_wave_length) { return; } if (LK.getScore() > 1000) { var groupX = Math.random() * (2048 - enemy_3_movemwnt_amplitude * 2) + enemy_3_movemwnt_amplitude; // Generate a random x position for the group odd = -1; for (var i = 0.0; i < enemy_3_wave_length; i++) { var enemy = new enemy_3(); enemy.n = i; enemy.odd = odd; enemy.y = -50 - i / 2 * 50; // Assign a slightly different y position to each enemy enemy.xpos = groupX; // Assign the group x position to the enemy enemy.group = enemy_3GroupCount; // Assign the group number to the enemy enemy_3s.push(enemy); game.addChild(enemy); odd *= -1; } // Increment enemy_1 group counter enemy_3GroupCount += 1; } } // Function to spawn enemy_4 function spawnEnemy_4() { if (LK.getScore() >= 2000) { // Limit the number of enemy_4 instances to reduce lag if (game.children.filter(function (child) { return child instanceof enemy_4; }).length < 5) { var enemy = new enemy_4(); enemy.y = Math.random() * 2732; // Random y position enemy.x = enemy.speed > 0 ? 0 : 2048; // Start from left or right based on speed game.addChild(enemy); } } } // Function to spawn enemy_5 function spawnEnemy_5() { if (LK.getScore() > 3000) { var enemy = new enemy_5(); game.addChild(enemy); } } var powerUpLevelText = new Text2('Power-Up Level: 0', { size: 100, fill: 0xFFFFFF }); powerUpLevelText.anchor.set(0, 0); LK.gui.topLeft.addChild(powerUpLevelText); // Function to update the power-up level display function updatePowerUpLevelDisplay() { powerUpLevelText.setText('Power-Up Level: ' + poweruplevel); } // Example: Update power-up level when player collects a power-up function onPowerUpCollected() { poweruplevel += 1; updatePowerUpLevelDisplay(); if (poweruplevel == 5) { LK.getSound('upgrade').play(); } else if (poweruplevel == 5) { LK.getSound('upgrade').play(); } else if (poweruplevel == 15) { LK.getSound('upgrade').play(); } else if (poweruplevel == 20) { LK.getSound('upgrade').play(); } else if (poweruplevel == 30) { LK.getSound('upgrade').play(); } else { LK.getSound('select_powerup').play(); } } var scoreText = new Text2('Score: 0', { size: 100, fill: 0xFFFFFF }); scoreText.anchor.set(1, 0); LK.gui.topRight.addChild(scoreText); // Function to update the score display function updateScoreDisplay() { scoreText.setText('Score: ' + LK.getScore()); } // Update the score display whenever the score changes LK.on('scoreChange', updateScoreDisplay); /**** * Variables ****/ // Initialize player var enemy_1_movemwnt_amplitude = 200; var enemy_2_movemwnt_amplitude = 20; var enemy_3_movemwnt_amplitude = 40; var game_speed = 1.0; var poweruplevel = 0; var playerFireSpeed = 15; // Variable to control the player's fire speed var player = game.addChild(new Player()); shotside = -1; player.x = 2048 / 2; player.y = 2500; // Initialize arrays var bullets = []; var powerUps = []; // Initialize arrays for enemy_1 instances var enemy_1s = []; // Initialize arrays for enemy_2 instances var enemy_2s = []; // Initialize arrays for enemy_3 instances var enemy_3s = []; // Initialize enemy_1 group counter var enemy_1GroupCount = 0; var enemy_2GroupCount = 0; var enemy_3GroupCount = 0; var enemy_1_wave_length = 5; var enemy_2_wave_length = 5; var enemy_3_wave_length = 14; // Game update function game.update = function () { // Make the player auto fire at a reasonable frequency if (LK.ticks % playerFireSpeed === 0) { // Fire every 15 ticks player.shoot(); } // Update stars for (var i = 0; i < stars.length; i++) { stars[i].update(); } // Update enemy_1s for (var i = enemy_1s.length - 1; i >= 0; i--) { var enemy_1 = enemy_1s[i]; //enemy_1.update(); if (enemy_1.y > 2732) { enemy_1.destroy(); enemy_1s.splice(i, 1); } } // Update enemy_2s for (var i = enemy_2s.length - 1; i >= 0; i--) { var enemy_2 = enemy_2s[i]; //enemy_2.update(); if (enemy_2.y > 2732) { enemy_2.destroy(); enemy_2s.splice(i, 1); } } // Update enemy_3s for (var i = enemy_3s.length - 1; i >= 0; i--) { var enemy_3 = enemy_3s[i]; //enemy_3.update(); if (enemy_3.y > 2732) { enemy_3.destroy(); enemy_3s.splice(i, 1); } } // Update bullets for (var j = bullets.length - 1; j >= 0; j--) { var bullet = bullets[j]; bullet.update(); if (bullet.y < 0 || bullet.y > 2732 || bullet.x < 0 || bullet.x > 2732) { bullet.destroy(); bullets.splice(j, 1); } } // Update enemy_4s for (var i = game.children.length - 1; i >= 0; i--) { var child = game.children[i]; if (child instanceof enemy_4) { child.update(); } } // Update power-ups for (var k = powerUps.length - 1; k >= 0; k--) { var powerUp = powerUps[k]; powerUp.update(); if (powerUp.y > 2732) { powerUp.destroy(); powerUps.splice(k, 1); } } // Check for collisions checkCollisions(); }; // Function to check for collisions function checkCollisions() { // Check bullet and enemy_4 collisions for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; for (var j = game.children.length - 1; j >= 0; j--) { var child = game.children[j]; if (child instanceof enemy_4 && bullet.intersects(child)) { LK.getSound('bullet_hit').play(); LK.effects.flashObject(child, 0xFFFFFF, 100); // Flash enemy_4 white for 100ms createExplosion(bullet.x, bullet.y); bullet.destroy(); child.lives -= bullet.power; child.healthBarForeground.width = Math.max(0, child.lives / child.maxLives * 100); if (child.lives <= 0) { createExplosion(child.x, child.y); child.destroy(); LK.getSound('enemy_eplode').play(); LK.setScore(LK.getScore() + 15); // Increase score by 15 for enemy_4 updateScoreDisplay(); } else { bullets.splice(i, 1); } break; } } } // Check player and power-up collisions for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; for (var j = enemy_1s.length - 1; j >= 0; j--) { var enemy_1 = enemy_1s[j]; if (bullet.intersects(enemy_1)) { LK.getSound('bullet_hit').play(); LK.effects.flashObject(enemy_1, 0xFFFFFF, 100); // Flash enemy_1 white for 100ms createExplosion(bullet.x, bullet.y); bullet.destroy(); enemy_1.lives -= bullet.power; enemy_1.healthBarForeground.width = Math.max(0, enemy_1.lives / enemy_1.maxLives * 100); if (enemy_1.lives <= 0) { createExplosion(enemy_1.x, enemy_1.y); enemy_1.destroy(); enemy_1s.splice(j, 1); LK.getSound('enemy_eplode').play(); LK.setScore(LK.getScore() + 10); // Increase score by 10 for enemy_1 updateScoreDisplay(); // Update the score display // Check if all enemies in the defeated enemy's group are also defeated if (!enemy_1s.some(function (e) { return e.group === enemy_1.group; })) { // If true, spawn a powerup spawnPowerUp(); } } else { bullets.splice(i, 1); } break; } } } // Check bullet and enemy_2 collisions for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; for (var j = enemy_2s.length - 1; j >= 0; j--) { var enemy_2 = enemy_2s[j]; if (bullet.intersects(enemy_2)) { LK.getSound('bullet_hit').play(); LK.effects.flashObject(enemy_2, 0xFFFFFF, 100); // Flash enemy_2 white for 100ms createExplosion(bullet.x, bullet.y); bullet.destroy(); enemy_2.lives -= bullet.power; enemy_2.healthBarForeground.width = Math.max(0, enemy_2.lives / enemy_2.maxLives * 100); if (enemy_2.lives < 0) { var explosion2 = LK.getAsset('explosion2', { anchorX: 0.5, anchorY: 0.5, x: enemy_2.x, y: enemy_2.y }); game.addChild(explosion2); LK.effects.flashObject(explosion2, 0xFFFFFF, 100); LK.setTimeout(function () { explosion2.destroy(); }, 100); enemy_2.destroy(); enemy_2s.splice(j, 1); LK.getSound('enemy_eplode').play(); LK.setScore(LK.getScore() + 20 * bullet.power); // Increase score by 20 for enemy_2 updateScoreDisplay(); // Update the score display if (!enemy_2s.some(function (e) { return e.group === enemy_2.group; })) { // If true, spawn a powerup spawnPowerUp(); } } else { bullets.splice(i, 1); } break; } } } // Check bullet and enemy_3 collisions for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; for (var j = enemy_3s.length - 1; j >= 0; j--) { var enemy_3 = enemy_3s[j]; if (bullet.intersects(enemy_3)) { LK.getSound('bullet_hit').play(); LK.effects.flashObject(enemy_3, 0xFFFFFF, 100); // Flash enemy_3 white for 100ms createExplosion(bullet.x, bullet.y); bullet.destroy(); enemy_3.lives -= bullet.power; enemy_3.healthBarForeground.width = Math.max(0, enemy_3.lives / enemy_3.maxLives * 100); if (enemy_3.lives < 0) { var explosion2 = LK.getAsset('explosion2', { anchorX: 0.5, anchorY: 0.5, x: enemy_3.x, y: enemy_3.y }); game.addChild(explosion2); LK.effects.flashObject(explosion2, 0xFFFFFF, 100); LK.setTimeout(function () { explosion2.destroy(); }, 100); createExplosion(enemy_3.x, enemy_3.y); enemy_3.destroy(); enemy_3s.splice(j, 1); LK.getSound('enemy_eplode').play(); LK.setScore(LK.getScore() + 50 * bullet.power); // Increase score by 20 for enemy_2 updateScoreDisplay(); // Update the score display if (!enemy_3s.some(function (e) { return e.group === enemy_3.group; })) { // If true, spawn a powerup spawnPowerUp(); } } else { bullets.splice(i, 1); } break; } } } // Check player and enemy_4 bullet collisions for (var i = game.children.length - 1; i >= 0; i--) { var child = game.children[i]; if (child instanceof EnemyBullet && player.collisionObject.intersects(child)) { var explosion2 = LK.getAsset('explosion2', { anchorX: 0.5, anchorY: 0.5, x: player.x, y: player.y }); game.addChild(explosion2); LK.effects.flashObject(explosion2, 0xFFFFFF, 100); LK.setTimeout(function () { explosion2.destroy(); }, 200); player.destroy(); LK.getSound('player_dead').play(); LK.setTimeout(function () { LK.showGameOver(); }, 3000); // Delay of 1000ms before showing game over return; } } // Check bullet and enemy_5 collisions for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; for (var j = game.children.length - 1; j >= 0; j--) { var child = game.children[j]; if (child instanceof enemy_5 && bullet.intersects(child)) { LK.getSound('bullet_hit').play(); LK.effects.flashObject(child, 0xFFFFFF, 100); // Flash enemy_5 white for 100ms createExplosion(bullet.x, bullet.y); bullet.destroy(); child.lives -= bullet.power; // Reduce lives by bullet power child.healthBarForeground.width = Math.max(0, child.lives / child.maxLives * 100); LK.setScore(LK.getScore() + 100 * bullet.power); // Increase score by 25 for enemy_5 if (child.lives <= 0) { var explosion_a = LK.getAsset('explosion2', { anchorX: 0.5, anchorY: 0.5, x: child.x, y: child.y }); var explosion_b = LK.getAsset('explosion2', { anchorX: 0.5, anchorY: 0.5, x: child.x + (Math.random() - 0.5) * 300, y: child.y + (Math.random() - 0.5) * 300 }); var explosion_c = LK.getAsset('explosion2', { anchorX: 0.5, anchorY: 0.5, x: child.x + (Math.random() - 0.5) * 300, y: child.y + (Math.random() - 0.5) * 300 }); game.addChild(explosion_a); game.addChild(explosion_b); game.addChild(explosion_c); LK.setTimeout(function () { explosion_a.destroy(); explosion_b.destroy(); explosion_c.destroy(); }, 100); createExplosion(child.x, child.y); child.destroy(); LK.getSound('enemy_eplode').play(); updateScoreDisplay(); } bullets.splice(i, 1); break; } } } // Check player bullet and enemy bullet collisions for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; for (var j = game.children.length - 1; j >= 0; j--) { var child = game.children[j]; if (child instanceof EnemyBullet && bullet.intersects(child)) { LK.getSound('bullet_hit').play(); createExplosion(bullet.x, bullet.y); bullet.destroy(); child.destroy(); bullets.splice(i, 1); break; } } } // Check player and power-up collisions for (var k = powerUps.length - 1; k >= 0; k--) { var powerUp = powerUps[k]; if (player.collisionObject.intersects(powerUp)) { powerUp.destroy(); powerUps.splice(k, 1); onPowerUpCollected(); } } // Check player and enemy collisions for (var i = enemy_1s.length - 1; i >= 0; i--) { var enemy_1 = enemy_1s[i]; if (player.collisionObject.intersects(enemy_1)) { var explosion2 = LK.getAsset('explosion2', { anchorX: 0.5, anchorY: 0.5, x: player.x, y: player.y }); game.addChild(explosion2); LK.effects.flashObject(explosion2, 0xFFFFFF, 100); LK.setTimeout(function () { explosion2.destroy(); }, 200); player.destroy(); LK.getSound('player_dead').play(); LK.setTimeout(function () { LK.showGameOver(); }, 3000); // Delay of 1000ms before showing game over return; } } for (var i = enemy_2s.length - 1; i >= 0; i--) { var enemy_2 = enemy_2s[i]; if (player.collisionObject.intersects(enemy_2)) { LK.showGameOver(); return; } } for (var i = enemy_3s.length - 1; i >= 0; i--) { var enemy_3 = enemy_3s[i]; if (player.collisionObject.intersects(enemy_3)) { LK.showGameOver(); return; } } for (var i = game.children.length - 1; i >= 0; i--) { var child = game.children[i]; if (child instanceof enemy_4 && player.collisionObject.intersects(child)) { var explosion2 = LK.getAsset('explosion2', { anchorX: 0.5, anchorY: 0.5, x: player.x, y: player.y }); game.addChild(explosion2); LK.effects.flashObject(explosion2, 0xFFFFFF, 100); LK.setTimeout(function () { explosion2.destroy(); }, 200); player.destroy(); LK.getSound('player_dead').play(); LK.setTimeout(function () { LK.showGameOver(); }, 3000); // Delay of 1000ms before showing game over return; } } // Check player and enemy_5 collisions for (var i = game.children.length - 1; i >= 0; i--) { var child = game.children[i]; if (child instanceof enemy_5 && player.collisionObject.intersects(child)) { var explosion2 = LK.getAsset('explosion2', { anchorX: 0.5, anchorY: 0.5, x: player.x, y: player.y }); game.addChild(explosion2); LK.effects.flashObject(explosion2, 0xFFFFFF, 100); LK.setTimeout(function () { explosion2.destroy(); }, 200); player.destroy(); LK.getSound('player_dead').play(); LK.setTimeout(function () { LK.showGameOver(); }, 3000); // Delay of 1000ms before showing game over return; } } } // Set intervals for spawning LK.setInterval(spawnEnemy_1, 4000); LK.setInterval(spawnEnemy_2, 6200); LK.setInterval(spawnEnemy_3, 8400); LK.setInterval(spawnEnemy_4, 10000); LK.setInterval(spawnEnemy_5, 13000); // Player controls game.down = function (x, y, obj) { player.x = x; player.y = y; }; game.move = function (x, y, obj) { player.x = x; player.y = y; }; game.up = function (x, y, obj) { //player.shoot(); };
===================================================================
--- original.js
+++ change.js
@@ -47,32 +47,51 @@
self.addChild(self.collisionObject);
self.shoot = function () {
LK.getSound('Player_shoot').play();
if (powerup_between(0, 5)) {
- //split_shot();
- forward_split_lazer();
- shotside *= -1;
+ split_shot();
+ //forward_split_lazer();
+ //side_plazma();
} else if (powerup_between(5, 15)) {
split_shot();
- shotside *= -1;
split_shot();
- shotside *= -1;
} else if (powerup_between(15, 20)) {
split_shot();
- shotside *= -1;
forward_lazer();
} else if (powerup_between(20, 30)) {
split_shot();
- shotside *= -1;
split_shot();
- shotside *= -1;
forward_lazer();
} else if (powerup_between(30, 40)) {
split_shot();
- shotside *= -1;
split_shot();
- shotside *= -1;
forward_plazma();
+ } else if (powerup_between(40, 50)) {
+ split_shot();
+ split_shot();
+ forward_plazma();
+ forward_split_lazer();
+ } else if (powerup_between(50, 60)) {
+ //split_shot();
+ //split_shot();
+ forward_plazma();
+ forward_split_lazer();
+ forward_split_lazer();
+ } else if (powerup_between(60, 70)) {
+ //split_shot();
+ //split_shot();
+ forward_plazma();
+ forward_split_lazer();
+ forward_split_lazer();
+ side_plazma();
+ } else if (powerup_between(70, 80)) {
+ //split_shot();
+ //split_shot();
+ forward_plazma();
+ forward_split_lazer();
+ forward_split_lazer();
+ side_plazma();
+ side_plazma();
}
};
});
// PowerUp class
@@ -316,8 +335,9 @@
anchorY: 0.5
});
bullets.push(bullet1);
game.addChild(bullet1);
+ shotside *= -1;
}
function forward_lazer() {
var bullet = new Bullet();
bullet.x = player.x;
@@ -331,19 +351,20 @@
game.addChild(bullet);
}
function forward_split_lazer() {
var bullet1 = new Bullet();
- bullet1.x = player.x + 80 * shotside;
- bullet1.y = player.y - 50;
+ bullet1.x = player.x + 100 * shotside;
+ bullet1.y = player.y - 200;
bullet1.power = 2;
- bullet1.speed_x = 0.9 * shotside;
+ bullet1.speed_x = 2 * shotside;
bullet1.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
- bullet.rotation = 20;
+ bullet1.rotation = .24 * shotside;
bullets.push(bullet1);
game.addChild(bullet1);
+ shotside *= -1;
}
function forward_plazma() {
var bullet = new Bullet();
bullet.x = player.x;
@@ -357,19 +378,24 @@
bullets.push(bullet);
game.addChild(bullet);
}
function side_plazma() {
- var bullet = new Bullet();
- bullet.x = player.x;
- bullet.y = player.y - 50;
- bullet.speedY = -18;
- bullet.power = 4;
- bullet.attachAsset('plazma', {
+ var bullet1 = new Bullet();
+ bullet1.x = player.x + 100 * shotside;
+ bullet1.y = player.y;
+ bullet1.power = 4;
+ bullet1.speed_x = 8 * shotside;
+ bullet1.speed_y = 0;
+ bullet1.attachAsset('plazma', {
anchorX: 0.5,
anchorY: 0.5
});
- bullets.push(bullet);
- game.addChild(bullet);
+ bullet1.rotation = Math.PI / 2;
+ bullet1.width /= 2;
+ bullet1.height /= 2;
+ bullets.push(bullet1);
+ game.addChild(bullet1);
+ shotside *= -1;
}
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
@@ -591,9 +617,9 @@
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
var bullet = bullets[j];
bullet.update();
- if (bullet.y < 0 || bullet.y > 2732) {
+ if (bullet.y < 0 || bullet.y > 2732 || bullet.x < 0 || bullet.x > 2732) {
bullet.destroy();
bullets.splice(j, 1);
}
}
spaceship, retro game, 2d. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
yellow ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
game flying saucer. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
star field. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
neon circle with a 'p'. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
fire explosion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
double sided space ship. symetrical. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows, color, neon
hot stone, red. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
large rock. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows