User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'toGlobal')' in or related to this line: 'var localPos = game.toLocal(obj.parent.toGlobal(obj.position));' Line Number: 285
User prompt
bahis sistemi koy ve en düşük bahis 10 coin olsun
User prompt
kazanma olasılıgı yarı yarıya olsun
User prompt
paranın bir kısmı mavi bir kısmı siyah olsun
User prompt
yazı kısmını mavi tura kısmını siyah yap
Code edit (1 edits merged)
Please save this source code
User prompt
Yazı Tura - Coin Flip Challenge
Initial prompt
yazı tura oyunu
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Coin = Container.expand(function () {
var self = Container.call(this);
// Create container for the coin halves
var coinContainer = new Container();
coinContainer.x = 0;
coinContainer.y = 0;
self.addChild(coinContainer);
// Create blue half (top)
var blueHalf = coinContainer.attachAsset('coinBlueHalf', {
anchorX: 0.5,
anchorY: 1
});
blueHalf.x = 0;
blueHalf.y = 0;
// Create black half (bottom)
var blackHalf = coinContainer.attachAsset('coinBlackHalf', {
anchorX: 0.5,
anchorY: 0
});
blackHalf.x = 0;
blackHalf.y = 0;
// Reference for animations (use the container)
var coinGraphics = coinContainer;
self.isFlipping = false;
self.result = null;
self.flip = function (callback) {
if (self.isFlipping) return;
self.isFlipping = true;
self.result = Math.random() < 0.5 ? 'heads' : 'tails';
// Play flip sound
LK.getSound('coinFlip').play();
// Animate coin flip with multiple rotations and scale changes
var rotations = 8 + Math.floor(Math.random() * 4); // 8-11 rotations
var duration = 2000 + Math.random() * 1000; // 2-3 seconds
// First phase: spin up with scale
tween(coinGraphics, {
rotation: Math.PI * rotations,
scaleX: 1.5,
scaleY: 0.3
}, {
duration: duration * 0.7,
easing: tween.easeOut,
onFinish: function onFinish() {
// Second phase: settle down
var finalRotation = self.result === 'heads' ? 0 : Math.PI;
tween(coinGraphics, {
rotation: finalRotation,
scaleX: 1,
scaleY: 1
}, {
duration: duration * 0.3,
easing: tween.easeInOut,
onFinish: function onFinish() {
self.isFlipping = false;
if (callback) callback(self.result);
}
});
}
});
// Vertical bounce animation
var originalY = self.y;
tween(self, {
y: originalY - 200
}, {
duration: duration * 0.5,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
y: originalY
}, {
duration: duration * 0.5,
easing: tween.bounceOut
});
}
});
};
return self;
});
var PredictionButton = Container.expand(function (type, color) {
var self = Container.call(this);
var buttonGraphics = self.attachAsset(type === 'heads' ? 'headsButton' : 'tailsButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2(type === 'heads' ? 'YAZI' : 'TURA', {
size: 60,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.type = type;
self.isEnabled = true;
self.setEnabled = function (enabled) {
self.isEnabled = enabled;
buttonGraphics.alpha = enabled ? 1 : 0.5;
};
self.down = function (x, y, obj) {
if (!self.isEnabled) return;
// Button press animation
tween(buttonGraphics, {
scaleX: 0.95,
scaleY: 0.95
}, {
duration: 100,
onFinish: function onFinish() {
tween(buttonGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
if (onPredictionMade) {
onPredictionMade(self.type);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
// Game state variables
var gameState = 'waiting'; // 'waiting', 'flipping', 'result'
var currentPrediction = null;
var streak = 0;
var maxStreak = 0;
var totalFlips = 0;
var correctFlips = 0;
// Create coin
var coin = game.addChild(new Coin());
coin.x = 2048 / 2;
coin.y = 2732 / 2 - 200;
// Create prediction buttons
var headsButton = game.addChild(new PredictionButton('heads'));
headsButton.x = 2048 / 2 - 250;
headsButton.y = 2732 - 300;
var tailsButton = game.addChild(new PredictionButton('tails'));
tailsButton.x = 2048 / 2 + 250;
tailsButton.y = 2732 - 300;
// Create UI elements
var scoreText = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var streakText = new Text2('Streak: 0', {
size: 60,
fill: 0xFFD700
});
streakText.anchor.set(0, 0);
streakText.x = 50;
streakText.y = 150;
LK.gui.addChild(streakText);
var maxStreakText = new Text2('Best: 0', {
size: 60,
fill: 0xFFD700
});
maxStreakText.anchor.set(1, 0);
maxStreakText.x = LK.gui.width - 50;
maxStreakText.y = 150;
LK.gui.addChild(maxStreakText);
var instructionText = new Text2('Predict the coin flip!', {
size: 70,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 2048 / 2;
instructionText.y = 2732 / 2 + 300;
game.addChild(instructionText);
var resultText = new Text2('', {
size: 100,
fill: 0x00FF00
});
resultText.anchor.set(0.5, 0.5);
resultText.x = 2048 / 2;
resultText.y = 2732 / 2 + 150;
game.addChild(resultText);
// Prediction callback
function onPredictionMade(prediction) {
if (gameState !== 'waiting') return;
currentPrediction = prediction;
gameState = 'flipping';
// Disable buttons during flip
headsButton.setEnabled(false);
tailsButton.setEnabled(false);
// Update instruction
instructionText.setText('Flipping...');
resultText.setText('');
// Start coin flip
coin.flip(function (result) {
gameState = 'result';
totalFlips++;
var isCorrect = currentPrediction === result;
if (isCorrect) {
correctFlips++;
streak++;
if (streak > maxStreak) {
maxStreak = streak;
}
// Award points (more points for longer streaks)
var points = 10 + Math.floor(streak / 5) * 5;
LK.setScore(LK.getScore() + points);
resultText.setText('CORRECT! +' + points);
resultText.tint = 0x00ff00;
// Play correct sound
LK.getSound('correct').play();
// Flash effect for correct guess
LK.effects.flashObject(coin, 0x00ff00, 500);
} else {
streak = 0;
resultText.setText('WRONG!');
resultText.tint = 0xff0000;
// Play wrong sound
LK.getSound('wrong').play();
// Flash effect for wrong guess
LK.effects.flashObject(coin, 0xff0000, 500);
}
// Update UI
updateUI();
// Show result for 2 seconds then reset
LK.setTimeout(function () {
resetForNextFlip();
}, 2000);
});
}
function updateUI() {
scoreText.setText('Score: ' + LK.getScore());
streakText.setText('Streak: ' + streak);
maxStreakText.setText('Best: ' + maxStreak);
// Animate streak text when it increases
if (streak > 0) {
tween(streakText, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
onFinish: function onFinish() {
tween(streakText, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}
});
}
}
function resetForNextFlip() {
gameState = 'waiting';
currentPrediction = null;
// Re-enable buttons
headsButton.setEnabled(true);
tailsButton.setEnabled(true);
// Reset instruction text
instructionText.setText('Predict the coin flip!');
resultText.setText('');
// Check for win condition (high score or long streak)
if (LK.getScore() >= 500 || maxStreak >= 20) {
LK.showYouWin();
}
}
// Initialize UI
updateUI(); ===================================================================
--- original.js
+++ change.js
@@ -7,12 +7,29 @@
* Classes
****/
var Coin = Container.expand(function () {
var self = Container.call(this);
- var coinGraphics = self.attachAsset('coin', {
+ // Create container for the coin halves
+ var coinContainer = new Container();
+ coinContainer.x = 0;
+ coinContainer.y = 0;
+ self.addChild(coinContainer);
+ // Create blue half (top)
+ var blueHalf = coinContainer.attachAsset('coinBlueHalf', {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 1
});
+ blueHalf.x = 0;
+ blueHalf.y = 0;
+ // Create black half (bottom)
+ var blackHalf = coinContainer.attachAsset('coinBlackHalf', {
+ anchorX: 0.5,
+ anchorY: 0
+ });
+ blackHalf.x = 0;
+ blackHalf.y = 0;
+ // Reference for animations (use the container)
+ var coinGraphics = coinContainer;
self.isFlipping = false;
self.result = null;
self.flip = function (callback) {
if (self.isFlipping) return;