User prompt
dragon normal speed
User prompt
dragon not panic when get hit
User prompt
slow move dragon ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
smooth animation about dragon ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
delete dragon4 asset
User prompt
fix a dragon
User prompt
background animation
User prompt
dragon animation
User prompt
increase dragon health bar
User prompt
blue fire ball asset
User prompt
add blue light ball asset
User prompt
fire change to blue light after bounce player ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
enemy dificult to defeat
User prompt
make paddle control smooth
User prompt
fix smooth paddle control
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'if (paddle.x < paddle.width / 2) {' Line Number: 435
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'easeOutQuad')' in or related to this line: 'tween(paddle, {' Line Number: 427
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'if (paddle.x < paddle.width / 2) {' Line Number: 435
User prompt
smooth control paddle
User prompt
fire ball interval release as 2 seconds ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
delete multiple fire ball
User prompt
erase multiple fire ball
User prompt
add background
User prompt
erase fire animation
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 Dragon = Container.expand(function () {
var self = Container.call(this);
var dragonFrames = ['dragon1', 'dragon2', 'dragon3'];
var currentFrame = 0;
var animationSpeed = 0.1;
var frameCount = 0;
var dragonGraphics = self.attachAsset('dragon2', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = 1;
self.speed = 3;
self.width = dragonGraphics.width;
self.height = dragonGraphics.height;
self.fireballCooldown = 0;
self.health = 200;
self.maxHealth = 200;
// Method to update dragon animation
self.updateAnimation = function () {
frameCount += animationSpeed;
if (frameCount >= 1) {
frameCount = 0;
currentFrame = (currentFrame + 1) % dragonFrames.length;
// Replace current graphics with next frame
dragonGraphics.destroy();
dragonGraphics = self.attachAsset(dragonFrames[currentFrame], {
anchorX: 0.5,
anchorY: 0.5,
tint: 0xFFFFFF
});
}
};
self.update = function () {
// Decrease fireball cooldown
if (self.fireballCooldown > 0) {
self.fireballCooldown--;
}
// Move dragon at normal speed
self.x += self.speed * self.direction;
// Check if we need to change direction
if (self.x + self.width / 2 > 2048 || self.x - self.width / 2 < 0) {
self.direction *= -1;
// Change dragon scale to flip horizontally when changing direction
dragonGraphics.scale.x = self.direction > 0 ? 1 : -1;
// Increase animation speed temporarily when changing direction
var originalAnimationSpeed = animationSpeed;
animationSpeed = 0.2;
LK.setTimeout(function () {
animationSpeed = originalAnimationSpeed;
}, 500);
}
// Update animation
self.updateAnimation();
};
self.takeDamage = function (damage) {
self.health -= damage;
if (self.health < 0) {
self.health = 0;
}
// Flash red when hit
LK.effects.flashObject(self, 0xFF0000, 500);
LK.getSound('dragonHit').play();
// Dragon remains calm when hit - no animation speed increase
};
return self;
});
var Fireball = Container.expand(function () {
var self = Container.call(this);
var fireballGraphics = self.attachAsset('fireball', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedY = 7;
self.speedX = 0;
self.fromDragon = true;
self.width = fireballGraphics.width;
self.height = fireballGraphics.height;
self.update = function () {
self.y += self.speedY;
self.x += self.speedX;
// No fireball rotation animation
};
self.slow = function () {
self.speedY = self.speedY * 0.5;
fireballGraphics.tint = 0x33CCFF; // Blue tint for slowed fireballs
};
self.bounce = function () {
self.speedY *= -1;
self.fromDragon = false;
// Add some random X velocity when bouncing
self.speedX = (Math.random() - 0.5) * 5;
// Change fireball to blue light ball after bounce
self.children[0].destroy();
var blueballGraphics = self.attachAsset('bluelightball', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0x33CCFF // Keep blue tint for extra effect
});
};
return self;
});
var HealthBar = Container.expand(function (maxHealth, color) {
var self = Container.call(this);
self.maxWidth = 300;
self.maxHealth = maxHealth || 100;
self.currentHealth = self.maxHealth;
var barBackground = self.attachAsset('healthBar', {
anchorX: 0,
anchorY: 0,
tint: 0x333333
});
var healthFill = self.attachAsset(color === 'dragon' ? 'dragonHealthBar' : 'healthBar', {
anchorX: 0,
anchorY: 0
});
self.updateHealth = function (health) {
self.currentHealth = health;
var healthPercentage = self.currentHealth / self.maxHealth;
healthFill.width = self.maxWidth * healthPercentage;
};
return self;
});
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 20;
self.width = paddleGraphics.width;
self.height = paddleGraphics.height;
self.shield = null;
self.activateShield = function () {
if (self.shield) {
return;
}
self.shield = self.attachAsset('shield', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5
});
LK.setTimeout(function () {
if (self.shield) {
self.shield.destroy();
self.shield = null;
}
}, 5000);
};
self.grow = function () {
tween(paddleGraphics, {
width: paddleGraphics.width * 1.5
}, {
duration: 300,
onFinish: function onFinish() {
self.width = paddleGraphics.width;
LK.setTimeout(function () {
tween(paddleGraphics, {
width: paddleGraphics.width / 1.5
}, {
duration: 300,
onFinish: function onFinish() {
self.width = paddleGraphics.width;
}
});
}, 5000);
}
});
};
return self;
});
var PowerUp = Container.expand(function (type) {
var self = Container.call(this);
self.type = type || 'shield'; // Default to shield type
var color;
switch (self.type) {
case 'grow':
color = 0x00FF00; // Green
break;
case 'slow':
color = 0x0000FF; // Blue
break;
case 'shield':
default:
color = 0xFFCC00; // Gold
break;
}
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5,
tint: color
});
self.speedY = 2;
self.width = powerUpGraphics.width;
self.height = powerUpGraphics.height;
self.update = function () {
self.y += self.speedY;
// Make it pulse slightly
var scale = 1 + 0.1 * Math.sin(LK.ticks * 0.1);
powerUpGraphics.scale.set(scale, scale);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x222244
});
/****
* Game Code
****/
// Game state variables
var paddle;
var dragon;
var fireballs = [];
var powerUps = [];
var playerHealth = 100;
var playerHealthBar;
var dragonHealthBar;
var gameOver = false;
var score = 0;
var scoreText;
var powerUpTypes = ['shield', 'grow', 'slow'];
var difficulty = 1;
var powerUpChance = 0.01; // 1% chance per frame
var difficultyIncreaseTimer;
var playerIsAlive = true;
function initGame() {
// Add background
var background = LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
width: 2048,
height: 2732
});
game.addChild(background);
// Create player paddle
paddle = new Paddle();
paddle.x = 2048 / 2;
paddle.y = 2732 - 150;
game.addChild(paddle);
// Create dragon
dragon = new Dragon();
dragon.x = 2048 / 2;
dragon.y = 200;
game.addChild(dragon);
// Dragon moves at normal speed now, no tween needed
// Create health bars
playerHealthBar = new HealthBar(100);
playerHealthBar.x = 50;
playerHealthBar.y = 2732 - 50;
game.addChild(playerHealthBar);
dragonHealthBar = new HealthBar(200, 'dragon');
dragonHealthBar.x = 2048 - 350;
dragonHealthBar.y = 50;
game.addChild(dragonHealthBar);
// Create score display
scoreText = new Text2('Score: 0', {
size: 50,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Reset game variables
fireballs = [];
powerUps = [];
playerHealth = 100;
dragon.health = 200;
gameOver = false;
score = 0;
LK.setScore(0);
playerIsAlive = true;
difficulty = 1;
updateHealthBars();
updateScoreDisplay();
// Start difficulty increase timer
difficultyIncreaseTimer = LK.setInterval(increaseDifficulty, 20000); // Every 20 seconds
// Play background music
LK.playMusic('gameMusic');
}
function increaseDifficulty() {
difficulty += 0.5;
dragon.speed = Math.min(6, 3 + (difficulty - 1));
powerUpChance = Math.max(0.005, 0.01 - (difficulty - 1) * 0.001);
}
function updateHealthBars() {
playerHealthBar.updateHealth(playerHealth);
dragonHealthBar.updateHealth(dragon.health);
}
function updateScoreDisplay() {
scoreText.setText('Score: ' + score);
}
function createFireball() {
if (dragon.fireballCooldown <= 0 && !gameOver && playerIsAlive) {
var fireball = new Fireball();
fireball.x = dragon.x;
fireball.y = dragon.y + dragon.height / 2;
fireballs.push(fireball);
game.addChild(fireball);
// Set cooldown to 2 seconds (120 frames at 60 FPS)
dragon.fireballCooldown = 120;
}
}
function createPowerUp() {
if (Math.random() < powerUpChance && !gameOver && playerIsAlive) {
var type = powerUpTypes[Math.floor(Math.random() * powerUpTypes.length)];
var powerUp = new PowerUp(type);
powerUp.x = Math.random() * (2048 - 100) + 50;
powerUp.y = 0;
powerUps.push(powerUp);
game.addChild(powerUp);
}
}
function handleFireballCollisions() {
for (var i = fireballs.length - 1; i >= 0; i--) {
var fireball = fireballs[i];
// Check for collision with paddle
if (fireball.fromDragon && fireball.intersects(paddle)) {
if (paddle.shield) {
// Shield absorbs the fireball
fireball.destroy();
fireballs.splice(i, 1);
// Destroy shield after absorbing
paddle.shield.destroy();
paddle.shield = null;
} else {
// Bounce the fireball
fireball.bounce();
LK.getSound('hit').play();
// Add points for successful deflection
score += 10;
LK.setScore(score);
updateScoreDisplay();
}
continue;
}
// Check for collision with dragon
if (!fireball.fromDragon && fireball.intersects(dragon)) {
dragon.takeDamage(10);
updateHealthBars();
// Remove the fireball
fireball.destroy();
fireballs.splice(i, 1);
// Add points for hitting the dragon
score += 50;
LK.setScore(score);
updateScoreDisplay();
// Check for win condition
if (dragon.health <= 0) {
gameOver = true;
playerIsAlive = false;
LK.showYouWin();
}
continue;
}
// Check if fireball is off-screen
if (fireball.y > 2732 + fireball.height) {
// Player missed a fireball
if (fireball.fromDragon) {
playerHealth -= 10;
updateHealthBars();
LK.getSound('playerDamage').play();
// Flash screen red to indicate damage
LK.effects.flashScreen(0xFF0000, 300);
// Check for lose condition
if (playerHealth <= 0) {
gameOver = true;
playerIsAlive = false;
LK.showGameOver();
}
}
// Remove the fireball
fireball.destroy();
fireballs.splice(i, 1);
} else if (fireball.y < -fireball.height) {
// Fireball went off the top of the screen
fireball.destroy();
fireballs.splice(i, 1);
} else if (fireball.x < -fireball.width || fireball.x > 2048 + fireball.width) {
// Fireball went off the sides of the screen
fireball.destroy();
fireballs.splice(i, 1);
}
}
}
function handlePowerUpCollisions() {
for (var i = powerUps.length - 1; i >= 0; i--) {
var powerUp = powerUps[i];
// Check for collision with paddle
if (powerUp.intersects(paddle)) {
// Apply power-up effect
switch (powerUp.type) {
case 'grow':
paddle.grow();
break;
case 'slow':
// Slow all current fireballs
fireballs.forEach(function (fireball) {
if (fireball.fromDragon) {
fireball.slow();
}
});
break;
case 'shield':
paddle.activateShield();
break;
}
// Play power-up sound
LK.getSound('powerUpCollect').play();
// Remove the power-up
powerUp.destroy();
powerUps.splice(i, 1);
// Add points
score += 20;
LK.setScore(score);
updateScoreDisplay();
continue;
}
// Check if power-up is off-screen
if (powerUp.y > 2732 + powerUp.height) {
powerUp.destroy();
powerUps.splice(i, 1);
}
}
}
// Handle movement for paddle
var isDragging = false;
game.down = function (x, y, obj) {
isDragging = true;
paddle.x = x;
};
game.move = function (x, y, obj) {
if (isDragging) {
// Convert event coordinates to game coordinates if needed
var targetX = x;
// Directly set the paddle position for more responsive control
paddle.x = targetX;
// Keep paddle within screen bounds
if (paddle.x < paddle.width / 2) {
paddle.x = paddle.width / 2;
} else if (paddle.x > 2048 - paddle.width / 2) {
paddle.x = 2048 - paddle.width / 2;
}
}
};
game.up = function (x, y, obj) {
isDragging = false;
};
// Game update loop
game.update = function () {
if (gameOver) {
return;
}
// Update dragon
dragon.update();
// Create new fireballs
createFireball();
// Create power-ups
createPowerUp();
// Update all fireballs
for (var i = 0; i < fireballs.length; i++) {
fireballs[i].update();
}
// Update all power-ups
for (var i = 0; i < powerUps.length; i++) {
powerUps[i].update();
}
// Check for collisions
handleFireballCollisions();
handlePowerUpCollisions();
};
// Initialize the game
initGame(); ===================================================================
--- original.js
+++ change.js
@@ -43,14 +43,12 @@
// Decrease fireball cooldown
if (self.fireballCooldown > 0) {
self.fireballCooldown--;
}
+ // Move dragon at normal speed
+ self.x += self.speed * self.direction;
// Check if we need to change direction
if (self.x + self.width / 2 > 2048 || self.x - self.width / 2 < 0) {
- // Stop any current movement tweens
- tween.stop(self, {
- x: true
- });
self.direction *= -1;
// Change dragon scale to flip horizontally when changing direction
dragonGraphics.scale.x = self.direction > 0 ? 1 : -1;
// Increase animation speed temporarily when changing direction
@@ -58,20 +56,8 @@
animationSpeed = 0.2;
LK.setTimeout(function () {
animationSpeed = originalAnimationSpeed;
}, 500);
- // Calculate new target position
- var targetX = self.direction > 0 ? 2048 - self.width / 2 - 50 :
- // Moving right
- self.width / 2 + 50; // Moving left
- // Start new tween for slow movement
- tween(self, {
- x: targetX
- }, {
- duration: 10000,
- // 10 seconds for slow movement
- easing: tween.linear
- });
}
// Update animation
self.updateAnimation();
};
@@ -268,16 +254,9 @@
dragon = new Dragon();
dragon.x = 2048 / 2;
dragon.y = 200;
game.addChild(dragon);
- // Start slow movement tween for dragon
- tween(dragon, {
- x: 2048 - dragon.width / 2 - 50
- }, {
- duration: 10000,
- // 10 seconds for slow movement
- easing: tween.linear
- });
+ // Dragon moves at normal speed now, no tween needed
// Create health bars
playerHealthBar = new HealthBar(100);
playerHealthBar.x = 50;
playerHealthBar.y = 2732 - 50;
red fire ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
pixel art dramatic epic medieval village castle burning bad day. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
pixel art blue light thunder ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows