User prompt
Let the game be level 10 and start from level 1
User prompt
Let the game last from eposide 1 to 10 and pass the chapters one by one.
User prompt
Pacman starts from one corner of the game
User prompt
Let's start from episode 1, final 10 episodes
User prompt
Don't let the game end when your Pacman monster dies.
User prompt
When Monter dies, the game doesn't end, it moves on to a new episode.
User prompt
swim bubbles in the game ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Monster dies in 10 hits
User prompt
Let the game be level 10
User prompt
Let the game be 10 perch
User prompt
Octopus monster explodes in 10 hits
User prompt
Make a sound when I hit the monster
User prompt
Let it be a sound effect that I uploaded in bubbles
User prompt
The music in the game should be the music I uploaded
User prompt
score 100
User prompt
If I can't pass the level in 99 seconds, game over.
User prompt
Let the enemy emerge from the beast's arms and some follow me ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
The enemy should not turn in place, but only move left and right.
User prompt
Pacman turns according to the direction of fire ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
don't let the enemy return
User prompt
I want 10 points for every fish I kill, let the fish swim towards me and let the bubbles I shoot not come back. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Let the fish direct the player ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Don't let the fish stand upside down ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Fish change direction by swimming left and right ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Let the fish turn and change direction and follow me ↪💡 Consider importing and using the following plugins: @upit/tween.v1
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.targetX = 0;
self.targetY = 0;
self.lastIntersecting = false;
self.returningToSpawn = false;
self.update = function () {
// Move towards target
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
} else {
// When reached target, destroy bullet instead of returning
var bulletIndex = bullets.indexOf(self);
if (bulletIndex !== -1) {
bullets.splice(bulletIndex, 1);
}
self.destroy();
}
// Check intersection with central monster
var currentIntersecting = self.intersects(centralMonster);
if (!self.lastIntersecting && currentIntersecting) {
// Hit the monster
monsterHits++;
centralMonster.grow();
// Remove from bullets array
var bulletIndex = bullets.indexOf(self);
if (bulletIndex !== -1) {
bullets.splice(bulletIndex, 1);
}
self.destroy();
}
self.lastIntersecting = currentIntersecting;
// Check intersection with enemies
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
if (self.intersects(enemy)) {
// Hit an enemy - destroy both bullet and enemy
// Award 10 points for killing fish
playerScore += 10;
scoreText.setText('Score: ' + playerScore);
enemy.destroy();
enemies.splice(i, 1);
// Remove bullet from bullets array
var bulletIndex = bullets.indexOf(self);
if (bulletIndex !== -1) {
bullets.splice(bulletIndex, 1);
}
self.destroy();
break; // Exit loop since bullet is destroyed
}
}
// Remove if off screen
if (self.x < -50 || self.x > 2098 || self.y < -50 || self.y > 2782) {
// Remove from bullets array
var bulletIndex = bullets.indexOf(self);
if (bulletIndex !== -1) {
bullets.splice(bulletIndex, 1);
}
self.destroy();
}
};
return self;
});
var CentralMonster = Container.expand(function () {
var self = Container.call(this);
var monsterGraphics = self.attachAsset('centralMonster', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
self.spawnTimer = 0;
self.spawnInterval = 120; // Spawn every 2 seconds at 60fps
self.armPositions = [{
x: -250,
y: -200
},
// Top left arm
{
x: 250,
y: -200
},
// Top right arm
{
x: -300,
y: 0
},
// Left arm
{
x: 300,
y: 0
},
// Right arm
{
x: -250,
y: 200
},
// Bottom left arm
{
x: 250,
y: 200
} // Bottom right arm
];
self.startMovement = function () {
// Create continuous floating movement
self.animateMovement();
};
self.animateMovement = function () {
// Escape from Pacman - move away from him
var dx = self.x - pacman.x;
var dy = self.y - pacman.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// If too close to Pacman, move away
if (distance < 400) {
// Normalize direction and move away
dx = dx / distance;
dy = dy / distance;
} else {
// Random movement when far enough
dx = (Math.random() - 0.5) * 2;
dy = (Math.random() - 0.5) * 2;
}
// Calculate new position (escape direction)
var newX = self.x + dx * (200 + Math.random() * 200);
var newY = self.y + dy * (200 + Math.random() * 200);
// Keep within screen bounds
newX = Math.max(200, Math.min(1848, newX));
newY = Math.max(200, Math.min(2532, newY));
tween(self, {
x: newX,
y: newY
}, {
duration: 1500 + Math.random() * 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
self.animateMovement(); // Continue movement
}
});
// Add rotation animation
tween(self, {
rotation: self.rotation + (Math.random() - 0.5) * 0.5
}, {
duration: 1500 + Math.random() * 1000,
easing: tween.easeInOut
});
};
self.update = function () {
self.spawnTimer++;
// Spawn enemies from arms
if (self.spawnTimer >= self.spawnInterval) {
self.spawnTimer = 0;
self.spawnEnemy();
}
};
self.spawnEnemy = function () {
// Pick random arm position
var armIndex = Math.floor(Math.random() * self.armPositions.length);
var armPos = self.armPositions[armIndex];
// Create enemy at arm position (relative to monster)
var enemy = new Enemy();
enemy.x = self.x + armPos.x;
enemy.y = self.y + armPos.y;
// Enemy will follow Pacman automatically in its update method
enemies.push(enemy);
game.addChild(enemy);
// Add spawn effect
enemy.alpha = 0;
tween(enemy, {
alpha: 1,
scaleX: 0.3,
scaleY: 0.3
}, {
duration: 500,
easing: tween.easeOut
});
};
self.grow = function () {
// Increase monster size
var newScale = monsterGraphics.scaleX + 0.1;
tween(monsterGraphics, {
scaleX: newScale,
scaleY: newScale
}, {
duration: 300,
easing: tween.easeOut
});
// Flash effect when hit
tween(monsterGraphics, {
tint: 0xff0000
}, {
duration: 100,
onFinish: function onFinish() {
tween(monsterGraphics, {
tint: 0xffffff
}, {
duration: 100
});
}
});
};
self.explode = function () {
// Stop all movement
tween.stop(self);
// Explosion animation
tween(monsterGraphics, {
scaleX: 3,
scaleY: 3,
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
// Level complete
LK.showYouWin();
}
});
// Flash screen
LK.effects.flashScreen(0xffffff, 500);
};
return self;
});
// Create central monster
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.3,
scaleY: 0.3
});
self.speed = 2;
self.targetX = 0;
self.targetY = 0;
self.lastX = 0;
self.lastY = 0;
self.directionChangeTimer = 0;
self.directionChangeInterval = 60 + Math.random() * 60; // Random direction changes
self.isChangingDirection = false;
self.update = function () {
self.lastX = self.x;
self.lastY = self.y;
// Direction change timer
self.directionChangeTimer++;
if (self.directionChangeTimer >= self.directionChangeInterval && !self.isChangingDirection) {
self.directionChangeTimer = 0;
self.directionChangeInterval = 60 + Math.random() * 60;
self.isChangingDirection = true;
// Fish swimming pattern - horizontal movement with direction changes
var swimmingDirection = Math.random() > 0.5 ? 1 : -1; // Left or right
var swimDistance = 200 + Math.random() * 300; // Random swim distance
var tempTargetX = self.x + swimmingDirection * swimDistance;
var tempTargetY = self.y + (Math.random() - 0.5) * 100; // Small vertical variation
// Keep within bounds
tempTargetX = Math.max(100, Math.min(1948, tempTargetX));
tempTargetY = Math.max(100, Math.min(2632, tempTargetY));
// Smooth swimming movement
tween(self, {
x: tempTargetX,
y: tempTargetY
}, {
duration: 1000 + Math.random() * 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
self.isChangingDirection = false;
}
});
// Turn fish sprite to face swimming direction
// Constrain rotation to prevent upside down fish
var targetRotation = swimmingDirection > 0 ? 0 : Math.PI;
if (targetRotation > Math.PI / 2 && targetRotation < 3 * Math.PI / 2) {
targetRotation = Math.PI / 2; // Face down instead of upside down
}
tween(enemyGraphics, {
rotation: targetRotation
}, {
duration: 300,
easing: tween.easeOut
});
}
// Swim towards Pacman instead of directing them
if (!self.isChangingDirection) {
var dx = pacman.x - self.x;
var dy = pacman.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
// Calculate direction towards Pacman
var targetDirection = Math.atan2(dy, dx);
// Constrain rotation to prevent upside down fish
// Keep rotation between -PI/2 and PI/2 (90 degrees up and down)
if (targetDirection > Math.PI / 2) {
targetDirection = Math.PI / 2;
} else if (targetDirection < -Math.PI / 2) {
targetDirection = -Math.PI / 2;
}
// Smooth rotation towards target direction using tween
tween(enemyGraphics, {
rotation: targetDirection
}, {
duration: 200,
easing: tween.easeOut
});
// Move towards Pacman
self.x += Math.cos(targetDirection) * self.speed;
self.y += Math.sin(targetDirection) * self.speed;
}
}
// Keep enemies within screen bounds instead of destroying them
if (self.x < 100) self.x = 100;
if (self.x > 1948) self.x = 1948;
if (self.y < 100) self.y = 100;
if (self.y > 2632) self.y = 2632;
};
return self;
});
var Pacman = Container.expand(function () {
var self = Container.call(this);
var pacmanGraphics = self.attachAsset('pacman', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.targetX = 0;
self.targetY = 0;
self.returningToSpawn = false;
self.update = function () {
// Move towards target position
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 10) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
} else {
// When reached target, start returning to spawn after a delay
if (!self.returningToSpawn) {
self.returningToSpawn = true;
LK.setTimeout(function () {
tween(self, {
x: spawnX,
y: spawnY
}, {
duration: 2000,
easing: tween.easeInOut,
onFinish: function onFinish() {
self.returningToSpawn = false;
}
});
}, 1000);
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0066cc
});
/****
* Game Code
****/
// Add sea background
var seaBackground = game.addChild(LK.getAsset('seaBackground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
// Create Pacman character
var pacman = game.addChild(new Pacman());
pacman.x = 1024;
pacman.y = 2000;
// Create central monster
var centralMonster = game.addChild(new CentralMonster());
centralMonster.x = 1024;
centralMonster.y = 1366;
// Array to track enemies
var enemies = [];
// Array to track bullets
var bullets = [];
// Track monster hits
var monsterHits = 0;
var hitsToWin = 20;
// Player lives
var playerLives = 3;
// Player score
var playerScore = 0;
// Store spawn position
var spawnX = 1024;
var spawnY = 2000;
// Touch controls for Pacman movement and shooting
game.down = function (x, y, obj) {
pacman.targetX = x;
pacman.targetY = y;
// Calculate angle from Pacman to target and rotate Pacman
var dx = x - pacman.x;
var dy = y - pacman.y;
var angle = Math.atan2(dy, dx);
// Rotate Pacman to face the firing direction
tween(pacman, {
rotation: angle
}, {
duration: 200,
easing: tween.easeOut
});
// Create bullet towards touch position
var bullet = new Bullet();
bullet.x = pacman.x;
bullet.y = pacman.y;
bullet.targetX = x;
bullet.targetY = y;
bullets.push(bullet);
game.addChild(bullet);
};
game.move = function (x, y, obj) {
pacman.targetX = x;
pacman.targetY = y;
};
// Game update loop
game.update = function () {
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
if (bullet.parent) {
// Bullet is still active
} else {
// Bullet was destroyed, remove from array
bullets.splice(i, 1);
}
}
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
var enemy = enemies[j];
if (enemy.parent) {
// Check collision with player
if (enemy.intersects(pacman)) {
// Player hit by enemy
playerLives--;
livesText.setText('Lives: ' + playerLives);
// Flash effect on hit
LK.effects.flashScreen(0xff0000, 300);
// Check game over
if (playerLives <= 0) {
LK.showGameOver();
return;
}
// Remove enemy that hit player
enemy.destroy();
enemies.splice(j, 1);
continue;
}
} else {
// Enemy was destroyed, remove from array
enemies.splice(j, 1);
}
}
// Check collision with central monster
if (centralMonster.intersects(pacman)) {
// Player hit by central monster
playerLives--;
livesText.setText('Lives: ' + playerLives);
// Flash effect on hit
LK.effects.flashScreen(0xff0000, 300);
// Check game over
if (playerLives <= 0) {
LK.showGameOver();
return;
}
// Push player away from monster
var dx = pacman.x - centralMonster.x;
var dy = pacman.y - centralMonster.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
pacman.x += dx / distance * 100;
pacman.y += dy / distance * 100;
}
}
// Check if monster should explode
if (monsterHits >= hitsToWin) {
centralMonster.explode();
monsterHits = 0; // Reset to prevent multiple explosions
}
};
// Create lives display
var livesText = new Text2('Lives: ' + playerLives, {
size: 80,
fill: 0xFFFFFF
});
livesText.anchor.set(0, 0);
livesText.x = 150;
livesText.y = 150;
LK.gui.topLeft.addChild(livesText);
// Create score display
var scoreText = new Text2('Score: ' + playerScore, {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
scoreText.x = 150;
scoreText.y = 250;
LK.gui.topLeft.addChild(scoreText);
// Start monster movement
centralMonster.startMovement();
; ===================================================================
--- original.js
+++ change.js
@@ -411,8 +411,19 @@
// Touch controls for Pacman movement and shooting
game.down = function (x, y, obj) {
pacman.targetX = x;
pacman.targetY = y;
+ // Calculate angle from Pacman to target and rotate Pacman
+ var dx = x - pacman.x;
+ var dy = y - pacman.y;
+ var angle = Math.atan2(dy, dx);
+ // Rotate Pacman to face the firing direction
+ tween(pacman, {
+ rotation: angle
+ }, {
+ duration: 200,
+ easing: tween.easeOut
+ });
// Create bullet towards touch position
var bullet = new Bullet();
bullet.x = pacman.x;
bullet.y = pacman.y;