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 = 2048; background.height = 2732; // Add furniture pieces var furniturePieces = []; // Bed var bed = new FurniturePiece('bed', 600, 300); bed.x = 1600; bed.y = 500; game.addChild(bed); furniturePieces.push(bed); // Table var table = new FurniturePiece('table', 300, 150); table.x = 500; table.y = 1200; game.addChild(table); furniturePieces.push(table); // Sofa var sofa = new FurniturePiece('sofa', 500, 200); sofa.x = 500; sofa.y = 1800; game.addChild(sofa); furniturePieces.push(sofa); // Bookshelf var bookshelf = new FurniturePiece('bookshelf', 300, 500); bookshelf.x = 1700; bookshelf.y = 1400; game.addChild(bookshelf); furniturePieces.push(bookshelf); // Plant var plant = new FurniturePiece('plant', 150, 200); plant.x = 1500; plant.y = 2000; game.addChild(plant); furniturePieces.push(plant); // Lamp var lamp = new FurniturePiece('lamp', 100, 250); lamp.x = 300; lamp.y = 500; game.addChild(lamp); furniturePieces.push(lamp); // Pillow var pillow = new FurniturePiece('pillow', 150, 150); pillow.x = 1700; pillow.y = 600; 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 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: 1650, y: 400 }, // Near the bed { x: 550, y: 1150 }, // On the table { x: 350, y: 1800 }, // Behind the sofa { x: 1700, y: 1200 }, // On bookshelf { x: 1550, y: 2050 }, // Behind plant { x: 300, y: 350 }, // Near lamp { x: 1750, y: 650 } // 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 = 1024; // Start at center of screen horizontally player.y = 1366; // Middle of the screen vertically game.addChild(player); // Game event handlers game.down = function (x, y, obj) { // Check if player was clicked if (obj.event.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; } }; // 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
@@ -78,8 +78,28 @@
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
****/
@@ -94,8 +114,9 @@
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
@@ -209,11 +230,19 @@
game.addChild(banana);
}
}
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
+game.addChild(player);
// Game event handlers
game.down = function (x, y, obj) {
- // Nothing specific needed here as bananas handle their own down events
+ // Check if player was clicked
+ if (obj.event.target === player) {
+ player.isDragging = true;
+ }
};
game.move = function (x, y, obj) {
// Move any dragged banana
for (var i = 0; i < bananas.length; i++) {
@@ -221,11 +250,19 @@
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;
+ }
};
// Play background music
LK.playMusic('bgmusic');
// Instructions