User prompt
Add collision to the walls and furniture.
User prompt
Add more furniture for the bananas to hide.
User prompt
When the enemy touches you, make it an automatic kill.
User prompt
Make the map bigger.
User prompt
Make the player's speed the same speed as the enemy's.
User prompt
Make the players slower.
User prompt
Enemy chase you. When it touches you, make a game over scene.
User prompt
the number of bananas that you have to collect from 7 to 20.
User prompt
Let the camera move with the player.
User prompt
Make the map bigger.
User prompt
When the player touches the banana, collect it and add it to the server bananas.
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'if (obj.event.target === player) {' Line Number: 260
User prompt
Make the player move with your finger.
Code edit (1 edits merged)
Please save this source code
User prompt
Banana Hunt: Find & Collect
Initial prompt
Make a game that you have to find seven bananas and collect them and put them on a desk.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Banana = Container.expand(function () { var self = Container.call(this); var bananaGraphics = self.attachAsset('banana', { anchorX: 0.5, anchorY: 0.5, rotation: Math.PI / 4 }); self.isCollected = false; self.isDragging = false; self.down = function (x, y, obj) { if (!self.isCollected) { self.isDragging = true; LK.getSound('pickup').play(); } }; self.up = function (x, y, obj) { self.isDragging = false; if (self.intersects(collectionDesk) && !self.isCollected) { self.isCollected = true; // Animate banana to center of desk var deskGlobal = collectionDesk.toGlobal({ x: 0, y: 0 }); var deskLocal = game.toLocal(deskGlobal); tween(self, { x: deskLocal.x + collectionDesk.width / 2, y: deskLocal.y + 50 + collectedBananas * 30 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { collectedBananas++; updateCollectionCounter(); LK.getSound('drop').play(); if (collectedBananas === totalBananas) { LK.setTimeout(function () { LK.getSound('success').play(); LK.showYouWin(); }, 1000); } } }); } }; return self; }); var CollectionDesk = Container.expand(function () { var self = Container.call(this); var deskGraphics = self.attachAsset('desk', { anchorX: 0.5, anchorY: 0.5 }); var labelText = new Text2('Collection Desk', { size: 40, fill: 0xFFFFFF }); labelText.anchor.set(0.5, 0.5); labelText.position.set(0, -60); self.addChild(labelText); return self; }); var FurniturePiece = Container.expand(function (assetName, width, height) { var self = Container.call(this); var furnitureGraphics = self.attachAsset(assetName, { anchorX: 0.5, anchorY: 0.5 }); self.width = width; self.height = height; return self; }); var Player = Container.expand(function () { var self = Container.call(this); // Create a simple player character using an existing shape var playerGraphics = self.attachAsset('pillow', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.8, scaleY: 0.8, tint: 0x00AAFF // Blue tint to distinguish from other pillows }); // Track if player is being dragged self.isDragging = false; self.down = function (x, y, obj) { self.isDragging = true; }; self.up = function (x, y, obj) { self.isDragging = false; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xF5F5DC }); /**** * Game Code ****/ // Game constants var totalBananas = 7; var collectedBananas = 0; var bananas = []; var draggedBanana = null; var player = null; // Add room background var background = game.addChild(LK.getAsset('roomBackground', { anchorX: 0, anchorY: 0 })); background.width = 4096; // Double the width background.height = 5464; // Double the height // Add furniture pieces var furniturePieces = []; // Bed var bed = new FurniturePiece('bed', 600, 300); bed.x = 3200; bed.y = 1000; game.addChild(bed); furniturePieces.push(bed); // Table var table = new FurniturePiece('table', 300, 150); table.x = 1000; table.y = 2400; game.addChild(table); furniturePieces.push(table); // Sofa var sofa = new FurniturePiece('sofa', 500, 200); sofa.x = 1000; sofa.y = 3600; game.addChild(sofa); furniturePieces.push(sofa); // Bookshelf var bookshelf = new FurniturePiece('bookshelf', 300, 500); bookshelf.x = 3400; bookshelf.y = 2800; game.addChild(bookshelf); furniturePieces.push(bookshelf); // Plant var plant = new FurniturePiece('plant', 150, 200); plant.x = 3000; plant.y = 4000; game.addChild(plant); furniturePieces.push(plant); // Lamp var lamp = new FurniturePiece('lamp', 100, 250); lamp.x = 600; lamp.y = 1000; game.addChild(lamp); furniturePieces.push(lamp); // Pillow var pillow = new FurniturePiece('pillow', 150, 150); pillow.x = 3400; pillow.y = 1200; game.addChild(pillow); furniturePieces.push(pillow); // Add collection desk var collectionDesk = new CollectionDesk(); collectionDesk.x = 2048; // Center of screen collectionDesk.y = 5000; // Bottom of screen game.addChild(collectionDesk); // Add collection counter var collectionCounter = new Text2('0/' + totalBananas + ' bananas', { size: 60, fill: 0x000000 }); collectionCounter.anchor.set(0.5, 0); LK.gui.top.addChild(collectionCounter); function updateCollectionCounter() { collectionCounter.setText(collectedBananas + "/" + totalBananas + " bananas"); } updateCollectionCounter(); // Create and hide bananas around the room function createBananas() { var bananaPositions = [{ x: 3300, y: 800 }, // Near the bed { x: 1100, y: 2300 }, // On the table { x: 700, y: 3600 }, // Behind the sofa { x: 3400, y: 2400 }, // On bookshelf { x: 3100, y: 4100 }, // Behind plant { x: 600, y: 700 }, // Near lamp { x: 3500, y: 1300 } // Under pillow ]; for (var i = 0; i < totalBananas; i++) { var banana = new Banana(); banana.x = bananaPositions[i].x; banana.y = bananaPositions[i].y; // Add slight random rotation banana.rotation = (Math.random() - 0.5) * 0.5; bananas.push(banana); game.addChild(banana); } } createBananas(); // Create and add player character player = new Player(); player.x = 2048; // Start at center of screen horizontally player.y = 2732; // Middle of the screen vertically game.addChild(player); // Game event handlers game.down = function (x, y, obj) { // Check if player was clicked if (obj.target === player) { player.isDragging = true; } }; game.move = function (x, y, obj) { // Move any dragged banana for (var i = 0; i < bananas.length; i++) { if (bananas[i].isDragging) { bananas[i].x = x; bananas[i].y = y; } } // Move player if being dragged if (player && player.isDragging) { player.x = x; player.y = y; } }; game.up = function (x, y, obj) { // Handled by individual banana objects if (player) { player.isDragging = false; } }; // Update function to check for player-banana collisions game.update = function () { // Check if player touches any banana if (player) { for (var i = 0; i < bananas.length; i++) { if (!bananas[i].isCollected && !bananas[i].isDragging && player.intersects(bananas[i])) { // Collect the banana bananas[i].isCollected = true; // Animate banana to center of desk var deskGlobal = collectionDesk.toGlobal({ x: 0, y: 0 }); var deskLocal = game.toLocal(deskGlobal); // Play pickup sound LK.getSound('pickup').play(); tween(bananas[i], { x: deskLocal.x + collectionDesk.width / 2, y: deskLocal.y + 50 + collectedBananas * 30 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { collectedBananas++; updateCollectionCounter(); LK.getSound('drop').play(); if (collectedBananas === totalBananas) { LK.setTimeout(function () { LK.getSound('success').play(); LK.showYouWin(); }, 1000); } } }); } } } }; // Play background music LK.playMusic('bgmusic'); // Instructions var instructionsText = new Text2("Find 7 hidden bananas and\ndrag them to the collection desk!", { size: 50, fill: 0x000000 }); instructionsText.anchor.set(0.5, 0); instructionsText.y = 100; LK.gui.top.addChild(instructionsText); // Auto-hide instructions after 5 seconds LK.setTimeout(function () { tween(instructionsText, { alpha: 0 }, { duration: 1000, easing: tween.easeOut }); }, 5000);
===================================================================
--- original.js
+++ change.js
@@ -120,58 +120,58 @@
var background = game.addChild(LK.getAsset('roomBackground', {
anchorX: 0,
anchorY: 0
}));
-background.width = 2048;
-background.height = 2732;
+background.width = 4096; // Double the width
+background.height = 5464; // Double the height
// Add furniture pieces
var furniturePieces = [];
// Bed
var bed = new FurniturePiece('bed', 600, 300);
-bed.x = 1600;
-bed.y = 500;
+bed.x = 3200;
+bed.y = 1000;
game.addChild(bed);
furniturePieces.push(bed);
// Table
var table = new FurniturePiece('table', 300, 150);
-table.x = 500;
-table.y = 1200;
+table.x = 1000;
+table.y = 2400;
game.addChild(table);
furniturePieces.push(table);
// Sofa
var sofa = new FurniturePiece('sofa', 500, 200);
-sofa.x = 500;
-sofa.y = 1800;
+sofa.x = 1000;
+sofa.y = 3600;
game.addChild(sofa);
furniturePieces.push(sofa);
// Bookshelf
var bookshelf = new FurniturePiece('bookshelf', 300, 500);
-bookshelf.x = 1700;
-bookshelf.y = 1400;
+bookshelf.x = 3400;
+bookshelf.y = 2800;
game.addChild(bookshelf);
furniturePieces.push(bookshelf);
// Plant
var plant = new FurniturePiece('plant', 150, 200);
-plant.x = 1500;
-plant.y = 2000;
+plant.x = 3000;
+plant.y = 4000;
game.addChild(plant);
furniturePieces.push(plant);
// Lamp
var lamp = new FurniturePiece('lamp', 100, 250);
-lamp.x = 300;
-lamp.y = 500;
+lamp.x = 600;
+lamp.y = 1000;
game.addChild(lamp);
furniturePieces.push(lamp);
// Pillow
var pillow = new FurniturePiece('pillow', 150, 150);
-pillow.x = 1700;
-pillow.y = 600;
+pillow.x = 3400;
+pillow.y = 1200;
game.addChild(pillow);
furniturePieces.push(pillow);
// Add collection desk
var collectionDesk = new CollectionDesk();
-collectionDesk.x = 1024; // Center of screen
-collectionDesk.y = 2500; // Bottom of screen
+collectionDesk.x = 2048; // Center of screen
+collectionDesk.y = 5000; // Bottom of screen
game.addChild(collectionDesk);
// Add collection counter
var collectionCounter = new Text2('0/' + totalBananas + ' bananas', {
size: 60,
@@ -185,40 +185,40 @@
updateCollectionCounter();
// Create and hide bananas around the room
function createBananas() {
var bananaPositions = [{
- x: 1650,
- y: 400
+ x: 3300,
+ y: 800
},
// Near the bed
{
- x: 550,
- y: 1150
+ x: 1100,
+ y: 2300
},
// On the table
{
- x: 350,
- y: 1800
+ x: 700,
+ y: 3600
},
// Behind the sofa
{
- x: 1700,
- y: 1200
+ x: 3400,
+ y: 2400
},
// On bookshelf
{
- x: 1550,
- y: 2050
+ x: 3100,
+ y: 4100
},
// Behind plant
{
- x: 300,
- y: 350
+ x: 600,
+ y: 700
},
// Near lamp
{
- x: 1750,
- y: 650
+ x: 3500,
+ y: 1300
} // Under pillow
];
for (var i = 0; i < totalBananas; i++) {
var banana = new Banana();
@@ -232,10 +232,10 @@
}
createBananas();
// Create and add player character
player = new Player();
-player.x = 1024; // Start at center of screen horizontally
-player.y = 1366; // Middle of the screen vertically
+player.x = 2048; // Start at center of screen horizontally
+player.y = 2732; // Middle of the screen vertically
game.addChild(player);
// Game event handlers
game.down = function (x, y, obj) {
// Check if player was clicked