User prompt
prevenu multiple clicks in menu
Code edit (5 edits merged)
Please save this source code
User prompt
in cleanMenuState animate alpha to 0 for menuBackground, menuPopup and startText
User prompt
in cleanMenuState fade out menuBackground, menuPopup and startText by animating alpha to 0
User prompt
in cleanMenuState fade out menuBackground, menuPopup and startText progressivelly
Code edit (1 edits merged)
Please save this source code
User prompt
in cleanMenuState remove startText, menuPopup and menuBackground
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
in initMenuState add text "Start"
User prompt
in initMenuState add the finalResultPopup asset
User prompt
in initMenuState add the menuBackground asset
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'update')' in or related to this line: 'currentTarget.update();' Line Number: 947
User prompt
we gonna add and new GAME_STATE MENU, List what should be changed
User prompt
ininitNewRoundState, play the sound corresponding to the currentLevel
Code edit (1 edits merged)
Please save this source code
User prompt
in LevelManager.levels, add a sound property
User prompt
in initNewRoundState, set readyText text to "Let's have fun..." when isRandomMode and currentLevel==0 and currentRound ==0 , else to 'Get Ready...'
User prompt
when isRendomMode, make getTarget returns a random target from any other level except the currentLevel
Code edit (3 edits merged)
Please save this source code
User prompt
in gameResultDown, when reaching last round of last level, if isRandomMode is false then set isRandomMode to true and initNewRoundState(); else initScoreState();
User prompt
add a global variable isRandomMode
Code edit (1 edits merged)
Please save this source code
User prompt
in ConfettiAnim, make the movement from top to bottom
/**** * Classes ****/ /***********************************************************************************/ /********************************** CAMERA HUD CLASS ************************************/ /***********************************************************************************/ var CameraHUD = Container.expand(function () { var self = Container.call(this); function createCorner(x, y, rotation) { var corner = new Container(); var line1 = LK.getAsset('line', { width: 100, height: 20, anchorX: 0, anchorY: 0 }); var line2 = LK.getAsset('line', { width: 100, height: 20, anchorX: 0, anchorY: 0 }); line2.rotation = Math.PI / 2; line1.alpha = 0.75; line2.alpha = 0.75; corner.addChild(line1); corner.addChild(line2); corner.x = x; corner.y = y; corner.rotation = rotation; return corner; } var topLeft = createCorner(256, 700, 0); var topRight = createCorner(2048 - 256, 700, Math.PI / 2); var bottomLeft = createCorner(256, 2732 - 700, -Math.PI / 2); var bottomRight = createCorner(2048 - 256, 2732 - 700, Math.PI); self.addChild(topLeft); self.addChild(topRight); self.addChild(bottomLeft); self.addChild(bottomRight); }); /***********************************************************************************/ /********************************** CONFETTI ANIM CLASS ****************************/ /***********************************************************************************/ var ConfettiAnim = Container.expand(function () { var self = Container.call(this); var confettiColors = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF]; var confettiPieces = []; for (var i = 0; i < 100; i++) { var confettiPiece = self.attachAsset('line', { width: 5, height: 25, tint: confettiColors[Math.floor(Math.random() * confettiColors.length)], anchorX: 0.5, anchorY: 0.5 }); confettiPiece.x = Math.random() * 2048; confettiPiece.y = -1 * Math.random() * 2732; confettiPiece.rotation = Math.random() * Math.PI * 2; confettiPiece.speedX = 0; confettiPiece.speedY = 10 + Math.random() * 5; confettiPieces.push(confettiPiece); } self.update = function () { for (var i = 0; i < confettiPieces.length; i++) { var piece = confettiPieces[i]; piece.x += piece.speedX; piece.y += piece.speedY; piece.rotation += 0.1; if (piece.y > 2732) { piece.x = Math.random() * 2048; piece.y = -20; } } }; }); /***********************************************************************************/ /********************************** FRAME BACKGROUND CLASS *************************/ /***********************************************************************************/ var FrameBackground = Container.expand(function () { var self = Container.call(this); var frameBackground = self.attachAsset(currentBackground, { anchorX: 0.5, anchorY: 0.5, width: xMax - xMin, height: yMax - yMin, x: (xMax + xMin) / 2, y: (yMax + yMin) / 2 }); }); /***********************************************************************************/ /********************************** FRAME MASK CLASS *************************/ /***********************************************************************************/ var FrameMask = Container.expand(function () { var self = Container.call(this); var top = self.attachAsset('line', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: yMin / 2, width: 2048, height: yMin, tint: isDebug ? 0xFF0000 : 0x8FA9B9 // Red tint in debug mode }); var left = self.attachAsset('line', { anchorX: 0.5, anchorY: 0.5, x: xMin / 2, y: 2732 / 2, width: xMin, height: 2732, tint: isDebug ? 0x00FF00 : 0x8FA9B9 // Green tint in debug mode }); var bottom = self.attachAsset('line', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: (2732 + yMax) / 2, width: 2048, height: 2732 - yMax, tint: isDebug ? 0x0000FF : 0x8FA9B9 // Blue tint in debug mode }); var right = self.attachAsset('line', { anchorX: 0.5, anchorY: 0.5, x: (2048 + xMax) / 2, y: 2732 / 2, width: 2048 - xMax, height: 2732, tint: isDebug ? 0xFFFF00 : 0x8FA9B9 // Yellow tint in debug mode }); self.addChild(top); self.addChild(left); self.addChild(bottom); self.addChild(right); }); /***********************************************************************************/ /********************************** MOVING TARGET CLASS ************************************/ /***********************************************************************************/ var MovingTarget = Container.expand(function (asset, revert) { var self = Container.call(this); var targetGraphics = self.attachAsset(asset, { anchorX: 0.5, anchorY: 0.5, scaleX: revert ? -1 : 1 }); self.speedX = 20 + levelManager.currentLevel * 5; self.update = function () { if (!isPlaying) { return; } var dx = self.endX - self.x; var dy = self.endY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); self.x += dx / distance * self.speedX; self.y += dy / distance * self.speedX; if (isDebug && LK.ticks % 60 === 0) { // Log position every second (assuming 60 FPS) log("MovingTarget position:", { x: self.x, y: self.y }); } // Check if the target is out of the screen bounds with an offset var offset = 128; // Example offset value if (self.x < -self.width - offset || self.x > 2048 + self.width + offset || self.y < -self.height - offset || self.y > 2732 + self.height + offset || distance < offset) { self.destroy(); cleanPlayingState(); initResultState(); } }; }); /***********************************************************************************/ /********************************** PHOTOFRAME CLASS ************************************/ /***********************************************************************************/ var PhotoFrame = Container.expand(function () { var self = Container.call(this); var frameBorderTop = self.attachAsset('line', { anchorX: 0.5, anchorY: 0.5 }); frameBorderTop.width = xMax - xMin + 16; frameBorderTop.height = 20; frameBorderTop.alpha = 1.0; frameBorderTop.x = (xMax + xMin) / 2; frameBorderTop.y = yMin; var frameBorderRight = self.attachAsset('line', { anchorX: 0.5, anchorY: 0.5, tint: 0xFFFFFF // Grey color }); frameBorderRight.width = 20; frameBorderRight.height = yMax - yMin; frameBorderRight.alpha = 1.0; frameBorderRight.x = xMax; frameBorderRight.y = (yMax + yMin) / 2; var frameBorderBottom = self.attachAsset('line', { anchorX: 0.5, anchorY: 0.5, tint: 0xFFFFFF // Grey color }); frameBorderBottom.width = xMax - xMin + 20; frameBorderBottom.height = 20; frameBorderBottom.alpha = 1.0; frameBorderBottom.x = (xMax + xMin) / 2; frameBorderBottom.y = yMax; var frameBorderLeft = self.attachAsset('line', { anchorX: 0.5, anchorY: 0.5 }); frameBorderLeft.width = 20; frameBorderLeft.height = yMax - yMin; frameBorderLeft.alpha = 1.0; frameBorderLeft.x = xMin; frameBorderLeft.y = (yMax + yMin) / 2; }); /***********************************************************************************/ /********************************** PHOTOFRAMESHADOW CLASS *************************/ /***********************************************************************************/ var PhotoFrameShadow = Container.expand(function () { var self = Container.call(this); for (var i = 0; i < 10; i++) { var shadowRight = self.attachAsset('line', { anchorX: 0, anchorY: 0, tint: 0x000000 // Red color for debugging }); shadowRight.width = 20 + i * 2; // Increase width by i*2 shadowRight.height = yMax - yMin; shadowRight.alpha = 0.1; shadowRight.x = xMax + 10; // Set the same x for all shadowRight shadowRight.y = yMin + 10; self.addChild(shadowRight); } for (var i = 0; i < 10; i++) { var shadowBottom = self.attachAsset('line', { anchorX: 0, anchorY: 0, tint: 0x000000 // Red color for debugging }); shadowBottom.width = xMax - xMin; shadowBottom.height = 20 + i * 2; // Increase height by i*2 shadowBottom.alpha = 0.1; shadowBottom.x = xMin + 10; shadowBottom.y = yMax + 10; // Set the same y for all shadowBottom self.addChild(shadowBottom); } // Add shadowCorner asset for (var i = 0; i < 10; i++) { var shadowCorner = self.attachAsset('line', { anchorX: 0, anchorY: 0, tint: 0x000000, x: xMax + 10, y: yMax + 10, width: 20 + i * 2, height: 20 + i * 2, alpha: 0.1 }); self.addChild(shadowCorner); } }); /***********************************************************************************/ /********************************** SHOTBUTTON CLASS ************************************/ /***********************************************************************************/ var ShotButton = Container.expand(function () { var self = Container.call(this); var circle1 = self.attachAsset('shotButton', { anchorX: 0.5, anchorY: 0.5 }); var circle2 = self.attachAsset('shotButton', { anchorX: 0.5, anchorY: 0.5, tint: 0x000000, scaleX: 0.9, scaleY: 0.9 }); var circle3 = self.attachAsset('shotButton', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.85, scaleY: 0.85 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x8FA9B9 //Init game with new color }); /**** * Game Code ****/ /***********************************************************************************/ /********************************** TARGET MANAGER CLASS ***************************/ /***********************************************************************************/ var TargetManager = function TargetManager() { this.targets = { 'bird1': { assetName: 'bird1', startCorners: [1, 3, 4, 5, 7, 8] }, 'bird2': { assetName: 'bird2', startCorners: [5, 7] }, 'bird3': { assetName: 'bird3', startCorners: [1, 3, 4, 5, 7, 8] }, 'bird4': { assetName: 'bird3', startCorners: [1, 3, 4, 5, 7, 8] }, 'bird5': { assetName: 'bird3', startCorners: [1, 3, 4, 5, 7, 8] }, 'fish1': { assetName: 'fish1', startCorners: [1, 3, 4, 5, 7, 8] }, 'fish2': { assetName: 'fish2', startCorners: [1, 3, 4, 5, 7, 8] }, 'fish3': { assetName: 'fish3', startCorners: [1, 3, 4, 5, 7, 8] }, 'fish4': { assetName: 'fish4', startCorners: [1, 3, 4, 5, 7, 8] }, 'fish5': { assetName: 'fish5', startCorners: [1, 3, 4, 5, 7, 8] }, 'insect1': { assetName: 'insect1', startCorners: [7, 5] }, 'insect2': { assetName: 'insect2', startCorners: [1, 3, 4, 5, 7, 8] }, 'insect3': { assetName: 'insect3', startCorners: [1, 3, 4, 5, 7, 8] }, 'insect4': { assetName: 'insect4', startCorners: [1, 3, 4, 5, 7, 8] }, 'insect5': { assetName: 'insect5', startCorners: [1, 3, 4, 5, 7, 8] }, 'spaceObject1': { assetName: 'spaceObject1', startCorners: [1, 2, 3, 4, 5, 6, 7, 8] }, 'spaceObject2': { assetName: 'spaceObject2', startCorners: [1, 2, 3, 4, 5, 6, 7, 8] }, 'spaceObject3': { assetName: 'spaceObject3', startCorners: [1, 2, 3, 4, 5, 6, 7, 8] }, 'spaceObject4': { assetName: 'spaceObject4', startCorners: [1, 3, 4, 5, 7, 8] }, 'spaceObject5': { assetName: 'spaceObject5', startCorners: [1, 3] }, 'townObject1': { assetName: 'townObject1', startCorners: [1, 2, 3, 4, 5, 6, 7, 8] }, 'townObject2': { assetName: 'townObject2', startCorners: [1, 2, 3, 4, 5, 6, 7, 8] }, 'townObject3': { assetName: 'townObject3', startCorners: [1, 3, 4, 8] }, 'townObject4': { assetName: 'townObject4', startCorners: [4, 8] }, 'townObject5': { assetName: 'townObject4', startCorners: [1, 2, 3, 4, 5, 6, 7, 8] } }; }; TargetManager.prototype.getTarget = function (key) { return this.targets[key]; }; TargetManager.prototype.getAllKeys = function () { return Object.keys(this.targets); }; targetManager = new TargetManager(); /***********************************************************************************/ /********************************** POSITION MANAGER CLASS *************************/ /***********************************************************************************/ var PositionManager = function PositionManager() { this.previousStartCornerIndex = null; this.nbMaxCorners = 8; // Constant }; PositionManager.prototype.getNextStartCorner = function (asset, revert) { var availableCorners = targetManager.getTarget(asset).startCorners; var possibleCorners = revert ? [2, 3, 4, 5, 6] : [1, 2, 6, 7, 8]; var validCorners = availableCorners.filter(function (corner) { return possibleCorners.includes(corner); }); var nextCorner = validCorners[Math.floor(Math.random() * validCorners.length)]; this.previousStartCornerIndex = nextCorner; return nextCorner; }; PositionManager.prototype.getEndCorner = function (startCornerIndex) { var possibleEndCorners = [1 + (startCornerIndex + 3) % 8]; var endCorner = possibleEndCorners[Math.floor(Math.random() * possibleEndCorners.length)]; log("Start corner index:", startCornerIndex); log("Possible end corners:", possibleEndCorners); log("Selected end corner:", endCorner); return endCorner; }; PositionManager.prototype.getCornerPosition = function (cornerIndex) { var randomOffset = Math.random() * 100 * 0; // Example random offset var targetSize = 1024; // Size of the target switch (cornerIndex) { case 1: return { x: xMin - targetSize - randomOffset, y: yMin - targetSize - randomOffset }; case 2: return { x: xMin + (xMax - xMin) / 2, y: -targetSize - randomOffset }; case 3: return { x: xMax + targetSize + randomOffset, y: yMin - targetSize - randomOffset }; case 4: return { x: xMax + targetSize + randomOffset, y: yMin + (yMax - yMin) / 2 }; case 5: return { x: xMax + targetSize + randomOffset, y: yMax + targetSize + randomOffset }; case 6: return { x: xMin + (xMax - xMin) / 2, y: 2732 + targetSize + randomOffset }; case 7: return { x: xMin - targetSize - randomOffset, y: yMax + targetSize + randomOffset }; case 8: return { x: xMin - targetSize - randomOffset, y: yMin + (yMax - yMin) / 2 }; default: return { x: 0, y: 0 }; } }; /***********************************************************************************/ /********************************** LEVEL MANAGER CLASS ****************************/ /***********************************************************************************/ var LevelManager = function LevelManager() { this.levels = [{ name: 'Forest', background: 'forest', targets: ['bird1', 'bird2', 'bird3', 'bird4', 'bird5'], sound: 'forestSound' }, { name: 'Underwater', background: 'underwater', targets: ['fish1', 'fish2', 'fish3', 'fish4', 'fish5'], sound: 'underwaterSound' }, { name: 'Countryside', background: 'countryside', targets: ['insect1', 'insect2', 'insect3', 'insect4', 'insect5'], sound: 'countrysideSound' }, { name: 'Town', background: 'town', targets: ['townObject1', 'townObject2', 'townObject3', 'townObject4', 'townObject5'], sound: 'townSound' }, { name: 'Space', background: 'space', targets: ['spaceObject1', 'spaceObject2', 'spaceObject3', 'spaceObject4', 'spaceObject5'], sound: 'spaceSound' }]; this.currentLevel = 0; this.currentRound = -1; }; LevelManager.prototype.getBackground = function () { return this.levels[levelManager.currentLevel].background; }; LevelManager.prototype.getTarget = function () { if (isRandomMode) { var otherLevels = this.levels.filter(function (_, index) { return index !== levelManager.currentLevel; }); var randomLevel = otherLevels[Math.floor(Math.random() * otherLevels.length)]; return randomLevel.targets[Math.floor(Math.random() * randomLevel.targets.length)]; } else { return this.levels[levelManager.currentLevel].targets[levelManager.currentRound]; } }; LevelManager.prototype.nextRound = function () { log("LevelManager nextRound() : was " + this.currentRound); this.currentRound++; log("now => " + this.currentRound); if (levelManager.currentLevel >= 0 && levelManager.currentLevel < this.levels.length && this.currentRound >= this.levels[levelManager.currentLevel].targets.length) { this.currentRound = 0; levelManager.currentLevel++; if (levelManager.currentLevel >= this.levels.length) { levelManager.currentLevel = 0; // Loop back to the first level } } }; /****************************************************************************************** */ /************************************** GLOBAL VARIABLES ********************************** */ /****************************************************************************************** */ var GAME_STATE = { INIT: 'INIT', NEW_ROUND: 'NEW_ROUND', PLAYING: 'PLAYING', RESULT: 'RESULT', SCORE: 'SCORE', MENU: 'MENU' }; // Game state variables var totalScore = 0; var totalRound = 0; var levelManager; var currentBackground = 'countryside'; var nbRoundsPerLevel = 5; var gameState = GAME_STATE.INIT; var isPlaying = false; var score = 0; var hasShot = false; var canClickInResultState = true; var canClickInMenuState = true; var targetShotX = 0; var targetShotY = 0; // Photo limits variables var xMin = 256; var xMax = 2048 - 256; var yMin = 700; var yMax = 2732 - 700; // Game elements variables var frameMask; var photoFrame; var photoFrameBackground; var background; var cameraHUD; var currentTarget; var currentTargetAsset; var currentTargetRevert = false; var shotButton; var confettiAnim; // Game layer variables var photoFrameShadow; var backgroundLayer; var foregroundLayer; // Result target variable var resultTarget; // UI variables var startText; var menuBackground; var menuPopup; var scoreTxt; var readyText; var finalScoreTxt; // Debug variables var isDebug = false; var isRandomMode = false; var debugMarker; var debugText; /****************************************************************************************** */ /*********************************** UTILITY FUNCTIONS ************************************ */ /****************************************************************************************** */ function log() { if (isDebug) { var _console; (_console = console).log.apply(_console, arguments); } } /****************************************************************************************** */ /************************************** INPUT HANDLERS ************************************ */ /****************************************************************************************** */ game.down = function (x, y, obj) { switch (gameState) { case GAME_STATE.NEW_ROUND: gameNewRoundDown(x, y, obj); break; case GAME_STATE.PLAYING: gamePlayingDown(x, y, obj); break; case GAME_STATE.RESULT: gameResultDown(x, y, obj); break; case GAME_STATE.SCORE: gameScoreDown(x, y, obj); break; case GAME_STATE.MENU: gameMenuDown(x, y, obj); break; } }; function gameMenuDown(x, y, obj) { log("gameMenuDown..."); if (canClickInMenuState) { canClickInMenuState = false; initNewRoundState(true); } } function gameNewRoundDown(x, y, obj) { log("gameNewRoundDown..."); } function gamePlayingDown(x, y, obj) { if (hasShot) { return; } hasShot = true; log("gamePlayingDown..."); LK.getSound('cameraShot').play(); targetShotX = currentTarget.x; targetShotY = currentTarget.y; // Add a black flash effect LK.effects.flashScreen(0x000000, 1000); // Flash duration of 1000ms } function gameResultDown(x, y, obj) { log("gameResultDown...from state " + gameState + " != " + GAME_STATE.NEW_ROUND, " canClickInResultState=", canClickInResultState); if (gameState != GAME_STATE.NEW_ROUND && canClickInResultState) { canClickInResultState = false; cleanResultState(); if (levelManager.currentLevel === levelManager.levels.length - 1 && levelManager.currentRound === levelManager.levels[levelManager.currentLevel].targets.length - 1) { if (!isRandomMode) { isRandomMode = true; initNewRoundState(); } else { initScoreState(); } } else { initNewRoundState(); } } } function gameScoreDown(x, y, obj) { log("gameScoreDown..."); cleanScoreState(); } /****************************************************************************************** */ /************************************* GAME STATES **************************************** */ /****************************************************************************************** */ function gameInitialize() { log("Game initialize..."); levelManager = new LevelManager(); targetManager = new TargetManager(); positionManager = new PositionManager(); levelManager.currentLevel = 0; // Ensure levelManager.currentLevel is set to a valid index levelManager.nextRound(); background = LK.getAsset(levelManager.getBackground(), { anchorX: 0, anchorY: 0, x: 0, y: 0 }); backgroundLayer = new Container(); foregroundLayer = new Container(); cameraHUD = new CameraHUD(); photoFrameBackground = new FrameBackground(); photoFrameBackground.visible = false; photoFrame = new PhotoFrame(); photoFrameShadow = new PhotoFrameShadow(); photoFrameShadow.visible = false; frameMask = new FrameMask(); frameMask.visible = false; photoFrameBackground.visible = false; game.addChild(backgroundLayer); game.addChild(foregroundLayer); //backgroundLayer.addChild(background); backgroundLayer.addChild(photoFrameBackground); backgroundLayer.addChild(cameraHUD); foregroundLayer.addChild(frameMask); foregroundLayer.addChild(photoFrame); foregroundLayer.addChild(frameMask); foregroundLayer.addChild(photoFrameShadow); // UI Elements score = 0; scoreTxt = new Text2('Quality: ' + score, { size: 100, fill: "#ffffff", weight: 1000, dropShadow: true }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); finalScoreTxt = new Text2('Final Score: ' + score, { size: 100, fill: "#ffffff", weight: 1000, dropShadow: true, align: "center", visible: false }); finalScoreTxt.anchor.set(0.5, 1); // Center the text both horizontally and vertically finalScoreTxt.visible = false; // Explicitly set visibility to false LK.gui.center.addChild(finalScoreTxt); readyText = new Text2('Get Ready...', { size: 100, fill: "#ffffff", weight: 1000, dropShadow: true, visible: false }); readyText.anchor.set(0.5, 0); // Center the text horizontally and set anchor to top LK.gui.top.addChild(readyText); shotButton = new ShotButton(); shotButton.x = 1024; shotButton.y = 2500; game.addChild(shotButton); if (isDebug) { debugMarker = LK.getAsset('debugMarker', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 - 50 }); game.addChild(debugMarker); debugText = new Text2('Debug Info', { size: 50, fill: "#ffffff" }); debugText.anchor.set(0.5, 1); // Anchor to the bottom-right LK.gui.bottom.addChild(debugText); } initMenuState(); } /**************************************** MENU STATE *********************************/ function initMenuState() { log("initMenuState..."); canClickInMenuState = true; gameState = GAME_STATE.MENU; readyText.visible = false; photoFrame.visible = false; photoFrameShadow.visible = false; shotButton.visible = false; scoreTxt.visible = false; cameraHUD.visible = false; menuBackground = LK.getAsset('menuBackground', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); backgroundLayer.addChild(menuBackground); menuPopup = LK.getAsset('finalResultPopup', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 1200 }); backgroundLayer.addChild(menuPopup); startText = new Text2('Start', { size: 240, fill: "#ffffff", weight: 1000, dropShadow: true, align: "center" }); startText.anchor.set(0.5, 0.5); startText.x = 2048 / 2; startText.y = 1200; backgroundLayer.addChild(startText); } function cleanMenuState() { log("cleanMenuState..."); canClickInMenuState = true; // Remove New round elements readyText.visible = false; if (startText) { backgroundLayer.removeChild(startText); startText = null; } if (menuPopup) { backgroundLayer.removeChild(menuPopup); menuPopup = null; } if (menuBackground) { backgroundLayer.removeChild(menuBackground); menuBackground = null; } } /**************************************** NEW ROUND STATE *********************************/ function initNewRoundState(keepRound) { log("initNewRoundState...before:", 'Level: ' + levelManager.currentLevel + ' Round: ' + levelManager.currentRound); gameState = GAME_STATE.NEW_ROUND; if (!keepRound) { levelManager.nextRound(); } log("initNewRoundState...after:", 'Level: ' + levelManager.currentLevel + ' Round: ' + levelManager.currentRound); totalRound++; currentTargetRevert = Math.random() >= 0.5; targetShotX = 0; targetShotY = 0; score = 0; // Reset score at the start of each new round scoreTxt.setText('Quality: ' + score + '%'); if (isDebug) { debugText.setText('Level: ' + levelManager.currentLevel + ' Round: ' + levelManager.currentRound); } currentBackground = levelManager.getBackground(); background = LK.getAsset(currentBackground, { anchorX: 0, anchorY: 0, x: 0, y: 0 }); backgroundLayer.addChild(background); backgroundLayer.addChild(cameraHUD); cameraHUD.visible = true; // TODO : handle Level change and target change currentTargetAsset = levelManager.getTarget(); var startCornerIndex = positionManager.getNextStartCorner(currentTargetAsset, currentTargetRevert); var endCornerIndex = positionManager.getEndCorner(startCornerIndex); var startPosition = positionManager.getCornerPosition(startCornerIndex); var endPosition = positionManager.getCornerPosition(endCornerIndex); log("Selected start position:", startPosition); log("Selected end position:", endPosition); currentTargetRevert = endPosition.x < startPosition.x; currentTarget = new MovingTarget(currentTargetAsset, currentTargetRevert); currentTarget.x = startPosition.x; currentTarget.y = startPosition.y; currentTarget.endX = endPosition.x; currentTarget.endY = endPosition.y; backgroundLayer.addChild(currentTarget); if (isRandomMode && levelManager.currentLevel === 0 && levelManager.currentRound === 0) { readyText.setText("Let's have fun..."); } else { readyText.setText('Get Ready...'); } readyText.visible = true; photoFrame.visible = false; photoFrameShadow.visible = false; shotButton.visible = true; scoreTxt.visible = false; LK.getSound(levelManager.levels[levelManager.currentLevel].sound).play(); LK.setTimeout(function () { cleanNewRoundState(); initPlayingState(); }, 1000 + 1000 + Math.random()); } function handleNewRoundLoop() { // Update New round elements } function cleanNewRoundState() { log("cleanNewRoundState..."); // Remove New round elements readyText.visible = false; } /**************************************** PLAYING STATE *********************************/ function initPlayingState() { log("initPlayingState..."); gameState = GAME_STATE.PLAYING; isPlaying = true; hasShot = false; canClickInResultState = false; } function handlePlayingLoop() { // Update game elements } function cleanPlayingState() { log("cleanPlayingState..."); isPlaying = false; // Remove game elements background.visible = false; cameraHUD.visible = false; } /**************************************** RESULT STATE *********************************/ function initResultState() { log("initResultState..."); shotButton.visible = false; scoreTxt.visible = true; frameMask.visible = true; foregroundLayer.addChildAt(frameMask, 0); gameState = GAME_STATE.RESULT; photoFrame.visible = true; photoFrameBackground = new FrameBackground(); photoFrameBackground.visible = true; backgroundLayer.addChild(photoFrameBackground); photoFrameShadow.visible = true; background.tint = 0x000000; // Set background to black // Show the target again at the shot position if within limits if (targetShotX >= xMin - currentTarget.width / 2 && targetShotX <= xMax + currentTarget.width / 2 && targetShotY >= yMin - currentTarget.height / 2 && targetShotY <= yMax + currentTarget.height / 2) { resultTarget = new Container(); var resultTargetGraphics = resultTarget.attachAsset(currentTargetAsset, { anchorX: 0.5, anchorY: 0.5, scaleX: currentTargetRevert ? -1 : 1 }); resultTarget.x = targetShotX; resultTarget.y = targetShotY; backgroundLayer.addChild(resultTarget); } // Calculate the center of the photo frame var centerX = (xMin + xMax) / 2; var centerY = (yMin + yMax) / 2; // Calculate the distance between the target shot and the center var distance = Math.sqrt(Math.pow(targetShotX - centerX, 2) + Math.pow(targetShotY - centerY, 2)); // Calculate the maximum possible distance (from center to any corner) var maxDistance = Math.sqrt(Math.pow((xMax - xMin) / 2, 2) + Math.pow((yMax - yMin) / 2, 2)); // Calculate the score (0 to 100) var shotScore = Math.max(0, 100 - distance / maxDistance * 100); // Update the score score = Math.round(shotScore); totalScore += score; scoreTxt.setText(score === 0 ? 'Missed!' : 'Quality: ' + score + '%'); LK.setTimeout(function () { log("Now canClickInResultState..."); canClickInResultState = true; }, 1000); log("initResultState End"); } function handleResultLoop() { // Update result elements } function cleanResultState() { log("cleanResultState..."); frameMask.visible = false; scoreTxt.visible = false; photoFrameBackground.visible = false; photoFrame.visible = false; photoFrameShadow.visible = false; foregroundLayer.removeChild(frameMask); if (resultTarget) { backgroundLayer.removeChild(resultTarget); resultTarget = null; } // Remove result elements //initNewRoundState(); } /**************************************** SCORE STATE *********************************/ function initScoreState() { log("initScoreState..."); gameState = GAME_STATE.SCORE; game.setBackgroundColor(0x8FA9B9); // Remove the background asset if (background) { backgroundLayer.removeChild(background); background = null; } // Add finalResultBackground as the background var finalResultBackground = LK.getAsset('finalResultBackground', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); backgroundLayer.addChild(finalResultBackground); var finalResultPopup = LK.getAsset('finalResultPopup', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 1200 }); backgroundLayer.addChild(finalResultPopup); averageQuality = Math.floor(totalScore / totalRound); LK.setScore(averageQuality); finalScoreTxt.visible = true; game.addChild(confettiAnim); currentQuality = 0; var qualityInterval = LK.setInterval(function () { if (currentQuality >= averageQuality) { LK.clearInterval(qualityInterval); if (averageQuality < 20) { LK.getSound('applauseBad').play(); } else if (averageQuality < 80) { LK.getSound('applauseNormal').play(); } else { LK.getSound('applause').play(); // Add confetti animation when averageQuality >= 80 var confettiAnim = new ConfettiAnim(); game.addChild(confettiAnim); } } else { currentQuality++; finalScoreTxt.setText('Average Quality\n' + currentQuality + '%'); } }, 50); // Adjust the interval time as needed } function handleScoreLoop() { // Update score elements if (currentQuality < averageQuality) { currentQuality++; finalScoreTxt.setText('Average Quality\n' + currentQuality + '%'); } } function cleanScoreState() { log("cleanScoreState..."); LK.showGameOver(); } /***********************************************************************************/ /******************************** MAIN GAME LOOP ***********************************/ /***********************************************************************************/ game.update = function () { switch (gameState) { case GAME_STATE.NEW_ROUND: handleNewRoundLoop(); break; case GAME_STATE.PLAYING: handlePlayingLoop(); break; case GAME_STATE.SCORE: handleScoreLoop(); break; } }; gameInitialize(); // Initialize the game var finalResultBackground; var finalResultPopup; var currentQuality; var averageQuality;
===================================================================
--- original.js
+++ change.js
@@ -20,10 +20,10 @@
anchorX: 0,
anchorY: 0
});
line2.rotation = Math.PI / 2;
- line1.alpha = 0.5;
- line2.alpha = 0.5;
+ line1.alpha = 0.75;
+ line2.alpha = 0.75;
corner.addChild(line1);
corner.addChild(line2);
corner.x = x;
corner.y = y;
@@ -310,30 +310,74 @@
'bird3': {
assetName: 'bird3',
startCorners: [1, 3, 4, 5, 7, 8]
},
+ 'bird4': {
+ assetName: 'bird3',
+ startCorners: [1, 3, 4, 5, 7, 8]
+ },
+ 'bird5': {
+ assetName: 'bird3',
+ startCorners: [1, 3, 4, 5, 7, 8]
+ },
'fish1': {
assetName: 'fish1',
startCorners: [1, 3, 4, 5, 7, 8]
},
'fish2': {
assetName: 'fish2',
startCorners: [1, 3, 4, 5, 7, 8]
},
+ 'fish3': {
+ assetName: 'fish3',
+ startCorners: [1, 3, 4, 5, 7, 8]
+ },
+ 'fish4': {
+ assetName: 'fish4',
+ startCorners: [1, 3, 4, 5, 7, 8]
+ },
+ 'fish5': {
+ assetName: 'fish5',
+ startCorners: [1, 3, 4, 5, 7, 8]
+ },
'insect1': {
assetName: 'insect1',
startCorners: [7, 5]
},
'insect2': {
assetName: 'insect2',
startCorners: [1, 3, 4, 5, 7, 8]
},
+ 'insect3': {
+ assetName: 'insect3',
+ startCorners: [1, 3, 4, 5, 7, 8]
+ },
+ 'insect4': {
+ assetName: 'insect4',
+ startCorners: [1, 3, 4, 5, 7, 8]
+ },
+ 'insect5': {
+ assetName: 'insect5',
+ startCorners: [1, 3, 4, 5, 7, 8]
+ },
'spaceObject1': {
assetName: 'spaceObject1',
startCorners: [1, 2, 3, 4, 5, 6, 7, 8]
},
'spaceObject2': {
assetName: 'spaceObject2',
+ startCorners: [1, 2, 3, 4, 5, 6, 7, 8]
+ },
+ 'spaceObject3': {
+ assetName: 'spaceObject3',
+ startCorners: [1, 2, 3, 4, 5, 6, 7, 8]
+ },
+ 'spaceObject4': {
+ assetName: 'spaceObject4',
+ startCorners: [1, 3, 4, 5, 7, 8]
+ },
+ 'spaceObject5': {
+ assetName: 'spaceObject5',
startCorners: [1, 3]
},
'townObject1': {
assetName: 'townObject1',
@@ -341,8 +385,20 @@
},
'townObject2': {
assetName: 'townObject2',
startCorners: [1, 2, 3, 4, 5, 6, 7, 8]
+ },
+ 'townObject3': {
+ assetName: 'townObject3',
+ startCorners: [1, 3, 4, 8]
+ },
+ 'townObject4': {
+ assetName: 'townObject4',
+ startCorners: [4, 8]
+ },
+ 'townObject5': {
+ assetName: 'townObject4',
+ startCorners: [1, 2, 3, 4, 5, 6, 7, 8]
}
};
};
TargetManager.prototype.getTarget = function (key) {
@@ -388,9 +444,9 @@
};
case 2:
return {
x: xMin + (xMax - xMin) / 2,
- y: yMin - targetSize - randomOffset
+ y: -targetSize - randomOffset
};
case 3:
return {
x: xMax + targetSize + randomOffset,
@@ -408,9 +464,9 @@
};
case 6:
return {
x: xMin + (xMax - xMin) / 2,
- y: yMax + targetSize + randomOffset
+ y: 2732 + targetSize + randomOffset
};
case 7:
return {
x: xMin - targetSize - randomOffset,
@@ -434,29 +490,29 @@
var LevelManager = function LevelManager() {
this.levels = [{
name: 'Forest',
background: 'forest',
- targets: ['bird1', 'bird2'],
+ targets: ['bird1', 'bird2', 'bird3', 'bird4', 'bird5'],
sound: 'forestSound'
}, {
name: 'Underwater',
background: 'underwater',
- targets: ['fish1', 'fish2'],
+ targets: ['fish1', 'fish2', 'fish3', 'fish4', 'fish5'],
sound: 'underwaterSound'
}, {
name: 'Countryside',
background: 'countryside',
- targets: ['insect1', 'insect2'],
+ targets: ['insect1', 'insect2', 'insect3', 'insect4', 'insect5'],
sound: 'countrysideSound'
}, {
name: 'Town',
background: 'town',
- targets: ['townObject1', 'townObject2'],
+ targets: ['townObject1', 'townObject2', 'townObject3', 'townObject4', 'townObject5'],
sound: 'townSound'
}, {
name: 'Space',
background: 'space',
- targets: ['spaceObject1', 'spaceObject2'],
+ targets: ['spaceObject1', 'spaceObject2', 'spaceObject3', 'spaceObject4', 'spaceObject5'],
sound: 'spaceSound'
}];
this.currentLevel = 0;
this.currentRound = -1;
@@ -508,8 +564,9 @@
var isPlaying = false;
var score = 0;
var hasShot = false;
var canClickInResultState = true;
+var canClickInMenuState = true;
var targetShotX = 0;
var targetShotY = 0;
// Photo limits variables
var xMin = 256;
@@ -577,9 +634,12 @@
}
};
function gameMenuDown(x, y, obj) {
log("gameMenuDown...");
- initNewRoundState();
+ if (canClickInMenuState) {
+ canClickInMenuState = false;
+ initNewRoundState(true);
+ }
}
function gameNewRoundDown(x, y, obj) {
log("gameNewRoundDown...");
}
@@ -705,8 +765,9 @@
}
/**************************************** MENU STATE *********************************/
function initMenuState() {
log("initMenuState...");
+ canClickInMenuState = true;
gameState = GAME_STATE.MENU;
readyText.visible = false;
photoFrame.visible = false;
photoFrameShadow.visible = false;
@@ -740,8 +801,9 @@
backgroundLayer.addChild(startText);
}
function cleanMenuState() {
log("cleanMenuState...");
+ canClickInMenuState = true;
// Remove New round elements
readyText.visible = false;
if (startText) {
backgroundLayer.removeChild(startText);
a forest.
flying Red-bellied Woodpecker.
flying Yellow-headed Blackbird.
flying Painted Bunting.
Underwater. only water and corals. NO animals
Countryside. 1 flower in foreground.
A Butterfly flying.
a fish swimming.
full dragonfly flying to the right.
full drone flying to the right.
a full hot air balloon with a basket flying to the right.
roofs of an empty modern city. day light
a satellite.
stary dark space. NO OBJECTS
a multitude of polaroids in bulk, with photos of birds, fishes, butterflies, planes, hot air baloons, satelites, dragonflies.....
A flying owl.
A flying parrot.
hippocampe.
shark. lateral view
diodon hystrix swimming. lateral view
fighting fish swimming. lateral view
a hang glider flying. full lateral view
un cerf-volant multicolore.
une coccinelle volante.
un scarabée vert irisé volant. side view
une gueppe volante. side view
un astronaute volant. full side view
une navette spaciale volante. full side view
un astéroïde volant dans l'espace. full side view
remove