User prompt
enemy fall out to bottom after hit ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
more enemy appear
User prompt
enemy loop
User prompt
fix game
User prompt
fix enemy spawn
User prompt
boss escape out to upper screen after hit by player
User prompt
make enemy fall out to bottom screen after hit
User prompt
make enemy fall after hit ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'ReferenceError: currentWave is not defined' in or related to this line: 'currentWave++;' Line Number: 75
User prompt
bullet change to white color
User prompt
delete wave asset. make loop game logic
User prompt
fix wave
User prompt
fix collor bullet to yellow
User prompt
add background asset
User prompt
enemy are spider. make animation enemy the spider walking to player ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
enemy one shoot dead. boss 5x shoot dead
User prompt
change rule. no dash attack. make be a shooter game
User prompt
delete auto shoot
User prompt
delete hazzard asset
User prompt
fix auto shoot
User prompt
add new logic. player can auto shoot
User prompt
player get more strenght
User prompt
reduce enemy appear
User prompt
more speed dash ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Boss = Container.expand(function () { var self = Container.call(this); var bossGraphic = self.attachAsset('boss', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1.5; self.health = 10; self.attackCooldown = 0; self.attackPattern = 0; self.scoreValue = 2000; self.active = true; self.init = function (x, y) { self.x = x; self.y = y; return self; }; self.takeDamage = function () { if (!self.active) { return; } self.health--; // Flash boss LK.effects.flashObject(self, 0xffffff, 300); LK.getSound('hit').play(); if (self.health <= 0) { self.die(); } else { // Speed up as health decreases self.speed = 1.5 + (10 - self.health) * 0.2; } }; self.die = function () { if (!self.active) { return; } self.active = false; LK.getSound('bossDeath').play(); // Flash and fade out LK.effects.flashObject(self, 0xffff00, 500); tween(self, { alpha: 0 }, { duration: 1000, onFinish: function onFinish() { self.destroy(); } }); currentWave++; bossDefeated = true; nextWaveTimer = 180; // 3 seconds until next wave return self.scoreValue; }; self.update = function () { if (!self.active) { return; } // Move toward hero but more intelligently if (hero) { var dx = hero.x - self.x; var dy = hero.y - self.y; var dist = Math.sqrt(dx * dx + dy * dy); // Different movement patterns if (self.attackPattern === 0) { // Direct approach if (dist > 0) { self.x += dx / dist * self.speed; self.y += dy / dist * self.speed; } } else if (self.attackPattern === 1) { // Circle around var angle = Math.atan2(dy, dx) + Math.PI / 4; self.x += Math.cos(angle) * self.speed * 1.5; self.y += Math.sin(angle) * self.speed * 1.5; } else if (self.attackPattern === 2) { // Charge attack if (self.attackCooldown > 30) { self.x += dx / dist * self.speed * 2.5; self.y += dy / dist * self.speed * 2.5; } else { // Wait } } // Check for collision with hero if (hero.invulnerable <= 0 && !hero.isDashing) { if (self.intersects(hero)) { hero.takeDamage(); } } } // Attack pattern cooldown self.attackCooldown--; if (self.attackCooldown <= 0) { self.attackPattern = (self.attackPattern + 1) % 3; self.attackCooldown = 120; // 2 seconds per pattern } // Keep within screen bounds self.x = Math.max(100, Math.min(2048 - 100, self.x)); self.y = Math.max(100, Math.min(2732 - 100, self.y)); }; return self; }); var DashTrail = Container.expand(function () { var self = Container.call(this); var trailGraphic = self.attachAsset('dashTrail', { anchorX: 0.5, anchorY: 0.5, alpha: 0.7 }); self.init = function (x, y) { self.x = x; self.y = y; self.lifetime = 20; // frames the trail will live return self; }; self.update = function () { self.lifetime--; trailGraphic.alpha = self.lifetime / 20 * 0.7; if (self.lifetime <= 0) { self.destroy(); } }; return self; }); var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphic = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.health = 1; self.scoreValue = 100; self.active = true; self.init = function (x, y) { self.x = x; self.y = y; return self; }; self.takeDamage = function () { if (!self.active) { return; } self.health--; if (self.health <= 0) { self.die(); } else { // Flash enemy LK.effects.flashObject(self, 0xffffff, 200); } }; self.die = function () { if (!self.active) { return; } self.active = false; LK.getSound('hit').play(); // Flash and fade out tween(self, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { self.destroy(); } }); return self.scoreValue; }; self.update = function () { if (!self.active) { return; } // Move toward hero if (hero && !hero.isDashing) { var dx = hero.x - self.x; var dy = hero.y - self.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist > 0) { self.x += dx / dist * self.speed; self.y += dy / dist * self.speed; } } // Check for collision with hero if (hero && !hero.isDashing && hero.invulnerable <= 0) { if (self.intersects(hero)) { hero.takeDamage(); } } }; return self; }); var Hazard = Container.expand(function () { var self = Container.call(this); var hazardGraphic = self.attachAsset('hazard', { anchorX: 0.5, anchorY: 0.5 }); self.active = true; self.rotateSpeed = 0.03; self.init = function (x, y) { self.x = x; self.y = y; return self; }; self.update = function () { if (!self.active) { return; } // Rotate hazard hazardGraphic.rotation += self.rotateSpeed; // Check for collision with hero if (hero && hero.invulnerable <= 0 && self.intersects(hero)) { if (hero.isDashing) { // Destroy hazard if hero is dashing self.destroy(); self.active = false; } else { hero.takeDamage(); } } }; return self; }); var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphic = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.dashSpeed = 40; self.dashDistance = 500; self.isDashing = false; self.dashCooldown = 0; self.health = 3; self.invulnerable = 0; self.combo = 0; self.score = 0; self.dashToPoint = function (targetX, targetY) { if (self.dashCooldown > 0 || self.isDashing) { return; } var dx = targetX - self.x; var dy = targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); // Normalize direction var dirX = dx / distance; var dirY = dy / distance; // Set dash parameters self.isDashing = true; self.dashDirection = { x: dirX, y: dirY }; self.dashRemaining = self.dashDistance; self.dashCooldown = 15; // frames before next dash // Play dash sound LK.getSound('dash').play(); }; self.takeDamage = function () { if (self.invulnerable > 0) { return; } self.health--; self.invulnerable = 60; // invulnerable for 1 second self.combo = 0; // Reset combo // Flash hero red LK.effects.flashObject(self, 0xff0000, 500); // Play damage sound LK.getSound('damage').play(); if (self.health <= 0) { LK.showGameOver(); } }; self.addScore = function (points) { self.combo++; var comboMultiplier = Math.min(4, 1 + self.combo * 0.1); var scoreToAdd = Math.floor(points * comboMultiplier); self.score += scoreToAdd; LK.setScore(self.score); }; self.update = function () { // Handle dash movement if (self.isDashing) { var moveX = self.dashDirection.x * self.dashSpeed; var moveY = self.dashDirection.y * self.dashSpeed; self.x += moveX; self.y += moveY; self.dashRemaining -= self.dashSpeed; // Create trail effect if (LK.ticks % 2 === 0) { var trail = new DashTrail().init(self.x, self.y); game.addChild(trail); trails.push(trail); } // End dash if we've gone far enough if (self.dashRemaining <= 0) { self.isDashing = false; } } // Keep within screen bounds self.x = Math.max(50, Math.min(2048 - 50, self.x)); self.y = Math.max(50, Math.min(2732 - 50, self.y)); // Cooldowns if (self.dashCooldown > 0) { self.dashCooldown--; } if (self.invulnerable > 0) { self.invulnerable--; // Flicker effect during invulnerability heroGraphic.alpha = LK.ticks % 6 < 3 ? 0.4 : 1; } else { heroGraphic.alpha = 1; } }; return self; }); var PowerUp = Container.expand(function () { var self = Container.call(this); var powerUpGraphic = self.attachAsset('powerUp', { anchorX: 0.5, anchorY: 0.5 }); self.type = 'health'; // Default type self.active = true; self.lifetime = 300; // 5 seconds self.init = function (x, y, type) { self.x = x; self.y = y; self.type = type || self.type; // Set color based on type if (self.type === 'health') { powerUpGraphic.tint = 0x2ecc71; // Green } else if (self.type === 'speed') { powerUpGraphic.tint = 0x3498db; // Blue } else if (self.type === 'power') { powerUpGraphic.tint = 0xe74c3c; // Red } return self; }; self.collect = function () { if (!self.active) { return; } self.active = false; LK.getSound('powerup').play(); if (self.type === 'health' && hero.health < 3) { hero.health++; } else if (self.type === 'speed') { hero.dashSpeed = 50; // Faster dash hero.dashDistance = 600; // Longer dash // Reset after 10 seconds LK.setTimeout(function () { if (hero) { hero.dashSpeed = 40; hero.dashDistance = 500; } }, 10000); } else if (self.type === 'power') { // Clear all enemies for (var i = enemies.length - 1; i >= 0; i--) { if (enemies[i].active) { var points = enemies[i].die(); hero.addScore(points); } } } // Flash and fade out tween(self, { alpha: 0, scaleX: 2, scaleY: 2 }, { duration: 300, onFinish: function onFinish() { self.destroy(); } }); }; self.update = function () { if (!self.active) { return; } // Floating animation self.y += Math.sin(LK.ticks * 0.1) * 0.5; // Rotate slowly powerUpGraphic.rotation += 0.02; // Check for collision with hero if (hero && (hero.intersects(self) || hero.isDashing && self.distanceTo(hero) < 100)) { self.collect(); } // Expire after lifetime self.lifetime--; if (self.lifetime <= 0) { tween(self, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { self.destroy(); } }); self.active = false; } }; self.distanceTo = function (target) { var dx = target.x - self.x; var dy = target.y - self.y; return Math.sqrt(dx * dx + dy * dy); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000022 }); /**** * Game Code ****/ // Game state variables var hero; var enemies = []; var powerUps = []; var hazards = []; var trails = []; var currentWave = 1; var nextWaveTimer = 0; var spawnTimer = 0; var bossDefeated = false; var swipeStart = { x: 0, y: 0 }; var isSwipeActive = false; // UI elements var scoreTxt; var waveTxt; var healthTxt; var comboTxt; // Game constants var SPAWN_INTERVAL = 60; // Frames between enemy spawns var POWER_UP_CHANCE = 0.15; // Chance to spawn power-up on enemy defeat var WAVE_ENEMY_COUNT = 10; // Enemies per wave // Initialize game elements function initGame() { // Create hero hero = new Hero(); hero.x = 2048 / 2; hero.y = 2732 / 2; game.addChild(hero); // Create UI elements scoreTxt = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreTxt.anchor.set(0, 0); LK.gui.topRight.addChild(scoreTxt); waveTxt = new Text2('Wave: 1', { size: 60, fill: 0xFFFFFF }); waveTxt.anchor.set(1, 0); LK.gui.top.addChild(waveTxt); healthTxt = new Text2('❤️❤️❤️', { size: 60, fill: 0xFFFFFF }); healthTxt.anchor.set(0, 0); LK.gui.bottom.addChild(healthTxt); comboTxt = new Text2('Combo: 0x', { size: 60, fill: 0xFFFFFF }); comboTxt.anchor.set(1, 0); LK.gui.bottom.addChild(comboTxt); // Start the first wave startNewWave(); // Play background music LK.playMusic('gameMusic', { fade: { start: 0, end: 0.5, duration: 1000 } }); } // Start a new wave of enemies function startNewWave() { waveTxt.setText('Wave: ' + currentWave); if (currentWave % 3 === 0) { // Boss wave spawnBoss(); } else { // Regular wave spawnTimer = 0; } // Add some hazards for (var i = 0; i < Math.min(currentWave, 5); i++) { spawnHazard(); } } // Spawn a regular enemy function spawnEnemy() { var edge = Math.floor(Math.random() * 4); // 0: top, 1: right, 2: bottom, 3: left var x, y; switch (edge) { case 0: // Top x = Math.random() * 2048; y = -50; break; case 1: // Right x = 2048 + 50; y = Math.random() * 2732; break; case 2: // Bottom x = Math.random() * 2048; y = 2732 + 50; break; case 3: // Left x = -50; y = Math.random() * 2732; break; } var enemy = new Enemy().init(x, y); enemy.speed = 2 + currentWave * 0.3; // Speed increases with wave if (currentWave > 2) { enemy.health = Math.min(3, 1 + Math.floor(currentWave / 3)); } game.addChild(enemy); enemies.push(enemy); } // Spawn a boss function spawnBoss() { var boss = new Boss().init(2048 / 2, -200); boss.health = 10 + currentWave / 3; game.addChild(boss); enemies.push(boss); // Make a dramatic entrance tween(boss, { y: 400 }, { duration: 2000, easing: tween.bounceOut }); } // Spawn a hazard function spawnHazard() { var x = 200 + Math.random() * (2048 - 400); var y = 200 + Math.random() * (2732 - 400); // Make sure it's not too close to the hero var dx = x - hero.x; var dy = y - hero.y; if (Math.sqrt(dx * dx + dy * dy) < 300) { x = x < 1024 ? x + 600 : x - 600; y = y < 1366 ? y + 600 : y - 600; } var hazard = new Hazard().init(x, y); game.addChild(hazard); hazards.push(hazard); } // Spawn a power-up function spawnPowerUp(x, y) { var types = ['health', 'speed', 'power']; var type = types[Math.floor(Math.random() * types.length)]; var powerUp = new PowerUp().init(x, y, type); game.addChild(powerUp); powerUps.push(powerUp); } // Handle touch/mouse down game.down = function (x, y, obj) { isSwipeActive = true; swipeStart.x = x; swipeStart.y = y; }; // Handle touch/mouse up game.up = function (x, y, obj) { if (isSwipeActive) { // Calculate swipe direction and distance var dx = x - swipeStart.x; var dy = y - swipeStart.y; var distance = Math.sqrt(dx * dx + dy * dy); // If it's a significant swipe, dash in that direction if (distance > 50) { // Calculate target point to dash towards var targetX = hero.x + dx * 2; var targetY = hero.y + dy * 2; hero.dashToPoint(targetX, targetY); } isSwipeActive = false; } }; // Handle touch/mouse move game.move = function (x, y, obj) { // We'll use swipe up/down instead of tracking movement }; // Main game update loop game.update = function () { // Update UI scoreTxt.setText('Score: ' + LK.getScore()); comboTxt.setText('Combo: ' + hero.combo + 'x'); // Update health display var healthStr = ''; for (var i = 0; i < hero.health; i++) { healthStr += '❤️'; } healthTxt.setText(healthStr); // Spawn enemies if (currentWave % 3 !== 0 || bossDefeated) { spawnTimer++; if (spawnTimer >= SPAWN_INTERVAL && enemies.length < WAVE_ENEMY_COUNT + Math.min(10, currentWave)) { spawnEnemy(); spawnTimer = 0; } } // Handle next wave if (nextWaveTimer > 0) { nextWaveTimer--; if (nextWaveTimer === 0) { bossDefeated = false; startNewWave(); } } else if (enemies.length === 0 && currentWave % 3 !== 0) { // Wave completed currentWave++; nextWaveTimer = 120; // 2 seconds until next wave } // Update game objects updateGameObjects(); // Detect collisions between hero dash and enemies if (hero.isDashing) { for (var i = enemies.length - 1; i >= 0; i--) { var enemy = enemies[i]; if (enemy.active && hero.intersects(enemy)) { enemy.takeDamage(); if (enemy.health <= 0) { // Award points hero.addScore(enemy.scoreValue); // Maybe spawn a power-up if (Math.random() < POWER_UP_CHANCE) { spawnPowerUp(enemy.x, enemy.y); } // Remove enemy from array enemies.splice(i, 1); } } } } // Clean up destroyed objects cleanupDestroyedObjects(); }; // Update all game objects function updateGameObjects() { // Update hero if (hero) { hero.update(); } // Update enemies for (var i = 0; i < enemies.length; i++) { if (enemies[i]) { enemies[i].update(); } } // Update power-ups for (var i = 0; i < powerUps.length; i++) { if (powerUps[i]) { powerUps[i].update(); } } // Update hazards for (var i = 0; i < hazards.length; i++) { if (hazards[i]) { hazards[i].update(); } } // Update trails for (var i = 0; i < trails.length; i++) { if (trails[i]) { trails[i].update(); } } } // Clean up destroyed objects function cleanupDestroyedObjects() { // Clean up destroyed enemies for (var i = enemies.length - 1; i >= 0; i--) { if (!enemies[i] || !enemies[i].parent) { enemies.splice(i, 1); } } // Clean up destroyed power-ups for (var i = powerUps.length - 1; i >= 0; i--) { if (!powerUps[i] || !powerUps[i].parent) { powerUps.splice(i, 1); } } // Clean up destroyed hazards for (var i = hazards.length - 1; i >= 0; i--) { if (!hazards[i] || !hazards[i].parent) { hazards.splice(i, 1); } } // Clean up destroyed trails for (var i = trails.length - 1; i >= 0; i--) { if (!trails[i] || !trails[i].parent) { trails.splice(i, 1); } } } // Initialize the game initGame();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Boss = Container.expand(function () {
var self = Container.call(this);
var bossGraphic = self.attachAsset('boss', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1.5;
self.health = 10;
self.attackCooldown = 0;
self.attackPattern = 0;
self.scoreValue = 2000;
self.active = true;
self.init = function (x, y) {
self.x = x;
self.y = y;
return self;
};
self.takeDamage = function () {
if (!self.active) {
return;
}
self.health--;
// Flash boss
LK.effects.flashObject(self, 0xffffff, 300);
LK.getSound('hit').play();
if (self.health <= 0) {
self.die();
} else {
// Speed up as health decreases
self.speed = 1.5 + (10 - self.health) * 0.2;
}
};
self.die = function () {
if (!self.active) {
return;
}
self.active = false;
LK.getSound('bossDeath').play();
// Flash and fade out
LK.effects.flashObject(self, 0xffff00, 500);
tween(self, {
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
self.destroy();
}
});
currentWave++;
bossDefeated = true;
nextWaveTimer = 180; // 3 seconds until next wave
return self.scoreValue;
};
self.update = function () {
if (!self.active) {
return;
}
// Move toward hero but more intelligently
if (hero) {
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var dist = Math.sqrt(dx * dx + dy * dy);
// Different movement patterns
if (self.attackPattern === 0) {
// Direct approach
if (dist > 0) {
self.x += dx / dist * self.speed;
self.y += dy / dist * self.speed;
}
} else if (self.attackPattern === 1) {
// Circle around
var angle = Math.atan2(dy, dx) + Math.PI / 4;
self.x += Math.cos(angle) * self.speed * 1.5;
self.y += Math.sin(angle) * self.speed * 1.5;
} else if (self.attackPattern === 2) {
// Charge attack
if (self.attackCooldown > 30) {
self.x += dx / dist * self.speed * 2.5;
self.y += dy / dist * self.speed * 2.5;
} else {
// Wait
}
}
// Check for collision with hero
if (hero.invulnerable <= 0 && !hero.isDashing) {
if (self.intersects(hero)) {
hero.takeDamage();
}
}
}
// Attack pattern cooldown
self.attackCooldown--;
if (self.attackCooldown <= 0) {
self.attackPattern = (self.attackPattern + 1) % 3;
self.attackCooldown = 120; // 2 seconds per pattern
}
// Keep within screen bounds
self.x = Math.max(100, Math.min(2048 - 100, self.x));
self.y = Math.max(100, Math.min(2732 - 100, self.y));
};
return self;
});
var DashTrail = Container.expand(function () {
var self = Container.call(this);
var trailGraphic = self.attachAsset('dashTrail', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.7
});
self.init = function (x, y) {
self.x = x;
self.y = y;
self.lifetime = 20; // frames the trail will live
return self;
};
self.update = function () {
self.lifetime--;
trailGraphic.alpha = self.lifetime / 20 * 0.7;
if (self.lifetime <= 0) {
self.destroy();
}
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphic = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.health = 1;
self.scoreValue = 100;
self.active = true;
self.init = function (x, y) {
self.x = x;
self.y = y;
return self;
};
self.takeDamage = function () {
if (!self.active) {
return;
}
self.health--;
if (self.health <= 0) {
self.die();
} else {
// Flash enemy
LK.effects.flashObject(self, 0xffffff, 200);
}
};
self.die = function () {
if (!self.active) {
return;
}
self.active = false;
LK.getSound('hit').play();
// Flash and fade out
tween(self, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
return self.scoreValue;
};
self.update = function () {
if (!self.active) {
return;
}
// Move toward hero
if (hero && !hero.isDashing) {
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist > 0) {
self.x += dx / dist * self.speed;
self.y += dy / dist * self.speed;
}
}
// Check for collision with hero
if (hero && !hero.isDashing && hero.invulnerable <= 0) {
if (self.intersects(hero)) {
hero.takeDamage();
}
}
};
return self;
});
var Hazard = Container.expand(function () {
var self = Container.call(this);
var hazardGraphic = self.attachAsset('hazard', {
anchorX: 0.5,
anchorY: 0.5
});
self.active = true;
self.rotateSpeed = 0.03;
self.init = function (x, y) {
self.x = x;
self.y = y;
return self;
};
self.update = function () {
if (!self.active) {
return;
}
// Rotate hazard
hazardGraphic.rotation += self.rotateSpeed;
// Check for collision with hero
if (hero && hero.invulnerable <= 0 && self.intersects(hero)) {
if (hero.isDashing) {
// Destroy hazard if hero is dashing
self.destroy();
self.active = false;
} else {
hero.takeDamage();
}
}
};
return self;
});
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphic = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.dashSpeed = 40;
self.dashDistance = 500;
self.isDashing = false;
self.dashCooldown = 0;
self.health = 3;
self.invulnerable = 0;
self.combo = 0;
self.score = 0;
self.dashToPoint = function (targetX, targetY) {
if (self.dashCooldown > 0 || self.isDashing) {
return;
}
var dx = targetX - self.x;
var dy = targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Normalize direction
var dirX = dx / distance;
var dirY = dy / distance;
// Set dash parameters
self.isDashing = true;
self.dashDirection = {
x: dirX,
y: dirY
};
self.dashRemaining = self.dashDistance;
self.dashCooldown = 15; // frames before next dash
// Play dash sound
LK.getSound('dash').play();
};
self.takeDamage = function () {
if (self.invulnerable > 0) {
return;
}
self.health--;
self.invulnerable = 60; // invulnerable for 1 second
self.combo = 0; // Reset combo
// Flash hero red
LK.effects.flashObject(self, 0xff0000, 500);
// Play damage sound
LK.getSound('damage').play();
if (self.health <= 0) {
LK.showGameOver();
}
};
self.addScore = function (points) {
self.combo++;
var comboMultiplier = Math.min(4, 1 + self.combo * 0.1);
var scoreToAdd = Math.floor(points * comboMultiplier);
self.score += scoreToAdd;
LK.setScore(self.score);
};
self.update = function () {
// Handle dash movement
if (self.isDashing) {
var moveX = self.dashDirection.x * self.dashSpeed;
var moveY = self.dashDirection.y * self.dashSpeed;
self.x += moveX;
self.y += moveY;
self.dashRemaining -= self.dashSpeed;
// Create trail effect
if (LK.ticks % 2 === 0) {
var trail = new DashTrail().init(self.x, self.y);
game.addChild(trail);
trails.push(trail);
}
// End dash if we've gone far enough
if (self.dashRemaining <= 0) {
self.isDashing = false;
}
}
// Keep within screen bounds
self.x = Math.max(50, Math.min(2048 - 50, self.x));
self.y = Math.max(50, Math.min(2732 - 50, self.y));
// Cooldowns
if (self.dashCooldown > 0) {
self.dashCooldown--;
}
if (self.invulnerable > 0) {
self.invulnerable--;
// Flicker effect during invulnerability
heroGraphic.alpha = LK.ticks % 6 < 3 ? 0.4 : 1;
} else {
heroGraphic.alpha = 1;
}
};
return self;
});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphic = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
self.type = 'health'; // Default type
self.active = true;
self.lifetime = 300; // 5 seconds
self.init = function (x, y, type) {
self.x = x;
self.y = y;
self.type = type || self.type;
// Set color based on type
if (self.type === 'health') {
powerUpGraphic.tint = 0x2ecc71; // Green
} else if (self.type === 'speed') {
powerUpGraphic.tint = 0x3498db; // Blue
} else if (self.type === 'power') {
powerUpGraphic.tint = 0xe74c3c; // Red
}
return self;
};
self.collect = function () {
if (!self.active) {
return;
}
self.active = false;
LK.getSound('powerup').play();
if (self.type === 'health' && hero.health < 3) {
hero.health++;
} else if (self.type === 'speed') {
hero.dashSpeed = 50; // Faster dash
hero.dashDistance = 600; // Longer dash
// Reset after 10 seconds
LK.setTimeout(function () {
if (hero) {
hero.dashSpeed = 40;
hero.dashDistance = 500;
}
}, 10000);
} else if (self.type === 'power') {
// Clear all enemies
for (var i = enemies.length - 1; i >= 0; i--) {
if (enemies[i].active) {
var points = enemies[i].die();
hero.addScore(points);
}
}
}
// Flash and fade out
tween(self, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
};
self.update = function () {
if (!self.active) {
return;
}
// Floating animation
self.y += Math.sin(LK.ticks * 0.1) * 0.5;
// Rotate slowly
powerUpGraphic.rotation += 0.02;
// Check for collision with hero
if (hero && (hero.intersects(self) || hero.isDashing && self.distanceTo(hero) < 100)) {
self.collect();
}
// Expire after lifetime
self.lifetime--;
if (self.lifetime <= 0) {
tween(self, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
self.active = false;
}
};
self.distanceTo = function (target) {
var dx = target.x - self.x;
var dy = target.y - self.y;
return Math.sqrt(dx * dx + dy * dy);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000022
});
/****
* Game Code
****/
// Game state variables
var hero;
var enemies = [];
var powerUps = [];
var hazards = [];
var trails = [];
var currentWave = 1;
var nextWaveTimer = 0;
var spawnTimer = 0;
var bossDefeated = false;
var swipeStart = {
x: 0,
y: 0
};
var isSwipeActive = false;
// UI elements
var scoreTxt;
var waveTxt;
var healthTxt;
var comboTxt;
// Game constants
var SPAWN_INTERVAL = 60; // Frames between enemy spawns
var POWER_UP_CHANCE = 0.15; // Chance to spawn power-up on enemy defeat
var WAVE_ENEMY_COUNT = 10; // Enemies per wave
// Initialize game elements
function initGame() {
// Create hero
hero = new Hero();
hero.x = 2048 / 2;
hero.y = 2732 / 2;
game.addChild(hero);
// Create UI elements
scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreTxt);
waveTxt = new Text2('Wave: 1', {
size: 60,
fill: 0xFFFFFF
});
waveTxt.anchor.set(1, 0);
LK.gui.top.addChild(waveTxt);
healthTxt = new Text2('❤️❤️❤️', {
size: 60,
fill: 0xFFFFFF
});
healthTxt.anchor.set(0, 0);
LK.gui.bottom.addChild(healthTxt);
comboTxt = new Text2('Combo: 0x', {
size: 60,
fill: 0xFFFFFF
});
comboTxt.anchor.set(1, 0);
LK.gui.bottom.addChild(comboTxt);
// Start the first wave
startNewWave();
// Play background music
LK.playMusic('gameMusic', {
fade: {
start: 0,
end: 0.5,
duration: 1000
}
});
}
// Start a new wave of enemies
function startNewWave() {
waveTxt.setText('Wave: ' + currentWave);
if (currentWave % 3 === 0) {
// Boss wave
spawnBoss();
} else {
// Regular wave
spawnTimer = 0;
}
// Add some hazards
for (var i = 0; i < Math.min(currentWave, 5); i++) {
spawnHazard();
}
}
// Spawn a regular enemy
function spawnEnemy() {
var edge = Math.floor(Math.random() * 4); // 0: top, 1: right, 2: bottom, 3: left
var x, y;
switch (edge) {
case 0:
// Top
x = Math.random() * 2048;
y = -50;
break;
case 1:
// Right
x = 2048 + 50;
y = Math.random() * 2732;
break;
case 2:
// Bottom
x = Math.random() * 2048;
y = 2732 + 50;
break;
case 3:
// Left
x = -50;
y = Math.random() * 2732;
break;
}
var enemy = new Enemy().init(x, y);
enemy.speed = 2 + currentWave * 0.3; // Speed increases with wave
if (currentWave > 2) {
enemy.health = Math.min(3, 1 + Math.floor(currentWave / 3));
}
game.addChild(enemy);
enemies.push(enemy);
}
// Spawn a boss
function spawnBoss() {
var boss = new Boss().init(2048 / 2, -200);
boss.health = 10 + currentWave / 3;
game.addChild(boss);
enemies.push(boss);
// Make a dramatic entrance
tween(boss, {
y: 400
}, {
duration: 2000,
easing: tween.bounceOut
});
}
// Spawn a hazard
function spawnHazard() {
var x = 200 + Math.random() * (2048 - 400);
var y = 200 + Math.random() * (2732 - 400);
// Make sure it's not too close to the hero
var dx = x - hero.x;
var dy = y - hero.y;
if (Math.sqrt(dx * dx + dy * dy) < 300) {
x = x < 1024 ? x + 600 : x - 600;
y = y < 1366 ? y + 600 : y - 600;
}
var hazard = new Hazard().init(x, y);
game.addChild(hazard);
hazards.push(hazard);
}
// Spawn a power-up
function spawnPowerUp(x, y) {
var types = ['health', 'speed', 'power'];
var type = types[Math.floor(Math.random() * types.length)];
var powerUp = new PowerUp().init(x, y, type);
game.addChild(powerUp);
powerUps.push(powerUp);
}
// Handle touch/mouse down
game.down = function (x, y, obj) {
isSwipeActive = true;
swipeStart.x = x;
swipeStart.y = y;
};
// Handle touch/mouse up
game.up = function (x, y, obj) {
if (isSwipeActive) {
// Calculate swipe direction and distance
var dx = x - swipeStart.x;
var dy = y - swipeStart.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// If it's a significant swipe, dash in that direction
if (distance > 50) {
// Calculate target point to dash towards
var targetX = hero.x + dx * 2;
var targetY = hero.y + dy * 2;
hero.dashToPoint(targetX, targetY);
}
isSwipeActive = false;
}
};
// Handle touch/mouse move
game.move = function (x, y, obj) {
// We'll use swipe up/down instead of tracking movement
};
// Main game update loop
game.update = function () {
// Update UI
scoreTxt.setText('Score: ' + LK.getScore());
comboTxt.setText('Combo: ' + hero.combo + 'x');
// Update health display
var healthStr = '';
for (var i = 0; i < hero.health; i++) {
healthStr += '❤️';
}
healthTxt.setText(healthStr);
// Spawn enemies
if (currentWave % 3 !== 0 || bossDefeated) {
spawnTimer++;
if (spawnTimer >= SPAWN_INTERVAL && enemies.length < WAVE_ENEMY_COUNT + Math.min(10, currentWave)) {
spawnEnemy();
spawnTimer = 0;
}
}
// Handle next wave
if (nextWaveTimer > 0) {
nextWaveTimer--;
if (nextWaveTimer === 0) {
bossDefeated = false;
startNewWave();
}
} else if (enemies.length === 0 && currentWave % 3 !== 0) {
// Wave completed
currentWave++;
nextWaveTimer = 120; // 2 seconds until next wave
}
// Update game objects
updateGameObjects();
// Detect collisions between hero dash and enemies
if (hero.isDashing) {
for (var i = enemies.length - 1; i >= 0; i--) {
var enemy = enemies[i];
if (enemy.active && hero.intersects(enemy)) {
enemy.takeDamage();
if (enemy.health <= 0) {
// Award points
hero.addScore(enemy.scoreValue);
// Maybe spawn a power-up
if (Math.random() < POWER_UP_CHANCE) {
spawnPowerUp(enemy.x, enemy.y);
}
// Remove enemy from array
enemies.splice(i, 1);
}
}
}
}
// Clean up destroyed objects
cleanupDestroyedObjects();
};
// Update all game objects
function updateGameObjects() {
// Update hero
if (hero) {
hero.update();
}
// Update enemies
for (var i = 0; i < enemies.length; i++) {
if (enemies[i]) {
enemies[i].update();
}
}
// Update power-ups
for (var i = 0; i < powerUps.length; i++) {
if (powerUps[i]) {
powerUps[i].update();
}
}
// Update hazards
for (var i = 0; i < hazards.length; i++) {
if (hazards[i]) {
hazards[i].update();
}
}
// Update trails
for (var i = 0; i < trails.length; i++) {
if (trails[i]) {
trails[i].update();
}
}
}
// Clean up destroyed objects
function cleanupDestroyedObjects() {
// Clean up destroyed enemies
for (var i = enemies.length - 1; i >= 0; i--) {
if (!enemies[i] || !enemies[i].parent) {
enemies.splice(i, 1);
}
}
// Clean up destroyed power-ups
for (var i = powerUps.length - 1; i >= 0; i--) {
if (!powerUps[i] || !powerUps[i].parent) {
powerUps.splice(i, 1);
}
}
// Clean up destroyed hazards
for (var i = hazards.length - 1; i >= 0; i--) {
if (!hazards[i] || !hazards[i].parent) {
hazards.splice(i, 1);
}
}
// Clean up destroyed trails
for (var i = trails.length - 1; i >= 0; i--) {
if (!trails[i] || !trails[i].parent) {
trails.splice(i, 1);
}
}
}
// Initialize the game
initGame();
colored spider. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
white silk web. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
amazing spider web on tree branch. anime image. green landscape Single Game Texture. In-Game asset. 2d.
flyn lady bug 2d cartoon objek. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
flyin evil woodpecker bird. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows