Code edit (2 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
All enemies except the boss will be fast but their attack will not change
User prompt
Let the enemy spawn in different places and make the game easier
User prompt
Each time the enemy and boss respawn, their attacks change and become more difficult.
User prompt
make the boss attack slower
User prompt
make a boss slower
User prompt
make a boss slower
User prompt
fix bugs and make your boss harder
User prompt
Remove the mutant's number limit and let the game continue even if the boss dies
User prompt
correct any errors
User prompt
Restore the boss's attack and make the boss bigger
User prompt
slow down the boss and do a different attack on the boss
User prompt
then at least add development for the character
User prompt
add boss at a certain score
User prompt
proceed by another method
User prompt
Instead of dragging our character, let's move forward with another method.
User prompt
At least change your play style and have no more than 1 enemy
Code edit (1 edits merged)
Please save this source code
User prompt
AGAINST MUTANTS: THE GREAT WAR
User prompt
name it ``AGAINST MUTANTS: THE GREAT WAR``
Initial prompt
Make a game where we can choose a character and fight one on one
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Boss enemy class
var Boss = Container.expand(function () {
var self = Container.call(this);
var bossSprite = self.attachAsset('mutant', {
anchorX: 0.5,
anchorY: 0.5
});
// Make boss visually distinct: scale up, tint, etc.
bossSprite.scaleX = 3.2;
bossSprite.scaleY = 3.2;
bossSprite.tint = 0x8e24aa; // purple
self.radius = bossSprite.width * 1.6;
self.speed = 0.6; // Boss is even slower
self.shootTimer = 36 + Math.floor(Math.random() * 30);
self.hp = 32; // Boss is much tougher
// Called every tick
self.update = function () {
self.y += self.speed;
self.shootTimer--;
if (self.shootTimer <= 0) {
// If boss HP is below half, alternate between spread and ring attacks
if (self.hp <= 16 && Math.random() < 0.5) {
self.shootRing();
} else {
self.shoot();
}
self.shootTimer = 60 + Math.floor(Math.random() * 40);
}
};
// Boss fires a spread of bullets downward (classic spread attack)
self.shoot = function () {
var numBullets = 9;
var spread = Math.PI * 0.7; // wider spread
var baseAngle = Math.PI / 2; // Downwards
for (var i = 0; i < numBullets; i++) {
var angle = baseAngle - spread / 2 + spread / (numBullets - 1) * i;
var bullet = new MutantBullet();
bullet.x = self.x;
bullet.y = self.y + self.radius;
bullet.speedX = Math.cos(angle) * 15;
bullet.speed = Math.sin(angle) * 15;
mutantBullets.push(bullet);
game.addChild(bullet);
}
LK.getSound('mutantShoot').play();
};
// Boss fires a ring of bullets in all directions (harder pattern)
self.shootRing = function () {
var numBullets = 16;
var baseAngle = Math.random() * Math.PI * 2; // randomize ring rotation
for (var i = 0; i < numBullets; i++) {
var angle = baseAngle + Math.PI * 2 / numBullets * i;
var bullet = new MutantBullet();
bullet.x = self.x;
bullet.y = self.y + self.radius * 0.7;
bullet.speedX = Math.cos(angle) * 10;
bullet.speed = Math.sin(angle) * 10;
mutantBullets.push(bullet);
game.addChild(bullet);
}
LK.getSound('mutantShoot').play();
};
// Take damage
self.hit = function () {
self.hp--;
LK.getSound('mutantHit').play();
LK.effects.flashObject(self, 0xffffff, 150);
if (self.hp <= 0) {
self.destroy();
// Allow further mutant spawning after boss dies
bossSpawned = false;
return true;
}
return false;
};
return self;
});
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroSprite = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.radius = heroSprite.width * 0.5;
self.shootCooldown = 0; // ticks until next shot allowed
// Called every tick
self.update = function () {
if (self.shootCooldown > 0) self.shootCooldown--;
};
// Shoot a bullet upwards
self.shoot = function () {
if (self.shootCooldown === 0) {
var bullet = new HeroBullet();
bullet.x = self.x;
bullet.y = self.y - self.radius - bullet.height * 0.5;
heroBullets.push(bullet);
game.addChild(bullet);
LK.getSound('heroShoot').play();
self.shootCooldown = 12; // 12 ticks cooldown (~0.2s)
}
};
return self;
});
// Hero bullet class
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletSprite = self.attachAsset('heroBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = bulletSprite.width;
self.height = bulletSprite.height;
self.speed = -22;
self.update = function () {
self.y += self.speed;
};
return self;
});
// Mutant enemy class
var Mutant = Container.expand(function () {
var self = Container.call(this);
var mutantSprite = self.attachAsset('mutant', {
anchorX: 0.5,
anchorY: 0.5
});
self.radius = mutantSprite.width * 0.5;
self.speed = 3 + Math.random() * 2; // Vary speed a bit
self.shootTimer = 60 + Math.floor(Math.random() * 60); // Randomize first shot
self.hp = 2; // Mutants take 2 hits
// Called every tick
self.update = function () {
self.y += self.speed;
self.shootTimer--;
if (self.shootTimer <= 0) {
self.shoot();
self.shootTimer = 90 + Math.floor(Math.random() * 60); // Next shot
}
};
// Shoot a bullet downwards
self.shoot = function () {
var bullet = new MutantBullet();
bullet.x = self.x;
bullet.y = self.y + self.radius + bullet.height * 0.5;
mutantBullets.push(bullet);
game.addChild(bullet);
LK.getSound('mutantShoot').play();
};
// Take damage
self.hit = function () {
self.hp--;
LK.getSound('mutantHit').play();
LK.effects.flashObject(self, 0xffffff, 150);
if (self.hp <= 0) {
self.destroy();
return true;
}
return false;
};
return self;
});
// Mutant bullet class
var MutantBullet = Container.expand(function () {
var self = Container.call(this);
var bulletSprite = self.attachAsset('mutantBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = bulletSprite.width;
self.height = bulletSprite.height;
self.speed = 14;
self.update = function () {
if (typeof self.speedX === "number") {
self.x += self.speedX;
}
if (typeof self.speed === "number") {
self.y += self.speed;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181818
});
/****
* Game Code
****/
// Music
// Sound effects
// Mutant bullet: red ellipse
// Hero bullet: yellow box
// Mutant: green ellipse
// Hero: blue box
// Game variables
var hero;
var mutants = [];
var heroBullets = [];
var mutantBullets = [];
var lastHeroX = 0,
lastHeroY = 0;
var score = 0;
var scoreTxt;
var wave = 1;
var spawnTimer = 0;
var gameOver = false;
var bossSpawned = false;
// Score display
scoreTxt = new Text2('0', {
size: 120,
fill: "#fff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Start music
LK.playMusic('bgmusic');
// Create hero
hero = new Hero();
hero.x = 2048 / 2;
hero.y = 2732 - 350;
game.addChild(hero);
// Helper: spawn a wave of mutants
function spawnMutantWave() {
// Boss appears at score >= 100, only once per game
if (typeof bossSpawned === "undefined") bossSpawned = false;
if (score >= 100 && !bossSpawned) {
var boss = new Boss();
boss.x = 2048 / 2;
boss.y = -220;
mutants.push(boss);
game.addChild(boss);
bossSpawned = true;
} else {
var m = new Mutant();
// Center mutant horizontally, randomize a bit
m.x = 2048 / 2 + (Math.random() - 0.5) * 80;
m.y = -100 - Math.random() * 200;
mutants.push(m);
game.addChild(m);
wave++;
}
}
// Initial wave
spawnMutantWave();
// Touch/mouse drag controls removed -- hero is now controlled by tap-to-move
// Tap left/right half of screen to move hero horizontally by a fixed amount
game.down = function (x, y, obj) {
var minX = hero.radius + 20;
var maxX = 2048 - hero.radius - 20;
// Only move horizontally, keep Y fixed
var moveAmount = 220;
if (x < 2048 / 2) {
// Tap left half: move left
hero.x = Math.max(minX, hero.x - moveAmount);
} else {
// Tap right half: move right
hero.x = Math.min(maxX, hero.x + moveAmount);
}
};
game.move = null;
game.up = null;
// Main game loop
game.update = function () {
if (gameOver) return;
// Hero update
hero.update();
// Show fire rate level above hero
if (!hero.fireRateTxt) {
hero.fireRateTxt = new Text2('', {
size: 60,
fill: "#fff"
});
hero.fireRateTxt.anchor.set(0.5, 1);
game.addChild(hero.fireRateTxt);
}
hero.fireRateTxt.x = hero.x;
hero.fireRateTxt.y = hero.y - hero.radius - 30;
var fireRateLevel = Math.floor(score / 50);
if (fireRateLevel > 0) {
hero.fireRateTxt.setText("Lv." + (fireRateLevel + 1));
hero.fireRateTxt.visible = true;
} else {
hero.fireRateTxt.visible = false;
}
// Hero auto-shoots, fire rate improves every 50 points (min cooldown 4 ticks)
var minCooldown = 4;
var baseCooldown = 10;
var fireRateLevel = Math.floor(score / 50);
var heroCooldown = Math.max(baseCooldown - fireRateLevel * 2, minCooldown);
if (LK.ticks % heroCooldown === 0) {
hero.shoot();
}
// Mutant update
for (var i = mutants.length - 1; i >= 0; i--) {
var m = mutants[i];
m.update();
// Remove if off screen
if (m.y > 2732 + 100) {
m.destroy();
mutants.splice(i, 1);
continue;
}
// Mutant collides with hero (game over)
if (m.intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.getSound('heroHit').play();
gameOver = true;
LK.showGameOver();
return;
}
}
// Hero bullets update
for (var i = heroBullets.length - 1; i >= 0; i--) {
var b = heroBullets[i];
b.update();
// Remove if off screen
if (b.y < -100) {
b.destroy();
heroBullets.splice(i, 1);
continue;
}
// Check collision with mutants
var hit = false;
for (var j = mutants.length - 1; j >= 0; j--) {
var m = mutants[j];
if (b.intersects(m)) {
b.destroy();
heroBullets.splice(i, 1);
if (m.hit()) {
// Mutant destroyed
mutants.splice(j, 1);
score += 10;
scoreTxt.setText(score);
} else {
score += 2;
scoreTxt.setText(score);
}
hit = true;
break;
}
}
if (hit) continue;
}
// Mutant bullets update
for (var i = mutantBullets.length - 1; i >= 0; i--) {
var b = mutantBullets[i];
b.update();
// Remove if off screen
if (b.y > 2732 + 100) {
b.destroy();
mutantBullets.splice(i, 1);
continue;
}
// Check collision with hero
if (b.intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.getSound('heroHit').play();
b.destroy();
mutantBullets.splice(i, 1);
gameOver = true;
LK.showGameOver();
return;
}
}
// Spawn new wave if all mutants gone
if (mutants.length === 0 && spawnTimer === 0) {
spawnTimer = 40; // Wait 40 ticks before next wave
}
if (spawnTimer > 0) {
spawnTimer--;
if (spawnTimer === 0) {
spawnMutantWave();
}
}
};
// Reset game state on restart
game.on('reset', function () {
// Remove all objects
for (var i = 0; i < mutants.length; i++) mutants[i].destroy();
for (var i = 0; i < heroBullets.length; i++) heroBullets[i].destroy();
for (var i = 0; i < mutantBullets.length; i++) mutantBullets[i].destroy();
mutants = [];
heroBullets = [];
mutantBullets = [];
score = 0;
scoreTxt.setText(score);
wave = 1;
spawnTimer = 0;
gameOver = false;
bossSpawned = false;
hero.x = 2048 / 2;
hero.y = 2732 - 350;
spawnMutantWave();
LK.playMusic('bgmusic');
}); ===================================================================
--- original.js
+++ change.js
@@ -31,9 +31,9 @@
self.shootRing();
} else {
self.shoot();
}
- self.shootTimer = 36 + Math.floor(Math.random() * 24);
+ self.shootTimer = 60 + Math.floor(Math.random() * 40);
}
};
// Boss fires a spread of bullets downward (classic spread attack)
self.shoot = function () {