Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'LK.Graphics is not a constructor' in or related to this line: 'var ropeGraphics = new LK.Graphics();' Line Number: 111
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'LK.Graphics is not a constructor' in or related to this line: 'var ropeGraphics = new LK.Graphics();' Line Number: 107
Code edit (3 edits merged)
Please save this source code
User prompt
Plugins failed to load. Please try again and if the problem persists, please contact technical support i got this error
User prompt
var tween = LK.import("@upit/tween.v1"); this is the problem ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
still have problem
User prompt
fix the error please
Code edit (1 edits merged)
Please save this source code
User prompt
Crane Balance Master
Initial prompt
I want to create a balancing game with square containers dropped from a crane. The surroundings can be a construction site.
/****
* Classes
****/
var Crane = Container.expand(function () {
var self = Container.call(this);
var craneGraphics = self.attachAsset('crane', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = 1;
self.speed = 2;
self.update = function () {
self.x += self.direction * self.speed;
if (self.x <= 200) {
self.direction = 1;
} else if (self.x >= 1848) {
self.direction = -1;
}
};
return self;
});
var GameContainer = Container.expand(function () {
var self = Container.call(this);
var containerGraphics = self.attachAsset('container', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocity = {
x: 0,
y: 0
};
self.grounded = false;
self.settled = false;
self.settleTimer = 0;
self.isAttached = true;
self.intersects = function (other) {
return Math.abs(self.x - other.x) < 100 && Math.abs(self.y - other.y) < 100;
};
self.update = function () {
if (self.isAttached) {
return;
}
if (!self.grounded) {
self.velocity.y += 0.8;
self.x += self.velocity.x;
self.y += self.velocity.y;
if (self.y >= platformY - 50) {
var hitSomething = false;
if (self.x >= platformX - 250 && self.x <= platformX + 250) {
self.y = platformY - 50;
hitSomething = true;
}
for (var i = 0; i < containers.length; i++) {
var other = containers[i];
if (other !== self && other.grounded && self.intersects(other)) {
self.y = other.y - 100;
hitSomething = true;
break;
}
}
if (hitSomething) {
self.grounded = true;
self.velocity.y = 0;
self.velocity.x *= 0.3;
self.settleTimer = 60;
LK.getSound('stack').play();
}
}
if (self.y > 2732 + 100) {
self.destroy();
containers.splice(containers.indexOf(self), 1);
LK.showGameOver();
}
} else {
if (self.settleTimer > 0) {
self.settleTimer--;
if (self.settleTimer <= 0) {
self.settled = true;
}
}
if (Math.abs(self.velocity.x) > 0.1) {
self.x += self.velocity.x;
self.velocity.x *= 0.95;
}
}
};
return self;
});
var Hook = Container.expand(function () {
var self = Container.call(this);
var hookGraphics = self.attachAsset('hook', {
anchorX: 0.5,
anchorY: 0.5
});
// İp için şekil varlığı oluştur
var ropeGraphics = null;
self.hasContainer = false;
self.attachedContainer = null;
self.update = function () {
self.x = crane.x;
// İp görselini güncelle
if (self.hasContainer && self.attachedContainer) {
// İp yoksa oluştur
if (!ropeGraphics) {
ropeGraphics = LK.getAsset('container', {
anchorX: 0.5,
anchorY: 0,
scaleX: 0.05,
tint: 0x000000
});
self.addChild(ropeGraphics);
}
// İp uzunluğunu ve pozisyonunu ayarla
var ropeLength = Math.abs(self.attachedContainer.y - self.y);
ropeGraphics.scaleY = ropeLength / 100;
ropeGraphics.x = 0;
ropeGraphics.y = 0;
ropeGraphics.visible = true;
self.attachedContainer.x = self.x;
self.attachedContainer.y = self.y + 80;
} else {
// İp gizle
if (ropeGraphics) {
ropeGraphics.visible = false;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var containers = [];
var crane;
var hook;
var platform;
var ground;
var platformX = 2048 / 2;
var platformY = 2732 - 300;
var scoreText;
var nextContainerTimer = 0;
var gameSpeed = 1;
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 - 50
}));
platform = game.addChild(LK.getAsset('platform', {
anchorX: 0.5,
anchorY: 0.5,
x: platformX,
y: platformY
}));
crane = game.addChild(new Crane());
crane.x = 2048 / 2;
crane.y = 200;
hook = game.addChild(new Hook());
hook.x = crane.x;
hook.y = 300;
scoreText = new Text2('Score: 0', {
size: 80,
fill: 0x000000
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
function createNewContainer() {
var newContainer = new GameContainer();
newContainer.x = hook.x;
newContainer.y = hook.y + 80;
newContainer.isAttached = true;
containers.push(newContainer);
game.addChild(newContainer);
hook.hasContainer = true;
hook.attachedContainer = newContainer;
}
function dropContainer() {
if (hook.hasContainer && hook.attachedContainer) {
hook.attachedContainer.isAttached = false;
hook.attachedContainer.velocity.x = crane.direction * crane.speed * 0.5;
hook.attachedContainer.velocity.y = 2;
hook.hasContainer = false;
hook.attachedContainer = null;
LK.getSound('drop').play();
LK.setScore(LK.getScore() + 10);
scoreText.setText('Score: ' + LK.getScore());
nextContainerTimer = 120;
if (LK.getScore() % 100 === 0) {
crane.speed += 0.5;
}
}
}
createNewContainer();
game.down = function (x, y, obj) {
dropContainer();
};
game.update = function () {
if (nextContainerTimer > 0) {
nextContainerTimer--;
if (nextContainerTimer <= 0 && !hook.hasContainer) {
createNewContainer();
}
}
for (var i = containers.length - 1; i >= 0; i--) {
var container = containers[i];
if (container.grounded && (container.x < platformX - 250 || container.x > platformX + 250)) {
LK.effects.flashScreen(0xff0000, 500);
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
break;
}
}
if (LK.getScore() >= 500) {
LK.showYouWin();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,9 +1,7 @@
/****
* Classes
****/
-// Tween eklentisi kullanılmadığı için kaldırıldı. Gerekirse dökümantasyona göre doğru eklenti eklenebilir.
-// var tween = LK.import("@upit/tween.v1");
var Crane = Container.expand(function () {
var self = Container.call(this);
var craneGraphics = self.attachAsset('crane', {
anchorX: 0.5,
@@ -12,9 +10,8 @@
self.direction = 1;
self.speed = 2;
self.update = function () {
self.x += self.direction * self.speed;
- // Bounce off edges
if (self.x <= 200) {
self.direction = 1;
} else if (self.x >= 1848) {
self.direction = -1;
@@ -34,62 +31,57 @@
};
self.grounded = false;
self.settled = false;
self.settleTimer = 0;
- // intersects metodunu tanımlıyoruz (orijinal kodda eksik)
+ self.isAttached = true;
self.intersects = function (other) {
- return Math.abs(self.x - other.x) < 120 && Math.abs(self.y - other.y) < 120;
+ return Math.abs(self.x - other.x) < 100 && Math.abs(self.y - other.y) < 100;
};
self.update = function () {
+ if (self.isAttached) {
+ return;
+ }
if (!self.grounded) {
- // Apply gravity
self.velocity.y += 0.8;
- // Update position
self.x += self.velocity.x;
self.y += self.velocity.y;
- // Check if hit platform or other containers
- if (self.y >= platformY - 60) {
+ if (self.y >= platformY - 50) {
var hitSomething = false;
- // Check collision with platform
- if (self.x >= platformX - 200 && self.x <= platformX + 200) {
- self.y = platformY - 60;
+ if (self.x >= platformX - 250 && self.x <= platformX + 250) {
+ self.y = platformY - 50;
hitSomething = true;
}
- // Check collision with other containers
for (var i = 0; i < containers.length; i++) {
var other = containers[i];
if (other !== self && other.grounded && self.intersects(other)) {
- self.y = other.y - 120;
+ self.y = other.y - 100;
hitSomething = true;
break;
}
}
if (hitSomething) {
self.grounded = true;
self.velocity.y = 0;
- self.velocity.x *= 0.3; // Friction
- self.settleTimer = 60; // 1 second to settle
+ self.velocity.x *= 0.3;
+ self.settleTimer = 60;
LK.getSound('stack').play();
}
}
- // Check if fell off screen
if (self.y > 2732 + 100) {
self.destroy();
- containers.splice(containers.indexOf(self), 1); // Daha verimli kaldırma
+ containers.splice(containers.indexOf(self), 1);
LK.showGameOver();
}
} else {
- // Container is grounded, check for settling
if (self.settleTimer > 0) {
self.settleTimer--;
if (self.settleTimer <= 0) {
self.settled = true;
}
}
- // Apply slight physics even when grounded for stacking realism
if (Math.abs(self.velocity.x) > 0.1) {
self.x += self.velocity.x;
- self.velocity.x *= 0.95; // Gradual friction
+ self.velocity.x *= 0.95;
}
}
};
return self;
@@ -99,17 +91,39 @@
var hookGraphics = self.attachAsset('hook', {
anchorX: 0.5,
anchorY: 0.5
});
+ // İp için şekil varlığı oluştur
+ var ropeGraphics = null;
self.hasContainer = false;
self.attachedContainer = null;
self.update = function () {
- // Follow crane position
self.x = crane.x;
- // Move attached container with hook
+ // İp görselini güncelle
if (self.hasContainer && self.attachedContainer) {
+ // İp yoksa oluştur
+ if (!ropeGraphics) {
+ ropeGraphics = LK.getAsset('container', {
+ anchorX: 0.5,
+ anchorY: 0,
+ scaleX: 0.05,
+ tint: 0x000000
+ });
+ self.addChild(ropeGraphics);
+ }
+ // İp uzunluğunu ve pozisyonunu ayarla
+ var ropeLength = Math.abs(self.attachedContainer.y - self.y);
+ ropeGraphics.scaleY = ropeLength / 100;
+ ropeGraphics.x = 0;
+ ropeGraphics.y = 0;
+ ropeGraphics.visible = true;
self.attachedContainer.x = self.x;
self.attachedContainer.y = self.y + 80;
+ } else {
+ // İp gizle
+ if (ropeGraphics) {
+ ropeGraphics.visible = false;
+ }
}
};
return self;
});
@@ -123,9 +137,8 @@
/****
* Game Code
****/
-// Ses varlıklarını daha açık bir şekilde başlatıyoruz, dosya yollarını varsayıyoruz
var containers = [];
var crane;
var hook;
var platform;
@@ -134,31 +147,26 @@
var platformY = 2732 - 300;
var scoreText;
var nextContainerTimer = 0;
var gameSpeed = 1;
-// Create ground
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 - 50
}));
-// Create platform
platform = game.addChild(LK.getAsset('platform', {
anchorX: 0.5,
anchorY: 0.5,
x: platformX,
y: platformY
}));
-// Create crane
crane = game.addChild(new Crane());
crane.x = 2048 / 2;
crane.y = 200;
-// Create hook
hook = game.addChild(new Hook());
hook.x = crane.x;
hook.y = 300;
-// Create score display
scoreText = new Text2('Score: 0', {
size: 80,
fill: 0x000000
});
@@ -167,47 +175,41 @@
function createNewContainer() {
var newContainer = new GameContainer();
newContainer.x = hook.x;
newContainer.y = hook.y + 80;
+ newContainer.isAttached = true;
containers.push(newContainer);
game.addChild(newContainer);
hook.hasContainer = true;
hook.attachedContainer = newContainer;
}
function dropContainer() {
if (hook.hasContainer && hook.attachedContainer) {
+ hook.attachedContainer.isAttached = false;
hook.attachedContainer.velocity.x = crane.direction * crane.speed * 0.5;
hook.attachedContainer.velocity.y = 2;
hook.hasContainer = false;
hook.attachedContainer = null;
LK.getSound('drop').play();
- // Increase score
LK.setScore(LK.getScore() + 10);
scoreText.setText('Score: ' + LK.getScore());
- // Schedule next container
- nextContainerTimer = 120; // 2 seconds
- // Increase difficulty slightly
+ nextContainerTimer = 120;
if (LK.getScore() % 100 === 0) {
crane.speed += 0.5;
}
}
}
-// Create first container
createNewContainer();
-// Touch controls
game.down = function (x, y, obj) {
dropContainer();
};
-// Main game loop
game.update = function () {
- // Handle next container creation
if (nextContainerTimer > 0) {
nextContainerTimer--;
if (nextContainerTimer <= 0 && !hook.hasContainer) {
createNewContainer();
}
}
- // Check for unstable stacks
for (var i = containers.length - 1; i >= 0; i--) {
var container = containers[i];
if (container.grounded && (container.x < platformX - 250 || container.x > platformX + 250)) {
LK.effects.flashScreen(0xff0000, 500);
@@ -216,9 +218,8 @@
}, 500);
break;
}
}
- // Check win condition
if (LK.getScore() >= 500) {
LK.showYouWin();
}
};
\ No newline at end of file