/**** * Classes ****/ var Controller = Container.expand(function () { var self = Container.call(this); var controllerGraphics = self.attachAsset('controller', { anchorX: 0.5, anchorY: 0.5 }); self.alpha = 0.5; // Make the controller semi-transparent }); var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.health = 3; self.shootTick = 180; // Set shootTick for enemy to shoot every 3 seconds self._move_migrated = function () { self.y += 2; // Move enemy downwards if (self.y > 2732 + self.height) { self.destroy(); enemies.splice(enemies.indexOf(self), 1); } }; self.shoot = function () { var bullet = new EnemyBullet(); bullet.x = self.x; bullet.y = self.y + self.height / 2; game.addChild(bullet); enemyBullets.push(bullet); }; }); var EnemyBoss = Container.expand(function () { var self = Container.call(this); var enemyBossGraphics = self.attachAsset('Enemyboss', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); self.health = 10; // Create a health bar self.healthBar = LK.getAsset('healthBar', { width: self.width, height: 10, anchorX: 0.5, anchorY: 0 }); self.addChild(self.healthBar); self.healthBar.y = -self.height / 2; self.shootTick = 120; // Set shootTick for boss to shoot every 2 seconds // Create a health bar self.healthBar = LK.getAsset('healthBar', { width: self.width, height: 10, anchorX: 0.5, anchorY: 0 }); self.addChild(self.healthBar); self.healthBar.y = -self.height / 2; self.stayTime = 0; self.lastX = self.x; self.lastY = self.y; self._move_migrated = function () { self.x += Math.cos(LK.ticks / 60) * 5; self.y += Math.sin(LK.ticks / 60) * 5; if (self.x < 0) { self.x = 0; } if (self.x > 2048 - self.width) { self.x = 2048 - self.width; } if (self.y < 0) { self.y = 0; } if (self.y > 2732 - self.height) { self.y = 2732 - self.height; } if (self.x === self.lastX && self.y === self.lastY) { self.stayTime++; } else { self.stayTime = 0; } if (self.stayTime >= 180) { self.x = Math.random() * (2048 - self.width); self.y = Math.random() * (2732 - self.height); self.stayTime = 0; } self.lastX = self.x; self.lastY = self.y; }; self.shoot = function () { var bullet = new EnemyBullet(); bullet.x = self.x; bullet.y = self.y + self.height / 2; game.addChild(bullet); enemyBullets.push(bullet); }; }); // EnemyBullet class var EnemyBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('enemyBullet', { anchorX: 0.5, anchorY: 0.5 }); self._move_migrated = function () { self.y += 5; if (self.y > 2732 + self.height) { self.destroy(); enemyBullets.splice(enemyBullets.indexOf(self), 1); } }; }); // EnemyType1 class var EnemyType1 = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); self.health = 2; self.shootTick = 600; // Set shootTick for enemy to shoot every 10 seconds // Create a health bar self.healthBar = LK.getAsset('healthBar', { width: self.width, height: 10, anchorX: 0.5, anchorY: 0 }); self.addChild(self.healthBar); self.healthBar.y = -self.height / 2; self._move_migrated = function () { self.y += Math.sin(LK.ticks / 60) * 5; self.x += Math.cos(LK.ticks / 60) * 5; if (self.y > 2732 - self.height) { self.y = 2732 - self.height; } if (self.y < 0) { self.y = 0; } if (self.x < 0) { self.x = 0; } if (self.x > 2048 - self.width) { self.x = 2048 - self.width; } }; self.shoot = function () { var bullet = new EnemyBullet(); bullet.x = self.x; bullet.y = self.y + self.height / 2; game.addChild(bullet); enemyBullets.push(bullet); }; }); // EnemyType2 class var EnemyType2 = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5, scaleX: 4, scaleY: 4 }); self.health = 4; self.shootTick = 600; // Set shootTick for enemy to shoot every 10 seconds // Create a health bar self.healthBar = LK.getAsset('healthBar', { width: self.width, height: 10, anchorX: 0.5, anchorY: 0 }); self.addChild(self.healthBar); self.healthBar.y = -self.height / 2; // Create a health bar self.healthBar = LK.getAsset('healthBar', { width: self.width, height: 10, anchorX: 0.5, anchorY: 0 }); self.addChild(self.healthBar); self.healthBar.y = -self.height / 2; self._move_migrated = function () { self.y += Math.sin(LK.ticks / 60) * 5; self.x += Math.cos(LK.ticks / 60) * 5; if (self.y > 2732 - self.height) { self.y = 2732 - self.height; } if (self.y < 0) { self.y = 0; } if (self.x < 0) { self.x = 0; } if (self.x > 2048 - self.width) { self.x = 2048 - self.width; } }; self.shoot = function () { var bullet1 = new EnemyBullet(); bullet1.x = self.x - self.width / 4; bullet1.y = self.y + self.height / 2; game.addChild(bullet1); enemyBullets.push(bullet1); var bullet2 = new EnemyBullet(); bullet2.x = self.x + self.width / 4; bullet2.y = self.y + self.height / 2; game.addChild(bullet2); enemyBullets.push(bullet2); }; }); var EnemyType3 = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); self.health = 2; self.shootTick = 600; // Set shootTick for enemy to shoot every 10 seconds // Create a health bar self.healthBar = LK.getAsset('healthBar', { width: self.width, height: 10, anchorX: 0.5, anchorY: 0 }); self.addChild(self.healthBar); self.healthBar.y = -self.height / 2; self._move_migrated = function () { self.y += Math.sin(LK.ticks / 60) * 5; self.x += Math.cos(LK.ticks / 60) * 5; if (self.y > 2732 - self.height) { self.y = 2732 - self.height; } if (self.y < 0) { self.y = 0; } if (self.x < 0) { self.x = 0; } if (self.x > 2048 - self.width) { self.x = 2048 - self.width; } }; }); var Explosion = Container.expand(function () { var self = Container.call(this); self.frames = 30; // 0.5 seconds at 60FPS self._update_migrated = function () { if (self.frames > 0) { self.alpha = self.frames / 30; self.scaleX += 0.1; self.scaleY += 0.1; self.frames--; } else { self.destroy(); } }; // After 2 seconds, destroy the explosion LK.setTimeout(function () { self.destroy(); }, 500); self.attachAsset('explosion', { anchorX: 0.5, anchorY: 0.5 }); }); var GoldenBadge = Container.expand(function () { var self = Container.call(this); self.on('down', function (x, y, obj) { self.destroy(); LK.resumeGame(); }); self.attachAsset('goldenBadge', { anchorX: 0.5, anchorY: 0.5 }); }); // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.minions = []; self.health = 3; // Add health property to Hero // Create a health bar self.healthBar = LK.getAsset('healthBar', { width: self.width, height: 10, anchorX: 0.5, anchorY: 0 }); self.addChild(self.healthBar); self.healthBar.y = -self.height / 2; // Position health bar above the hero self.shoot = function () { var bullet = new HeroBullet(); bullet.x = self.x; bullet.y = self.y - self.height / 2; game.addChild(bullet); heroBullets.push(bullet); self.minions.forEach(function (minion) { minion.shoot(); }); }; }); // HeroBullet class var HeroBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('heroBullet', { anchorX: 0.5, anchorY: 0.5 }); self._move_migrated = function () { self.y -= 10; if (self.y < -self.height) { self.destroy(); heroBullets.splice(heroBullets.indexOf(self), 1); } }; }); var KillBar = Container.expand(function () { var self = Container.call(this); self.bar = LK.getAsset('healthBar', { width: 200, height: 20, anchorX: 0.5, anchorY: 0.5, color: 0xff0000 }); self.addChild(self.bar); self.updateBar = function (kills) { self.bar.width = kills * 10; // Assuming each kill increases the bar by 10 units }; }); var SpaceBackground = Container.expand(function () { var self = Container.call(this); self.attachAsset('spaceBackground', { anchorX: 0.5, anchorY: 0.5 }); var planet1 = self.attachAsset('planet1', { anchorX: 0.5, anchorY: 0.5, x: 500, y: 600 }); var planet2 = self.attachAsset('planet2', { anchorX: 0.5, anchorY: 0.5, x: 1500, y: 2000 }); var stars = []; for (var i = 0; i < 100; i++) { var star = self.attachAsset('star', { anchorX: 0.5, anchorY: 0.5, x: Math.random() * 2048, y: Math.random() * 2732 }); stars.push(star); } }); var SuperBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('Superbullet', { anchorX: 0.5, anchorY: 0.5 }); self._move_migrated = function () { self.y -= 15; // Move upwards faster than regular bullets if (self.y < -self.height) { self.destroy(); superBullets.splice(superBullets.indexOf(self), 1); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000020 // Init game with cosmic background color }); /**** * Game Code ****/ var spaceBackground = game.addChild(new SpaceBackground()); spaceBackground.x = 2048 / 2; spaceBackground.y = 2732 / 2; // Define the assets for the hero, enemy robots, and bullets // Initialize hero var hero = game.addChild(new Hero()); hero.x = 2048 / 2; hero.y = 2732 - 100; // Initialize enemy, bullet, and minion arrays var enemies = []; var heroBullets = []; var enemyBullets = []; var superBullets = []; // Array to track super bullets var minions = []; // Add initial enemies to the game for (var i = 0; i < 5; i++) { var enemy = new Enemy(); enemy.x = Math.random() * (2048 - enemy.width) + enemy.width / 2; enemy.y = Math.random() * 500; // Random starting position game.addChild(enemy); enemies.push(enemy); } // Spawn boss at start of game var enemyBoss = new EnemyBoss(); enemyBoss.x = 2048 / 2; enemyBoss.y = 0; game.addChild(enemyBoss); enemies.push(enemyBoss); // Add controllers to the game var leftController = game.addChild(new Controller()); leftController.x = 200; leftController.y = 2732 - 200; var rightController = game.addChild(new Controller()); rightController.x = 2048 - 200; rightController.y = 2732 - 200; // Track touch state for controllers var isDragging = false; var touchStartX = 0; var touchStartY = 0; // Handle shooting and moving the hero game.on('down', function (x, y, obj) { isDragging = true; touchStartX = x; touchStartY = y; // Check if touching left controller for shooting if (leftController.intersects({ x: x, y: y, width: 1, height: 1 })) { hero.shoot(); } // Check if touching right controller for shooting if (rightController.intersects({ x: x, y: y, width: 1, height: 1 })) { hero.shoot(); } }); // Handle movement game.on('move', function (x, y, obj) { if (isDragging) { var deltaX = x - touchStartX; var deltaY = y - touchStartY; // Move hero based on touch delta hero.x += deltaX * 0.1; hero.y += deltaY * 0.1; // Keep hero within screen bounds if (hero.x < hero.width / 2) hero.x = hero.width / 2; if (hero.x > 2048 - hero.width / 2) hero.x = 2048 - hero.width / 2; if (hero.y < hero.height / 2) hero.y = hero.height / 2; if (hero.y > 2732 - hero.height / 2) hero.y = 2732 - hero.height / 2; touchStartX = x; touchStartY = y; } }); // Handle touch up game.on('up', function (x, y, obj) { isDragging = false; }); // Initialize 20 minutes timer and kill count var timer = 20 * 60; var killCount = 0; // Create a timer text object var timerTxt = new Text2('20:00', { size: 100, fill: '#ffffff' }); // Attach the timer text object to the top right corner of the screen LK.gui.topRight.addChild(timerTxt); // Create a kill count text object var killCountTxt = new Text2('Kills: 0', { size: 100, fill: '#ffffff' }); // Attach the kill count text object to the top left corner of the screen LK.gui.topLeft.addChild(killCountTxt); // Initialize and add the kill bar to the game var killBar = new KillBar(); killBar.x = 2048 / 2; killBar.y = 100; game.addChild(killBar); // Game tick event LK.on('tick', function () { // Update timer every second if (LK.ticks % 60 == 0) { timer--; // Update timer text var minutes = Math.floor(timer / 60); var seconds = timer % 60; timerTxt.setText(minutes + ':' + (seconds < 10 ? '0' : '') + seconds); } // Move hero bullets for (var i = heroBullets.length - 1; i >= 0; i--) { heroBullets[i]._move_migrated(); } // Move super bullets for (var sb = superBullets.length - 1; sb >= 0; sb--) { superBullets[sb]._move_migrated(); // Check for collisions between super bullets and enemies for (var e = enemies.length - 1; e >= 0; e--) { if (superBullets[sb].intersects(enemies[e])) { superBullets[sb].destroy(); superBullets.splice(sb, 1); enemies[e].destroy(); enemies.splice(e, 1); break; } } } // Move enemy bullets for (var j = enemyBullets.length - 1; j >= 0; j--) { enemyBullets[j]._move_migrated(); } // Move enemies and randomly shoot for (var k = enemies.length - 1; k >= 0; k--) { enemies[k]._move_migrated(); // Update the health bar if (self && self.healthBar) { self.healthBar.width = self.health / 10 * self.width; } // Enemies shoot based on their unique shootTick value if (enemies[k].shootTick && LK.ticks % enemies[k].shootTick === 0) { enemies[k].shoot(); } } // Spawn enemies if (LK.ticks % 120 == 0) { var enemy = new EnemyType1(); enemy.x = Math.random() * (2048 - enemy.width) + enemy.width / 2; enemy.y = -enemy.height; // Assign a unique shootTick value to each enemy enemy.shootTick = 120 + Math.floor(Math.random() * 60); game.addChild(enemy); enemies.push(enemy); } // Spawn enemy boss every six minutes if (LK.ticks % (60 * 60 * 6) == 0) { var enemyBoss = new EnemyBoss(); enemyBoss.x = Math.random() * (2048 - enemyBoss.width) + enemyBoss.width / 2; enemyBoss.y = -enemyBoss.height; // Assign a unique shootTick value to each enemy boss enemyBoss.shootTick = 120 + Math.floor(Math.random() * 60); game.addChild(enemyBoss); enemies.push(enemyBoss); } if (LK.ticks % 72000 == 0 && enemies.length == 0) { var goldenBadge = new GoldenBadge(); goldenBadge.x = 2048 / 2; goldenBadge.y = 2732 / 2; game.addChild(goldenBadge); LK.pauseGame(); } // Check for collisions between hero bullets and enemies for (var h = heroBullets.length - 1; h >= 0; h--) { for (var e = enemies.length - 1; e >= 0; e--) { if (heroBullets[h].intersects(enemies[e])) { heroBullets[h].destroy(); heroBullets.splice(h, 1); enemies[e].health -= 1; if (enemies[e].health <= 0) { // Remove all bullets of the defeated enemy boss for (var b = enemyBullets.length - 1; b >= 0; b--) { if (enemyBullets[b].x === enemies[e].x && enemyBullets[b].y === enemies[e].y) { enemyBullets[b].destroy(); enemyBullets.splice(b, 1); } } // Remove all bullets of the defeated enemy for (var b = enemyBullets.length - 1; b >= 0; b--) { if (enemyBullets[b].x === enemies[e].x && enemyBullets[b].y === enemies[e].y) { enemyBullets[b].destroy(); enemyBullets.splice(b, 1); } } enemies[e].destroy(); enemies.splice(e, 1); // Increment kill count by 2 if enemy is EnemyBoss, otherwise by 1 var killIncrement = enemies[e] instanceof EnemyBoss ? 2 : 1; killCount += killIncrement; killCountTxt.setText('Kills: ' + killCount); killBar.updateBar(killCount); // Trigger super bullet after 20 kills if (killCount >= 20) { var superBullet = new SuperBullet(); superBullet.x = hero.x; superBullet.y = hero.y - hero.height / 2; game.addChild(superBullet); superBullets.push(superBullet); killCount = 0; // Reset kill count after firing super bullet } } else { if (enemies[e].healthBar) { enemies[e].healthBar.width = enemies[e].health / 4 * enemies[e].width; // Update health bar } } break; } } } // Check for collisions between hero bullets and enemy bullets for (var hb = heroBullets.length - 1; hb >= 0; hb--) { for (var eb = enemyBullets.length - 1; eb >= 0; eb--) { if (heroBullets[hb].intersects(enemyBullets[eb])) { // Bullets pass through each other without being destroyed break; } } } // Check for collisions between enemy bullets and hero for (var eb = enemyBullets.length - 1; eb >= 0; eb--) { if (enemyBullets[eb].intersects(hero)) { hero.health -= 1; hero.healthBar.width = hero.health / 4 * hero.width; // Update health bar enemyBullets[eb].destroy(); enemyBullets.splice(eb, 1); if (hero.health <= 0) { // Flash screen red for 1 second (1000ms) to show damage taken LK.effects.flashScreen(0xff0000, 1000); // Show game over LK.showGameOver(); break; } } } });
/****
* Classes
****/
var Controller = Container.expand(function () {
var self = Container.call(this);
var controllerGraphics = self.attachAsset('controller', {
anchorX: 0.5,
anchorY: 0.5
});
self.alpha = 0.5; // Make the controller semi-transparent
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 3;
self.shootTick = 180; // Set shootTick for enemy to shoot every 3 seconds
self._move_migrated = function () {
self.y += 2; // Move enemy downwards
if (self.y > 2732 + self.height) {
self.destroy();
enemies.splice(enemies.indexOf(self), 1);
}
};
self.shoot = function () {
var bullet = new EnemyBullet();
bullet.x = self.x;
bullet.y = self.y + self.height / 2;
game.addChild(bullet);
enemyBullets.push(bullet);
};
});
var EnemyBoss = Container.expand(function () {
var self = Container.call(this);
var enemyBossGraphics = self.attachAsset('Enemyboss', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
self.health = 10;
// Create a health bar
self.healthBar = LK.getAsset('healthBar', {
width: self.width,
height: 10,
anchorX: 0.5,
anchorY: 0
});
self.addChild(self.healthBar);
self.healthBar.y = -self.height / 2;
self.shootTick = 120; // Set shootTick for boss to shoot every 2 seconds
// Create a health bar
self.healthBar = LK.getAsset('healthBar', {
width: self.width,
height: 10,
anchorX: 0.5,
anchorY: 0
});
self.addChild(self.healthBar);
self.healthBar.y = -self.height / 2;
self.stayTime = 0;
self.lastX = self.x;
self.lastY = self.y;
self._move_migrated = function () {
self.x += Math.cos(LK.ticks / 60) * 5;
self.y += Math.sin(LK.ticks / 60) * 5;
if (self.x < 0) {
self.x = 0;
}
if (self.x > 2048 - self.width) {
self.x = 2048 - self.width;
}
if (self.y < 0) {
self.y = 0;
}
if (self.y > 2732 - self.height) {
self.y = 2732 - self.height;
}
if (self.x === self.lastX && self.y === self.lastY) {
self.stayTime++;
} else {
self.stayTime = 0;
}
if (self.stayTime >= 180) {
self.x = Math.random() * (2048 - self.width);
self.y = Math.random() * (2732 - self.height);
self.stayTime = 0;
}
self.lastX = self.x;
self.lastY = self.y;
};
self.shoot = function () {
var bullet = new EnemyBullet();
bullet.x = self.x;
bullet.y = self.y + self.height / 2;
game.addChild(bullet);
enemyBullets.push(bullet);
};
});
// EnemyBullet class
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('enemyBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self._move_migrated = function () {
self.y += 5;
if (self.y > 2732 + self.height) {
self.destroy();
enemyBullets.splice(enemyBullets.indexOf(self), 1);
}
};
});
// EnemyType1 class
var EnemyType1 = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
self.health = 2;
self.shootTick = 600; // Set shootTick for enemy to shoot every 10 seconds
// Create a health bar
self.healthBar = LK.getAsset('healthBar', {
width: self.width,
height: 10,
anchorX: 0.5,
anchorY: 0
});
self.addChild(self.healthBar);
self.healthBar.y = -self.height / 2;
self._move_migrated = function () {
self.y += Math.sin(LK.ticks / 60) * 5;
self.x += Math.cos(LK.ticks / 60) * 5;
if (self.y > 2732 - self.height) {
self.y = 2732 - self.height;
}
if (self.y < 0) {
self.y = 0;
}
if (self.x < 0) {
self.x = 0;
}
if (self.x > 2048 - self.width) {
self.x = 2048 - self.width;
}
};
self.shoot = function () {
var bullet = new EnemyBullet();
bullet.x = self.x;
bullet.y = self.y + self.height / 2;
game.addChild(bullet);
enemyBullets.push(bullet);
};
});
// EnemyType2 class
var EnemyType2 = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4
});
self.health = 4;
self.shootTick = 600; // Set shootTick for enemy to shoot every 10 seconds
// Create a health bar
self.healthBar = LK.getAsset('healthBar', {
width: self.width,
height: 10,
anchorX: 0.5,
anchorY: 0
});
self.addChild(self.healthBar);
self.healthBar.y = -self.height / 2;
// Create a health bar
self.healthBar = LK.getAsset('healthBar', {
width: self.width,
height: 10,
anchorX: 0.5,
anchorY: 0
});
self.addChild(self.healthBar);
self.healthBar.y = -self.height / 2;
self._move_migrated = function () {
self.y += Math.sin(LK.ticks / 60) * 5;
self.x += Math.cos(LK.ticks / 60) * 5;
if (self.y > 2732 - self.height) {
self.y = 2732 - self.height;
}
if (self.y < 0) {
self.y = 0;
}
if (self.x < 0) {
self.x = 0;
}
if (self.x > 2048 - self.width) {
self.x = 2048 - self.width;
}
};
self.shoot = function () {
var bullet1 = new EnemyBullet();
bullet1.x = self.x - self.width / 4;
bullet1.y = self.y + self.height / 2;
game.addChild(bullet1);
enemyBullets.push(bullet1);
var bullet2 = new EnemyBullet();
bullet2.x = self.x + self.width / 4;
bullet2.y = self.y + self.height / 2;
game.addChild(bullet2);
enemyBullets.push(bullet2);
};
});
var EnemyType3 = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
self.health = 2;
self.shootTick = 600; // Set shootTick for enemy to shoot every 10 seconds
// Create a health bar
self.healthBar = LK.getAsset('healthBar', {
width: self.width,
height: 10,
anchorX: 0.5,
anchorY: 0
});
self.addChild(self.healthBar);
self.healthBar.y = -self.height / 2;
self._move_migrated = function () {
self.y += Math.sin(LK.ticks / 60) * 5;
self.x += Math.cos(LK.ticks / 60) * 5;
if (self.y > 2732 - self.height) {
self.y = 2732 - self.height;
}
if (self.y < 0) {
self.y = 0;
}
if (self.x < 0) {
self.x = 0;
}
if (self.x > 2048 - self.width) {
self.x = 2048 - self.width;
}
};
});
var Explosion = Container.expand(function () {
var self = Container.call(this);
self.frames = 30; // 0.5 seconds at 60FPS
self._update_migrated = function () {
if (self.frames > 0) {
self.alpha = self.frames / 30;
self.scaleX += 0.1;
self.scaleY += 0.1;
self.frames--;
} else {
self.destroy();
}
};
// After 2 seconds, destroy the explosion
LK.setTimeout(function () {
self.destroy();
}, 500);
self.attachAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5
});
});
var GoldenBadge = Container.expand(function () {
var self = Container.call(this);
self.on('down', function (x, y, obj) {
self.destroy();
LK.resumeGame();
});
self.attachAsset('goldenBadge', {
anchorX: 0.5,
anchorY: 0.5
});
});
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.minions = [];
self.health = 3; // Add health property to Hero
// Create a health bar
self.healthBar = LK.getAsset('healthBar', {
width: self.width,
height: 10,
anchorX: 0.5,
anchorY: 0
});
self.addChild(self.healthBar);
self.healthBar.y = -self.height / 2; // Position health bar above the hero
self.shoot = function () {
var bullet = new HeroBullet();
bullet.x = self.x;
bullet.y = self.y - self.height / 2;
game.addChild(bullet);
heroBullets.push(bullet);
self.minions.forEach(function (minion) {
minion.shoot();
});
};
});
// HeroBullet class
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('heroBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self._move_migrated = function () {
self.y -= 10;
if (self.y < -self.height) {
self.destroy();
heroBullets.splice(heroBullets.indexOf(self), 1);
}
};
});
var KillBar = Container.expand(function () {
var self = Container.call(this);
self.bar = LK.getAsset('healthBar', {
width: 200,
height: 20,
anchorX: 0.5,
anchorY: 0.5,
color: 0xff0000
});
self.addChild(self.bar);
self.updateBar = function (kills) {
self.bar.width = kills * 10; // Assuming each kill increases the bar by 10 units
};
});
var SpaceBackground = Container.expand(function () {
var self = Container.call(this);
self.attachAsset('spaceBackground', {
anchorX: 0.5,
anchorY: 0.5
});
var planet1 = self.attachAsset('planet1', {
anchorX: 0.5,
anchorY: 0.5,
x: 500,
y: 600
});
var planet2 = self.attachAsset('planet2', {
anchorX: 0.5,
anchorY: 0.5,
x: 1500,
y: 2000
});
var stars = [];
for (var i = 0; i < 100; i++) {
var star = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5,
x: Math.random() * 2048,
y: Math.random() * 2732
});
stars.push(star);
}
});
var SuperBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('Superbullet', {
anchorX: 0.5,
anchorY: 0.5
});
self._move_migrated = function () {
self.y -= 15; // Move upwards faster than regular bullets
if (self.y < -self.height) {
self.destroy();
superBullets.splice(superBullets.indexOf(self), 1);
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000020 // Init game with cosmic background color
});
/****
* Game Code
****/
var spaceBackground = game.addChild(new SpaceBackground());
spaceBackground.x = 2048 / 2;
spaceBackground.y = 2732 / 2;
// Define the assets for the hero, enemy robots, and bullets
// Initialize hero
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 100;
// Initialize enemy, bullet, and minion arrays
var enemies = [];
var heroBullets = [];
var enemyBullets = [];
var superBullets = []; // Array to track super bullets
var minions = [];
// Add initial enemies to the game
for (var i = 0; i < 5; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * (2048 - enemy.width) + enemy.width / 2;
enemy.y = Math.random() * 500; // Random starting position
game.addChild(enemy);
enemies.push(enemy);
}
// Spawn boss at start of game
var enemyBoss = new EnemyBoss();
enemyBoss.x = 2048 / 2;
enemyBoss.y = 0;
game.addChild(enemyBoss);
enemies.push(enemyBoss);
// Add controllers to the game
var leftController = game.addChild(new Controller());
leftController.x = 200;
leftController.y = 2732 - 200;
var rightController = game.addChild(new Controller());
rightController.x = 2048 - 200;
rightController.y = 2732 - 200;
// Track touch state for controllers
var isDragging = false;
var touchStartX = 0;
var touchStartY = 0;
// Handle shooting and moving the hero
game.on('down', function (x, y, obj) {
isDragging = true;
touchStartX = x;
touchStartY = y;
// Check if touching left controller for shooting
if (leftController.intersects({
x: x,
y: y,
width: 1,
height: 1
})) {
hero.shoot();
}
// Check if touching right controller for shooting
if (rightController.intersects({
x: x,
y: y,
width: 1,
height: 1
})) {
hero.shoot();
}
});
// Handle movement
game.on('move', function (x, y, obj) {
if (isDragging) {
var deltaX = x - touchStartX;
var deltaY = y - touchStartY;
// Move hero based on touch delta
hero.x += deltaX * 0.1;
hero.y += deltaY * 0.1;
// Keep hero within screen bounds
if (hero.x < hero.width / 2) hero.x = hero.width / 2;
if (hero.x > 2048 - hero.width / 2) hero.x = 2048 - hero.width / 2;
if (hero.y < hero.height / 2) hero.y = hero.height / 2;
if (hero.y > 2732 - hero.height / 2) hero.y = 2732 - hero.height / 2;
touchStartX = x;
touchStartY = y;
}
});
// Handle touch up
game.on('up', function (x, y, obj) {
isDragging = false;
});
// Initialize 20 minutes timer and kill count
var timer = 20 * 60;
var killCount = 0;
// Create a timer text object
var timerTxt = new Text2('20:00', {
size: 100,
fill: '#ffffff'
});
// Attach the timer text object to the top right corner of the screen
LK.gui.topRight.addChild(timerTxt);
// Create a kill count text object
var killCountTxt = new Text2('Kills: 0', {
size: 100,
fill: '#ffffff'
});
// Attach the kill count text object to the top left corner of the screen
LK.gui.topLeft.addChild(killCountTxt);
// Initialize and add the kill bar to the game
var killBar = new KillBar();
killBar.x = 2048 / 2;
killBar.y = 100;
game.addChild(killBar);
// Game tick event
LK.on('tick', function () {
// Update timer every second
if (LK.ticks % 60 == 0) {
timer--;
// Update timer text
var minutes = Math.floor(timer / 60);
var seconds = timer % 60;
timerTxt.setText(minutes + ':' + (seconds < 10 ? '0' : '') + seconds);
}
// Move hero bullets
for (var i = heroBullets.length - 1; i >= 0; i--) {
heroBullets[i]._move_migrated();
}
// Move super bullets
for (var sb = superBullets.length - 1; sb >= 0; sb--) {
superBullets[sb]._move_migrated();
// Check for collisions between super bullets and enemies
for (var e = enemies.length - 1; e >= 0; e--) {
if (superBullets[sb].intersects(enemies[e])) {
superBullets[sb].destroy();
superBullets.splice(sb, 1);
enemies[e].destroy();
enemies.splice(e, 1);
break;
}
}
}
// Move enemy bullets
for (var j = enemyBullets.length - 1; j >= 0; j--) {
enemyBullets[j]._move_migrated();
}
// Move enemies and randomly shoot
for (var k = enemies.length - 1; k >= 0; k--) {
enemies[k]._move_migrated();
// Update the health bar
if (self && self.healthBar) {
self.healthBar.width = self.health / 10 * self.width;
}
// Enemies shoot based on their unique shootTick value
if (enemies[k].shootTick && LK.ticks % enemies[k].shootTick === 0) {
enemies[k].shoot();
}
}
// Spawn enemies
if (LK.ticks % 120 == 0) {
var enemy = new EnemyType1();
enemy.x = Math.random() * (2048 - enemy.width) + enemy.width / 2;
enemy.y = -enemy.height;
// Assign a unique shootTick value to each enemy
enemy.shootTick = 120 + Math.floor(Math.random() * 60);
game.addChild(enemy);
enemies.push(enemy);
}
// Spawn enemy boss every six minutes
if (LK.ticks % (60 * 60 * 6) == 0) {
var enemyBoss = new EnemyBoss();
enemyBoss.x = Math.random() * (2048 - enemyBoss.width) + enemyBoss.width / 2;
enemyBoss.y = -enemyBoss.height;
// Assign a unique shootTick value to each enemy boss
enemyBoss.shootTick = 120 + Math.floor(Math.random() * 60);
game.addChild(enemyBoss);
enemies.push(enemyBoss);
}
if (LK.ticks % 72000 == 0 && enemies.length == 0) {
var goldenBadge = new GoldenBadge();
goldenBadge.x = 2048 / 2;
goldenBadge.y = 2732 / 2;
game.addChild(goldenBadge);
LK.pauseGame();
}
// Check for collisions between hero bullets and enemies
for (var h = heroBullets.length - 1; h >= 0; h--) {
for (var e = enemies.length - 1; e >= 0; e--) {
if (heroBullets[h].intersects(enemies[e])) {
heroBullets[h].destroy();
heroBullets.splice(h, 1);
enemies[e].health -= 1;
if (enemies[e].health <= 0) {
// Remove all bullets of the defeated enemy boss
for (var b = enemyBullets.length - 1; b >= 0; b--) {
if (enemyBullets[b].x === enemies[e].x && enemyBullets[b].y === enemies[e].y) {
enemyBullets[b].destroy();
enemyBullets.splice(b, 1);
}
}
// Remove all bullets of the defeated enemy
for (var b = enemyBullets.length - 1; b >= 0; b--) {
if (enemyBullets[b].x === enemies[e].x && enemyBullets[b].y === enemies[e].y) {
enemyBullets[b].destroy();
enemyBullets.splice(b, 1);
}
}
enemies[e].destroy();
enemies.splice(e, 1);
// Increment kill count by 2 if enemy is EnemyBoss, otherwise by 1
var killIncrement = enemies[e] instanceof EnemyBoss ? 2 : 1;
killCount += killIncrement;
killCountTxt.setText('Kills: ' + killCount);
killBar.updateBar(killCount);
// Trigger super bullet after 20 kills
if (killCount >= 20) {
var superBullet = new SuperBullet();
superBullet.x = hero.x;
superBullet.y = hero.y - hero.height / 2;
game.addChild(superBullet);
superBullets.push(superBullet);
killCount = 0; // Reset kill count after firing super bullet
}
} else {
if (enemies[e].healthBar) {
enemies[e].healthBar.width = enemies[e].health / 4 * enemies[e].width; // Update health bar
}
}
break;
}
}
}
// Check for collisions between hero bullets and enemy bullets
for (var hb = heroBullets.length - 1; hb >= 0; hb--) {
for (var eb = enemyBullets.length - 1; eb >= 0; eb--) {
if (heroBullets[hb].intersects(enemyBullets[eb])) {
// Bullets pass through each other without being destroyed
break;
}
}
}
// Check for collisions between enemy bullets and hero
for (var eb = enemyBullets.length - 1; eb >= 0; eb--) {
if (enemyBullets[eb].intersects(hero)) {
hero.health -= 1;
hero.healthBar.width = hero.health / 4 * hero.width; // Update health bar
enemyBullets[eb].destroy();
enemyBullets.splice(eb, 1);
if (hero.health <= 0) {
// Flash screen red for 1 second (1000ms) to show damage taken
LK.effects.flashScreen(0xff0000, 1000);
// Show game over
LK.showGameOver();
break;
}
}
}
});
Blue,laser like. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Golden badge shaped. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Red ufo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Big version of enemy and only dies after shot four times rest of features are from original enemies. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Red bullet facing towards the bottom of the game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Like a big animated explosion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Looks exactly like a realistic rocket. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Imagined cosmic planet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Star. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A golden glowing ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A nuke (no background). Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows