Code edit (1 edits merged)
Please save this source code
User prompt
Fruit Fusion Drop
Initial prompt
Yukardan düşen meyveleri birleştirip daha büyük meyveler yapma ile ilgili bir oyun istiyorum yukarda bir cizgi olacak ve o cizgiye değecek sekilde meyve dolmuş olursa oyun bitecek. 2 meyve birleşince yeni bjr meyve oluşacak. Örnegin 2 üzüm birleşti bir erik oluştu iki erik birleşti bir elma oluştu gibi. En son en büyük meyve karpuz olsun karpuza ulaşan oyunu kazanmış olsun.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Fruit = Container.expand(function (type) {
var self = Container.call(this);
self.type = type;
self.merged = false;
self.velocityY = 0;
self.velocityX = 0;
self.gravity = 0.5;
self.friction = 0.98;
self.bounce = 0.3;
var fruitGraphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
self.getRadius = function () {
return fruitGraphics.width / 2;
};
self.update = function () {
if (self.merged) return;
// Apply physics
self.velocityY += self.gravity;
self.x += self.velocityX;
self.y += self.velocityY;
// Ground collision
var groundY = 2732 - 100;
if (self.y + self.getRadius() > groundY) {
self.y = groundY - self.getRadius();
self.velocityY *= -self.bounce;
self.velocityX *= self.friction;
if (Math.abs(self.velocityY) < 1) {
self.velocityY = 0;
}
}
// Wall collisions
if (self.x - self.getRadius() < 20) {
self.x = 20 + self.getRadius();
self.velocityX *= -self.bounce;
}
if (self.x + self.getRadius() > 2048 - 20) {
self.x = 2048 - 20 - self.getRadius();
self.velocityX *= -self.bounce;
}
// Check danger line
if (self.y - self.getRadius() < dangerLineY + 10) {
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var fruitTypes = ['grape', 'plum', 'apple', 'orange', 'peach', 'pineapple', 'melon', 'watermelon'];
var fruitScores = [10, 25, 50, 100, 200, 400, 800, 1600];
var fruits = [];
var dropX = 1024;
var currentFruitType = 'grape';
var dangerLineY = 300;
var canDrop = true;
// Create walls
var leftWall = game.addChild(LK.getAsset('walls', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
var rightWall = game.addChild(LK.getAsset('walls', {
anchorX: 0,
anchorY: 0,
x: 2048 - 20,
y: 0
}));
// Create ground
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 2732 - 100
}));
// Create danger line
var dangerLine = game.addChild(LK.getAsset('dangerLine', {
anchorX: 0,
anchorY: 0,
x: 0,
y: dangerLineY
}));
// Create score text
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create next fruit indicator
var nextFruitTxt = new Text2('Next: Grape', {
size: 60,
fill: 0xFFFFFF
});
nextFruitTxt.anchor.set(0.5, 0);
nextFruitTxt.y = 100;
LK.gui.top.addChild(nextFruitTxt);
// Create preview fruit
var previewFruit = game.addChild(LK.getAsset(currentFruitType, {
anchorX: 0.5,
anchorY: 0.5,
x: dropX,
y: 150,
alpha: 0.7
}));
function getRandomFruitType() {
var randomIndex = Math.floor(Math.random() * Math.min(5, fruitTypes.length));
return fruitTypes[randomIndex];
}
function updatePreviewFruit() {
game.removeChild(previewFruit);
previewFruit = game.addChild(LK.getAsset(currentFruitType, {
anchorX: 0.5,
anchorY: 0.5,
x: dropX,
y: 150,
alpha: 0.7
}));
var capitalizedType = currentFruitType.charAt(0).toUpperCase() + currentFruitType.slice(1);
nextFruitTxt.setText('Next: ' + capitalizedType);
}
function dropFruit() {
if (!canDrop) return;
var newFruit = new Fruit(currentFruitType);
newFruit.x = dropX;
newFruit.y = 200;
fruits.push(newFruit);
game.addChild(newFruit);
LK.getSound('drop').play();
currentFruitType = getRandomFruitType();
updatePreviewFruit();
canDrop = false;
LK.setTimeout(function () {
canDrop = true;
}, 500);
}
function checkMerges() {
for (var i = 0; i < fruits.length; i++) {
if (fruits[i].merged) continue;
for (var j = i + 1; j < fruits.length; j++) {
if (fruits[j].merged) continue;
var fruit1 = fruits[i];
var fruit2 = fruits[j];
if (fruit1.type === fruit2.type) {
var dx = fruit1.x - fruit2.x;
var dy = fruit1.y - fruit2.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var minDistance = fruit1.getRadius() + fruit2.getRadius();
if (distance < minDistance) {
mergeFruits(fruit1, fruit2);
break;
}
}
}
}
}
function mergeFruits(fruit1, fruit2) {
var currentTypeIndex = fruitTypes.indexOf(fruit1.type);
if (currentTypeIndex < fruitTypes.length - 1) {
var nextType = fruitTypes[currentTypeIndex + 1];
// Create new merged fruit
var mergedFruit = new Fruit(nextType);
mergedFruit.x = (fruit1.x + fruit2.x) / 2;
mergedFruit.y = (fruit1.y + fruit2.y) / 2;
fruits.push(mergedFruit);
game.addChild(mergedFruit);
// Add score
var scoreToAdd = fruitScores[currentTypeIndex + 1];
LK.setScore(LK.getScore() + scoreToAdd);
scoreTxt.setText('Score: ' + LK.getScore());
// Check for watermelon win condition
if (nextType === 'watermelon') {
LK.setTimeout(function () {
LK.showYouWin();
}, 1000);
}
LK.getSound('merge').play();
// Flash effect
LK.effects.flashObject(mergedFruit, 0xFFFF00, 500);
}
// Mark fruits as merged and remove them
fruit1.merged = true;
fruit2.merged = true;
// Remove from fruits array
for (var i = fruits.length - 1; i >= 0; i--) {
if (fruits[i].merged) {
fruits[i].destroy();
fruits.splice(i, 1);
}
}
}
game.move = function (x, y, obj) {
if (canDrop) {
dropX = Math.max(40, Math.min(2048 - 40, x));
previewFruit.x = dropX;
}
};
game.down = function (x, y, obj) {
dropFruit();
};
game.update = function () {
for (var i = 0; i < fruits.length; i++) {
fruits[i].update();
}
checkMerges();
};
// Initialize first fruit type
updatePreviewFruit(); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,228 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Fruit = Container.expand(function (type) {
+ var self = Container.call(this);
+ self.type = type;
+ self.merged = false;
+ self.velocityY = 0;
+ self.velocityX = 0;
+ self.gravity = 0.5;
+ self.friction = 0.98;
+ self.bounce = 0.3;
+ var fruitGraphics = self.attachAsset(type, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.getRadius = function () {
+ return fruitGraphics.width / 2;
+ };
+ self.update = function () {
+ if (self.merged) return;
+ // Apply physics
+ self.velocityY += self.gravity;
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ // Ground collision
+ var groundY = 2732 - 100;
+ if (self.y + self.getRadius() > groundY) {
+ self.y = groundY - self.getRadius();
+ self.velocityY *= -self.bounce;
+ self.velocityX *= self.friction;
+ if (Math.abs(self.velocityY) < 1) {
+ self.velocityY = 0;
+ }
+ }
+ // Wall collisions
+ if (self.x - self.getRadius() < 20) {
+ self.x = 20 + self.getRadius();
+ self.velocityX *= -self.bounce;
+ }
+ if (self.x + self.getRadius() > 2048 - 20) {
+ self.x = 2048 - 20 - self.getRadius();
+ self.velocityX *= -self.bounce;
+ }
+ // Check danger line
+ if (self.y - self.getRadius() < dangerLineY + 10) {
+ LK.effects.flashScreen(0xFF0000, 1000);
+ LK.showGameOver();
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+var fruitTypes = ['grape', 'plum', 'apple', 'orange', 'peach', 'pineapple', 'melon', 'watermelon'];
+var fruitScores = [10, 25, 50, 100, 200, 400, 800, 1600];
+var fruits = [];
+var dropX = 1024;
+var currentFruitType = 'grape';
+var dangerLineY = 300;
+var canDrop = true;
+// Create walls
+var leftWall = game.addChild(LK.getAsset('walls', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: 0
+}));
+var rightWall = game.addChild(LK.getAsset('walls', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 2048 - 20,
+ y: 0
+}));
+// Create ground
+var ground = game.addChild(LK.getAsset('ground', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: 2732 - 100
+}));
+// Create danger line
+var dangerLine = game.addChild(LK.getAsset('dangerLine', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: dangerLineY
+}));
+// Create score text
+var scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Create next fruit indicator
+var nextFruitTxt = new Text2('Next: Grape', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+nextFruitTxt.anchor.set(0.5, 0);
+nextFruitTxt.y = 100;
+LK.gui.top.addChild(nextFruitTxt);
+// Create preview fruit
+var previewFruit = game.addChild(LK.getAsset(currentFruitType, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: dropX,
+ y: 150,
+ alpha: 0.7
+}));
+function getRandomFruitType() {
+ var randomIndex = Math.floor(Math.random() * Math.min(5, fruitTypes.length));
+ return fruitTypes[randomIndex];
+}
+function updatePreviewFruit() {
+ game.removeChild(previewFruit);
+ previewFruit = game.addChild(LK.getAsset(currentFruitType, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: dropX,
+ y: 150,
+ alpha: 0.7
+ }));
+ var capitalizedType = currentFruitType.charAt(0).toUpperCase() + currentFruitType.slice(1);
+ nextFruitTxt.setText('Next: ' + capitalizedType);
+}
+function dropFruit() {
+ if (!canDrop) return;
+ var newFruit = new Fruit(currentFruitType);
+ newFruit.x = dropX;
+ newFruit.y = 200;
+ fruits.push(newFruit);
+ game.addChild(newFruit);
+ LK.getSound('drop').play();
+ currentFruitType = getRandomFruitType();
+ updatePreviewFruit();
+ canDrop = false;
+ LK.setTimeout(function () {
+ canDrop = true;
+ }, 500);
+}
+function checkMerges() {
+ for (var i = 0; i < fruits.length; i++) {
+ if (fruits[i].merged) continue;
+ for (var j = i + 1; j < fruits.length; j++) {
+ if (fruits[j].merged) continue;
+ var fruit1 = fruits[i];
+ var fruit2 = fruits[j];
+ if (fruit1.type === fruit2.type) {
+ var dx = fruit1.x - fruit2.x;
+ var dy = fruit1.y - fruit2.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ var minDistance = fruit1.getRadius() + fruit2.getRadius();
+ if (distance < minDistance) {
+ mergeFruits(fruit1, fruit2);
+ break;
+ }
+ }
+ }
+ }
+}
+function mergeFruits(fruit1, fruit2) {
+ var currentTypeIndex = fruitTypes.indexOf(fruit1.type);
+ if (currentTypeIndex < fruitTypes.length - 1) {
+ var nextType = fruitTypes[currentTypeIndex + 1];
+ // Create new merged fruit
+ var mergedFruit = new Fruit(nextType);
+ mergedFruit.x = (fruit1.x + fruit2.x) / 2;
+ mergedFruit.y = (fruit1.y + fruit2.y) / 2;
+ fruits.push(mergedFruit);
+ game.addChild(mergedFruit);
+ // Add score
+ var scoreToAdd = fruitScores[currentTypeIndex + 1];
+ LK.setScore(LK.getScore() + scoreToAdd);
+ scoreTxt.setText('Score: ' + LK.getScore());
+ // Check for watermelon win condition
+ if (nextType === 'watermelon') {
+ LK.setTimeout(function () {
+ LK.showYouWin();
+ }, 1000);
+ }
+ LK.getSound('merge').play();
+ // Flash effect
+ LK.effects.flashObject(mergedFruit, 0xFFFF00, 500);
+ }
+ // Mark fruits as merged and remove them
+ fruit1.merged = true;
+ fruit2.merged = true;
+ // Remove from fruits array
+ for (var i = fruits.length - 1; i >= 0; i--) {
+ if (fruits[i].merged) {
+ fruits[i].destroy();
+ fruits.splice(i, 1);
+ }
+ }
+}
+game.move = function (x, y, obj) {
+ if (canDrop) {
+ dropX = Math.max(40, Math.min(2048 - 40, x));
+ previewFruit.x = dropX;
+ }
+};
+game.down = function (x, y, obj) {
+ dropFruit();
+};
+game.update = function () {
+ for (var i = 0; i < fruits.length; i++) {
+ fruits[i].update();
+ }
+ checkMerges();
+};
+// Initialize first fruit type
+updatePreviewFruit();
\ No newline at end of file