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;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xF5F5DC
});
/****
* Game Code
****/
// Game constants
var totalBananas = 7;
var collectedBananas = 0;
var bananas = [];
var draggedBanana = 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();
// Game event handlers
game.down = function (x, y, obj) {
// Nothing specific needed here as bananas handle their own down events
};
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;
}
}
};
game.up = function (x, y, obj) {
// Handled by individual banana objects
};
// 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
@@ -1,6 +1,247 @@
-/****
+/****
+* 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;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0xF5F5DC
+});
+
+/****
+* Game Code
+****/
+// Game constants
+var totalBananas = 7;
+var collectedBananas = 0;
+var bananas = [];
+var draggedBanana = 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();
+// Game event handlers
+game.down = function (x, y, obj) {
+ // Nothing specific needed here as bananas handle their own down events
+};
+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;
+ }
+ }
+};
+game.up = function (x, y, obj) {
+ // Handled by individual banana objects
+};
+// 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);
\ No newline at end of file