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;
// 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);
// 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 stacked vertically at end of platform, centered horizontally
var gateX = 2048 / 2;
var gateY = platformY - 80;
var gateSpacing = 220; // vertical distance between gates
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: one above the other, both centered horizontally
gate1.x = gateX;
gate2.x = gateX;
gate1.y = gateY;
gate2.y = gateY - gateSpacing;
game.addChild(gate1);
game.addChild(gate2);
gates.push(gate1);
gates.push(gate2);
// Center obstacle on platform (if only one obstacle, always center it)
if (obstacles.length === 1) {
obstacles[0].x = 2048 / 2;
obstacles[0].y = platformY;
}
}
// 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
// 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 reset level
LK.effects.flashScreen(0xde4444, 600);
setupLevel(currentLevel);
return;
}
}
// Gate check (only if player is at the end of the platform, i.e. at the last gates)
var lastGateY = gates.length > 0 ? gates[0].y : null;
var lastGateSpacing = gates.length > 1 ? Math.abs(gates[0].y - gates[1].y) : 0;
var isAtLastGates = false;
if (gates.length > 0) {
// Check if player is at the y position of either gate (since they are stacked vertically)
for (var g = 0; g < gates.length; g++) {
var gate = gates[g];
if (playerAtGate(gate)) {
isAtLastGates = true;
// Only allow gate choice if at the last gates (i.e. at the end of the platform)
if (gate.gateType === 'correct') {
// Next level
currentLevel += 1;
LK.effects.flashScreen(0x44de83, 400);
setupLevel(currentLevel);
} else {
// Wrong gate: game over
LK.effects.flashScreen(0xde4444, 1000);
LK.showGameOver();
}
return;
}
}
}
};
// Asset initialization (shapes)
// Start first level
setupLevel(currentLevel); ===================================================================
--- original.js
+++ change.js
@@ -234,23 +234,31 @@
setupLevel(currentLevel);
return;
}
}
- // Gate check (if at end of platform)
- for (var g = 0; g < gates.length; g++) {
- var gate = gates[g];
- if (playerAtGate(gate)) {
- if (gate.gateType === 'correct') {
- // Next level
- currentLevel += 1;
- LK.effects.flashScreen(0x44de83, 400);
- setupLevel(currentLevel);
- } else {
- // Wrong gate: game over
- LK.effects.flashScreen(0xde4444, 1000);
- LK.showGameOver();
+ // Gate check (only if player is at the end of the platform, i.e. at the last gates)
+ var lastGateY = gates.length > 0 ? gates[0].y : null;
+ var lastGateSpacing = gates.length > 1 ? Math.abs(gates[0].y - gates[1].y) : 0;
+ var isAtLastGates = false;
+ if (gates.length > 0) {
+ // Check if player is at the y position of either gate (since they are stacked vertically)
+ for (var g = 0; g < gates.length; g++) {
+ var gate = gates[g];
+ if (playerAtGate(gate)) {
+ isAtLastGates = true;
+ // Only allow gate choice if at the last gates (i.e. at the end of the platform)
+ if (gate.gateType === 'correct') {
+ // Next level
+ currentLevel += 1;
+ LK.effects.flashScreen(0x44de83, 400);
+ setupLevel(currentLevel);
+ } else {
+ // Wrong gate: game over
+ LK.effects.flashScreen(0xde4444, 1000);
+ LK.showGameOver();
+ }
+ return;
}
- return;
}
}
};
// Asset initialization (shapes)