User prompt
enemy act jumping ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
player can move left and right
User prompt
enemy death one hit
User prompt
reduce number of enemy
User prompt
Please fix the bug: 'Uncaught TypeError: setTimeout is not a function' in or related to this line: 'setTimeout(function () {' Line Number: 113
Code edit (1 edits merged)
Please save this source code
User prompt
Shadow Blade Runner
Initial prompt
hack and slash game side scroller
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Enemy = Container.expand(function (type) {
var self = Container.call(this);
var assetName = type === 'armored' ? 'armoredEnemy' : 'basicEnemy';
var enemyGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 1.0
});
self.type = type || 'basic';
self.speed = type === 'armored' ? -3 : -4;
self.maxHealth = type === 'armored' ? 3 : 1;
self.health = self.maxHealth;
self.damage = type === 'armored' ? 30 : 20;
self.points = type === 'armored' ? 30 : 10;
self.takeDamage = function (damage) {
self.health -= damage;
LK.effects.flashObject(self, 0xffffff, 200);
LK.getSound('enemyHit').play();
if (self.health <= 0) {
// Award points
LK.setScore(LK.getScore() + self.points);
// Chance to drop power-up
if (Math.random() < 0.15) {
var powerUp = game.addChild(new PowerUp());
powerUp.x = self.x;
powerUp.y = self.y - 20;
powerUps.push(powerUp);
}
// Remove from enemies array
var index = enemies.indexOf(self);
if (index > -1) {
enemies.splice(index, 1);
}
self.destroy();
}
};
self.update = function () {
self.x += self.speed;
// Check collision with player
if (self.intersects(player) && !player.invulnerable) {
player.takeDamage(self.damage);
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
self.maxHealth = 100;
self.health = self.maxHealth;
self.slashDamage = 1;
self.slashRange = 150;
self.isSlashing = false;
self.slashCooldown = 0;
self.invulnerable = false;
self.invulnerabilityTime = 0;
self.slash = function () {
if (self.slashCooldown <= 0 && !self.isSlashing) {
self.isSlashing = true;
self.slashCooldown = 20; // 1/3 second at 60fps
// Create slash effect
var slashEffect = game.addChild(LK.getAsset('slashEffect', {
anchorX: 0.5,
anchorY: 0.5
}));
slashEffect.x = self.x + 75;
slashEffect.y = self.y - 60;
slashEffect.alpha = 0.8;
// Animate slash effect
tween(slashEffect, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 200,
onFinish: function onFinish() {
slashEffect.destroy();
}
});
LK.getSound('slash').play();
// Check for enemy hits
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
var distance = Math.sqrt(Math.pow(enemy.x - self.x, 2) + Math.pow(enemy.y - self.y, 2));
if (distance < self.slashRange && enemy.x > self.x - 50) {
enemy.takeDamage(self.slashDamage);
}
}
setTimeout(function () {
self.isSlashing = false;
}, 200);
}
};
self.takeDamage = function (damage) {
if (!self.invulnerable) {
self.health -= damage;
self.invulnerable = true;
self.invulnerabilityTime = 120; // 2 seconds at 60fps
// Flash effect
LK.effects.flashObject(self, 0xff0000, 500);
if (self.health <= 0) {
self.health = 0;
LK.showGameOver();
}
}
};
self.update = function () {
if (self.slashCooldown > 0) {
self.slashCooldown--;
}
if (self.invulnerabilityTime > 0) {
self.invulnerabilityTime--;
if (self.invulnerabilityTime <= 0) {
self.invulnerable = false;
}
}
};
return self;
});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -2;
self.bobOffset = 0;
self.update = function () {
self.x += self.speed;
self.bobOffset += 0.1;
self.y += Math.sin(self.bobOffset) * 0.5;
// Check collision with player
if (self.intersects(player)) {
self.collect();
}
};
self.collect = function () {
LK.getSound('powerUpSound').play();
// Random power-up effect
var powerType = Math.floor(Math.random() * 3);
switch (powerType) {
case 0:
// Increased damage
player.slashDamage += 1;
break;
case 1:
// Wider slash range
player.slashRange += 50;
break;
case 2:
// Temporary invincibility
player.invulnerable = true;
player.invulnerabilityTime = 300; // 5 seconds
break;
}
// Remove from powerUps array
var index = powerUps.indexOf(self);
if (index > -1) {
powerUps.splice(index, 1);
}
self.destroy();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// Game variables
var player;
var enemies = [];
var powerUps = [];
var enemySpawnTimer = 0;
var enemySpawnRate = 120; // Start spawning every 2 seconds
var gameTime = 0;
var healthBar;
var healthBarBg;
// Create UI elements
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
scoreTxt.x = 120;
scoreTxt.y = 50;
LK.gui.topLeft.addChild(scoreTxt);
// Create health bar background
healthBarBg = game.addChild(LK.getAsset('healthBarBg', {
anchorX: 0,
anchorY: 0
}));
healthBarBg.x = 120;
healthBarBg.y = 120;
// Create health bar
healthBar = game.addChild(LK.getAsset('healthBar', {
anchorX: 0,
anchorY: 0
}));
healthBar.x = 122;
healthBar.y = 122;
// Create health text
var healthTxt = new Text2('Health', {
size: 40,
fill: 0xFFFFFF
});
healthTxt.anchor.set(0, 0);
healthTxt.x = 120;
healthTxt.y = 160;
game.addChild(healthTxt);
// Create player
player = game.addChild(new Player());
player.x = 300;
player.y = 2732 - 150; // Near bottom of screen
// Tap to slash
game.down = function (x, y, obj) {
player.slash();
};
// Spawn enemies
function spawnEnemy() {
var enemyType = Math.random() < 0.7 ? 'basic' : 'armored';
var enemy = game.addChild(new Enemy(enemyType));
enemy.x = 2048 + 100; // Start off-screen right
enemy.y = 2732 - 150 + Math.random() * 100 - 50; // Vary height slightly
enemies.push(enemy);
}
// Main game loop
game.update = function () {
gameTime++;
// Update score display
scoreTxt.setText('Score: ' + LK.getScore());
// Update health bar
var healthPercent = player.health / player.maxHealth;
healthBar.width = 200 * healthPercent;
// Spawn enemies
enemySpawnTimer++;
if (enemySpawnTimer >= enemySpawnRate) {
spawnEnemy();
enemySpawnTimer = 0;
// Increase difficulty over time
if (enemySpawnRate > 30) {
// Minimum spawn rate
enemySpawnRate -= 0.5;
}
}
// Clean up off-screen enemies
for (var i = enemies.length - 1; i >= 0; i--) {
var enemy = enemies[i];
if (enemy.x < -100) {
enemy.destroy();
enemies.splice(i, 1);
}
}
// Clean up off-screen power-ups
for (var i = powerUps.length - 1; i >= 0; i--) {
var powerUp = powerUps[i];
if (powerUp.x < -100) {
powerUp.destroy();
powerUps.splice(i, 1);
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,278 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Enemy = Container.expand(function (type) {
+ var self = Container.call(this);
+ var assetName = type === 'armored' ? 'armoredEnemy' : 'basicEnemy';
+ var enemyGraphics = self.attachAsset(assetName, {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ self.type = type || 'basic';
+ self.speed = type === 'armored' ? -3 : -4;
+ self.maxHealth = type === 'armored' ? 3 : 1;
+ self.health = self.maxHealth;
+ self.damage = type === 'armored' ? 30 : 20;
+ self.points = type === 'armored' ? 30 : 10;
+ self.takeDamage = function (damage) {
+ self.health -= damage;
+ LK.effects.flashObject(self, 0xffffff, 200);
+ LK.getSound('enemyHit').play();
+ if (self.health <= 0) {
+ // Award points
+ LK.setScore(LK.getScore() + self.points);
+ // Chance to drop power-up
+ if (Math.random() < 0.15) {
+ var powerUp = game.addChild(new PowerUp());
+ powerUp.x = self.x;
+ powerUp.y = self.y - 20;
+ powerUps.push(powerUp);
+ }
+ // Remove from enemies array
+ var index = enemies.indexOf(self);
+ if (index > -1) {
+ enemies.splice(index, 1);
+ }
+ self.destroy();
+ }
+ };
+ self.update = function () {
+ self.x += self.speed;
+ // Check collision with player
+ if (self.intersects(player) && !player.invulnerable) {
+ player.takeDamage(self.damage);
+ }
+ };
+ return self;
+});
+var Player = Container.expand(function () {
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ self.maxHealth = 100;
+ self.health = self.maxHealth;
+ self.slashDamage = 1;
+ self.slashRange = 150;
+ self.isSlashing = false;
+ self.slashCooldown = 0;
+ self.invulnerable = false;
+ self.invulnerabilityTime = 0;
+ self.slash = function () {
+ if (self.slashCooldown <= 0 && !self.isSlashing) {
+ self.isSlashing = true;
+ self.slashCooldown = 20; // 1/3 second at 60fps
+ // Create slash effect
+ var slashEffect = game.addChild(LK.getAsset('slashEffect', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ slashEffect.x = self.x + 75;
+ slashEffect.y = self.y - 60;
+ slashEffect.alpha = 0.8;
+ // Animate slash effect
+ tween(slashEffect, {
+ scaleX: 1.5,
+ scaleY: 1.5,
+ alpha: 0
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ slashEffect.destroy();
+ }
+ });
+ LK.getSound('slash').play();
+ // Check for enemy hits
+ for (var i = 0; i < enemies.length; i++) {
+ var enemy = enemies[i];
+ var distance = Math.sqrt(Math.pow(enemy.x - self.x, 2) + Math.pow(enemy.y - self.y, 2));
+ if (distance < self.slashRange && enemy.x > self.x - 50) {
+ enemy.takeDamage(self.slashDamage);
+ }
+ }
+ setTimeout(function () {
+ self.isSlashing = false;
+ }, 200);
+ }
+ };
+ self.takeDamage = function (damage) {
+ if (!self.invulnerable) {
+ self.health -= damage;
+ self.invulnerable = true;
+ self.invulnerabilityTime = 120; // 2 seconds at 60fps
+ // Flash effect
+ LK.effects.flashObject(self, 0xff0000, 500);
+ if (self.health <= 0) {
+ self.health = 0;
+ LK.showGameOver();
+ }
+ }
+ };
+ self.update = function () {
+ if (self.slashCooldown > 0) {
+ self.slashCooldown--;
+ }
+ if (self.invulnerabilityTime > 0) {
+ self.invulnerabilityTime--;
+ if (self.invulnerabilityTime <= 0) {
+ self.invulnerable = false;
+ }
+ }
+ };
+ return self;
+});
+var PowerUp = Container.expand(function () {
+ var self = Container.call(this);
+ var powerUpGraphics = self.attachAsset('powerUp', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -2;
+ self.bobOffset = 0;
+ self.update = function () {
+ self.x += self.speed;
+ self.bobOffset += 0.1;
+ self.y += Math.sin(self.bobOffset) * 0.5;
+ // Check collision with player
+ if (self.intersects(player)) {
+ self.collect();
+ }
+ };
+ self.collect = function () {
+ LK.getSound('powerUpSound').play();
+ // Random power-up effect
+ var powerType = Math.floor(Math.random() * 3);
+ switch (powerType) {
+ case 0:
+ // Increased damage
+ player.slashDamage += 1;
+ break;
+ case 1:
+ // Wider slash range
+ player.slashRange += 50;
+ break;
+ case 2:
+ // Temporary invincibility
+ player.invulnerable = true;
+ player.invulnerabilityTime = 300; // 5 seconds
+ break;
+ }
+ // Remove from powerUps array
+ var index = powerUps.indexOf(self);
+ if (index > -1) {
+ powerUps.splice(index, 1);
+ }
+ self.destroy();
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2c3e50
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var player;
+var enemies = [];
+var powerUps = [];
+var enemySpawnTimer = 0;
+var enemySpawnRate = 120; // Start spawning every 2 seconds
+var gameTime = 0;
+var healthBar;
+var healthBarBg;
+// Create UI elements
+var scoreTxt = new Text2('Score: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0, 0);
+scoreTxt.x = 120;
+scoreTxt.y = 50;
+LK.gui.topLeft.addChild(scoreTxt);
+// Create health bar background
+healthBarBg = game.addChild(LK.getAsset('healthBarBg', {
+ anchorX: 0,
+ anchorY: 0
+}));
+healthBarBg.x = 120;
+healthBarBg.y = 120;
+// Create health bar
+healthBar = game.addChild(LK.getAsset('healthBar', {
+ anchorX: 0,
+ anchorY: 0
+}));
+healthBar.x = 122;
+healthBar.y = 122;
+// Create health text
+var healthTxt = new Text2('Health', {
+ size: 40,
+ fill: 0xFFFFFF
+});
+healthTxt.anchor.set(0, 0);
+healthTxt.x = 120;
+healthTxt.y = 160;
+game.addChild(healthTxt);
+// Create player
+player = game.addChild(new Player());
+player.x = 300;
+player.y = 2732 - 150; // Near bottom of screen
+// Tap to slash
+game.down = function (x, y, obj) {
+ player.slash();
+};
+// Spawn enemies
+function spawnEnemy() {
+ var enemyType = Math.random() < 0.7 ? 'basic' : 'armored';
+ var enemy = game.addChild(new Enemy(enemyType));
+ enemy.x = 2048 + 100; // Start off-screen right
+ enemy.y = 2732 - 150 + Math.random() * 100 - 50; // Vary height slightly
+ enemies.push(enemy);
+}
+// Main game loop
+game.update = function () {
+ gameTime++;
+ // Update score display
+ scoreTxt.setText('Score: ' + LK.getScore());
+ // Update health bar
+ var healthPercent = player.health / player.maxHealth;
+ healthBar.width = 200 * healthPercent;
+ // Spawn enemies
+ enemySpawnTimer++;
+ if (enemySpawnTimer >= enemySpawnRate) {
+ spawnEnemy();
+ enemySpawnTimer = 0;
+ // Increase difficulty over time
+ if (enemySpawnRate > 30) {
+ // Minimum spawn rate
+ enemySpawnRate -= 0.5;
+ }
+ }
+ // Clean up off-screen enemies
+ for (var i = enemies.length - 1; i >= 0; i--) {
+ var enemy = enemies[i];
+ if (enemy.x < -100) {
+ enemy.destroy();
+ enemies.splice(i, 1);
+ }
+ }
+ // Clean up off-screen power-ups
+ for (var i = powerUps.length - 1; i >= 0; i--) {
+ var powerUp = powerUps[i];
+ if (powerUp.x < -100) {
+ powerUp.destroy();
+ powerUps.splice(i, 1);
+ }
+ }
+};
\ No newline at end of file
efek slash kepala naga petir ke depan. In-Game asset. 2d. High contrast. No shadows
side scroller blue steel armored ninja aksi koreographi dua tangan memegang pedang ke depan In-Game asset. 2d. No shadows
side scroller image fat orc samurai front holding big axe. In-Game asset. 2d. High contrast. No shadows
side scroller kepala evil kelinci berapi. In-Game asset. 2d. High contrast. No shadows
realistic 2d anime style front field old samurai palace temple with pig evil ornament at midnight. In-Game asset. 2d. High contrast. No shadows