User prompt
Watermelon should fire less bullets, and banana and watermelon should deal 5 damage per bullet
User prompt
Banana should have a gun
User prompt
Game must have horizontal screen
Code edit (1 edits merged)
Please save this source code
User prompt
Banana vs. Watermelon Boss Battle
Initial prompt
Make me a Boss Fighting game like Cuphead. The main character is a banana, and the boss is big watermelon
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Banana = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('banana', {
anchorX: 0.5,
anchorY: 0.5
});
self.maxHealth = 100;
self.health = self.maxHealth;
self.shootCooldown = 0;
self.invulnerable = false;
self.invulnerableTimer = 0;
self.takeDamage = function (damage) {
if (self.invulnerable) return;
self.health -= damage;
self.invulnerable = true;
self.invulnerableTimer = 60; // 1 second at 60fps
// Flash effect
LK.effects.flashObject(self, 0xFF0000, 500);
LK.getSound('hit').play();
if (self.health <= 0) {
LK.showGameOver();
}
};
self.update = function () {
if (self.shootCooldown > 0) {
self.shootCooldown--;
}
if (self.invulnerable && self.invulnerableTimer > 0) {
self.invulnerableTimer--;
if (self.invulnerableTimer <= 0) {
self.invulnerable = false;
}
}
};
return self;
});
var BananaProjectile = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('bananaProjectile', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.damage = 10;
self.update = function () {
self.y -= self.speed;
};
return self;
});
var WatermelonBoss = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('watermelon', {
anchorX: 0.5,
anchorY: 0.5
});
self.maxHealth = 500;
self.health = self.maxHealth;
self.attackTimer = 0;
self.attackCooldown = 120; // 2 seconds
self.phase = 1;
self.moveDirection = 1;
self.moveSpeed = 1;
self.takeDamage = function (damage) {
self.health -= damage;
LK.effects.flashObject(self, 0xFF0000, 200);
LK.getSound('bosshit').play();
// Change phase based on health
if (self.health <= self.maxHealth * 0.66 && self.phase === 1) {
self.phase = 2;
self.attackCooldown = 90; // Faster attacks
} else if (self.health <= self.maxHealth * 0.33 && self.phase === 2) {
self.phase = 3;
self.attackCooldown = 60; // Even faster attacks
}
if (self.health <= 0) {
LK.showYouWin();
}
};
self.seedAttack = function () {
var numSeeds = self.phase === 1 ? 3 : self.phase === 2 ? 5 : 8;
for (var i = 0; i < numSeeds; i++) {
var seed = new WatermelonSeed();
seed.x = self.x + (Math.random() - 0.5) * 100;
seed.y = self.y + 50;
var angle = Math.random() * Math.PI * 2;
var speed = 2 + Math.random() * 3;
seed.speedX = Math.cos(angle) * speed;
seed.speedY = Math.sin(angle) * speed;
watermelonSeeds.push(seed);
game.addChild(seed);
}
};
self.update = function () {
// Movement
self.x += self.moveDirection * self.moveSpeed;
if (self.x <= 150 || self.x >= 1898) {
self.moveDirection *= -1;
}
// Attack logic
self.attackTimer++;
if (self.attackTimer >= self.attackCooldown) {
self.seedAttack();
self.attackTimer = 0;
}
};
return self;
});
var WatermelonSeed = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('watermelonSeed', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
self.speedY = 0;
self.damage = 20;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Music
// Sound effects
// Projectile assets
// Character assets
// Game variables
var banana;
var watermelonBoss;
var bananaProjectiles = [];
var watermelonSeeds = [];
var dragNode = null;
// UI Elements
var healthBar = new Text2('Health: 100', {
size: 40,
fill: 0xFFFFFF
});
healthBar.anchor.set(0, 0);
LK.gui.topLeft.addChild(healthBar);
var bossHealthBar = new Text2('Boss Health: 500', {
size: 40,
fill: 0xFF0000
});
bossHealthBar.anchor.set(0.5, 0);
LK.gui.top.addChild(bossHealthBar);
// Initialize game objects
banana = game.addChild(new Banana());
banana.x = 1024;
banana.y = 2400;
watermelonBoss = game.addChild(new WatermelonBoss());
watermelonBoss.x = 1024;
watermelonBoss.y = 400;
// Event handlers
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
// Keep banana within bounds
if (dragNode.x < 50) dragNode.x = 50;
if (dragNode.x > 1998) dragNode.x = 1998;
if (dragNode.y < 800) dragNode.y = 800;
if (dragNode.y > 2680) dragNode.y = 2680;
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
dragNode = banana;
handleMove(x, y, obj);
// Shoot projectile
if (banana.shootCooldown <= 0) {
var projectile = new BananaProjectile();
projectile.x = banana.x;
projectile.y = banana.y - 60;
bananaProjectiles.push(projectile);
game.addChild(projectile);
banana.shootCooldown = 15; // 0.25 seconds
LK.getSound('shoot').play();
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Main game loop
game.update = function () {
// Update UI
healthBar.setText('Health: ' + banana.health);
bossHealthBar.setText('Boss Health: ' + watermelonBoss.health);
// Handle banana projectiles
for (var i = bananaProjectiles.length - 1; i >= 0; i--) {
var projectile = bananaProjectiles[i];
// Remove if off screen
if (projectile.y < -50) {
projectile.destroy();
bananaProjectiles.splice(i, 1);
continue;
}
// Check collision with boss
if (projectile.intersects(watermelonBoss)) {
watermelonBoss.takeDamage(projectile.damage);
projectile.destroy();
bananaProjectiles.splice(i, 1);
continue;
}
}
// Handle watermelon seeds
for (var j = watermelonSeeds.length - 1; j >= 0; j--) {
var seed = watermelonSeeds[j];
// Remove if off screen
if (seed.x < -50 || seed.x > 2098 || seed.y < -50 || seed.y > 2782) {
seed.destroy();
watermelonSeeds.splice(j, 1);
continue;
}
// Check collision with banana
if (seed.intersects(banana)) {
banana.takeDamage(seed.damage);
seed.destroy();
watermelonSeeds.splice(j, 1);
continue;
}
}
};
// Start battle music
LK.playMusic('battle'); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,243 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Banana = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('banana', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.maxHealth = 100;
+ self.health = self.maxHealth;
+ self.shootCooldown = 0;
+ self.invulnerable = false;
+ self.invulnerableTimer = 0;
+ self.takeDamage = function (damage) {
+ if (self.invulnerable) return;
+ self.health -= damage;
+ self.invulnerable = true;
+ self.invulnerableTimer = 60; // 1 second at 60fps
+ // Flash effect
+ LK.effects.flashObject(self, 0xFF0000, 500);
+ LK.getSound('hit').play();
+ if (self.health <= 0) {
+ LK.showGameOver();
+ }
+ };
+ self.update = function () {
+ if (self.shootCooldown > 0) {
+ self.shootCooldown--;
+ }
+ if (self.invulnerable && self.invulnerableTimer > 0) {
+ self.invulnerableTimer--;
+ if (self.invulnerableTimer <= 0) {
+ self.invulnerable = false;
+ }
+ }
+ };
+ return self;
+});
+var BananaProjectile = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('bananaProjectile', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 8;
+ self.damage = 10;
+ self.update = function () {
+ self.y -= self.speed;
+ };
+ return self;
+});
+var WatermelonBoss = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('watermelon', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.maxHealth = 500;
+ self.health = self.maxHealth;
+ self.attackTimer = 0;
+ self.attackCooldown = 120; // 2 seconds
+ self.phase = 1;
+ self.moveDirection = 1;
+ self.moveSpeed = 1;
+ self.takeDamage = function (damage) {
+ self.health -= damage;
+ LK.effects.flashObject(self, 0xFF0000, 200);
+ LK.getSound('bosshit').play();
+ // Change phase based on health
+ if (self.health <= self.maxHealth * 0.66 && self.phase === 1) {
+ self.phase = 2;
+ self.attackCooldown = 90; // Faster attacks
+ } else if (self.health <= self.maxHealth * 0.33 && self.phase === 2) {
+ self.phase = 3;
+ self.attackCooldown = 60; // Even faster attacks
+ }
+ if (self.health <= 0) {
+ LK.showYouWin();
+ }
+ };
+ self.seedAttack = function () {
+ var numSeeds = self.phase === 1 ? 3 : self.phase === 2 ? 5 : 8;
+ for (var i = 0; i < numSeeds; i++) {
+ var seed = new WatermelonSeed();
+ seed.x = self.x + (Math.random() - 0.5) * 100;
+ seed.y = self.y + 50;
+ var angle = Math.random() * Math.PI * 2;
+ var speed = 2 + Math.random() * 3;
+ seed.speedX = Math.cos(angle) * speed;
+ seed.speedY = Math.sin(angle) * speed;
+ watermelonSeeds.push(seed);
+ game.addChild(seed);
+ }
+ };
+ self.update = function () {
+ // Movement
+ self.x += self.moveDirection * self.moveSpeed;
+ if (self.x <= 150 || self.x >= 1898) {
+ self.moveDirection *= -1;
+ }
+ // Attack logic
+ self.attackTimer++;
+ if (self.attackTimer >= self.attackCooldown) {
+ self.seedAttack();
+ self.attackTimer = 0;
+ }
+ };
+ return self;
+});
+var WatermelonSeed = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('watermelonSeed', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speedX = 0;
+ self.speedY = 0;
+ self.damage = 20;
+ self.update = function () {
+ self.x += self.speedX;
+ self.y += self.speedY;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+// Music
+// Sound effects
+// Projectile assets
+// Character assets
+// Game variables
+var banana;
+var watermelonBoss;
+var bananaProjectiles = [];
+var watermelonSeeds = [];
+var dragNode = null;
+// UI Elements
+var healthBar = new Text2('Health: 100', {
+ size: 40,
+ fill: 0xFFFFFF
+});
+healthBar.anchor.set(0, 0);
+LK.gui.topLeft.addChild(healthBar);
+var bossHealthBar = new Text2('Boss Health: 500', {
+ size: 40,
+ fill: 0xFF0000
+});
+bossHealthBar.anchor.set(0.5, 0);
+LK.gui.top.addChild(bossHealthBar);
+// Initialize game objects
+banana = game.addChild(new Banana());
+banana.x = 1024;
+banana.y = 2400;
+watermelonBoss = game.addChild(new WatermelonBoss());
+watermelonBoss.x = 1024;
+watermelonBoss.y = 400;
+// Event handlers
+function handleMove(x, y, obj) {
+ if (dragNode) {
+ dragNode.x = x;
+ dragNode.y = y;
+ // Keep banana within bounds
+ if (dragNode.x < 50) dragNode.x = 50;
+ if (dragNode.x > 1998) dragNode.x = 1998;
+ if (dragNode.y < 800) dragNode.y = 800;
+ if (dragNode.y > 2680) dragNode.y = 2680;
+ }
+}
+game.move = handleMove;
+game.down = function (x, y, obj) {
+ dragNode = banana;
+ handleMove(x, y, obj);
+ // Shoot projectile
+ if (banana.shootCooldown <= 0) {
+ var projectile = new BananaProjectile();
+ projectile.x = banana.x;
+ projectile.y = banana.y - 60;
+ bananaProjectiles.push(projectile);
+ game.addChild(projectile);
+ banana.shootCooldown = 15; // 0.25 seconds
+ LK.getSound('shoot').play();
+ }
+};
+game.up = function (x, y, obj) {
+ dragNode = null;
+};
+// Main game loop
+game.update = function () {
+ // Update UI
+ healthBar.setText('Health: ' + banana.health);
+ bossHealthBar.setText('Boss Health: ' + watermelonBoss.health);
+ // Handle banana projectiles
+ for (var i = bananaProjectiles.length - 1; i >= 0; i--) {
+ var projectile = bananaProjectiles[i];
+ // Remove if off screen
+ if (projectile.y < -50) {
+ projectile.destroy();
+ bananaProjectiles.splice(i, 1);
+ continue;
+ }
+ // Check collision with boss
+ if (projectile.intersects(watermelonBoss)) {
+ watermelonBoss.takeDamage(projectile.damage);
+ projectile.destroy();
+ bananaProjectiles.splice(i, 1);
+ continue;
+ }
+ }
+ // Handle watermelon seeds
+ for (var j = watermelonSeeds.length - 1; j >= 0; j--) {
+ var seed = watermelonSeeds[j];
+ // Remove if off screen
+ if (seed.x < -50 || seed.x > 2098 || seed.y < -50 || seed.y > 2782) {
+ seed.destroy();
+ watermelonSeeds.splice(j, 1);
+ continue;
+ }
+ // Check collision with banana
+ if (seed.intersects(banana)) {
+ banana.takeDamage(seed.damage);
+ seed.destroy();
+ watermelonSeeds.splice(j, 1);
+ continue;
+ }
+ }
+};
+// Start battle music
+LK.playMusic('battle');
\ No newline at end of file