/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Enemy
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemy = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = enemy.width;
self.height = enemy.height;
self.speed = 4 + Math.random() * 2;
self.update = function () {
self.x -= self.speed;
};
return self;
});
// Exit Door
var ExitDoor = Container.expand(function () {
var self = Container.call(this);
var exit = self.attachAsset('exit', {
anchorX: 0.5,
anchorY: 1
});
self.width = exit.width;
self.height = exit.height;
return self;
});
// Gold
var Gold = Container.expand(function () {
var self = Container.call(this);
var gold = self.attachAsset('gold', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = gold.width;
self.height = gold.height;
self.collected = false;
return self;
});
// MagicCarpet: Player
var MagicCarpet = Container.expand(function () {
var self = Container.call(this);
var carpet = self.attachAsset('carpet', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
self.width = carpet.width;
self.height = carpet.height;
self.baseY = 0;
self.swayTick = 0;
self.update = function () {
// Sway up and down
self.swayTick += 0.07;
self.y = self.baseY + Math.sin(self.swayTick) * 18;
};
return self;
});
// ParallaxLayer: For background movement
var ParallaxLayer = Container.expand(function () {
var self = Container.call(this);
self.speed = 0;
self.sprites = [];
self.assetId = '';
self.y = 0;
self.height = 0;
self.init = function (assetId, y, speed, count) {
self.assetId = assetId;
self.y = y;
self.speed = speed;
self.height = LK.getAsset(assetId, {}).height;
for (var i = 0; i < count; i++) {
var sprite = self.attachAsset(assetId, {
anchorX: 0,
anchorY: 0,
x: i * LK.getAsset(assetId, {}).width,
y: 0
});
self.sprites.push(sprite);
}
};
self.update = function () {
for (var i = 0; i < self.sprites.length; i++) {
var s = self.sprites[i];
s.x -= self.speed;
if (s.x <= -s.width) {
// Move to right
s.x += s.width * self.sprites.length;
}
}
};
return self;
});
// Potion
var Potion = Container.expand(function () {
var self = Container.call(this);
var potion = self.attachAsset('potion', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = potion.width;
self.height = potion.height;
self.collected = false;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb // Sky blue
});
/****
* Game Code
****/
// Uzun arkaplan müziği (örnek id: 'longbgmusic', gerçek id asset pipeline'dan gelir)
// --- Parallax Layers ---
// Arkaplan müziğini başlat (loop açık, fade ile yumuşak başlat)
LK.playMusic('longbgmusic', {
fade: {
start: 0,
end: 0.7,
duration: 1800
}
});
// Sihirli Halı (Magic Carpet)
// Altın (Gold)
// İksir (Potion)
// Düşman (Enemy)
// Çıkış Kapısı (Exit Door)
// Zemin (Ground, parallax layer 1)
// Dağlar (Mountains, parallax layer 2)
// Bulut (Cloud, parallax layer 3)
// Joystick tabanı
// Joystick topu
var parallaxLayers = [];
// Layer 1: Ground (closest)
var groundLayer = new ParallaxLayer();
groundLayer.init('ground', 2732 - 300, 2.5, 2);
game.addChild(groundLayer);
parallaxLayers.push(groundLayer);
// Layer 2: Mountains (middle)
var mountainLayer = new ParallaxLayer();
mountainLayer.init('mountain', 2732 - 300 - 180, 1.2, 2);
game.addChild(mountainLayer);
parallaxLayers.push(mountainLayer);
// Layer 3: Clouds (farthest, randomized positions and sizes, more scattered)
var cloudSprites = [];
var cloudCount = 12 + Math.floor(Math.random() * 5); // 12-16 clouds for more density
for (var i = 0; i < cloudCount; i++) {
// More variety in scale and position, allow overlap and wide spread
var scale = 0.5 + Math.random() * 2.0; // 0.5x to 2.5x
var y = 40 + Math.random() * 900; // Spread vertically in upper 940px
var x = Math.random() * 2048;
var cloud = LK.getAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: scale,
scaleY: scale,
x: x,
y: y
});
cloud._cloudSpeed = 0.25 + Math.random() * 0.7; // 0.25-0.95 px/frame
game.addChild(cloud);
cloudSprites.push(cloud);
}
parallaxLayers.push({
// Dummy for compatibility, update will be handled below
update: function update() {
for (var i = 0; i < cloudSprites.length; i++) {
var c = cloudSprites[i];
c.x -= c._cloudSpeed;
if (c.x < -c.width / 2) {
// When respawning, randomize both X and Y for more scattered effect
c.x = 2048 + c.width / 2 + Math.random() * 300;
c.y = 40 + Math.random() * 900;
c._cloudSpeed = 0.25 + Math.random() * 0.7;
var scale = 0.5 + Math.random() * 2.0;
c.scaleX = scale;
c.scaleY = scale;
}
}
}
});
// --- Exit Door ---
var exitDoor = new ExitDoor();
exitDoor.x = 2048 - 200;
exitDoor.y = 2732 - 300 - 10;
exitDoor.visible = false;
game.addChild(exitDoor);
// --- Magic Carpet (Player) ---
var carpet = new MagicCarpet();
carpet.x = 320;
carpet.baseY = 2732 / 2;
carpet.y = carpet.baseY;
carpet.targetX = carpet.x;
carpet.targetBaseY = carpet.baseY;
game.addChild(carpet);
// --- Collectibles ---
var golds = [];
var potions = [];
// Gold positions (spread out, not overlapping, not too close to edges)
var goldPositions = [{
x: 700,
y: 700
}, {
x: 1200,
y: 900
}, {
x: 900,
y: 1700
}, {
x: 1500,
y: 1200
}, {
x: 1800,
y: 2100
}];
for (var i = 0; i < 5; i++) {
var g = new Gold();
g.x = goldPositions[i].x;
g.y = goldPositions[i].y;
golds.push(g);
game.addChild(g);
}
// Potion positions
var potionPositions = [{
x: 1100,
y: 2200
}, {
x: 1700,
y: 600
}];
for (var i = 0; i < 2; i++) {
var p = new Potion();
p.x = potionPositions[i].x;
p.y = potionPositions[i].y;
potions.push(p);
game.addChild(p);
}
// --- Enemies ---
var enemies = [];
function spawnEnemies() {
// 3 enemies, random vertical positions, spaced horizontally
enemies.length = 0;
for (var i = 0; i < 3; i++) {
var e = new Enemy();
e.x = 2048 + 200 + i * 300;
e.y = 600 + Math.random() * (2732 - 1200);
enemies.push(e);
game.addChild(e);
}
}
spawnEnemies();
// --- GUI: Score/Progress ---
var progressTxt = new Text2('', {
size: 80,
fill: "#fff"
});
progressTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(progressTxt);
// --- State ---
var collectedGold = 0;
var collectedPotion = 0;
var allCollected = false;
var gameOver = false;
var youWin = false;
// --- Helper: Update Progress Text ---
function updateProgressText() {
progressTxt.setText("Altın: " + collectedGold + "/5 İksir: " + collectedPotion + "/2");
}
updateProgressText();
// --- Helper: Reset Game State ---
function resetGame() {
// Reset collectibles
for (var i = 0; i < golds.length; i++) {
golds[i].collected = false;
golds[i].visible = true;
}
for (var i = 0; i < potions.length; i++) {
potions[i].collected = false;
potions[i].visible = true;
}
collectedGold = 0;
collectedPotion = 0;
allCollected = false;
updateProgressText();
// Reset player
carpet.x = 320;
carpet.baseY = 2732 / 2;
carpet.swayTick = 0;
carpet.targetX = carpet.x;
carpet.targetBaseY = carpet.baseY;
// Reset enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].destroy();
}
spawnEnemies();
// Hide exit
exitDoor.visible = false;
gameOver = false;
youWin = false;
}
// --- Main Game Move Handler (for mobile drag outside joystick) ---
// Touch/drag anywhere on the game area (except joystick) to move the player directly
var draggingPlayer = false;
game.down = function (x, y, obj) {
draggingPlayer = true;
// Set target position for smooth movement
var margin = 60;
var px = x;
var py = y;
if (px < margin + carpet.width / 2) px = margin + carpet.width / 2;
if (px > 2048 - margin - carpet.width / 2) px = 2048 - margin - carpet.width / 2;
if (py < margin + carpet.height / 2) py = margin + carpet.height / 2;
if (py > 2732 - 300 - margin - carpet.height / 2) py = 2732 - 300 - margin - carpet.height / 2;
carpet.targetX = px;
carpet.targetBaseY = py;
};
game.move = function (x, y, obj) {
if (draggingPlayer) {
// Set target position for smooth movement
var margin = 60;
var px = x;
var py = y;
if (px < margin + carpet.width / 2) px = margin + carpet.width / 2;
if (px > 2048 - margin - carpet.width / 2) px = 2048 - margin - carpet.width / 2;
if (py < margin + carpet.height / 2) py = margin + carpet.height / 2;
if (py > 2732 - 300 - margin - carpet.height / 2) py = 2732 - 300 - margin - carpet.height / 2;
carpet.targetX = px;
carpet.targetBaseY = py;
}
};
game.up = function (x, y, obj) {
draggingPlayer = false;
carpet.targetX = undefined;
carpet.targetBaseY = undefined;
};
// --- Main Game Update Loop ---
game.update = function () {
if (gameOver || youWin) return;
// Parallax layers
for (var i = 0; i < parallaxLayers.length; i++) {
parallaxLayers[i].update();
}
// Smooth movement toward target if dragging
if (typeof carpet.targetX === "number" && typeof carpet.targetBaseY === "number") {
// Only move if not already at target
var dx = carpet.targetX - carpet.x;
var dy = carpet.targetBaseY - carpet.baseY;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist > 2) {
// Move a fraction toward target (lerp)
var moveSpeed = 0.22; // 0..1, higher = faster
carpet.x += dx * moveSpeed;
carpet.baseY += dy * moveSpeed;
} else {
// Snap to target if close enough
carpet.x = carpet.targetX;
carpet.baseY = carpet.targetBaseY;
}
}
// Clamp inside play area (not too close to edges)
var margin = 60;
if (carpet.x < margin + carpet.width / 2) carpet.x = margin + carpet.width / 2;
if (carpet.x > 2048 - margin - carpet.width / 2) carpet.x = 2048 - margin - carpet.width / 2;
if (carpet.baseY < margin + carpet.height / 2) carpet.baseY = margin + carpet.height / 2;
if (carpet.baseY > 2732 - 300 - margin - carpet.height / 2) carpet.baseY = 2732 - 300 - margin - carpet.height / 2;
// Sway
carpet.update();
// Collectibles: Gold
for (var i = 0; i < golds.length; i++) {
var g = golds[i];
if (!g.collected && carpet.intersects(g)) {
g.collected = true;
g.visible = false;
// Play gold collect sound
LK.getSound('gold_collect').play();
// Sparkle effect: create a large, fully opaque yellow circle at gold position
var sparkle = LK.getAsset('shape', {
width: g.width * 2.5,
height: g.height * 2.5,
anchorX: 0.5,
anchorY: 0.5,
alpha: 1,
x: g.x,
y: g.y,
color: 0xf7d13b,
shape: 'ellipse'
});
game.addChild(sparkle);
// Animate: scale up and fade out quickly, then remove
tween(sparkle, {
scaleX: 2.8,
scaleY: 2.8,
alpha: 0
}, {
duration: 340,
easing: tween.easeOut,
complete: function complete() {
sparkle.destroy();
}
});
collectedGold++;
updateProgressText();
}
}
// Collectibles: Potion
for (var i = 0; i < potions.length; i++) {
var p = potions[i];
if (!p.collected && carpet.intersects(p)) {
p.collected = true;
p.visible = false;
// Play potion collect sound
LK.getSound('potion_collect').play();
// --- Blue circle explosion effect for potion ---
var sparkle = LK.getAsset('blue_ellipse', {
width: p.width * 2.5,
height: p.width * 2.5,
// Make it a perfect circle
anchorX: 0.5,
anchorY: 0.5,
alpha: 1,
x: p.x,
y: p.y
});
game.addChild(sparkle);
// Animate: scale up and fade out quickly, then remove
tween(sparkle, {
scaleX: 2.8,
scaleY: 2.8,
alpha: 0
}, {
duration: 340,
easing: tween.easeOut,
complete: function complete() {
sparkle.destroy();
}
});
collectedPotion++;
updateProgressText();
}
}
// All collected?
if (!allCollected && collectedGold === 5 && collectedPotion === 2) {
allCollected = true;
// Show exit door
exitDoor.visible = true;
// Animate door (flash green)
tween(exitDoor, {
tint: 0x00ff00
}, {
duration: 600,
easing: tween.bounceOut
});
}
// Enemies
for (var i = 0; i < enemies.length; i++) {
var e = enemies[i];
e.update();
// If off screen left, respawn to right
if (e.x < -e.width) {
e.x = 2048 + 200 + Math.random() * 200;
e.y = 600 + Math.random() * (2732 - 1200);
e.speed = 4 + Math.random() * 2;
}
// Collision with player
if (carpet.intersects(e)) {
// Game over
gameOver = true;
// Play lose sound
LK.getSound('lose').play();
LK.effects.flashScreen(0xff0000, 900);
LK.setTimeout(function () {
LK.showGameOver();
}, 900);
return;
}
}
// Win condition: All collected and reached exit
if (allCollected && carpet.intersects(exitDoor)) {
youWin = true;
// Play win sound
LK.getSound('win').play();
LK.effects.flashScreen(0x00ff00, 700);
LK.setTimeout(function () {
LK.showYouWin();
}, 700);
return;
}
};
// --- Game Over/Win Reset Handler ---
LK.on('gameover', function () {
resetGame();
});
LK.on('youwin', function () {
resetGame();
}); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Enemy
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemy = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = enemy.width;
self.height = enemy.height;
self.speed = 4 + Math.random() * 2;
self.update = function () {
self.x -= self.speed;
};
return self;
});
// Exit Door
var ExitDoor = Container.expand(function () {
var self = Container.call(this);
var exit = self.attachAsset('exit', {
anchorX: 0.5,
anchorY: 1
});
self.width = exit.width;
self.height = exit.height;
return self;
});
// Gold
var Gold = Container.expand(function () {
var self = Container.call(this);
var gold = self.attachAsset('gold', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = gold.width;
self.height = gold.height;
self.collected = false;
return self;
});
// MagicCarpet: Player
var MagicCarpet = Container.expand(function () {
var self = Container.call(this);
var carpet = self.attachAsset('carpet', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
self.width = carpet.width;
self.height = carpet.height;
self.baseY = 0;
self.swayTick = 0;
self.update = function () {
// Sway up and down
self.swayTick += 0.07;
self.y = self.baseY + Math.sin(self.swayTick) * 18;
};
return self;
});
// ParallaxLayer: For background movement
var ParallaxLayer = Container.expand(function () {
var self = Container.call(this);
self.speed = 0;
self.sprites = [];
self.assetId = '';
self.y = 0;
self.height = 0;
self.init = function (assetId, y, speed, count) {
self.assetId = assetId;
self.y = y;
self.speed = speed;
self.height = LK.getAsset(assetId, {}).height;
for (var i = 0; i < count; i++) {
var sprite = self.attachAsset(assetId, {
anchorX: 0,
anchorY: 0,
x: i * LK.getAsset(assetId, {}).width,
y: 0
});
self.sprites.push(sprite);
}
};
self.update = function () {
for (var i = 0; i < self.sprites.length; i++) {
var s = self.sprites[i];
s.x -= self.speed;
if (s.x <= -s.width) {
// Move to right
s.x += s.width * self.sprites.length;
}
}
};
return self;
});
// Potion
var Potion = Container.expand(function () {
var self = Container.call(this);
var potion = self.attachAsset('potion', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = potion.width;
self.height = potion.height;
self.collected = false;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb // Sky blue
});
/****
* Game Code
****/
// Uzun arkaplan müziği (örnek id: 'longbgmusic', gerçek id asset pipeline'dan gelir)
// --- Parallax Layers ---
// Arkaplan müziğini başlat (loop açık, fade ile yumuşak başlat)
LK.playMusic('longbgmusic', {
fade: {
start: 0,
end: 0.7,
duration: 1800
}
});
// Sihirli Halı (Magic Carpet)
// Altın (Gold)
// İksir (Potion)
// Düşman (Enemy)
// Çıkış Kapısı (Exit Door)
// Zemin (Ground, parallax layer 1)
// Dağlar (Mountains, parallax layer 2)
// Bulut (Cloud, parallax layer 3)
// Joystick tabanı
// Joystick topu
var parallaxLayers = [];
// Layer 1: Ground (closest)
var groundLayer = new ParallaxLayer();
groundLayer.init('ground', 2732 - 300, 2.5, 2);
game.addChild(groundLayer);
parallaxLayers.push(groundLayer);
// Layer 2: Mountains (middle)
var mountainLayer = new ParallaxLayer();
mountainLayer.init('mountain', 2732 - 300 - 180, 1.2, 2);
game.addChild(mountainLayer);
parallaxLayers.push(mountainLayer);
// Layer 3: Clouds (farthest, randomized positions and sizes, more scattered)
var cloudSprites = [];
var cloudCount = 12 + Math.floor(Math.random() * 5); // 12-16 clouds for more density
for (var i = 0; i < cloudCount; i++) {
// More variety in scale and position, allow overlap and wide spread
var scale = 0.5 + Math.random() * 2.0; // 0.5x to 2.5x
var y = 40 + Math.random() * 900; // Spread vertically in upper 940px
var x = Math.random() * 2048;
var cloud = LK.getAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: scale,
scaleY: scale,
x: x,
y: y
});
cloud._cloudSpeed = 0.25 + Math.random() * 0.7; // 0.25-0.95 px/frame
game.addChild(cloud);
cloudSprites.push(cloud);
}
parallaxLayers.push({
// Dummy for compatibility, update will be handled below
update: function update() {
for (var i = 0; i < cloudSprites.length; i++) {
var c = cloudSprites[i];
c.x -= c._cloudSpeed;
if (c.x < -c.width / 2) {
// When respawning, randomize both X and Y for more scattered effect
c.x = 2048 + c.width / 2 + Math.random() * 300;
c.y = 40 + Math.random() * 900;
c._cloudSpeed = 0.25 + Math.random() * 0.7;
var scale = 0.5 + Math.random() * 2.0;
c.scaleX = scale;
c.scaleY = scale;
}
}
}
});
// --- Exit Door ---
var exitDoor = new ExitDoor();
exitDoor.x = 2048 - 200;
exitDoor.y = 2732 - 300 - 10;
exitDoor.visible = false;
game.addChild(exitDoor);
// --- Magic Carpet (Player) ---
var carpet = new MagicCarpet();
carpet.x = 320;
carpet.baseY = 2732 / 2;
carpet.y = carpet.baseY;
carpet.targetX = carpet.x;
carpet.targetBaseY = carpet.baseY;
game.addChild(carpet);
// --- Collectibles ---
var golds = [];
var potions = [];
// Gold positions (spread out, not overlapping, not too close to edges)
var goldPositions = [{
x: 700,
y: 700
}, {
x: 1200,
y: 900
}, {
x: 900,
y: 1700
}, {
x: 1500,
y: 1200
}, {
x: 1800,
y: 2100
}];
for (var i = 0; i < 5; i++) {
var g = new Gold();
g.x = goldPositions[i].x;
g.y = goldPositions[i].y;
golds.push(g);
game.addChild(g);
}
// Potion positions
var potionPositions = [{
x: 1100,
y: 2200
}, {
x: 1700,
y: 600
}];
for (var i = 0; i < 2; i++) {
var p = new Potion();
p.x = potionPositions[i].x;
p.y = potionPositions[i].y;
potions.push(p);
game.addChild(p);
}
// --- Enemies ---
var enemies = [];
function spawnEnemies() {
// 3 enemies, random vertical positions, spaced horizontally
enemies.length = 0;
for (var i = 0; i < 3; i++) {
var e = new Enemy();
e.x = 2048 + 200 + i * 300;
e.y = 600 + Math.random() * (2732 - 1200);
enemies.push(e);
game.addChild(e);
}
}
spawnEnemies();
// --- GUI: Score/Progress ---
var progressTxt = new Text2('', {
size: 80,
fill: "#fff"
});
progressTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(progressTxt);
// --- State ---
var collectedGold = 0;
var collectedPotion = 0;
var allCollected = false;
var gameOver = false;
var youWin = false;
// --- Helper: Update Progress Text ---
function updateProgressText() {
progressTxt.setText("Altın: " + collectedGold + "/5 İksir: " + collectedPotion + "/2");
}
updateProgressText();
// --- Helper: Reset Game State ---
function resetGame() {
// Reset collectibles
for (var i = 0; i < golds.length; i++) {
golds[i].collected = false;
golds[i].visible = true;
}
for (var i = 0; i < potions.length; i++) {
potions[i].collected = false;
potions[i].visible = true;
}
collectedGold = 0;
collectedPotion = 0;
allCollected = false;
updateProgressText();
// Reset player
carpet.x = 320;
carpet.baseY = 2732 / 2;
carpet.swayTick = 0;
carpet.targetX = carpet.x;
carpet.targetBaseY = carpet.baseY;
// Reset enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].destroy();
}
spawnEnemies();
// Hide exit
exitDoor.visible = false;
gameOver = false;
youWin = false;
}
// --- Main Game Move Handler (for mobile drag outside joystick) ---
// Touch/drag anywhere on the game area (except joystick) to move the player directly
var draggingPlayer = false;
game.down = function (x, y, obj) {
draggingPlayer = true;
// Set target position for smooth movement
var margin = 60;
var px = x;
var py = y;
if (px < margin + carpet.width / 2) px = margin + carpet.width / 2;
if (px > 2048 - margin - carpet.width / 2) px = 2048 - margin - carpet.width / 2;
if (py < margin + carpet.height / 2) py = margin + carpet.height / 2;
if (py > 2732 - 300 - margin - carpet.height / 2) py = 2732 - 300 - margin - carpet.height / 2;
carpet.targetX = px;
carpet.targetBaseY = py;
};
game.move = function (x, y, obj) {
if (draggingPlayer) {
// Set target position for smooth movement
var margin = 60;
var px = x;
var py = y;
if (px < margin + carpet.width / 2) px = margin + carpet.width / 2;
if (px > 2048 - margin - carpet.width / 2) px = 2048 - margin - carpet.width / 2;
if (py < margin + carpet.height / 2) py = margin + carpet.height / 2;
if (py > 2732 - 300 - margin - carpet.height / 2) py = 2732 - 300 - margin - carpet.height / 2;
carpet.targetX = px;
carpet.targetBaseY = py;
}
};
game.up = function (x, y, obj) {
draggingPlayer = false;
carpet.targetX = undefined;
carpet.targetBaseY = undefined;
};
// --- Main Game Update Loop ---
game.update = function () {
if (gameOver || youWin) return;
// Parallax layers
for (var i = 0; i < parallaxLayers.length; i++) {
parallaxLayers[i].update();
}
// Smooth movement toward target if dragging
if (typeof carpet.targetX === "number" && typeof carpet.targetBaseY === "number") {
// Only move if not already at target
var dx = carpet.targetX - carpet.x;
var dy = carpet.targetBaseY - carpet.baseY;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist > 2) {
// Move a fraction toward target (lerp)
var moveSpeed = 0.22; // 0..1, higher = faster
carpet.x += dx * moveSpeed;
carpet.baseY += dy * moveSpeed;
} else {
// Snap to target if close enough
carpet.x = carpet.targetX;
carpet.baseY = carpet.targetBaseY;
}
}
// Clamp inside play area (not too close to edges)
var margin = 60;
if (carpet.x < margin + carpet.width / 2) carpet.x = margin + carpet.width / 2;
if (carpet.x > 2048 - margin - carpet.width / 2) carpet.x = 2048 - margin - carpet.width / 2;
if (carpet.baseY < margin + carpet.height / 2) carpet.baseY = margin + carpet.height / 2;
if (carpet.baseY > 2732 - 300 - margin - carpet.height / 2) carpet.baseY = 2732 - 300 - margin - carpet.height / 2;
// Sway
carpet.update();
// Collectibles: Gold
for (var i = 0; i < golds.length; i++) {
var g = golds[i];
if (!g.collected && carpet.intersects(g)) {
g.collected = true;
g.visible = false;
// Play gold collect sound
LK.getSound('gold_collect').play();
// Sparkle effect: create a large, fully opaque yellow circle at gold position
var sparkle = LK.getAsset('shape', {
width: g.width * 2.5,
height: g.height * 2.5,
anchorX: 0.5,
anchorY: 0.5,
alpha: 1,
x: g.x,
y: g.y,
color: 0xf7d13b,
shape: 'ellipse'
});
game.addChild(sparkle);
// Animate: scale up and fade out quickly, then remove
tween(sparkle, {
scaleX: 2.8,
scaleY: 2.8,
alpha: 0
}, {
duration: 340,
easing: tween.easeOut,
complete: function complete() {
sparkle.destroy();
}
});
collectedGold++;
updateProgressText();
}
}
// Collectibles: Potion
for (var i = 0; i < potions.length; i++) {
var p = potions[i];
if (!p.collected && carpet.intersects(p)) {
p.collected = true;
p.visible = false;
// Play potion collect sound
LK.getSound('potion_collect').play();
// --- Blue circle explosion effect for potion ---
var sparkle = LK.getAsset('blue_ellipse', {
width: p.width * 2.5,
height: p.width * 2.5,
// Make it a perfect circle
anchorX: 0.5,
anchorY: 0.5,
alpha: 1,
x: p.x,
y: p.y
});
game.addChild(sparkle);
// Animate: scale up and fade out quickly, then remove
tween(sparkle, {
scaleX: 2.8,
scaleY: 2.8,
alpha: 0
}, {
duration: 340,
easing: tween.easeOut,
complete: function complete() {
sparkle.destroy();
}
});
collectedPotion++;
updateProgressText();
}
}
// All collected?
if (!allCollected && collectedGold === 5 && collectedPotion === 2) {
allCollected = true;
// Show exit door
exitDoor.visible = true;
// Animate door (flash green)
tween(exitDoor, {
tint: 0x00ff00
}, {
duration: 600,
easing: tween.bounceOut
});
}
// Enemies
for (var i = 0; i < enemies.length; i++) {
var e = enemies[i];
e.update();
// If off screen left, respawn to right
if (e.x < -e.width) {
e.x = 2048 + 200 + Math.random() * 200;
e.y = 600 + Math.random() * (2732 - 1200);
e.speed = 4 + Math.random() * 2;
}
// Collision with player
if (carpet.intersects(e)) {
// Game over
gameOver = true;
// Play lose sound
LK.getSound('lose').play();
LK.effects.flashScreen(0xff0000, 900);
LK.setTimeout(function () {
LK.showGameOver();
}, 900);
return;
}
}
// Win condition: All collected and reached exit
if (allCollected && carpet.intersects(exitDoor)) {
youWin = true;
// Play win sound
LK.getSound('win').play();
LK.effects.flashScreen(0x00ff00, 700);
LK.setTimeout(function () {
LK.showYouWin();
}, 700);
return;
}
};
// --- Game Over/Win Reset Handler ---
LK.on('gameover', function () {
resetGame();
});
LK.on('youwin', function () {
resetGame();
});
Fullscreen modern App Store landscape banner, 16:9, high definition, for a game titled "Sihirli Halı: Çöl Macerası" and with the description "Sihirli halı ile çöl manzarasında süzül, altın ve iksirleri topla, düşmanlardan kaç ve çıkış kapısına ulaş!". No text on banner!
Pofuduk yumuşacık bulut. In-Game asset. 2d. High contrast. No shadows
sihirli iksir mavi renk. In-Game asset. 2d. High contrast. No shadows
red angry bird transparan. In-Game asset. 2d. High contrast. No shadows
Green wood arabic door. In-Game asset. 2d. High contrast. No shadows
Gold coin up view tranparent. In-Game asset. 2d. High contrast. No shadows no text