User prompt
Make the enemies move slow
User prompt
Make my health more
User prompt
Make the enemies move
User prompt
More enemies that come towards you
User prompt
Make the water shoot farther
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'waterMaster.activateShield();' Line Number: 531
User prompt
Please fix the bug: 'tween.create is not a function. (In 'tween.create(sourceGraphics.scale)', 'tween.create' is undefined)' in or related to this line: 'tween.create(sourceGraphics.scale).to({' Line Number: 270 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
More code
User prompt
Aqua Master: Elemental Flow
Initial prompt
A person that shoots our water from their hands and controls water
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Enemy = Container.expand(function () { var self = Container.call(this); // Create enemy graphic var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); // Enemy properties self.health = 100; self.speedX = 0; self.speedY = 0; self.attackRange = 300; self.lastX = 0; self.lastY = 0; self.lastWasIntersecting = false; // Initialize enemy with properties self.init = function (health, speedX, speedY) { self.health = health || 100; self.speedX = speedX || 0; self.speedY = speedY || 0; }; // Take damage from water self.takeDamage = function (amount) { self.health -= amount; // Visual feedback LK.effects.flashObject(self, 0xFF0000, 500); // Play sound LK.getSound('enemyHit').play(); // Check if enemy is defeated if (self.health <= 0) { return true; } return false; }; // Move toward target self.moveToward = function (targetX, targetY, speed) { // Calculate direction vector var dirX = targetX - self.x; var dirY = targetY - self.y; // Calculate distance var distance = Math.sqrt(dirX * dirX + dirY * dirY); // Only move if not too close if (distance > 10) { // Normalize direction vector dirX /= distance; dirY /= distance; // Set velocity self.speedX = dirX * speed; self.speedY = dirY * speed; } else { // Stop if close enough self.speedX = 0; self.speedY = 0; } }; // Update method called every tick self.update = function () { // Store last position self.lastX = self.x; self.lastY = self.y; // Move enemy self.x += self.speedX; self.y += self.speedY; // Keep enemy within game bounds if (self.x < 50) self.x = 50; if (self.x > 2048 - 50) self.x = 2048 - 50; if (self.y < 50) self.y = 50; if (self.y > 2732 - 50) self.y = 2732 - 50; }; return self; }); var WaterMaster = Container.expand(function () { var self = Container.call(this); // Create character graphic var characterGraphics = self.attachAsset('waterMaster', { anchorX: 0.5, anchorY: 0.5 }); // Water power properties self.waterReserve = 100; // Maximum water reserve self.currentWater = 100; // Current water level self.waterRegenRate = 0.2; // Water regeneration rate per tick self.shootCost = 10; // Cost of shooting water self.lastShootTime = 0; // Track last shoot time for cooldown self.shootCooldown = 15; // Cooldown between shots in ticks self.isCharging = false; // Track if charging a water shot self.chargeAmount = 0; // Current charge amount self.chargeMax = 60; // Maximum charge amount self.lastX = 0; self.lastY = 0; // Create water shield self.shield = self.addChild(LK.getAsset('waterShield', { anchorX: 0.5, anchorY: 0.5, alpha: 0 })); // Event handlers for touch interactions self.down = function (x, y, obj) { self.isCharging = true; self.chargeAmount = 0; }; self.up = function (x, y, obj) { if (self.isCharging && self.currentWater >= self.shootCost) { // Calculate direction based on charge time var chargeRatio = Math.min(self.chargeAmount / self.chargeMax, 1); var power = 5 + 10 * chargeRatio; // Create water projectile self.shootWater(power); // Reset charging self.isCharging = false; self.chargeAmount = 0; } }; // Shoot water in direction self.shootWater = function (power) { if (LK.ticks - self.lastShootTime < self.shootCooldown || self.currentWater < self.shootCost) { return; } // Create water projectile if (typeof game !== 'undefined' && game.createWaterProjectile) { // Determine direction vector from center to touch point var touchX = game.lastTouchX || self.x; var touchY = game.lastTouchY || self.y; // Calculate direction vector var dirX = touchX - self.x; var dirY = touchY - self.y; // Normalize direction vector var length = Math.sqrt(dirX * dirX + dirY * dirY); if (length > 0) { dirX /= length; dirY /= length; } else { dirX = 0; dirY = -1; // Default direction up } // Create projectile game.createWaterProjectile(self.x, self.y, dirX * power, dirY * power); // Reduce water reserve self.currentWater -= self.shootCost; // Play sound LK.getSound('waterShoot').play(); // Track last shoot time self.lastShootTime = LK.ticks; } }; // Activate shield self.activateShield = function () { if (self.currentWater >= 20) { self.shield.alpha = 0.7; self.currentWater -= 20; // Auto-disable shield after 3 seconds LK.setTimeout(function () { self.shield.alpha = 0; }, 3000); } }; // Refill water reserve self.refillWater = function (amount) { self.currentWater = Math.min(self.currentWater + amount, self.waterReserve); }; // Update method called every tick self.update = function () { // Store last position self.lastX = self.x; self.lastY = self.y; // Slowly regenerate water if (self.currentWater < self.waterReserve) { self.currentWater += self.waterRegenRate; if (self.currentWater > self.waterReserve) { self.currentWater = self.waterReserve; } } // Update charging if (self.isCharging) { self.chargeAmount++; if (self.chargeAmount > self.chargeMax) { self.chargeAmount = self.chargeMax; } } }; return self; }); var WaterProjectile = Container.expand(function () { var self = Container.call(this); // Create projectile graphic var projectileGraphics = self.attachAsset('waterProjectile', { anchorX: 0.5, anchorY: 0.5 }); // Projectile properties self.speedX = 0; self.speedY = 0; self.power = 1; self.lifespan = 120; // Projectile lifespan in ticks self.age = 0; self.lastX = 0; self.lastY = 0; self.lastWasIntersecting = false; // Initialize projectile with direction and speed self.init = function (speedX, speedY, power) { self.speedX = speedX; self.speedY = speedY; self.power = power || 1; // Scale based on power var scale = 0.5 + self.power * 0.1; projectileGraphics.scale.set(scale, scale); }; // Update method called every tick self.update = function () { // Store last position self.lastX = self.x; self.lastY = self.y; // Move projectile self.x += self.speedX; self.y += self.speedY; // Age the projectile self.age++; // Make projectile gradually fade out if (self.age > self.lifespan * 0.7) { var fadeRatio = 1 - (self.age - self.lifespan * 0.7) / (self.lifespan * 0.3); self.alpha = Math.max(fadeRatio, 0); } }; return self; }); var WaterSource = Container.expand(function () { var self = Container.call(this); // Create water source graphic var sourceGraphics = self.attachAsset('waterSource', { anchorX: 0.5, anchorY: 0.5 }); // Water source properties self.refillAmount = 50; self.refillCooldown = 180; // 3 seconds at 60 FPS self.lastRefillTime = 0; self.lastWasIntersecting = false; // Pulsating animation function startPulsating() { tween(sourceGraphics.scale, { x: 1.1, y: 1.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(sourceGraphics.scale, { x: 0.9, y: 0.9 }, { duration: 1000, easing: tween.easeInOut, onFinish: startPulsating }); } }); } // Start pulsating animation startPulsating(); // Provide water to player self.refillPlayerWater = function () { if (LK.ticks - self.lastRefillTime > self.refillCooldown) { self.lastRefillTime = LK.ticks; LK.getSound('waterRefill').play(); return self.refillAmount; } return 0; }; return self; }); /**** * Initialize Game ****/ // Set water-themed background color var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Set water-themed background color // Initialize assets for the water elementalist game // Import tween plugin for animations game.setBackgroundColor(0x1A75FF); // Game variables var waterMaster; var waterProjectiles = []; var enemies = []; var waterSources = []; var score = 0; var level = 1; var gameActive = true; // UI elements var waterBar; var scoreText; var levelText; // Initialize game UI function initializeUI() { // Create water bar background var waterBarBg = new Container(); var waterBarBgGraphic = waterBarBg.addChild(LK.getAsset('bullet', { anchorX: 0, anchorY: 0, width: 400, height: 40, tint: 0x555555 })); // Create water bar waterBar = new Container(); var waterBarGraphic = waterBar.addChild(LK.getAsset('bullet', { anchorX: 0, anchorY: 0, width: 396, height: 36, tint: 0x00BFFF })); // Position water bar waterBarBg.x = 20; waterBarBg.y = 20; waterBar.x = 22; waterBar.y = 22; // Add to GUI LK.gui.topLeft.addChild(waterBarBg); LK.gui.topLeft.addChild(waterBar); // Create score text scoreText = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreText.anchor.set(1, 0); scoreText.x = -20; scoreText.y = 20; LK.gui.topRight.addChild(scoreText); // Create level text levelText = new Text2('Level: 1', { size: 60, fill: 0xFFFFFF }); levelText.anchor.set(0.5, 0); levelText.y = 20; LK.gui.top.addChild(levelText); } // Initialize player character function initializePlayer() { waterMaster = game.addChild(new WaterMaster()); waterMaster.x = 2048 / 2; waterMaster.y = 2732 - 300; } // Initialize water sources function initializeWaterSources() { // Add water sources at different locations var positions = [{ x: 300, y: 500 }, { x: 1700, y: 500 }, { x: 1000, y: 1500 }]; for (var i = 0; i < positions.length; i++) { var waterSource = new WaterSource(); waterSource.x = positions[i].x; waterSource.y = positions[i].y; waterSource.lastWasIntersecting = false; waterSources.push(waterSource); game.addChild(waterSource); } } // Create a water projectile game.createWaterProjectile = function (x, y, speedX, speedY) { var projectile = new WaterProjectile(); projectile.x = x; projectile.y = y; projectile.lastX = x; projectile.lastY = y; projectile.init(speedX, speedY, 1 + level * 0.2); projectile.lastWasIntersecting = false; waterProjectiles.push(projectile); game.addChild(projectile); }; // Spawn enemies function spawnEnemies() { // Determine number of enemies based on level var enemyCount = Math.min(2 + level, 8); // Clear any existing enemies for (var i = 0; i < enemies.length; i++) { if (enemies[i].parent) { enemies[i].parent.removeChild(enemies[i]); } } enemies = []; // Create new enemies for (var i = 0; i < enemyCount; i++) { var enemy = new Enemy(); // Position enemy randomly but not too close to player do { enemy.x = Math.random() * 1848 + 100; enemy.y = Math.random() * 1500 + 100; } while (Math.sqrt(Math.pow(enemy.x - waterMaster.x, 2) + Math.pow(enemy.y - waterMaster.y, 2)) < 500); enemy.lastX = enemy.x; enemy.lastY = enemy.y; enemy.init(80 + level * 20, 0, 0); enemy.lastWasIntersecting = false; enemies.push(enemy); game.addChild(enemy); } } // Update score and level function updateScore(points) { score += points; scoreText.setText('Score: ' + score); // Check for level up if (score >= level * 100) { levelUp(); } } // Level up function levelUp() { level++; levelText.setText('Level: ' + level); // Flash screen to indicate level up LK.effects.flashScreen(0x00FFFF, 500); // Spawn new enemies for the level spawnEnemies(); } // Game initialization initializeUI(); initializePlayer(); initializeWaterSources(); spawnEnemies(); // Game touch handling game.lastTouchX = 0; game.lastTouchY = 0; // Dragging functionality var isDragging = false; // Touch down event game.down = function (x, y, obj) { // Store touch position game.lastTouchX = x; game.lastTouchY = y; // Check if touching water master if (waterMaster) { var touchPoint = { x: x, y: y }; var distance = Math.sqrt(Math.pow(touchPoint.x - waterMaster.x, 2) + Math.pow(touchPoint.y - waterMaster.y, 2)); if (distance < 100) { // Start dragging player isDragging = true; } else { // Start charging water shot waterMaster.down(x, y, obj); } } }; // Touch move event game.move = function (x, y, obj) { // Store touch position game.lastTouchX = x; game.lastTouchY = y; if (isDragging && waterMaster) { // Move water master with touch waterMaster.x = x; waterMaster.y = y; // Keep within game bounds if (waterMaster.x < 100) waterMaster.x = 100; if (waterMaster.x > 2048 - 100) waterMaster.x = 2048 - 100; if (waterMaster.y < 100) waterMaster.y = 100; if (waterMaster.y > 2732 - 100) waterMaster.y = 2732 - 100; } }; // Touch up event game.up = function (x, y, obj) { // If was charging water shot if (!isDragging && waterMaster) { waterMaster.up(x, y, obj); } // Stop dragging isDragging = false; }; // Double tap to activate shield var lastTapTime = 0; game.down = function (x, y, obj) { var currentTime = Date.now(); // Check for double tap (within 300ms) if (currentTime - lastTapTime < 300) { if (waterMaster) { waterMaster.activateShield(); } } lastTapTime = currentTime; // Also handle regular down event game.down(x, y, obj); }; // Game update loop game.update = function () { if (!gameActive) return; // Update water master if (waterMaster) { waterMaster.update(); // Update water bar UI if (waterBar) { var waterRatio = waterMaster.currentWater / waterMaster.waterReserve; waterBar.children[0].width = 396 * waterRatio; } // Check water master collisions with water sources for (var i = 0; i < waterSources.length; i++) { var source = waterSources[i]; var isIntersecting = waterMaster.intersects(source); // Refill water if touching a water source for the first time if (!source.lastWasIntersecting && isIntersecting) { var refillAmount = source.refillPlayerWater(); if (refillAmount > 0) { waterMaster.refillWater(refillAmount); // Visual feedback LK.effects.flashObject(source, 0x00FFFF, 500); } } source.lastWasIntersecting = isIntersecting; } } // Update water projectiles for (var i = waterProjectiles.length - 1; i >= 0; i--) { var projectile = waterProjectiles[i]; projectile.update(); // Check if projectile is out of bounds or expired if (projectile.x < -100 || projectile.x > 2148 || projectile.y < -100 || projectile.y > 2832 || projectile.age > projectile.lifespan) { if (projectile.parent) { projectile.parent.removeChild(projectile); } waterProjectiles.splice(i, 1); continue; } // Check collisions with enemies for (var j = 0; j < enemies.length; j++) { var enemy = enemies[j]; var isIntersecting = projectile.intersects(enemy); // Handle collision if not already intersecting if (!projectile.lastWasIntersecting && isIntersecting) { // Enemy takes damage based on projectile power var isDefeated = enemy.takeDamage(20 * projectile.power); // Remove projectile if (projectile.parent) { projectile.parent.removeChild(projectile); } waterProjectiles.splice(i, 1); // Play hit sound LK.getSound('waterHit').play(); // If enemy was defeated if (isDefeated) { if (enemy.parent) { enemy.parent.removeChild(enemy); } enemies.splice(j, 1); updateScore(10); } break; } if (projectile.lastWasIntersecting !== undefined) { projectile.lastWasIntersecting = isIntersecting; } } } // Update enemies for (var i = 0; i < enemies.length; i++) { var enemy = enemies[i]; // Move toward player if in range var distanceToPlayer = Math.sqrt(Math.pow(enemy.x - waterMaster.x, 2) + Math.pow(enemy.y - waterMaster.y, 2)); if (distanceToPlayer < 800) { enemy.moveToward(waterMaster.x, waterMaster.y, 1 + level * 0.2); } enemy.update(); // Check collision with player var isIntersecting = enemy.intersects(waterMaster); // Handle collision if not already intersecting and shield is not active if (!enemy.lastWasIntersecting && isIntersecting && waterMaster.shield.alpha < 0.1) { // Game over if no shield LK.effects.flashScreen(0xFF0000, 1000); LK.showGameOver(); gameActive = false; } else if (!enemy.lastWasIntersecting && isIntersecting && waterMaster.shield.alpha >= 0.1) { // Push enemy away if shield is active var dirX = enemy.x - waterMaster.x; var dirY = enemy.y - waterMaster.y; var length = Math.sqrt(dirX * dirX + dirY * dirY); if (length > 0) { dirX /= length; dirY /= length; } enemy.x += dirX * 200; enemy.y += dirY * 200; enemy.takeDamage(10); } enemy.lastWasIntersecting = isIntersecting; } // Check if all enemies are defeated if (enemies.length === 0) { // Spawn more enemies spawnEnemies(); updateScore(level * 20); } };
===================================================================
--- original.js
+++ change.js
@@ -244,17 +244,25 @@
self.lastRefillTime = 0;
self.lastWasIntersecting = false;
// Pulsating animation
function startPulsating() {
- tween.create(sourceGraphics.scale).to({
+ tween(sourceGraphics.scale, {
x: 1.1,
y: 1.1
- }, 1000).easing(tween.Easing.Sinusoidal.InOut).onComplete(function () {
- tween.create(sourceGraphics.scale).to({
- x: 0.9,
- y: 0.9
- }, 1000).easing(tween.Easing.Sinusoidal.InOut).onComplete(startPulsating).start();
- }).start();
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(sourceGraphics.scale, {
+ x: 0.9,
+ y: 0.9
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ onFinish: startPulsating
+ });
+ }
+ });
}
// Start pulsating animation
startPulsating();
// Provide water to player