User prompt
self.speed = -12;
User prompt
self.jumpPower = -250; self.jump = function () { if (self.onGround) { self.velocityY = self.jumpPower; self.onGround = false; } };
User prompt
function jump() { if (orb.y >= 1090) { orb.setVelocity(0, -100); // En hafif zıplama } }
User prompt
function jump() { if (orb.y >= 1090) { orb.setVelocity(0, -250); // Çok düşük zıplama } }
User prompt
function jump() { if (orb.y >= 1090) { orb.setVelocity(0, -700); // Daha yüksek zıplama } }
User prompt
Please fix the bug: 'LK.init is not a function' in or related to this line: 'LK.init({' Line Number: 13
User prompt
LK.init({ size: [720, 1280], gravity: [0, 2500], // Yerden çekim kuvveti backgroundColor: 0x111111, }); let ground = LK.add.shape({ shape: "box", width: 720, height: 40, x: 360, y: 1260, physics: "static", color: 0x333333, }); let orb = LK.add.shape({ shape: "circle", radius: 50, x: 360, y: 1200, color: 0x00ffff, physics: "dynamic", restitution: 0, // Sekme kapalı friction: 0.5, }); function jump() { // Sadece yerdeyken zıplama if (orb.y > 1150) { orb.setVelocity(0, -700); } } LK.onKeyDown("space", jump); LK.onPointerDown(jump); function spawnObstacle() { let obs = LK.add.shape({ shape: "box", width: 100, height: 30, x: 800, y: 1210, // Yere çok yakın, ama topun üstünden atlaması için biraz yukarıda color: 0xff4444, physics: "kinematic", }); obs.setVelocity(-250, 0); LK.onCollide(orb, obs, () => LK.scene.restart()); LK.wait(6, () => obs.destroy()); } LK.every(1.5, spawnObstacle); let score = 0; let scoreText = LK.add.text({ text: "Skor: 0", size: 45, x: 30, y: 60, anchorX: "left", color: 0xffffff, }); LK.every(1, () => { score++; scoreText.text = "Skor: " + score; });
User prompt
function spawnObstacle() { let obs = LK.add.shape({ shape: "box", width: 100, height: 30, x: 800, y: 1170, // Yere yakın engel yüksekliği color: 0xff4444, physics: "kinematic", }); obs.setVelocity(-250, 0); LK.onCollide(orb, obs, () => { LK.scene.restart(); }); LK.wait(6, () => obs.destroy()); }
User prompt
function spawnObstacle() { let obs = LK.add.shape({ shape: "box", width: 100, height: 30, x: 800, y: LK.random(1140, 1220), // Rastgele yükseklik color: 0xff4444, physics: "kinematic", }); obs.setVelocity(-250, 0); LK.onCollide(orb, obs, () => { LK.scene.restart(); // Çarpınca oyun biter }); LK.wait(6, () => obs.destroy()); }
User prompt
let obs = LK.add.shape({ shape: "box", width: 100, height: 30, x: 800, y: 1180, // AŞAĞI ALINDI color: 0xff4444, physics: "kinematic", });
User prompt
let orb = LK.add.shape({ shape: "circle", radius: 50, x: 360, y: 1100, // daha aşağıdan başlar color: 0x00ffff, physics: "dynamic", restitution: 0, friction: 0.5, density: 1, });
Code edit (1 edits merged)
Please save this source code
User prompt
Jump Orb Runner
Initial prompt
// Başlat LK.init({ size: [720, 1280], gravity: [0, 2200], backgroundColor: 0x111122, }); // Zemin let ground = LK.add.shape({ shape: "box", width: 720, height: 40, x: 360, y: 1260, physics: "static", color: 0x333333, }); // Top let orb = LK.add.shape({ shape: "circle", radius: 50, x: 360, y: 1000, color: 0x00ffff, physics: "dynamic", restitution: 0, // Sekme kapalı friction: 0.5, density: 1, }); // Zıplama fonksiyonu function jump() { // Yerdeyse zıplasın (fazla zıplamasın) if (orb.y > 950) { orb.setVelocity(0, -700); // Az zıplama } } // Kontroller LK.onKeyDown("space", jump); LK.onPointerDown(jump); // Engel örneği function spawnObstacle() { let obs = LK.add.shape({ shape: "box", width: 100, height: 30, x: 800, y: 1150, color: 0xff4444, physics: "kinematic", }); obs.setVelocity(-250, 0); LK.onCollide(orb, obs, () => { LK.scene.restart(); // Çarpınca oyun biter }); LK.wait(6, () => obs.destroy()); } LK.every(1.5, spawnObstacle); // Skor let score = 0; let scoreText = LK.add.text({ text: "Skor: 0", size: 45, x: 30, y: 60, anchorX: "left", color: 0xffffff, }); LK.every(1, () => { score++; scoreText.text = "Skor: " + score; });
/****
* Classes
****/
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -8;
self.update = function () {
self.x += self.speed;
};
return self;
});
var Orb = Container.expand(function () {
var self = Container.call(this);
var orbGraphics = self.attachAsset('orb', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 0;
self.gravity = 15;
self.jumpPower = -25;
self.onGround = false;
self.update = function () {
self.velocityY += self.gravity;
self.y += self.velocityY;
// Ground collision
if (self.y > 2632 - 80 - 50) {
self.y = 2632 - 80 - 50;
self.velocityY = 0;
self.onGround = true;
} else {
self.onGround = false;
}
};
self.jump = function () {
if (self.onGround) {
self.velocityY = self.jumpPower;
self.onGround = false;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x111111
});
/****
* Game Code
****/
// Create ground
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2632 - 40
}));
// Create orb
var orb = game.addChild(new Orb());
orb.x = 1024;
orb.y = 2632 - 80 - 50;
// Game input handling
game.down = function (x, y, obj) {
orb.jump();
};
// Obstacles array
var obstacles = [];
var score = 0;
// Score display
var scoreText = new Text2('Skor: 0', {
size: 45,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
LK.gui.topLeft.addChild(scoreText);
scoreText.x = 30;
scoreText.y = 60;
// Spawn obstacles
function spawnObstacle() {
var obs = game.addChild(new Obstacle());
obs.x = 2048 + 50;
obs.y = 2632 - 80 - 15;
obs.lastIntersecting = false;
obstacles.push(obs);
}
// Spawn timer
var spawnTimer = 0;
var spawnInterval = 90; // 1.5 seconds at 60fps
// Score timer
var scoreTimer = 0;
var scoreInterval = 60; // 1 second at 60fps
game.update = function () {
// Spawn obstacles
spawnTimer++;
if (spawnTimer >= spawnInterval) {
spawnObstacle();
spawnTimer = 0;
}
// Update score
scoreTimer++;
if (scoreTimer >= scoreInterval) {
score++;
scoreText.setText('Skor: ' + score);
scoreTimer = 0;
}
// Check obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obs = obstacles[i];
// Remove off-screen obstacles
if (obs.x < -50) {
obs.destroy();
obstacles.splice(i, 1);
continue;
}
// Check collision
var currentIntersecting = orb.intersects(obs);
if (!obs.lastIntersecting && currentIntersecting) {
LK.showGameOver();
return;
}
obs.lastIntersecting = currentIntersecting;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,76 +1,129 @@
/****
+* Classes
+****/
+var Obstacle = Container.expand(function () {
+ var self = Container.call(this);
+ var obstacleGraphics = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -8;
+ self.update = function () {
+ self.x += self.speed;
+ };
+ return self;
+});
+var Orb = Container.expand(function () {
+ var self = Container.call(this);
+ var orbGraphics = self.attachAsset('orb', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.velocityY = 0;
+ self.gravity = 15;
+ self.jumpPower = -25;
+ self.onGround = false;
+ self.update = function () {
+ self.velocityY += self.gravity;
+ self.y += self.velocityY;
+ // Ground collision
+ if (self.y > 2632 - 80 - 50) {
+ self.y = 2632 - 80 - 50;
+ self.velocityY = 0;
+ self.onGround = true;
+ } else {
+ self.onGround = false;
+ }
+ };
+ self.jump = function () {
+ if (self.onGround) {
+ self.velocityY = self.jumpPower;
+ self.onGround = false;
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000
+ backgroundColor: 0x111111
});
/****
* Game Code
****/
-// No classes needed for physics-based implementation
-// No assets needed for physics-based implementation
-LK.init({
- size: [720, 1280],
- gravity: [0, 2500],
- backgroundColor: 0x111111
-});
-// Ground
-var ground = LK.add.shape({
- shape: "box",
- width: 720,
- height: 40,
- x: 360,
- y: 1260,
- physics: "static",
- color: 0x333333
-});
-var orb = LK.add.shape({
- shape: "circle",
- radius: 50,
- x: 360,
- y: 1200,
- color: 0x00ffff,
- physics: "dynamic",
- restitution: 0,
- friction: 0.5
-});
-function jump() {
- if (orb.y > 1150) {
- orb.setVelocity(0, -700);
- }
-}
-LK.onKeyDown("space", jump);
-LK.onPointerDown(jump);
-function spawnObstacle() {
- var obs = LK.add.shape({
- shape: "box",
- width: 100,
- height: 30,
- x: 800,
- y: 1210,
- color: 0xff4444,
- physics: "kinematic"
- });
- obs.setVelocity(-250, 0);
- LK.onCollide(orb, obs, function () {
- return LK.scene.restart();
- });
- LK.wait(6, function () {
- return obs.destroy();
- });
-}
-LK.every(1.5, spawnObstacle);
+// Create ground
+var ground = game.addChild(LK.getAsset('ground', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 1024,
+ y: 2632 - 40
+}));
+// Create orb
+var orb = game.addChild(new Orb());
+orb.x = 1024;
+orb.y = 2632 - 80 - 50;
+// Game input handling
+game.down = function (x, y, obj) {
+ orb.jump();
+};
+// Obstacles array
+var obstacles = [];
var score = 0;
-var scoreText = LK.add.text({
- text: "Skor: 0",
+// Score display
+var scoreText = new Text2('Skor: 0', {
size: 45,
- x: 30,
- y: 60,
- anchorX: "left",
- color: 0xffffff
+ fill: 0xFFFFFF
});
-LK.every(1, function () {
- score++;
- scoreText.text = "Skor: " + score;
-});
\ No newline at end of file
+scoreText.anchor.set(0, 0);
+LK.gui.topLeft.addChild(scoreText);
+scoreText.x = 30;
+scoreText.y = 60;
+// Spawn obstacles
+function spawnObstacle() {
+ var obs = game.addChild(new Obstacle());
+ obs.x = 2048 + 50;
+ obs.y = 2632 - 80 - 15;
+ obs.lastIntersecting = false;
+ obstacles.push(obs);
+}
+// Spawn timer
+var spawnTimer = 0;
+var spawnInterval = 90; // 1.5 seconds at 60fps
+// Score timer
+var scoreTimer = 0;
+var scoreInterval = 60; // 1 second at 60fps
+game.update = function () {
+ // Spawn obstacles
+ spawnTimer++;
+ if (spawnTimer >= spawnInterval) {
+ spawnObstacle();
+ spawnTimer = 0;
+ }
+ // Update score
+ scoreTimer++;
+ if (scoreTimer >= scoreInterval) {
+ score++;
+ scoreText.setText('Skor: ' + score);
+ scoreTimer = 0;
+ }
+ // Check obstacles
+ for (var i = obstacles.length - 1; i >= 0; i--) {
+ var obs = obstacles[i];
+ // Remove off-screen obstacles
+ if (obs.x < -50) {
+ obs.destroy();
+ obstacles.splice(i, 1);
+ continue;
+ }
+ // Check collision
+ var currentIntersecting = orb.intersects(obs);
+ if (!obs.lastIntersecting && currentIntersecting) {
+ LK.showGameOver();
+ return;
+ }
+ obs.lastIntersecting = currentIntersecting;
+ }
+};
\ No newline at end of file