User prompt
in LevelManager set currentLevel & currentRound to -1 initally
User prompt
in initNewRoundState write the new level and round numbers in debugtext
Code edit (1 edits merged)
Please save this source code
User prompt
set cameraHUD visible in initNewRoundState
Code edit (3 edits merged)
Please save this source code
User prompt
re-add the CameraHUD in the initNewRoundState
User prompt
re-add background to backgroundLayer in initNewRoundState
Code edit (6 edits merged)
Please save this source code
User prompt
photoFrameBackground stands in backgroundLayer fix that in initResultState
User prompt
recreate the photoFrameBackground in initResultState
User prompt
in initnewRound, set the currentBackground using the levelManager the use that
User prompt
Use the LevelManager to get the background asset
Code edit (2 edits merged)
Please save this source code
User prompt
Add a name property to the levels.
Code edit (1 edits merged)
Please save this source code
User prompt
créons un variable global nommé niveau, non, niveau actuel
User prompt
Please fix the bug: 'ReferenceError: levelManager is not defined' in or related to this line: 'background = LK.getAsset(levelManager.getBackground(), {' Line Number: 469
User prompt
create a technical class named LevelManager responsible of providing the name of the assets to use for the background and the targets for each level and each round
User prompt
replace 0xAEC6CF by 0x8FA9B9
User prompt
replace 0xAEC6CF by 0xB2C4CF
Code edit (1 edits merged)
Please save this source code
User prompt
Changez la couleur du texte prêt à l'écran à blanc.
Code edit (5 edits merged)
Please save this source code
User prompt
use score text options for result text
Code edit (1 edits merged)
Please save this source code
/**** * 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.5; line2.alpha = 0.5; 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); }); /***********************************************************************************/ /********************************** FRAME BACKGROUND CLASS *************************/ /***********************************************************************************/ var FrameBackground = Container.expand(function () { var self = Container.call(this); var frameBackground = self.attachAsset('background', { 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 () { var self = Container.call(this); var targets = levelManager.getTargets(); currentTargetAsset = targets[Math.floor(Math.random() * targets.length)]; var targetGraphics = self.attachAsset(currentTargetAsset, { anchorX: 0.5, anchorY: 0.5 }); self.speedX = 10; self.update = function () { if (!isPlaying) { return; } self.x += self.speedX; self.y = Math.max(yMin, Math.min(self.y, yMax)); if (self.x > 2048 + self.width) { 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 ****/ /***********************************************************************************/ /********************************** LEVEL MANAGER CLASS ****************************/ /***********************************************************************************/ /****************************************************************************************** */ /************************************** GLOBAL VARIABLES ********************************** */ /****************************************************************************************** */ // Enumeration for game states var LevelManager = function LevelManager() { this.levels = [{ background: 'background1', targets: ['bird1', 'bird2'] }, { background: 'background2', targets: ['bird3', 'bird1'] }, { background: 'background3', targets: ['bird2', 'bird3'] }]; this.currentLevel = 0; this.currentRound = 0; }; LevelManager.prototype.getBackground = function () { return this.levels[this.currentLevel].background; }; LevelManager.prototype.getTargets = function () { return this.levels[this.currentLevel].targets; }; LevelManager.prototype.nextRound = function () { this.currentRound++; if (this.currentRound >= this.levels[this.currentLevel].targets.length) { this.currentRound = 0; this.currentLevel++; if (this.currentLevel >= this.levels.length) { this.currentLevel = 0; // Loop back to the first level } } }; var GAME_STATE = { INIT: 'INIT', NEW_ROUND: 'NEW_ROUND', PLAYING: 'PLAYING', RESULT: 'RESULT', SCORE: 'SCORE' }; // Game state variables var levelManager; var gameState = GAME_STATE.INIT; var isPlaying = false; var score = 0; var hasShot = false; 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 shotButton; // Game layer variables var photoFrameShadow; var backgroundLayer; var foregroundLayer; // Result target variable var resultTarget; // UI variables var scoreTxt; var readyText; // Debug variables var isDebug = 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); case GAME_STATE.SCORE: gameScoreDown(x, y, obj); break; } }; function gameNewRoundDown(x, y, obj) { log("gameNewRoundDown..."); cleanNewRoundState(); initPlayingState(); } 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..."); cleanResultState(); } function gameScoreDown(x, y, obj) { log("gameScoreDown..."); cleanScoreState(); } /****************************************************************************************** */ /************************************* GAME STATES **************************************** */ /****************************************************************************************** */ function gameInitialize() { log("Game initialize..."); levelManager = new LevelManager(); background = LK.getAsset('background', { 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); 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); } initNewRoundState(); } /**************************************** NEW ROUND STATE *********************************/ function initNewRoundState() { log("initNewRoundState..."); background = LK.getAsset(levelManager.getBackground(), { anchorX: 0, anchorY: 0, x: 0, y: 0 }); background.visible = true; gameState = GAME_STATE.NEW_ROUND; // TODO : handle Level change and target change currentTarget = new MovingTarget(); currentTarget.x = -currentTarget.width; // Spawn out of the screen on the left currentTarget.y = 1366 - 256 + 512 * Math.random(); // Random vertical position backgroundLayer.addChild(currentTarget); readyText.visible = true; photoFrame.visible = false; photoFrameShadow.visible = false; shotButton.visible = true; scoreTxt.visible = false; LK.getSound('forestSound').play(); LK.setTimeout(function () { cleanNewRoundState(); initPlayingState(); }, 3000); } 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; } 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.visible = true; 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 }); 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); scoreTxt.setText('Quality: ' + score + '%'); } function handleResultLoop() { // Update result elements } function cleanResultState() { log("cleanResultState..."); frameMask.visible = false; levelManager.nextRound(); 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; } function handleScoreLoop() { // Update score elements } function cleanScoreState() { log("cleanScoreState..."); LK.showGameOver(); } /***********************************************************************************/ /******************************** MAIN GAME LOOP ***********************************/ /***********************************************************************************/ game.update = function () { currentTarget.update(); 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
===================================================================
--- original.js
+++ change.js
@@ -292,8 +292,9 @@
RESULT: 'RESULT',
SCORE: 'SCORE'
};
// Game state variables
+var levelManager;
var gameState = GAME_STATE.INIT;
var isPlaying = false;
var score = 0;
var hasShot = false;
@@ -382,9 +383,9 @@
/************************************* GAME STATES **************************************** */
/****************************************************************************************** */
function gameInitialize() {
log("Game initialize...");
- var levelManager = new LevelManager();
+ levelManager = new LevelManager();
background = LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
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