User prompt
engele corporsa 5 saniye süresi ozolt
User prompt
10 Soniye süremiz olsun o süre içinde seçemezsek oyun bitsin doğru tercih yapılına süresi sıfırla nsın
User prompt
tercih yapıldıktan sonra 1 süre be kle
User prompt
Karakter tercihlere dokunacak
User prompt
Terc ihlere dokununca bi ri doğru diğeri yanlış
User prompt
en sondo olacak tercihler
User prompt
Geçitler üst üste olsun engel platformun ortasında olsun
User prompt
Karakter yukarı sürüklenebilsin
User prompt
Biz karakteri sürükleyebilirsiniz
User prompt
bu otomatik hareket etmesin
User prompt
koraktor hareket etmesin
User prompt
Biz bir yere tıklayarak hareket edelim
User prompt
Karoktoni hareket ettiredin
Code edit (1 edits merged)
Please save this source code
User prompt
Doğru Geçidi Bul: Platform Macerası
Initial prompt
Bir platform üzerinde hareket edelim bir engellen otlayalım ve platformun sonunda 2 farklı geçit olsun biri doğru olsun
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Gate class var Gate = Container.expand(function () { var self = Container.call(this); // Attach gate asset (ellipse, color depends on type) var gateAsset = self.attachAsset(self.gateType === 'correct' ? 'gateCorrect' : 'gateWrong', { anchorX: 0.5, anchorY: 1 }); self.width = gateAsset.width; self.height = gateAsset.height; // Type: 'correct' or 'wrong' self.gateType = 'wrong'; // Set color based on type self.setType = function (type) { self.gateType = type; var color = type === 'correct' ? 0x44de83 : 0xde4444; gateAsset.tint = color; }; return self; }); // Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); // Attach obstacle asset (yellow box) var obsAsset = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 1 }); self.width = obsAsset.width; self.height = obsAsset.height; return self; }); // Player character class var Player = Container.expand(function () { var self = Container.call(this); // Attach player asset (red box) var playerAsset = self.attachAsset('player', { anchorX: 0.5, anchorY: 1 }); // Player movement speed self.speed = 18; self.jumpPower = 60; self.isJumping = false; self.velocityY = 0; // For collision detection self.width = playerAsset.width; self.height = playerAsset.height; // Jump method self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.velocityY = -self.jumpPower; } }; // Update method (called every tick) self.update = function () { // No automatic horizontal movement // Gravity if (self.isJumping) { self.y += self.velocityY; self.velocityY += 6; // gravity // If landed on platform if (self.y >= platformY) { self.y = platformY; self.isJumping = false; self.velocityY = 0; } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ // No title, no description // Always backgroundColor is black backgroundColor: 0x000000 }); /**** * Game Code ****/ // Platform Y position (ground level) var platformY = 2200; // Level state var currentLevel = 1; // Arrays for obstacles and gates var obstacles = []; var gates = []; // Dragging state for player movement var dragPlayer = false; // Score text var scoreTxt = new Text2('Seviye: 1', { size: 100, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Platform asset (long gray box) var platform = LK.getAsset('platform', { width: 1800, height: 60, color: 0x888888, shape: 'box', anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: platformY + 30 }); game.addChild(platform); // Create player var player = new Player(); game.addChild(player); player.x = 400; player.y = platformY; // Timer for level selection var levelTimer = null; var levelTimeLeft = 10; var timerTxt = null; // Level setup function function setupLevel(level) { // Remove old obstacles and gates for (var i = 0; i < obstacles.length; i++) { obstacles[i].destroy(); } obstacles = []; for (var j = 0; j < gates.length; j++) { gates[j].destroy(); } gates = []; // Update score text scoreTxt.setText('Seviye: ' + level); // Reset and show timer levelTimeLeft = 10; // Clear obstacle timer if active if (game.obstacleTimer) { LK.clearInterval(game.obstacleTimer); game.obstacleTimer = null; game.obstacleTimerActive = false; } if (!timerTxt) { timerTxt = new Text2('10', { size: 100, fill: 0xFFD700 }); timerTxt.anchor.set(0.5, 0); LK.gui.top.addChild(timerTxt); } timerTxt.setText('10'); // Place player at start player.x = 400; player.y = platformY; player.isJumping = false; player.velocityY = 0; // Place obstacles (random positions, but not too close to start or end) var numObstacles = Math.min(2 + level, 6); for (var o = 0; o < numObstacles; o++) { var obs = new Obstacle(); var minX = 600; var maxX = 2048 - 600; var obsX = minX + Math.floor((maxX - minX) * (o + 1) / (numObstacles + 1)); obs.x = obsX; obs.y = platformY; game.addChild(obs); obstacles.push(obs); } // Place gates at end of platform var gateY = platformY; var gateOffset = 250; var gate1 = new Gate(); var gate2 = new Gate(); // Randomly assign correct/wrong var correctGate = Math.random() < 0.5 ? 1 : 2; if (correctGate === 1) { gate1.setType('correct'); gate2.setType('wrong'); } else { gate1.setType('wrong'); gate2.setType('correct'); } // Place gates gate1.x = 2048 / 2 - gateOffset; gate2.x = 2048 / 2 + gateOffset; gate1.y = gateY - 80; gate2.y = gateY - 80; game.addChild(gate1); game.addChild(gate2); gates.push(gate1); gates.push(gate2); // Clear previous timer if any if (levelTimer) { LK.clearInterval(levelTimer); levelTimer = null; } // Start 10 second timer levelTimer = LK.setInterval(function () { levelTimeLeft -= 1; if (timerTxt) timerTxt.setText(levelTimeLeft.toString()); if (levelTimeLeft <= 0) { LK.clearInterval(levelTimer); levelTimer = null; LK.effects.flashScreen(0xde4444, 1000); LK.setTimeout(function () { LK.showGameOver(); }, 1000); } }, 1000); } // Helper: check collision between two containers (AABB) function isColliding(a, b) { return a.x - a.width / 2 < b.x + b.width / 2 && a.x + a.width / 2 > b.x - b.width / 2 && a.y - a.height < b.y && a.y > b.y - b.height; } // Helper: check if player is at a gate function playerAtGate(gate) { // Player must be at the same x as gate, and at the end of platform return Math.abs(player.x - gate.x) < gate.width / 2 && player.y === platformY; } // Touch/mouse controls: Drag player horizontally on the platform game.down = function (x, y, obj) { // Only start drag if touch/click is on player // Only start drag if touch/click is on player // Check if the touch is within the player's bounds if (x >= player.x - player.width / 2 && x <= player.x + player.width / 2 && y >= player.y - player.height && y <= player.y) { dragPlayer = true; } }; game.move = function (x, y, obj) { if (dragPlayer) { // Restrict movement to platform bounds var minX = player.width / 2; var maxX = 2048 - player.width / 2; var minY = platformY - 1000; // Allow dragging up to 1000px above platform var maxY = platformY; player.x = Math.max(minX, Math.min(maxX, x)); player.y = Math.max(minY, Math.min(maxY, y)); } }; game.up = function (x, y, obj) { dragPlayer = false; }; // Main game update loop game.update = function () { player.update(); // Prevent player from falling below platform if (player.y > platformY) { player.y = platformY; player.isJumping = false; player.velocityY = 0; } // Obstacle collision for (var i = 0; i < obstacles.length; i++) { var obs = obstacles[i]; if (isColliding(player, obs) && player.y === platformY // Only if on ground ) { // Flash and start 5 second timer for game over if (!game.obstacleTimerActive) { game.obstacleTimerActive = true; LK.effects.flashScreen(0xde4444, 600); // Show 5 second timer on timerTxt if (timerTxt) timerTxt.setText('5'); var obstacleTimeLeft = 5; if (levelTimer) { LK.clearInterval(levelTimer); levelTimer = null; } // Start 5 second timer game.obstacleTimer = LK.setInterval(function () { obstacleTimeLeft -= 1; if (timerTxt) timerTxt.setText(obstacleTimeLeft.toString()); if (obstacleTimeLeft <= 0) { LK.clearInterval(game.obstacleTimer); game.obstacleTimer = null; if (timerTxt) timerTxt.setText(''); LK.setTimeout(function () { LK.showGameOver(); game.obstacleTimerActive = false; }, 500); } }, 1000); } return; } } // Gate check (trigger only if player physically touches a gate) for (var g = 0; g < gates.length; g++) { var gate = gates[g]; if (isColliding(player, gate)) { // Prevent multiple triggers if (!game.gateTriggered) { game.gateTriggered = true; if (gate.gateType === 'correct') { // Next level after delay currentLevel += 1; // Stop timer if (levelTimer) { LK.clearInterval(levelTimer); levelTimer = null; } // Clear obstacle timer if active if (game.obstacleTimer) { LK.clearInterval(game.obstacleTimer); game.obstacleTimer = null; game.obstacleTimerActive = false; } if (timerTxt) timerTxt.setText(''); LK.effects.flashScreen(0x44de83, 400); LK.setTimeout(function () { setupLevel(currentLevel); game.gateTriggered = false; }, 900); } else { // Wrong gate: game over after delay if (levelTimer) { LK.clearInterval(levelTimer); levelTimer = null; } // Clear obstacle timer if active if (game.obstacleTimer) { LK.clearInterval(game.obstacleTimer); game.obstacleTimer = null; game.obstacleTimerActive = false; } if (timerTxt) timerTxt.setText(''); LK.effects.flashScreen(0xde4444, 1000); LK.setTimeout(function () { LK.showGameOver(); game.gateTriggered = false; }, 1000); } } return; } } }; // Asset initialization (shapes) // Start first level setupLevel(currentLevel);
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Gate class
var Gate = Container.expand(function () {
var self = Container.call(this);
// Attach gate asset (ellipse, color depends on type)
var gateAsset = self.attachAsset(self.gateType === 'correct' ? 'gateCorrect' : 'gateWrong', {
anchorX: 0.5,
anchorY: 1
});
self.width = gateAsset.width;
self.height = gateAsset.height;
// Type: 'correct' or 'wrong'
self.gateType = 'wrong';
// Set color based on type
self.setType = function (type) {
self.gateType = type;
var color = type === 'correct' ? 0x44de83 : 0xde4444;
gateAsset.tint = color;
};
return self;
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
// Attach obstacle asset (yellow box)
var obsAsset = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 1
});
self.width = obsAsset.width;
self.height = obsAsset.height;
return self;
});
// Player character class
var Player = Container.expand(function () {
var self = Container.call(this);
// Attach player asset (red box)
var playerAsset = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1
});
// Player movement speed
self.speed = 18;
self.jumpPower = 60;
self.isJumping = false;
self.velocityY = 0;
// For collision detection
self.width = playerAsset.width;
self.height = playerAsset.height;
// Jump method
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.velocityY = -self.jumpPower;
}
};
// Update method (called every tick)
self.update = function () {
// No automatic horizontal movement
// Gravity
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += 6; // gravity
// If landed on platform
if (self.y >= platformY) {
self.y = platformY;
self.isJumping = false;
self.velocityY = 0;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
// No title, no description
// Always backgroundColor is black
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Platform Y position (ground level)
var platformY = 2200;
// Level state
var currentLevel = 1;
// Arrays for obstacles and gates
var obstacles = [];
var gates = [];
// Dragging state for player movement
var dragPlayer = false;
// Score text
var scoreTxt = new Text2('Seviye: 1', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Platform asset (long gray box)
var platform = LK.getAsset('platform', {
width: 1800,
height: 60,
color: 0x888888,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: platformY + 30
});
game.addChild(platform);
// Create player
var player = new Player();
game.addChild(player);
player.x = 400;
player.y = platformY;
// Timer for level selection
var levelTimer = null;
var levelTimeLeft = 10;
var timerTxt = null;
// Level setup function
function setupLevel(level) {
// Remove old obstacles and gates
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].destroy();
}
obstacles = [];
for (var j = 0; j < gates.length; j++) {
gates[j].destroy();
}
gates = [];
// Update score text
scoreTxt.setText('Seviye: ' + level);
// Reset and show timer
levelTimeLeft = 10;
// Clear obstacle timer if active
if (game.obstacleTimer) {
LK.clearInterval(game.obstacleTimer);
game.obstacleTimer = null;
game.obstacleTimerActive = false;
}
if (!timerTxt) {
timerTxt = new Text2('10', {
size: 100,
fill: 0xFFD700
});
timerTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(timerTxt);
}
timerTxt.setText('10');
// Place player at start
player.x = 400;
player.y = platformY;
player.isJumping = false;
player.velocityY = 0;
// Place obstacles (random positions, but not too close to start or end)
var numObstacles = Math.min(2 + level, 6);
for (var o = 0; o < numObstacles; o++) {
var obs = new Obstacle();
var minX = 600;
var maxX = 2048 - 600;
var obsX = minX + Math.floor((maxX - minX) * (o + 1) / (numObstacles + 1));
obs.x = obsX;
obs.y = platformY;
game.addChild(obs);
obstacles.push(obs);
}
// Place gates at end of platform
var gateY = platformY;
var gateOffset = 250;
var gate1 = new Gate();
var gate2 = new Gate();
// Randomly assign correct/wrong
var correctGate = Math.random() < 0.5 ? 1 : 2;
if (correctGate === 1) {
gate1.setType('correct');
gate2.setType('wrong');
} else {
gate1.setType('wrong');
gate2.setType('correct');
}
// Place gates
gate1.x = 2048 / 2 - gateOffset;
gate2.x = 2048 / 2 + gateOffset;
gate1.y = gateY - 80;
gate2.y = gateY - 80;
game.addChild(gate1);
game.addChild(gate2);
gates.push(gate1);
gates.push(gate2);
// Clear previous timer if any
if (levelTimer) {
LK.clearInterval(levelTimer);
levelTimer = null;
}
// Start 10 second timer
levelTimer = LK.setInterval(function () {
levelTimeLeft -= 1;
if (timerTxt) timerTxt.setText(levelTimeLeft.toString());
if (levelTimeLeft <= 0) {
LK.clearInterval(levelTimer);
levelTimer = null;
LK.effects.flashScreen(0xde4444, 1000);
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
}
}, 1000);
}
// Helper: check collision between two containers (AABB)
function isColliding(a, b) {
return a.x - a.width / 2 < b.x + b.width / 2 && a.x + a.width / 2 > b.x - b.width / 2 && a.y - a.height < b.y && a.y > b.y - b.height;
}
// Helper: check if player is at a gate
function playerAtGate(gate) {
// Player must be at the same x as gate, and at the end of platform
return Math.abs(player.x - gate.x) < gate.width / 2 && player.y === platformY;
}
// Touch/mouse controls: Drag player horizontally on the platform
game.down = function (x, y, obj) {
// Only start drag if touch/click is on player
// Only start drag if touch/click is on player
// Check if the touch is within the player's bounds
if (x >= player.x - player.width / 2 && x <= player.x + player.width / 2 && y >= player.y - player.height && y <= player.y) {
dragPlayer = true;
}
};
game.move = function (x, y, obj) {
if (dragPlayer) {
// Restrict movement to platform bounds
var minX = player.width / 2;
var maxX = 2048 - player.width / 2;
var minY = platformY - 1000; // Allow dragging up to 1000px above platform
var maxY = platformY;
player.x = Math.max(minX, Math.min(maxX, x));
player.y = Math.max(minY, Math.min(maxY, y));
}
};
game.up = function (x, y, obj) {
dragPlayer = false;
};
// Main game update loop
game.update = function () {
player.update();
// Prevent player from falling below platform
if (player.y > platformY) {
player.y = platformY;
player.isJumping = false;
player.velocityY = 0;
}
// Obstacle collision
for (var i = 0; i < obstacles.length; i++) {
var obs = obstacles[i];
if (isColliding(player, obs) && player.y === platformY // Only if on ground
) {
// Flash and start 5 second timer for game over
if (!game.obstacleTimerActive) {
game.obstacleTimerActive = true;
LK.effects.flashScreen(0xde4444, 600);
// Show 5 second timer on timerTxt
if (timerTxt) timerTxt.setText('5');
var obstacleTimeLeft = 5;
if (levelTimer) {
LK.clearInterval(levelTimer);
levelTimer = null;
}
// Start 5 second timer
game.obstacleTimer = LK.setInterval(function () {
obstacleTimeLeft -= 1;
if (timerTxt) timerTxt.setText(obstacleTimeLeft.toString());
if (obstacleTimeLeft <= 0) {
LK.clearInterval(game.obstacleTimer);
game.obstacleTimer = null;
if (timerTxt) timerTxt.setText('');
LK.setTimeout(function () {
LK.showGameOver();
game.obstacleTimerActive = false;
}, 500);
}
}, 1000);
}
return;
}
}
// Gate check (trigger only if player physically touches a gate)
for (var g = 0; g < gates.length; g++) {
var gate = gates[g];
if (isColliding(player, gate)) {
// Prevent multiple triggers
if (!game.gateTriggered) {
game.gateTriggered = true;
if (gate.gateType === 'correct') {
// Next level after delay
currentLevel += 1;
// Stop timer
if (levelTimer) {
LK.clearInterval(levelTimer);
levelTimer = null;
}
// Clear obstacle timer if active
if (game.obstacleTimer) {
LK.clearInterval(game.obstacleTimer);
game.obstacleTimer = null;
game.obstacleTimerActive = false;
}
if (timerTxt) timerTxt.setText('');
LK.effects.flashScreen(0x44de83, 400);
LK.setTimeout(function () {
setupLevel(currentLevel);
game.gateTriggered = false;
}, 900);
} else {
// Wrong gate: game over after delay
if (levelTimer) {
LK.clearInterval(levelTimer);
levelTimer = null;
}
// Clear obstacle timer if active
if (game.obstacleTimer) {
LK.clearInterval(game.obstacleTimer);
game.obstacleTimer = null;
game.obstacleTimerActive = false;
}
if (timerTxt) timerTxt.setText('');
LK.effects.flashScreen(0xde4444, 1000);
LK.setTimeout(function () {
LK.showGameOver();
game.gateTriggered = false;
}, 1000);
}
}
return;
}
}
};
// Asset initialization (shapes)
// Start first level
setupLevel(currentLevel);