User prompt
make the background colorful
User prompt
Lets Restart The project. Change The Game To A Game Like Makes 10,100,500,1000,5000 coin flips and shows the percent results
User prompt
The Words On The Background Are Bugged
User prompt
Change Heads To Yazı And Tails To Tura
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'feedbackTxt.style.fill = "#00FF00";' Line Number: 272
Code edit (1 edits merged)
Please save this source code
User prompt
Coin Flip Frenzy
Initial prompt
Make me a game for flipping coins
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Coin class: handles flipping animation and result display var Coin = Container.expand(function () { var self = Container.call(this); // Coin base var coinBase = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); // Heads overlay var headsOverlay = self.attachAsset('heads', { anchorX: 0.5, anchorY: 0.5 }); // Heads text var headsText = new Text2('Y', { size: 100, fill: 0x000000 }); headsText.anchor.set(0.5, 0.5); headsOverlay.addChild(headsText); // Tails overlay var tailsOverlay = self.attachAsset('tails', { anchorX: 0.5, anchorY: 0.5 }); // Tails text var tailsText = new Text2('T', { size: 100, fill: 0x000000 }); tailsText.anchor.set(0.5, 0.5); tailsOverlay.addChild(tailsText); // Start with heads showing headsOverlay.visible = true; tailsOverlay.visible = false; // Add overlays to coin self.addChild(headsOverlay); self.addChild(tailsOverlay); // State self.currentFace = 'heads'; // 'heads' or 'tails' self.flipping = false; // Show result self.showFace = function (face) { self.currentFace = face; headsOverlay.visible = face === 'heads'; tailsOverlay.visible = face === 'tails'; }; // Flip animation: returns after animation, calls cb(face) self.flip = function (cb, flipDuration) { if (self.flipping) return; self.flipping = true; // Randomly pick heads or tails var result = Math.random() < 0.5 ? 'heads' : 'tails'; // Animate: scaleX 1 -> 0 (hide), swap face, 0 -> 1 (show) tween(self, { scaleX: 0 }, { duration: flipDuration / 2, easing: tween.cubicIn, onFinish: function onFinish() { self.showFace(result); tween(self, { scaleX: 1 }, { duration: flipDuration / 2, easing: tween.cubicOut, onFinish: function onFinish() { self.flipping = false; if (cb) cb(result); } }); } }); }; // Reset to heads, scaleX 1 self.reset = function () { self.scaleX = 1; self.showFace('heads'); self.flipping = false; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a1a }); /**** * Game Code ****/ // Center positions var centerX = 2048 / 2; var centerY = 2732 / 2; // Draw background "YAZI" and "TURA" words var bgWords = []; for (var i = 0; i < 6; i++) { var word = i % 2 === 0 ? "YAZI" : "TURA"; var txt = new Text2(word, { size: 220, fill: i % 2 === 0 ? 0xffffff : 0xcccccc, alpha: 0.08 }); txt.anchor.set(0.5, 0.5); // Staggered positions, diagonally txt.x = 400 + i * 300; txt.y = 600 + i * 350; txt.rotation = i % 2 === 0 ? -0.18 : 0.18; game.addChild(txt); bgWords.push(txt); } // --- Coin Flip Simulator UI --- // Number of flips options var flipOptions = [10, 100, 500, 1000, 5000]; var flipButtons = []; var resultsText = null; var coin = null; // Title var titleTxt = new Text2('Coin Flip Simulator', { size: 100, fill: 0xFFD700 }); titleTxt.anchor.set(0.5, 0); titleTxt.x = centerX; titleTxt.y = 120; LK.gui.top.addChild(titleTxt); // Prompt var promptTxt = new Text2('Kaç kez yazı-tura atılsın?', { size: 70, fill: 0xFFFFFF }); promptTxt.anchor.set(0.5, 0.5); promptTxt.x = centerX; promptTxt.y = centerY - 200; game.addChild(promptTxt); // Create flip buttons var btnY = centerY + 100; var btnSpacing = 260; for (var i = 0; i < flipOptions.length; i++) { var btn = LK.getAsset('coin', { anchorX: 0.5, anchorY: 0.5, x: centerX + (i - 2) * btnSpacing, y: btnY }); game.addChild(btn); var btnLabel = new Text2(flipOptions[i] + '', { size: 60, fill: 0x000000 }); btnLabel.anchor.set(0.5, 0.5); btn.addChild(btnLabel); flipButtons.push(btn); // Button event (function (n) { btn.down = function (x, y, obj) { startSimulation(n); }; })(flipOptions[i]); } // Results text resultsText = new Text2('', { size: 80, fill: 0xffffff }); resultsText.anchor.set(0.5, 0.5); resultsText.x = centerX; resultsText.y = centerY + 400; game.addChild(resultsText); // Coin display (for fun, shows last result) coin = new Coin(); coin.x = centerX; coin.y = centerY - 40; game.addChild(coin); // Simulate coin flips and show results function startSimulation(numFlips) { // Disable buttons during simulation for (var i = 0; i < flipButtons.length; i++) { flipButtons[i].interactive = false; flipButtons[i].alpha = 0.5; } promptTxt.setText(numFlips + ' kez atılıyor...'); resultsText.setText(''); coin.reset(); // Simulate flips var heads = 0; var tails = 0; var flipsDone = 0; // Animate a few flips visually, then do the rest instantly var visualFlips = Math.min(10, numFlips); function doVisualFlip() { if (flipsDone >= visualFlips) { // Do the rest instantly for (var j = flipsDone; j < numFlips; j++) { if (Math.random() < 0.5) heads++;else tails++; } showResults(); return; } coin.flip(function (face) { if (face === 'heads') heads++;else tails++; flipsDone++; if (flipsDone < visualFlips) { LK.setTimeout(doVisualFlip, 120); } else { // Do the rest instantly for (var j = flipsDone; j < numFlips; j++) { if (Math.random() < 0.5) heads++;else tails++; } showResults(); } }, 180); } doVisualFlip(); function showResults() { var percentHeads = Math.round(heads / numFlips * 1000) / 10; var percentTails = Math.round(tails / numFlips * 1000) / 10; resultsText.setText('YAZI: ' + heads + ' (' + percentHeads + '%)\n' + 'TURA: ' + tails + ' (' + percentTails + '%)'); promptTxt.setText('Tekrar denemek için bir sayı seçin!'); // Enable buttons for (var i = 0; i < flipButtons.length; i++) { flipButtons[i].interactive = true; flipButtons[i].alpha = 1; } } } // No drag or move needed game.down = function (x, y, obj) { // No-op, handled by buttons }; game.update = function () { // No per-frame logic needed };
===================================================================
--- original.js
+++ change.js
@@ -118,186 +118,126 @@
txt.rotation = i % 2 === 0 ? -0.18 : 0.18;
game.addChild(txt);
bgWords.push(txt);
}
-// Game state
-var waitingForPrediction = true;
-var prediction = null; // 'heads' or 'tails'
-var canPredict = true;
-var streak = 0;
-var flipSpeed = 600; // ms, decreases as streak increases, min 250ms
-var flipTimeout = null;
-// Coin instance
-var coin = new Coin();
-coin.x = centerX;
-coin.y = centerY - 100;
-game.addChild(coin);
-// Score text
-var scoreTxt = new Text2('0', {
- size: 120,
- fill: 0xFFFFFF
-});
-scoreTxt.anchor.set(0.5, 0);
-LK.gui.top.addChild(scoreTxt);
-// Streak text
-var streakTxt = new Text2('', {
- size: 60,
+// --- Coin Flip Simulator UI ---
+// Number of flips options
+var flipOptions = [10, 100, 500, 1000, 5000];
+var flipButtons = [];
+var resultsText = null;
+var coin = null;
+// Title
+var titleTxt = new Text2('Coin Flip Simulator', {
+ size: 100,
fill: 0xFFD700
});
-streakTxt.anchor.set(0.5, 0);
-LK.gui.top.addChild(streakTxt);
-streakTxt.y = 130;
-// Prompt text
-var promptTxt = new Text2('YAZI mı TURA mı? Tahmin et!', {
+titleTxt.anchor.set(0.5, 0);
+titleTxt.x = centerX;
+titleTxt.y = 120;
+LK.gui.top.addChild(titleTxt);
+// Prompt
+var promptTxt = new Text2('Kaç kez yazı-tura atılsın?', {
size: 70,
fill: 0xFFFFFF
});
promptTxt.anchor.set(0.5, 0.5);
-promptTxt.y = centerY + 350;
promptTxt.x = centerX;
+promptTxt.y = centerY - 200;
game.addChild(promptTxt);
-// Heads button
-var headsBtn = LK.getAsset('heads', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: centerX - 250,
- y: centerY + 350
+// Create flip buttons
+var btnY = centerY + 100;
+var btnSpacing = 260;
+for (var i = 0; i < flipOptions.length; i++) {
+ var btn = LK.getAsset('coin', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: centerX + (i - 2) * btnSpacing,
+ y: btnY
+ });
+ game.addChild(btn);
+ var btnLabel = new Text2(flipOptions[i] + '', {
+ size: 60,
+ fill: 0x000000
+ });
+ btnLabel.anchor.set(0.5, 0.5);
+ btn.addChild(btnLabel);
+ flipButtons.push(btn);
+ // Button event
+ (function (n) {
+ btn.down = function (x, y, obj) {
+ startSimulation(n);
+ };
+ })(flipOptions[i]);
+}
+// Results text
+resultsText = new Text2('', {
+ size: 80,
+ fill: 0xffffff
});
-game.addChild(headsBtn);
-var headsBtnText = new Text2('YAZI', {
- size: 60,
- fill: 0x000000
-});
-headsBtnText.anchor.set(0.5, 0.5);
-headsBtn.addChild(headsBtnText);
-// Tails button
-var tailsBtn = LK.getAsset('tails', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: centerX + 250,
- y: centerY + 350
-});
-game.addChild(tailsBtn);
-var tailsBtnText = new Text2('TURA', {
- size: 60,
- fill: 0x000000
-});
-tailsBtnText.anchor.set(0.5, 0.5);
-tailsBtn.addChild(tailsBtnText);
-// Feedback text
-var feedbackTxt = new Text2('', {
- size: 100,
- fill: 0x00FF00
-});
-feedbackTxt.anchor.set(0.5, 0.5);
-feedbackTxt.x = centerX;
-feedbackTxt.y = centerY - 350;
-game.addChild(feedbackTxt);
-// Helper: update score and streak
-function updateScoreDisplay() {
- scoreTxt.setText(LK.getScore());
- if (streak > 1) {
- streakTxt.setText('Streak: ' + streak);
- } else {
- streakTxt.setText('');
+resultsText.anchor.set(0.5, 0.5);
+resultsText.x = centerX;
+resultsText.y = centerY + 400;
+game.addChild(resultsText);
+// Coin display (for fun, shows last result)
+coin = new Coin();
+coin.x = centerX;
+coin.y = centerY - 40;
+game.addChild(coin);
+// Simulate coin flips and show results
+function startSimulation(numFlips) {
+ // Disable buttons during simulation
+ for (var i = 0; i < flipButtons.length; i++) {
+ flipButtons[i].interactive = false;
+ flipButtons[i].alpha = 0.5;
}
-}
-// Helper: reset game state
-function resetGameState() {
- waitingForPrediction = true;
- prediction = null;
- canPredict = true;
- streak = 0;
- flipSpeed = 600;
- LK.setScore(0);
- updateScoreDisplay();
- feedbackTxt.setText('');
- promptTxt.setText('YAZI mı TURA mı? Tahmin et!');
+ promptTxt.setText(numFlips + ' kez atılıyor...');
+ resultsText.setText('');
coin.reset();
-}
-// Button event handlers
-headsBtn.down = function (x, y, obj) {
- if (!canPredict || coin.flipping) return;
- makePrediction('heads');
-};
-tailsBtn.down = function (x, y, obj) {
- if (!canPredict || coin.flipping) return;
- makePrediction('tails');
-};
-// Main prediction logic
-function makePrediction(face) {
- if (!waitingForPrediction) return;
- waitingForPrediction = false;
- canPredict = false;
- prediction = face;
- promptTxt.setText('Flipping...');
- feedbackTxt.setText('');
- // Animate selected button
- var btn = face === 'heads' ? headsBtn : tailsBtn;
- tween(btn, {
- scaleX: 1.15,
- scaleY: 1.15
- }, {
- duration: 120,
- easing: tween.cubicOut,
- onFinish: function onFinish() {
- tween(btn, {
- scaleX: 1,
- scaleY: 1
- }, {
- duration: 120
- });
+ // Simulate flips
+ var heads = 0;
+ var tails = 0;
+ var flipsDone = 0;
+ // Animate a few flips visually, then do the rest instantly
+ var visualFlips = Math.min(10, numFlips);
+ function doVisualFlip() {
+ if (flipsDone >= visualFlips) {
+ // Do the rest instantly
+ for (var j = flipsDone; j < numFlips; j++) {
+ if (Math.random() < 0.5) heads++;else tails++;
+ }
+ showResults();
+ return;
}
- });
- // Start coin flip
- coin.flip(function (result) {
- // Show result feedback
- if (result === prediction) {
- // Correct!
- LK.getSound('correct').play();
- streak += 1;
- var bonus = streak > 1 ? streak : 1;
- LK.setScore(LK.getScore() + bonus);
- updateScoreDisplay();
- feedbackTxt.setText('✔');
- feedbackTxt.setStyle({
- fill: 0x00FF00
- });
- promptTxt.setText('Doğru! Tekrar tahmin et.');
- // Increase speed, min 250ms
- flipSpeed = Math.max(250, 600 - streak * 30);
- // Next round after short delay
- flipTimeout = LK.setTimeout(function () {
- waitingForPrediction = true;
- canPredict = true;
- promptTxt.setText('YAZI mı TURA mı? Tahmin et!');
- feedbackTxt.setText('');
- }, 700);
- } else {
- // Wrong!
- LK.getSound('wrong').play();
- feedbackTxt.setText('✖');
- feedbackTxt.setStyle({
- fill: 0xFF2222
- });
- promptTxt.setText('Wrong! Game Over');
- // Flash screen red
- LK.effects.flashScreen(0xff0000, 800);
- // Show game over after short delay
- LK.setTimeout(function () {
- LK.showGameOver();
- }, 900);
+ coin.flip(function (face) {
+ if (face === 'heads') heads++;else tails++;
+ flipsDone++;
+ if (flipsDone < visualFlips) {
+ LK.setTimeout(doVisualFlip, 120);
+ } else {
+ // Do the rest instantly
+ for (var j = flipsDone; j < numFlips; j++) {
+ if (Math.random() < 0.5) heads++;else tails++;
+ }
+ showResults();
+ }
+ }, 180);
+ }
+ doVisualFlip();
+ function showResults() {
+ var percentHeads = Math.round(heads / numFlips * 1000) / 10;
+ var percentTails = Math.round(tails / numFlips * 1000) / 10;
+ resultsText.setText('YAZI: ' + heads + ' (' + percentHeads + '%)\n' + 'TURA: ' + tails + ' (' + percentTails + '%)');
+ promptTxt.setText('Tekrar denemek için bir sayı seçin!');
+ // Enable buttons
+ for (var i = 0; i < flipButtons.length; i++) {
+ flipButtons[i].interactive = true;
+ flipButtons[i].alpha = 1;
}
- }, flipSpeed);
+ }
}
-// Reset game state on game start
-resetGameState();
-// On game over, LK will reset the game and re-run this code
-// Prevent accidental double taps
+// No drag or move needed
game.down = function (x, y, obj) {
// No-op, handled by buttons
};
-// No drag or move needed
-// Main update loop (not used for logic here)
game.update = function () {
// No per-frame logic needed
};
\ No newline at end of file