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
****/
// 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 () {
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;
// 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() {
// Only spawn a single mutant at a time
if (mutants.length >= 1) return;
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();
// Hero auto-shoots every 10 ticks
if (LK.ticks % 10 === 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
m.destroy();
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;
hero.x = 2048 / 2;
hero.y = 2732 - 350;
spawnMutantWave();
LK.playMusic('bgmusic');
}); ===================================================================
--- original.js
+++ change.js
@@ -162,17 +162,21 @@
}
// Initial wave
spawnMutantWave();
// Touch/mouse drag controls removed -- hero is now controlled by tap-to-move
-// Tap anywhere to move hero to that location (clamped to game area)
+// Tap left/right half of screen to move hero horizontally by a fixed amount
game.down = function (x, y, obj) {
- // Clamp hero inside game area, avoid top 100px and bottom 100px
var minX = hero.radius + 20;
var maxX = 2048 - hero.radius - 20;
- var minY = 120 + hero.radius;
- var maxY = 2732 - hero.radius - 40;
- hero.x = Math.max(minX, Math.min(maxX, x));
- hero.y = Math.max(minY, Math.min(maxY, y));
+ // 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