/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var MainButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('mainButton', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2('PRESS ME', { size: 60, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); var pressedEffect = self.attachAsset('buttonPressed', { anchorX: 0.5, anchorY: 0.5, alpha: 0 }); var lossEffect = self.attachAsset('buttonLoss', { anchorX: 0.5, anchorY: 0.5, alpha: 0 }); self.showSuccess = function () { pressedEffect.alpha = 1; tween(pressedEffect, { alpha: 0 }, { duration: 200 }); tween(buttonGraphics, { scaleX: 1.1, scaleY: 1.1 }, { duration: 100, onFinish: function onFinish() { tween(buttonGraphics, { scaleX: 1, scaleY: 1 }, { duration: 100 }); } }); }; self.showFailure = function () { lossEffect.alpha = 1; tween(lossEffect, { alpha: 0 }, { duration: 500 }); tween(buttonGraphics, { scaleX: 0.9, scaleY: 0.9 }, { duration: 150, onFinish: function onFinish() { tween(buttonGraphics, { scaleX: 1, scaleY: 1 }, { duration: 150 }); } }); }; self.down = function (x, y, obj) { if (gameState === 'playing') { pressButton(); } }; return self; }); var RestartButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('restartButton', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2('RESTART', { size: 40, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.down = function (x, y, obj) { restartGame(); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a1a }); /**** * Game Code ****/ var gameState = 'playing'; var consecutiveSuccess = 0; // Create main button var mainButton = game.addChild(new MainButton()); mainButton.x = 2048 / 2; mainButton.y = 2732 / 2; // Create restart button var restartButton = game.addChild(new RestartButton()); restartButton.x = 2048 / 2; restartButton.y = 2732 / 2 + 400; // Create score display var scoreText = new Text2('Streak: 0', { size: 80, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); scoreText.y = 150; // Create instruction text var instructionText = new Text2('1 in 10 chance of losing!', { size: 50, fill: 0x888888 }); instructionText.anchor.set(0.5, 1); LK.gui.bottom.addChild(instructionText); instructionText.y = -150; // Create game over text (initially hidden) var gameOverText = new Text2('', { size: 100, fill: 0xFF4444 }); gameOverText.anchor.set(0.5, 0.5); gameOverText.alpha = 0; game.addChild(gameOverText); gameOverText.x = 2048 / 2; gameOverText.y = 2732 / 2 - 200; function pressButton() { if (gameState !== 'playing') return; // Generate random number 1-10 var randomRoll = Math.floor(Math.random() * 10) + 1; if (randomRoll === 1) { // Player loses (10% chance) gameState = 'gameover'; mainButton.showFailure(); LK.getSound('failure').play(); gameOverText.setText('UNLUCKY!\nStreak: ' + consecutiveSuccess); gameOverText.alpha = 1; LK.effects.flashScreen(0xFF0000, 800); // Update high score LK.setScore(Math.max(LK.getScore(), consecutiveSuccess)); } else { // Player succeeds (90% chance) consecutiveSuccess++; mainButton.showSuccess(); LK.getSound('success').play(); scoreText.setText('Streak: ' + consecutiveSuccess); // Visual feedback for building tension if (consecutiveSuccess % 5 === 0) { LK.effects.flashScreen(0xFFFF00, 300); } } } function restartGame() { gameState = 'playing'; consecutiveSuccess = 0; scoreText.setText('Streak: 0'); gameOverText.alpha = 0; // Reset button visual state tween.stop(mainButton); mainButton.scaleX = 1; mainButton.scaleY = 1; } // Initialize score display scoreText.setText('Streak: 0');
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,183 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var MainButton = Container.expand(function () {
+ var self = Container.call(this);
+ var buttonGraphics = self.attachAsset('mainButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var buttonText = new Text2('PRESS ME', {
+ size: 60,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ self.addChild(buttonText);
+ var pressedEffect = self.attachAsset('buttonPressed', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0
+ });
+ var lossEffect = self.attachAsset('buttonLoss', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0
+ });
+ self.showSuccess = function () {
+ pressedEffect.alpha = 1;
+ tween(pressedEffect, {
+ alpha: 0
+ }, {
+ duration: 200
+ });
+ tween(buttonGraphics, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 100,
+ onFinish: function onFinish() {
+ tween(buttonGraphics, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 100
+ });
+ }
+ });
+ };
+ self.showFailure = function () {
+ lossEffect.alpha = 1;
+ tween(lossEffect, {
+ alpha: 0
+ }, {
+ duration: 500
+ });
+ tween(buttonGraphics, {
+ scaleX: 0.9,
+ scaleY: 0.9
+ }, {
+ duration: 150,
+ onFinish: function onFinish() {
+ tween(buttonGraphics, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 150
+ });
+ }
+ });
+ };
+ self.down = function (x, y, obj) {
+ if (gameState === 'playing') {
+ pressButton();
+ }
+ };
+ return self;
+});
+var RestartButton = Container.expand(function () {
+ var self = Container.call(this);
+ var buttonGraphics = self.attachAsset('restartButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var buttonText = new Text2('RESTART', {
+ size: 40,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ self.addChild(buttonText);
+ self.down = function (x, y, obj) {
+ restartGame();
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x1a1a1a
+});
+
+/****
+* Game Code
+****/
+var gameState = 'playing';
+var consecutiveSuccess = 0;
+// Create main button
+var mainButton = game.addChild(new MainButton());
+mainButton.x = 2048 / 2;
+mainButton.y = 2732 / 2;
+// Create restart button
+var restartButton = game.addChild(new RestartButton());
+restartButton.x = 2048 / 2;
+restartButton.y = 2732 / 2 + 400;
+// Create score display
+var scoreText = new Text2('Streak: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+scoreText.y = 150;
+// Create instruction text
+var instructionText = new Text2('1 in 10 chance of losing!', {
+ size: 50,
+ fill: 0x888888
+});
+instructionText.anchor.set(0.5, 1);
+LK.gui.bottom.addChild(instructionText);
+instructionText.y = -150;
+// Create game over text (initially hidden)
+var gameOverText = new Text2('', {
+ size: 100,
+ fill: 0xFF4444
+});
+gameOverText.anchor.set(0.5, 0.5);
+gameOverText.alpha = 0;
+game.addChild(gameOverText);
+gameOverText.x = 2048 / 2;
+gameOverText.y = 2732 / 2 - 200;
+function pressButton() {
+ if (gameState !== 'playing') return;
+ // Generate random number 1-10
+ var randomRoll = Math.floor(Math.random() * 10) + 1;
+ if (randomRoll === 1) {
+ // Player loses (10% chance)
+ gameState = 'gameover';
+ mainButton.showFailure();
+ LK.getSound('failure').play();
+ gameOverText.setText('UNLUCKY!\nStreak: ' + consecutiveSuccess);
+ gameOverText.alpha = 1;
+ LK.effects.flashScreen(0xFF0000, 800);
+ // Update high score
+ LK.setScore(Math.max(LK.getScore(), consecutiveSuccess));
+ } else {
+ // Player succeeds (90% chance)
+ consecutiveSuccess++;
+ mainButton.showSuccess();
+ LK.getSound('success').play();
+ scoreText.setText('Streak: ' + consecutiveSuccess);
+ // Visual feedback for building tension
+ if (consecutiveSuccess % 5 === 0) {
+ LK.effects.flashScreen(0xFFFF00, 300);
+ }
+ }
+}
+function restartGame() {
+ gameState = 'playing';
+ consecutiveSuccess = 0;
+ scoreText.setText('Streak: 0');
+ gameOverText.alpha = 0;
+ // Reset button visual state
+ tween.stop(mainButton);
+ mainButton.scaleX = 1;
+ mainButton.scaleY = 1;
+}
+// Initialize score display
+scoreText.setText('Streak: 0');
\ No newline at end of file