User prompt
tambah 2 enemy lagi
User prompt
rubah text ball menjadi rose
User prompt
pertajam bacground
User prompt
perbaiki latar belakang agar muncul background
User prompt
fix background
User prompt
pindahkan labirin ke tengah
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'baseTexture')' in or related to this line: 'background.texture.baseTexture.scaleMode = 0; // NEAREST filtering for crisp pixels' Line Number: 535
User prompt
saya ingin backgroundnya terlihat jelas
User prompt
buat gambar backgroundnya jelas
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'baseTexture')' in or related to this line: 'background.texture.baseTexture.scaleMode = 0; // NEAREST filtering for crisp pixels' Line Number: 535
User prompt
make background sharp
User prompt
add background to game
User prompt
fix background
User prompt
background problem
User prompt
add background
User prompt
add background for game
User prompt
hapus bacground
User prompt
buat player bisa berbalik ke kanan atau ke kiri
User prompt
ubah animasi goldenball jadi melayang vertical ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
buat animasi enemy saat di tembak terpental jauh keluar dari maze ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
setelah enemy ditembak mati dalam 5 detik muncul lagi ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
perbaiki kontrol biar bisa player di kontrol tap dari luar maze
User prompt
perbaiki masalah game lagg
User prompt
buat ukuran maze lebih besar
User prompt
buat maze tanpa jalan buntu
/**** * 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.speedX = 0; self.speedY = 0; self.speed = 8; self.update = function () { // Store previous position for wall collision detection var prevX = self.x; var prevY = self.y; self.x += self.speedX; self.y += self.speedY; // Check if bullet hit a wall var mazeX = Math.floor((self.x - MAZE_START_X) / CELL_SIZE); var mazeY = Math.floor((self.y - MAZE_START_Y) / CELL_SIZE); // If bullet is inside maze bounds and hits a wall, destroy it if (mazeX >= 0 && mazeX < MAZE_WIDTH && mazeY >= 0 && mazeY < MAZE_HEIGHT) { if (maze[mazeY][mazeX] === 1) { self.destroy(); return; } } // Remove bullet if it goes off screen if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) { self.destroy(); } }; self.setDirection = function (dirX, dirY) { var length = Math.sqrt(dirX * dirX + dirY * dirY); if (length > 0) { self.speedX = dirX / length * self.speed; self.speedY = dirY / length * self.speed; } }; return self; }); var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.targetX = 0; self.targetY = 0; self.moveTimer = 0; self.moveDelay = 60; // Change direction every 60 frames self.directions = [{ x: 0, y: -1 }, // up { x: 1, y: 0 }, // right { x: 0, y: 1 }, // down { x: -1, y: 0 } // left ]; self.update = function () { // Only update every 3 frames to reduce computation if (LK.ticks % 3 !== 0) return; // AI movement - change direction periodically self.moveTimer++; if (self.moveTimer >= self.moveDelay) { self.moveTimer = 0; self.chooseNewDirection(); } var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 2) { // Simplified movement - don't check walls every frame self.x += dx > 0 ? self.speed : dx < 0 ? -self.speed : 0; self.y += dy > 0 ? self.speed : dy < 0 ? -self.speed : 0; } else { // Reached target, choose new direction self.chooseNewDirection(); } }; self.chooseNewDirection = function () { var currentMazeX = Math.floor((self.x - MAZE_START_X) / CELL_SIZE); var currentMazeY = Math.floor((self.y - MAZE_START_Y) / CELL_SIZE); var validDirections = []; // Check each direction for valid movement for (var i = 0; i < self.directions.length; i++) { var dir = self.directions[i]; var newMazeX = currentMazeX + dir.x; var newMazeY = currentMazeY + dir.y; if (newMazeX >= 0 && newMazeX < MAZE_WIDTH && newMazeY >= 0 && newMazeY < MAZE_HEIGHT) { if (maze[newMazeY][newMazeX] === 0) { validDirections.push(dir); } } } if (validDirections.length > 0) { var chosenDir = validDirections[Math.floor(Math.random() * validDirections.length)]; var targetMazeX = currentMazeX + chosenDir.x; var targetMazeY = currentMazeY + chosenDir.y; self.targetX = MAZE_START_X + targetMazeX * CELL_SIZE + CELL_SIZE / 2; self.targetY = MAZE_START_Y + targetMazeY * CELL_SIZE + CELL_SIZE / 2; } }; return self; }); var GoldenBall = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('goldenBall', { anchorX: 0.5, anchorY: 0.5 }); self.collected = false; self.update = function () { if (!self.collected && LK.ticks % 2 === 0) { ballGraphics.rotation += 0.1; } }; self.collect = function () { if (!self.collected) { self.collected = true; tween(ballGraphics, { scaleX: 0, scaleY: 0, alpha: 0 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { self.visible = false; } }); } }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 4; self.targetX = 0; self.targetY = 0; self.update = function () { var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 2) { // Calculate next position var nextX = self.x + dx / distance * self.speed; var nextY = self.y + dy / distance * self.speed; // Check if next position is valid (not a wall) var mazeX = Math.floor((nextX - MAZE_START_X) / CELL_SIZE); var mazeY = Math.floor((nextY - MAZE_START_Y) / CELL_SIZE); // Only move if the next position is valid if (mazeX >= 0 && mazeX < MAZE_WIDTH && mazeY >= 0 && mazeY < MAZE_HEIGHT) { if (maze[mazeY][mazeX] === 0) { self.x = nextX; self.y = nextY; } } else { // If outside maze bounds, allow movement (for entrance/exit areas) self.x = nextX; self.y = nextY; } } }; self.setTarget = function (x, y) { self.targetX = x; self.targetY = y; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2c3e50 }); /**** * Game Code ****/ var CELL_SIZE = 48; var MAZE_WIDTH = 16; var MAZE_HEIGHT = 20; var MAZE_START_X = (2048 - MAZE_WIDTH * CELL_SIZE) / 2; var MAZE_START_Y = 2732 - MAZE_HEIGHT * CELL_SIZE - 100; var maze = []; var walls = []; var floors = []; var player; var goldenBalls = []; var totalBalls = 0; var collectedBalls = 0; var bullets = []; var enemies = []; var enemyCount = 1; var swipeStart = { x: 0, y: 0 }; var isSwipping = false; // Tap controls - no drag node needed // Score display var scoreText = new Text2('Balls: 0/0', { size: 50, fill: 0xFFD700 }); scoreText.anchor.set(1, 0); LK.gui.topRight.addChild(scoreText); scoreText.x = -20; scoreText.y = 80; function generateMaze() { // Initialize maze with walls for (var y = 0; y < MAZE_HEIGHT; y++) { maze[y] = []; for (var x = 0; x < MAZE_WIDTH; x++) { maze[y][x] = 1; // 1 = wall, 0 = path } } // Generate maze without dead ends using modified algorithm var startX = 1; var startY = 1; maze[startY][startX] = 0; var directions = [{ x: 0, y: -2 }, // up { x: 2, y: 0 }, // right { x: 0, y: 2 }, // down { x: -2, y: 0 } // left ]; // First pass: create main paths using recursive backtracking var stack = []; stack.push({ x: startX, y: startY }); while (stack.length > 0) { var current = stack[stack.length - 1]; var neighbors = []; for (var i = 0; i < directions.length; i++) { var nx = current.x + directions[i].x; var ny = current.y + directions[i].y; if (nx > 0 && nx < MAZE_WIDTH - 1 && ny > 0 && ny < MAZE_HEIGHT - 1 && maze[ny][nx] === 1) { neighbors.push({ x: nx, y: ny, dir: directions[i] }); } } if (neighbors.length > 0) { var next = neighbors[Math.floor(Math.random() * neighbors.length)]; maze[next.y][next.x] = 0; maze[current.y + next.dir.y / 2][current.x + next.dir.x / 2] = 0; stack.push({ x: next.x, y: next.y }); } else { stack.pop(); } } // Second pass: add loops to eliminate dead ends for (var attempts = 0; attempts < 20; attempts++) { // Find all dead ends (cells with only one neighbor) var deadEnds = []; for (var y = 1; y < MAZE_HEIGHT - 1; y += 2) { for (var x = 1; x < MAZE_WIDTH - 1; x += 2) { if (maze[y][x] === 0) { var pathCount = 0; var possibleConnections = []; // Check all four directions if (y > 1 && maze[y - 1][x] === 0) pathCount++; if (y < MAZE_HEIGHT - 2 && maze[y + 1][x] === 0) pathCount++; if (x > 1 && maze[y][x - 1] === 0) pathCount++; if (x < MAZE_WIDTH - 2 && maze[y][x + 1] === 0) pathCount++; // If it's a dead end, try to connect it to another path if (pathCount === 1) { // Try to connect to nearby paths for (var i = 0; i < directions.length; i++) { var newX = x + directions[i].x; var newY = y + directions[i].y; if (newX > 0 && newX < MAZE_WIDTH - 1 && newY > 0 && newY < MAZE_HEIGHT - 1) { if (maze[newY][newX] === 0) { var wallX = x + directions[i].x / 2; var wallY = y + directions[i].y / 2; if (maze[wallY][wallX] === 1) { possibleConnections.push({ wallX: wallX, wallY: wallY }); } } } } if (possibleConnections.length > 0) { var connection = possibleConnections[Math.floor(Math.random() * possibleConnections.length)]; maze[connection.wallY][connection.wallX] = 0; } } } } } } // Create entrance var entranceX = Math.floor(Math.random() * (MAZE_WIDTH - 2)) + 1; maze[0][entranceX] = 0; return { x: entranceX, y: 0 }; } function createMazeVisuals() { for (var y = 0; y < MAZE_HEIGHT; y++) { for (var x = 0; x < MAZE_WIDTH; x++) { var cellX = MAZE_START_X + x * CELL_SIZE; var cellY = MAZE_START_Y + y * CELL_SIZE; if (maze[y][x] === 1) { var wall = game.addChild(LK.getAsset('wall', { x: cellX, y: cellY })); walls.push(wall); } else { var floor = game.addChild(LK.getAsset('floor', { x: cellX, y: cellY })); floors.push(floor); } } } } function spawnEnemies() { var spawnedEnemies = 0; var attempts = 0; var maxAttempts = 100; while (spawnedEnemies < enemyCount && attempts < maxAttempts) { var x = Math.floor(Math.random() * MAZE_WIDTH); var y = Math.floor(Math.random() * MAZE_HEIGHT); // Make sure enemy spawns in a path cell and not too close to player start if (maze[y][x] === 0 && (Math.abs(x - entrance.x) > 3 || Math.abs(y - entrance.y) > 3)) { var cellX = MAZE_START_X + x * CELL_SIZE + CELL_SIZE / 2; var cellY = MAZE_START_Y + y * CELL_SIZE + CELL_SIZE / 2; var enemy = game.addChild(new Enemy()); enemy.x = cellX; enemy.y = cellY; enemy.targetX = cellX; enemy.targetY = cellY; enemy.mazeX = x; enemy.mazeY = y; enemies.push(enemy); spawnedEnemies++; } attempts++; } } function placeholdenBalls() { var ballCount = Math.floor(MAZE_WIDTH * MAZE_HEIGHT * 0.02); // 2% of maze cells var placedBalls = 0; while (placedBalls < ballCount) { var x = Math.floor(Math.random() * MAZE_WIDTH); var y = Math.floor(Math.random() * MAZE_HEIGHT); if (maze[y][x] === 0) { var cellX = MAZE_START_X + x * CELL_SIZE + CELL_SIZE / 2; var cellY = MAZE_START_Y + y * CELL_SIZE + CELL_SIZE / 2; var ball = game.addChild(new GoldenBall()); ball.x = cellX; ball.y = cellY; ball.mazeX = x; ball.mazeY = y; goldenBalls.push(ball); placedBalls++; } } totalBalls = goldenBalls.length; updateScoreText(); } function updateScoreText() { scoreText.setText('Balls: ' + collectedBalls + '/' + totalBalls); } function isValidPosition(x, y) { var mazeX = Math.floor((x - MAZE_START_X) / CELL_SIZE); var mazeY = Math.floor((y - MAZE_START_Y) / CELL_SIZE); if (mazeX < 0 || mazeX >= MAZE_WIDTH || mazeY < 0 || mazeY >= MAZE_HEIGHT) { return false; } return maze[mazeY][mazeX] === 0; } function getValidTargetPosition(targetX, targetY) { var currentMazeX = Math.floor((player.x - MAZE_START_X) / CELL_SIZE); var currentMazeY = Math.floor((player.y - MAZE_START_Y) / CELL_SIZE); var targetMazeX = Math.floor((targetX - MAZE_START_X) / CELL_SIZE); var targetMazeY = Math.floor((targetY - MAZE_START_Y) / CELL_SIZE); if (targetMazeX < 0 || targetMazeX >= MAZE_WIDTH || targetMazeY < 0 || targetMazeY >= MAZE_HEIGHT) { return { x: player.x, y: player.y }; } if (maze[targetMazeY][targetMazeX] === 1) { return { x: player.x, y: player.y }; } var cellCenterX = MAZE_START_X + targetMazeX * CELL_SIZE + CELL_SIZE / 2; var cellCenterY = MAZE_START_Y + targetMazeY * CELL_SIZE + CELL_SIZE / 2; return { x: cellCenterX, y: cellCenterY }; } // Initialize maze var entrance = generateMaze(); createMazeVisuals(); // Create player player = game.addChild(new Player()); player.x = MAZE_START_X + entrance.x * CELL_SIZE + CELL_SIZE / 2; player.y = MAZE_START_Y + entrance.y * CELL_SIZE + CELL_SIZE / 2; player.setTarget(player.x, player.y); // Place golden balls placeholdenBalls(); // Spawn enemies spawnEnemies(); // Touch controls - swipe to shoot, tap to move game.down = function (x, y, obj) { swipeStart.x = x; swipeStart.y = y; isSwipping = true; }; game.move = function (x, y, obj) { // Track swipe movement but don't move player during swipe }; game.up = function (x, y, obj) { if (isSwipping) { var swipeEndX = x; var swipeEndY = y; var swipeDistanceX = swipeEndX - swipeStart.x; var swipeDistanceY = swipeEndY - swipeStart.y; var swipeDistance = Math.sqrt(swipeDistanceX * swipeDistanceX + swipeDistanceY * swipeDistanceY); if (swipeDistance > 30) { // Minimum swipe distance // Create bullet and shoot in swipe direction var bullet = game.addChild(new Bullet()); bullet.x = player.x; bullet.y = player.y; bullet.setDirection(swipeDistanceX, swipeDistanceY); bullets.push(bullet); LK.getSound('shoot').play(); } else { // Short tap - move player var validPos = getValidTargetPosition(x, y); player.setTarget(validPos.x, validPos.y); } isSwipping = false; } }; // Game update loop game.update = function () { // Clean up destroyed bullets for (var b = bullets.length - 1; b >= 0; b--) { var bullet = bullets[b]; if (!bullet.parent) { // Bullet has been destroyed bullets.splice(b, 1); } } // Only check collisions every other frame to reduce load if (LK.ticks % 2 === 0) { // Check player-enemy collision for (var e = 0; e < enemies.length; e++) { var enemy = enemies[e]; if (player.intersects(enemy)) { // Player touched enemy - game over LK.showGameOver(); return; } } } // Check bullet-enemy collision (keep this every frame for responsiveness) for (var b = bullets.length - 1; b >= 0; b--) { var bullet = bullets[b]; var hitEnemy = false; for (var e = enemies.length - 1; e >= 0; e--) { var enemy = enemies[e]; if (bullet.intersects(enemy)) { // Remove enemy and bullet enemy.destroy(); enemies.splice(e, 1); bullet.destroy(); bullets.splice(b, 1); // Add score for defeating enemy LK.setScore(LK.getScore() + 10); hitEnemy = true; break; } } if (hitEnemy) break; } // Check ball collection every 3 frames if (LK.ticks % 3 === 0) { for (var i = 0; i < goldenBalls.length; i++) { var ball = goldenBalls[i]; if (!ball.collected && player.intersects(ball)) { ball.collect(); collectedBalls++; LK.setScore(collectedBalls); updateScoreText(); LK.getSound('collect').play(); // Check win condition if (collectedBalls >= totalBalls) { LK.getSound('complete').play(); LK.setTimeout(function () { LK.showYouWin(); }, 500); } } } } };
===================================================================
--- original.js
+++ change.js
@@ -76,8 +76,10 @@
y: 0
} // left
];
self.update = function () {
+ // Only update every 3 frames to reduce computation
+ if (LK.ticks % 3 !== 0) return;
// AI movement - change direction periodically
self.moveTimer++;
if (self.moveTimer >= self.moveDelay) {
self.moveTimer = 0;
@@ -86,27 +88,11 @@
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 2) {
- // Calculate next position
- var nextX = self.x + dx / distance * self.speed;
- var nextY = self.y + dy / distance * self.speed;
- // Check if next position is valid (not a wall)
- var mazeX = Math.floor((nextX - MAZE_START_X) / CELL_SIZE);
- var mazeY = Math.floor((nextY - MAZE_START_Y) / CELL_SIZE);
- // Only move if the next position is valid
- if (mazeX >= 0 && mazeX < MAZE_WIDTH && mazeY >= 0 && mazeY < MAZE_HEIGHT) {
- if (maze[mazeY][mazeX] === 0) {
- self.x = nextX;
- self.y = nextY;
- } else {
- // Hit a wall, choose new direction immediately
- self.chooseNewDirection();
- }
- } else {
- // Outside maze bounds, choose new direction
- self.chooseNewDirection();
- }
+ // Simplified movement - don't check walls every frame
+ self.x += dx > 0 ? self.speed : dx < 0 ? -self.speed : 0;
+ self.y += dy > 0 ? self.speed : dy < 0 ? -self.speed : 0;
} else {
// Reached target, choose new direction
self.chooseNewDirection();
}
@@ -143,12 +129,10 @@
anchorY: 0.5
});
self.collected = false;
self.update = function () {
- if (!self.collected) {
- ballGraphics.rotation += 0.05;
- ballGraphics.scaleX = 1 + Math.sin(LK.ticks * 0.1) * 0.1;
- ballGraphics.scaleY = 1 + Math.sin(LK.ticks * 0.1) * 0.1;
+ if (!self.collected && LK.ticks % 2 === 0) {
+ ballGraphics.rotation += 0.1;
}
};
self.collect = function () {
if (!self.collected) {
@@ -218,10 +202,10 @@
/****
* Game Code
****/
var CELL_SIZE = 48;
-var MAZE_WIDTH = 20;
-var MAZE_HEIGHT = 25;
+var MAZE_WIDTH = 16;
+var MAZE_HEIGHT = 20;
var MAZE_START_X = (2048 - MAZE_WIDTH * CELL_SIZE) / 2;
var MAZE_START_Y = 2732 - MAZE_HEIGHT * CELL_SIZE - 100;
var maze = [];
var walls = [];
@@ -231,9 +215,9 @@
var totalBalls = 0;
var collectedBalls = 0;
var bullets = [];
var enemies = [];
-var enemyCount = 2;
+var enemyCount = 1;
var swipeStart = {
x: 0,
y: 0
};
@@ -407,9 +391,9 @@
attempts++;
}
}
function placeholdenBalls() {
- var ballCount = Math.floor(MAZE_WIDTH * MAZE_HEIGHT * 0.05); // 5% of maze cells
+ var ballCount = Math.floor(MAZE_WIDTH * MAZE_HEIGHT * 0.02); // 2% of maze cells
var placedBalls = 0;
while (placedBalls < ballCount) {
var x = Math.floor(Math.random() * MAZE_WIDTH);
var y = Math.floor(Math.random() * MAZE_HEIGHT);
@@ -517,21 +501,25 @@
// Bullet has been destroyed
bullets.splice(b, 1);
}
}
- // Check player-enemy collision
- for (var e = 0; e < enemies.length; e++) {
- var enemy = enemies[e];
- if (player.intersects(enemy)) {
- // Player touched enemy - game over
- LK.showGameOver();
- return;
+ // Only check collisions every other frame to reduce load
+ if (LK.ticks % 2 === 0) {
+ // Check player-enemy collision
+ for (var e = 0; e < enemies.length; e++) {
+ var enemy = enemies[e];
+ if (player.intersects(enemy)) {
+ // Player touched enemy - game over
+ LK.showGameOver();
+ return;
+ }
}
}
- // Check bullet-enemy collision
- for (var b = 0; b < bullets.length; b++) {
+ // Check bullet-enemy collision (keep this every frame for responsiveness)
+ for (var b = bullets.length - 1; b >= 0; b--) {
var bullet = bullets[b];
- for (var e = 0; e < enemies.length; e++) {
+ var hitEnemy = false;
+ for (var e = enemies.length - 1; e >= 0; e--) {
var enemy = enemies[e];
if (bullet.intersects(enemy)) {
// Remove enemy and bullet
enemy.destroy();
@@ -539,27 +527,31 @@
bullet.destroy();
bullets.splice(b, 1);
// Add score for defeating enemy
LK.setScore(LK.getScore() + 10);
+ hitEnemy = true;
break;
}
}
+ if (hitEnemy) break;
}
- // Check ball collection
- for (var i = 0; i < goldenBalls.length; i++) {
- var ball = goldenBalls[i];
- if (!ball.collected && player.intersects(ball)) {
- ball.collect();
- collectedBalls++;
- LK.setScore(collectedBalls);
- updateScoreText();
- LK.getSound('collect').play();
- // Check win condition
- if (collectedBalls >= totalBalls) {
- LK.getSound('complete').play();
- LK.setTimeout(function () {
- LK.showYouWin();
- }, 500);
+ // Check ball collection every 3 frames
+ if (LK.ticks % 3 === 0) {
+ for (var i = 0; i < goldenBalls.length; i++) {
+ var ball = goldenBalls[i];
+ if (!ball.collected && player.intersects(ball)) {
+ ball.collect();
+ collectedBalls++;
+ LK.setScore(collectedBalls);
+ updateScoreText();
+ LK.getSound('collect').play();
+ // Check win condition
+ if (collectedBalls >= totalBalls) {
+ LK.getSound('complete').play();
+ LK.setTimeout(function () {
+ LK.showYouWin();
+ }, 500);
+ }
}
}
}
};
\ No newline at end of file
2d side scroller bee. In-Game asset. 2d. High contrast. No shadows
big evil wasp. In-Game asset. 2d. High contrast. No shadows
2d side scroller rose fresh rose flower. In-Game asset. 2d. High contrast. No shadows
image 2d classic full warna tentang hamparan bunga bunga liar disuatu lembah. In-Game asset. 2d. High contrast. No shadows