User prompt
you must add yellow background traffic light
Code edit (8 edits merged)
Please save this source code
User prompt
you sould be traffic light ellipse and color must be red to green. And bcakround is yellow ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
traffic light should be real formula one race ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
traffic light is ligting orderly. for example first light first second. Second light 2. second ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Let the lights shine in sequence. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
When the game starts, the Formula 1 traffic lights should turn from green to red. There should be 2 lights vertically and 5 lights horizontally. They should light up in sequence and the race should start. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Remove all settings related to traffic lights.
Code edit (1 edits merged)
Please save this source code
User prompt
traffic light return red to grey. And seperate each other a little
User prompt
Let the traffic lights turn from red to gray. And let them match the light locations in the background asset. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
After a while, the trackbarrier starts to appear from top to bottom. When in the menu, the game should remain stationary and only the menu should be visible.
User prompt
track barrier layer is low than menu background please
User prompt
trackbarrier still see in menu fix that
User prompt
You make menu page come the first game. And menu must have background.
User prompt
Snow and rain will be a lot ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Snow mode is not see in menu , please check it ,
User prompt
You add snowmode in menu and if it is will be active, snow in game ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
You add rain mode in menu and if it is will be active, rain in game ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Let there be a rainy mode option in the menu. When it is activated, it should rain in the game.
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.bestPosition = undefined;' Line Number: 449 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'storage.get is not a function' in or related to this line: 'var bestPosition = storage.get('bestPosition') || 'Not Set';' Line Number: 430 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Design the menu as if it were a separate page.
Code edit (1 edits merged)
Please save this source code
User prompt
users max speed 250 km/h ↪💡 Consider importing and using the following plugins: @upit/tween.v1
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var BotCar = Container.expand(function (carIndex) { var self = Container.call(this); // Use different car assets based on car index var carAssetName = 'botCar' + (carIndex % 8 + 1); var carGraphics = self.attachAsset(carAssetName, { anchorX: 0.5, anchorY: 0.5 }); // Create more varied bot speeds based on car index for distinct racing styles (200-235 km/h = 20-23.5 speed units) var speedVariations = [22, // Fast aggressive bot 20.5, // Medium-fast bot 23.5, // Very fast bot (235 km/h max) 20, // Slower cautious bot 22.5, // Medium bot 23.5, // Fastest bot (235 km/h max) 21, // Medium-slow bot 23 // Fast bot ]; self.baseSpeed = speedVariations[carIndex % 8]; // Assign specific speed based on car index self.currentSpeed = 0; // Start stationary until race begins self.lanePosition = Math.floor(Math.random() * 3); // 0=left, 1=center, 2=right self.targetX = 400 + self.lanePosition * 600; // Lane positions self.aiTimer = 0; self.carNumber = carIndex + 1; self.isChangingLanes = false; // Track lane changing state self.collisionCooldown = 0; // Prevent frequent collisions // Bot cars now use their default asset colors without tinting self.lapCount = 1; self.raceDistance = 0; self.hasFinished = false; self.update = function () { // Only move if race has started if (!raceStarted) { return; } // AI behavior - change lanes occasionally self.aiTimer++; if (self.aiTimer > 120 && Math.random() < 0.03 && !self.isChangingLanes) { // Every 2 seconds, 3% chance, only if not already changing lanes self.aiTimer = 0; var newLane = Math.floor(Math.random() * 3); if (newLane !== self.lanePosition) { self.lanePosition = newLane; self.targetX = 400 + self.lanePosition * 600; self.isChangingLanes = true; // Smooth lane change with tween and rotation var direction = self.targetX > self.x ? 1 : -1; // Add slight rotation during lane change for stability (reduced rotation) tween(carGraphics, { rotation: direction * 0.05 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { // Return to straight after lane change (faster return) tween(carGraphics, { rotation: 0 }, { duration: 150, easing: tween.easeInOut }); } }); // Smooth X movement (faster lane change) tween(self, { x: self.targetX }, { duration: 400, easing: tween.easeInOut, onFinish: function onFinish() { self.isChangingLanes = false; } }); } } // Update collision cooldown if (self.collisionCooldown > 0) { self.collisionCooldown--; } // Check for collision with other bot cars before moving var canMove = true; var needsLaneChange = false; for (var b = 0; b < botCars.length; b++) { var otherBot = botCars[b]; if (otherBot !== self && otherBot.intersects) { var distanceX = Math.abs(otherBot.x - self.x); var distanceY = Math.abs(otherBot.y - self.y); // Prevent bot cars from passing each other - maintain strict order if (distanceY < 450 && otherBot.y < self.y) { // Another bot is ahead, significantly slow down to maintain position self.currentSpeed = Math.min(23.5, Math.max(otherBot.currentSpeed - 2, 3)); // Cap at 23.5 (235 km/h) canMove = false; } else if (distanceY < 300 && otherBot.y > self.y) { // Another bot is behind and getting too close, maintain speed to keep distance self.currentSpeed = Math.min(23.5, Math.max(self.currentSpeed, otherBot.currentSpeed + 1)); // Cap at 23.5 (235 km/h) } // Direct collision detection with cooldown if (otherBot.intersects(self) && self.collisionCooldown <= 0) { // Set collision cooldown to prevent frequent collisions self.collisionCooldown = 60; // 1 second cooldown otherBot.collisionCooldown = 60; // Reduce speed less drastically self.currentSpeed = Math.max(4, self.currentSpeed - 2); otherBot.currentSpeed = Math.max(4, otherBot.currentSpeed - 2); // Add collision visual effects using tween // Flash both cars red to show collision var selfGraphics = self.children[0]; // Get the car graphics var otherGraphics = otherBot.children[0]; // Get the other car graphics // Flash effect for self tween(selfGraphics, { tint: 0xff0000 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(selfGraphics, { tint: 0xffffff }, { duration: 300, easing: tween.easeIn }); } }); // Flash effect for other bot tween(otherGraphics, { tint: 0xff0000 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(otherGraphics, { tint: 0xffffff }, { duration: 300, easing: tween.easeIn }); } }); // Shake effect for collision impact var originalSelfX = self.x; var originalOtherX = otherBot.x; // Push cars apart more gently if (self.x < otherBot.x) { self.x -= 30; otherBot.x += 30; } else { self.x += 30; otherBot.x -= 30; } canMove = false; } // Improved collision avoidance - larger detection zone else if (distanceX < 250 && distanceY < 500) { // Bot is getting close, take evasive action if (otherBot.y < self.y && distanceY < 350) { // Bot ahead, slow down and consider lane change self.currentSpeed = Math.max(6, self.currentSpeed - 1); needsLaneChange = true; canMove = false; } else if (otherBot.y > self.y && distanceY < 300) { // Bot behind is catching up, speed up slightly self.currentSpeed = Math.min(23.5, Math.min(self.baseSpeed + 2, self.currentSpeed + 0.5)); // Cap at 23.5 (235 km/h) } } } } // Trigger lane change more aggressively when needed if (needsLaneChange && !self.isChangingLanes && Math.random() < 0.15) { // 15% chance to change lanes when avoiding collision var availableLanes = []; for (var lane = 0; lane < 3; lane++) { if (lane !== self.lanePosition) { availableLanes.push(lane); } } if (availableLanes.length > 0) { var newLane = availableLanes[Math.floor(Math.random() * availableLanes.length)]; self.lanePosition = newLane; self.targetX = 400 + self.lanePosition * 600; self.isChangingLanes = true; // Smooth lane change with tween and rotation var direction = self.targetX > self.x ? 1 : -1; // Add slight rotation during lane change for stability (reduced rotation) tween(carGraphics, { rotation: direction * 0.05 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { // Return to straight after lane change (faster return) tween(carGraphics, { rotation: 0 }, { duration: 150, easing: tween.easeInOut }); } }); // Smooth X movement (faster lane change) tween(self, { x: self.targetX }, { duration: 300, // Faster lane change for collision avoidance easing: tween.easeInOut, onFinish: function onFinish() { self.isChangingLanes = false; } }); } } // Move forward (relative to player) - faster movement if (canMove) { self.y += raceSpeed - self.currentSpeed; } else { self.y += raceSpeed - self.currentSpeed * 0.5; // Move slower when blocked } // Keep within screen bounds if (self.x < 100) { self.x = 100; } if (self.x > 1948) { self.x = 1948; } // Track bot lap progress if (!self.hasFinished) { self.raceDistance += self.currentSpeed; if (self.raceDistance >= lapDistance) { self.raceDistance = 0; self.lapCount++; // Finish after completing 20 laps if (self.lapCount > 20) { self.hasFinished = true; botsFinished++; } } } }; return self; }); var FinishLine = Container.expand(function () { var self = Container.call(this); // Create left pole var leftPole = self.attachAsset('finishPole', { anchorX: 0.5, anchorY: 1 }); leftPole.x = -800; leftPole.y = 0; // Create right pole var rightPole = self.attachAsset('finishPole', { anchorX: 0.5, anchorY: 1 }); rightPole.x = 800; rightPole.y = 0; // Create checkered pattern for (var i = 0; i < 16; i++) { for (var j = 0; j < 2; j++) { var isBlack = (i + j) % 2 === 0; var square = self.attachAsset(isBlack ? 'checkeredSquare1' : 'checkeredSquare2', { anchorX: 0.5, anchorY: 0.5 }); square.x = (i - 7.5) * 100; square.y = (j - 0.5) * 40; } } self.update = function () { self.y += raceSpeed; }; return self; }); var GameMenu = Container.expand(function () { var self = Container.call(this); // Menu background var menuBg = self.attachAsset('menuBackground', { anchorX: 0.5, anchorY: 0.5 }); menuBg.alpha = 0.95; // Menu panel var menuPanel = self.attachAsset('menuPanel', { anchorX: 0.5, anchorY: 0.5 }); menuPanel.y = -100; // Title var titleText = new Text2('RACING CHAMPIONSHIP', { size: 70, fill: 0xFFD700 }); titleText.anchor.set(0.5, 0.5); titleText.y = -600; self.addChild(titleText); // Instructions var instructionText = new Text2('Drag to steer your car\nComplete 20 laps to win!\nAvoid barriers and other cars', { size: 40, fill: 0xFFFFFF, align: 'center' }); instructionText.anchor.set(0.5, 0.5); instructionText.y = -400; self.addChild(instructionText); // Car selection display self.selectedCarIndex = 0; var carPreview = self.attachAsset('playerCar', { anchorX: 0.5, anchorY: 0.5 }); carPreview.y = -150; carPreview.scaleX = 0.8; carPreview.scaleY = 0.8; var carLabel = new Text2('Your Car', { size: 35, fill: 0x00FF00 }); carLabel.anchor.set(0.5, 0.5); carLabel.y = -50; self.addChild(carLabel); // Start button var startButton = new MenuButton('start', 'START RACE', function () { self.startRace(); }); startButton.y = 200; self.addChild(startButton); // Rain mode toggle self.rainMode = false; var rainToggleButton = new MenuButton('carSelect', self.rainMode ? 'Rain: ON' : 'Rain: OFF', function () { self.rainMode = !self.rainMode; rainToggleButton.children[1].setText(self.rainMode ? 'Rain: ON' : 'Rain: OFF'); rainToggleButton.children[1].tint = self.rainMode ? 0x00FF00 : 0xFFFFFF; }); rainToggleButton.y = 100; self.addChild(rainToggleButton); // Best time display (placeholder) var bestTimeText = new Text2('Best Position: Not Set', { size: 30, fill: 0xCCCCCC }); bestTimeText.anchor.set(0.5, 0.5); bestTimeText.y = 350; self.addChild(bestTimeText); self.startRace = function () { // Store rain mode setting globally isRainMode = self.rainMode; // Hide menu with animation tween(self, { alpha: 0, y: self.y - 200 }, { duration: 800, easing: tween.easeInOut, onFinish: function onFinish() { self.destroy(); // Start the race countdown LK.setTimeout(function () { raceStartSequence = true; }, 500); } }); }; return self; }); var MenuButton = Container.expand(function (buttonType, text, onClick) { var self = Container.call(this); var buttonAsset = buttonType === 'start' ? 'startButton' : 'carSelectButton'; var buttonGraphics = self.attachAsset(buttonAsset, { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2(text, { size: buttonType === 'start' ? 50 : 35, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.onClick = onClick; self.down = function (x, y, obj) { // Button press effect tween(buttonGraphics, { scaleX: 0.95, scaleY: 0.95 }, { duration: 100, easing: tween.easeOut }); if (self.onClick) { self.onClick(); } }; self.up = function (x, y, obj) { // Button release effect tween(buttonGraphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeOut }); }; return self; }); var PlayerCar = Container.expand(function () { var self = Container.call(this); var carGraphics = self.attachAsset('playerCar', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.maxSpeed = 250; self.acceleration = 0.2; self.currentSpeed = 0; self.update = function () { // Simulate acceleration/deceleration based on movement if (Math.abs(self.lastX - self.x) > 5) { self.currentSpeed = Math.min(self.maxSpeed, self.currentSpeed + self.acceleration); } else { self.currentSpeed = Math.max(0, self.currentSpeed - self.acceleration * 0.5); } // Player speed is now controlled by the 10-second tween acceleration system // Remove this section to avoid conflicts with the new tween-based system self.lastX = self.x; }; return self; }); var RainDrop = Container.expand(function () { var self = Container.call(this); // Create a small white line for rain drop var rainGraphics = LK.getAsset('roadLine', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.1, scaleY: 0.3 }); rainGraphics.tint = 0x87CEEB; // Sky blue color for rain rainGraphics.alpha = 0.7; self.addChild(rainGraphics); // Rain properties self.speed = Math.random() * 15 + 20; // Random speed between 20-35 self.windEffect = Math.random() * 2 - 1; // Random wind effect self.update = function () { self.y += self.speed; self.x += self.windEffect; // Add slight wind effect }; return self; }); var RoadLine = Container.expand(function () { var self = Container.call(this); var lineGraphics = self.attachAsset('roadLine', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.update = function () { self.y += raceSpeed; }; return self; }); var TrackEdge = Container.expand(function (barrierIndex) { var self = Container.call(this); // Use different barrier assets based on index (1-5) var barrierAssetName = 'trackBarrier' + (barrierIndex % 5 + 1); var edgeGraphics = self.attachAsset(barrierAssetName, { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y += raceSpeed; }; return self; }); var TrafficLight = Container.expand(function () { var self = Container.call(this); // Create larger frame background (5x bigger to fit 5 lights) var lightBackground = self.attachAsset('trafficLight', { anchorX: 0.5, anchorY: 0.5 }); lightBackground.scaleX = 5; lightBackground.scaleY = 3; // Create 5 lights in a horizontal row self.lights = []; for (var i = 0; i < 5; i++) { var light = self.attachAsset('lightRed', { anchorX: 0.5, anchorY: 0.5 }); light.scaleX = 2; light.scaleY = 2; light.x = (i - 2) * 200; // Space lights 200 pixels apart for better separation light.alpha = 1.0; light.tint = 0xff0000; // Start all red self.lights.push(light); } self.setAllRed = function () { for (var i = 0; i < self.lights.length; i++) { self.lights[i].tint = 0xff0000; // Red color // Add glow effect with tween tween(self.lights[i], { scaleX: 2.3, scaleY: 2.3 }, { duration: 200, easing: tween.easeOut }); } }; self.setLightGreen = function (lightIndex) { if (lightIndex >= 0 && lightIndex < self.lights.length) { var light = self.lights[lightIndex]; light.tint = 0x00ff00; // Green color light.alpha = 1.0; // Ensure full visibility // Force the light to render on top by moving to front self.removeChild(light); self.addChild(light); // Add glow effect with tween tween(light, { scaleX: 2.3, scaleY: 2.3 }, { duration: 200, easing: tween.easeOut }); } }; self.setOff = function () { for (var i = 0; i < self.lights.length; i++) { self.lights[i].alpha = 0.2; // Reset scale self.lights[i].scaleX = 2; self.lights[i].scaleY = 2; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2d2d2d }); /**** * Game Code ****/ // Function to update background color based on rain mode function updateBackgroundForRain() { if (isRainMode && raceStarted) { // Darker, more overcast background for rain game.setBackgroundColor(0x1a1a2e); } else { // Normal background game.setBackgroundColor(0x2d2d2d); } } // Game variables var player; var botCars = []; var roadLines = []; var finishLines = []; var trackEdges = []; var botSpawnTimer = 0; var lineSpawnTimer = 0; var checkpointTimer = 0; var raceSpeed = 8; var lapNumber = 1; var position = 9; // Starting position (9th out of 9) var raceDistance = 0; var lapDistance = 5000; // Distance for one lap var raceFinished = false; var finalPosition = 9; var botsFinished = 0; var raceStarted = false; var raceSpeedAccelerating = false; var trafficLights = []; var lightSequenceStep = 0; var lightSequenceTimer = 0; var raceStartSequence = false; var startText = null; var gameMenu = null; var menuActive = true; // Rain mode variables var isRainMode = false; var rainDrops = []; var rainSpawnTimer = 0; // Clean position tracking - start at 9th position // Show menu first gameMenu = new GameMenu(); gameMenu.x = 1024; gameMenu.y = 1366; game.addChild(gameMenu); // UI Elements (initially hidden) var positionTxt = new Text2('Position: 9/9', { size: 50, fill: 0xFFFFFF }); positionTxt.anchor.set(0, 0); positionTxt.alpha = 0; // Hide initially LK.gui.topLeft.addChild(positionTxt); positionTxt.x = 120; positionTxt.y = 20; var lapTxt = new Text2('Lap: 1/20', { size: 40, fill: 0xFFFF00 }); lapTxt.anchor.set(1, 0); lapTxt.alpha = 0; // Hide initially LK.gui.topRight.addChild(lapTxt); lapTxt.x = -20; lapTxt.y = 20; var speedTxt = new Text2('Speed: 0', { size: 35, fill: 0x00FF00 }); speedTxt.anchor.set(0, 0); speedTxt.alpha = 0; // Hide initially LK.gui.topLeft.addChild(speedTxt); speedTxt.x = 120; speedTxt.y = 80; // Initialize player player = new PlayerCar(); player.x = 1300; player.y = 2450; // Player starts at the back of the vertical line player.lastX = player.x; player.minSpeed = 8; // Minimum speed (80 km/h) player.maxSpeedTarget = 25.0; // Maximum speed target (250 km/h) player.isAccelerating = false; // Track acceleration state game.addChild(player); // Create starting grid with 8 bot cars in vertical single-file line var startingPositions = [ // Position 1 (pole position) { x: 700, y: 500 }, // Position 2 { x: 700, y: 1050 }, // Position 3 { x: 700, y: 1600 }, // Position 4 { x: 700, y: 2150 }, // Position 5 { x: 1300, y: 250 }, // Position 6 { x: 1300, y: 800 }, // Position 7 { x: 1300, y: 1350 }, // Position 8 { x: 1300, y: 1900 } // Last position ]; for (var i = 0; i < 8; i++) { var bot = new BotCar(i); bot.x = startingPositions[i].x; bot.y = startingPositions[i].y; bot.startingPosition = i + 1; bot.minSpeed = 20; // Minimum speed for bots bot.maxSpeedTarget = 23.5; // Maximum speed target for bots bot.isAccelerating = false; // Track acceleration state botCars.push(bot); game.addChild(bot); } // Create 5-light traffic light system var trafficLight = new TrafficLight(); trafficLight.x = 1024; // Center of screen trafficLight.y = 600; trafficLight.setAllRed(); trafficLights.push(trafficLight); game.addChild(trafficLight); // Create start text (initially hidden) startText = new Text2('START!', { size: 120, fill: 0x00ff00 }); startText.anchor.set(0.5, 0.5); startText.x = 1024; startText.y = 1000; startText.alpha = 0; game.addChild(startText); // Initialize race elements but don't start sequence yet (menu controls this) // Race elements are created but hidden until menu starts the race // Create track barriers - 5 continuous barriers on each side with no gaps var leftBarriers = []; var rightBarriers = []; for (var i = 0; i < 5; i++) { // Left side barriers var leftBarrier = new TrackEdge(i); leftBarrier.x = 150; leftBarrier.y = i * 546 - 200; // Position barriers adjacently based on barrier height (546px) leftBarrier.side = 'left'; leftBarriers.push(leftBarrier); trackEdges.push(leftBarrier); game.addChild(leftBarrier); // Right side barriers var rightBarrier = new TrackEdge(i); rightBarrier.x = 1898; rightBarrier.y = i * 546 - 200; // Position barriers adjacently based on barrier height (546px) rightBarrier.side = 'right'; rightBarriers.push(rightBarrier); trackEdges.push(rightBarrier); game.addChild(rightBarrier); } // Create initial road lines (add to background first) for (var i = 0; i < 15; i++) { var line1 = new RoadLine(); line1.x = 700; line1.y = i * 200 - 100; roadLines.push(line1); game.addChildAt(line1, 0); var line2 = new RoadLine(); line2.x = 1300; line2.y = i * 200 - 100; roadLines.push(line2); game.addChildAt(line2, 0); } // Input handling var dragTarget = null; game.down = function (x, y, obj) { if (!menuActive) { dragTarget = player; handleMove(x, y, obj); } }; game.up = function (x, y, obj) { dragTarget = null; }; function handleMove(x, y, obj) { if (dragTarget && !menuActive) { dragTarget.x = x; // Keep player within racing lanes if (dragTarget.x < 300) { dragTarget.x = 300; } if (dragTarget.x > 1748) { dragTarget.x = 1748; } // Only allow speed increases based on movement, no automatic decreases if (Math.abs(dragTarget.x - dragTarget.lastX) > 5) { raceSpeed = Math.min(25.0, raceSpeed + 0.2); // Cap at 25.0 (250 km/h) } } } game.move = handleMove; // Spawn bot car function function spawnBotCar() { var carIndex = Math.floor(Math.random() * 8); var bot = new BotCar(carIndex); bot.x = 400 + Math.floor(Math.random() * 3) * 600; // Random lane bot.y = -100; botCars.push(bot); game.addChild(bot); } // Spawn road lines function function spawnRoadLines() { var line1 = new RoadLine(); line1.x = 700; line1.y = -50; roadLines.push(line1); game.addChildAt(line1, 0); var line2 = new RoadLine(); line2.x = 1300; line2.y = -50; roadLines.push(line2); game.addChildAt(line2, 0); } // Main game update game.update = function () { // Only update race mechanics if race has started if (raceStarted) { // Update race distance raceDistance += raceSpeed; // Update speed display (scale to show realistic racing speeds) speedTxt.setText('Speed: ' + Math.floor(raceSpeed * 10) + ' km/h'); } else { // Show stationary speed during countdown speedTxt.setText('Speed: 0'); } // Only handle race mechanics if race has started if (raceStarted) { // Check for lap completion or finish line crossing if (raceDistance >= lapDistance && !raceFinished) { raceDistance = 0; lapNumber++; lapTxt.setText('Lap: ' + lapNumber + '/20'); LK.getSound('checkpoint').play(); } } // Check for race completion after lap 20 if (lapNumber >= 20 && !raceFinished) { raceFinished = true; // Calculate final position more accurately - use current position at finish finalPosition = position; // Use the current position when player finishes // Show single checkered flag at finish line var finishFlag = new FinishLine(); finishFlag.x = 1024; // Center of screen finishFlag.y = -200; // Start above screen finishLines.push(finishFlag); game.addChild(finishFlag); // Create prominent final ranking display var rankingBackground = LK.getAsset('menuPanel', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.8, scaleY: 0.6 }); rankingBackground.x = 1024; rankingBackground.y = 1366; rankingBackground.alpha = 0; game.addChild(rankingBackground); // Main ranking title var rankingTitle = new Text2('RACE COMPLETE!', { size: 80, fill: 0xFFD700 }); rankingTitle.anchor.set(0.5, 0.5); rankingTitle.x = 1024; rankingTitle.y = 1200; rankingTitle.alpha = 0; game.addChild(rankingTitle); // Final position display with color coding based on performance var positionColor = 0xFF0000; // Red by default if (finalPosition <= 3) { positionColor = 0x00FF00; // Green for top 3 } else if (finalPosition <= 6) { positionColor = 0xFFFF00; // Yellow for middle positions } // Create more prominent final position text var finalRankingText = new Text2('YOU FINISHED ' + finalPosition + '/9', { size: 75, fill: positionColor }); finalRankingText.anchor.set(0.5, 0.5); finalRankingText.x = 1024; finalRankingText.y = 1320; finalRankingText.alpha = 0; game.addChild(finalRankingText); // Add position suffix (1st, 2nd, 3rd, etc.) var positionSuffix = ''; if (finalPosition === 1) { positionSuffix = '1ST PLACE'; } else if (finalPosition === 2) { positionSuffix = '2ND PLACE'; } else if (finalPosition === 3) { positionSuffix = '3RD PLACE'; } else { positionSuffix = finalPosition + 'TH PLACE'; } var positionSuffixText = new Text2(positionSuffix, { size: 60, fill: positionColor }); positionSuffixText.anchor.set(0.5, 0.5); positionSuffixText.x = 1024; positionSuffixText.y = 1380; positionSuffixText.alpha = 0; game.addChild(positionSuffixText); // Performance message based on ranking var performanceMessage = ''; if (finalPosition === 1) { performanceMessage = 'CHAMPION!'; } else if (finalPosition <= 3) { performanceMessage = 'PODIUM FINISH!'; } else if (finalPosition <= 6) { performanceMessage = 'GOOD RACE!'; } else { performanceMessage = 'KEEP TRYING!'; } var performanceText = new Text2(performanceMessage, { size: 50, fill: 0xFFFFFF }); performanceText.anchor.set(0.5, 0.5); performanceText.x = 1024; performanceText.y = 1450; performanceText.alpha = 0; game.addChild(performanceText); var lapsCompletedText = new Text2('Laps Completed: 20/20', { size: 40, fill: 0xCCCCCC }); lapsCompletedText.anchor.set(0.5, 0.5); lapsCompletedText.x = 1024; lapsCompletedText.y = 1520; lapsCompletedText.alpha = 0; game.addChild(lapsCompletedText); // Animate the ranking display tween(rankingBackground, { alpha: 0.9 }, { duration: 800, easing: tween.easeInOut }); tween(rankingTitle, { alpha: 1, scaleX: 1.2, scaleY: 1.2 }, { duration: 1000, easing: tween.bounceOut }); tween(finalRankingText, { alpha: 1, scaleX: 1.3, scaleY: 1.3 }, { duration: 1200, easing: tween.bounceOut, delay: 500 }); tween(positionSuffixText, { alpha: 1, scaleX: 1.2, scaleY: 1.2 }, { duration: 1000, easing: tween.bounceOut, delay: 700 }); tween(performanceText, { alpha: 1 }, { duration: 800, easing: tween.easeOut, delay: 1000 }); tween(lapsCompletedText, { alpha: 1 }, { duration: 800, easing: tween.easeOut, delay: 1200 }); LK.setScore(900 - finalPosition * 100); // Higher score for better position // Show you win after 4 seconds to allow time to see ranking LK.setTimeout(function () { LK.showYouWin(); }, 4000); } // Handle traffic light sequence if (raceStartSequence && !raceStarted) { // Show UI elements when race sequence starts if (lightSequenceTimer === 0) { tween(positionTxt, { alpha: 1 }, { duration: 500 }); tween(lapTxt, { alpha: 1 }, { duration: 500 }); tween(speedTxt, { alpha: 1 }, { duration: 500 }); menuActive = false; } lightSequenceTimer++; // Turn lights green one by one every 60 frames (1 second each) if (lightSequenceTimer === 60) { // First light turns green after 1 second trafficLights[0].setLightGreen(0); } else if (lightSequenceTimer === 120) { // Second light turns green after 2 seconds trafficLights[0].setLightGreen(1); } else if (lightSequenceTimer === 180) { // Third light turns green after 3 seconds trafficLights[0].setLightGreen(2); } else if (lightSequenceTimer === 240) { // Fourth light turns green after 4 seconds trafficLights[0].setLightGreen(3); } else if (lightSequenceTimer === 300) { // Fifth light turns green after 5 seconds - RACE STARTS trafficLights[0].setLightGreen(4); // Show START text with tween animation tween(startText, { alpha: 1, scaleX: 1.5, scaleY: 1.5 }, { duration: 500, easing: tween.bounceOut, onFinish: function onFinish() { // Fade out start text after 1 second tween(startText, { alpha: 0 }, { duration: 1000 }); } }); raceStarted = true; // Update background for rain mode updateBackgroundForRain(); // Start 10-second race speed acceleration if (!raceSpeedAccelerating) { raceSpeedAccelerating = true; var initialRaceSpeed = 8; // Starting race speed var maxRaceSpeed = 25.0; // Maximum race speed (250 km/h) raceSpeed = initialRaceSpeed; tween(window, { raceSpeed: maxRaceSpeed }, { duration: 10000, // 10 seconds easing: tween.easeInOut }); } // Start 10-second speed acceleration for player if (!player.isAccelerating) { player.isAccelerating = true; tween(player, { speed: player.maxSpeedTarget }, { duration: 10000, // 10 seconds easing: tween.easeInOut }); } // Activate bot cars with 10-second speed acceleration for (var i = 0; i < botCars.length; i++) { botCars[i].currentSpeed = botCars[i].minSpeed; // Start from minimum speed if (!botCars[i].isAccelerating) { botCars[i].isAccelerating = true; // Accelerate each bot from min to max over 10 seconds tween(botCars[i], { currentSpeed: botCars[i].maxSpeedTarget, baseSpeed: botCars[i].maxSpeedTarget }, { duration: 10000, // 10 seconds easing: tween.easeInOut }); } } // Hide traffic light with animation tween(trafficLights[0], { alpha: 0, y: trafficLights[0].y - 100 }, { duration: 1000, easing: tween.easeOut }); } } // Spawn road lines lineSpawnTimer++; if (lineSpawnTimer >= 25) { lineSpawnTimer = 0; spawnRoadLines(); } // Update and check bot cars for (var i = botCars.length - 1; i >= 0; i--) { var bot = botCars[i]; if (bot.lastY === undefined) { bot.lastY = bot.y; } if (bot.lastIntersecting === undefined) { bot.lastIntersecting = false; } // Gradual speed recovery to maintain bot speed differences if (raceStarted && bot.currentSpeed < bot.baseSpeed) { bot.currentSpeed = Math.min(bot.baseSpeed, bot.currentSpeed + 0.1); } // Progressive speed boost system - bots get faster as race progresses if (raceStarted && LK.ticks % 900 === 0) { // Every 15 seconds // Add speed boost based on lap progress var speedBoostMultiplier = 1 + lapNumber * 0.05; // 5% speed increase per lap var boostedSpeed = Math.min(30.0, bot.baseSpeed * speedBoostMultiplier); // Apply speed boost with smooth transition tween(bot, { baseSpeed: boostedSpeed, currentSpeed: Math.min(30.0, bot.currentSpeed * speedBoostMultiplier) }, { duration: 2500, easing: tween.easeInOut }); } // Increase bot speeds over time to make race more challenging with smooth transitions if (raceStarted && LK.ticks % 300 === 0) { // Every 5 seconds, increase bot speeds more gradually var newBaseSpeed = Math.min(28.0, bot.baseSpeed + 0.3); // Allow bots to reach up to 280 km/h over time var newCurrentSpeed = Math.min(28.0, bot.currentSpeed + 0.3); // Use tween for smooth speed transitions tween(bot, { baseSpeed: newBaseSpeed }, { duration: 1500, easing: tween.easeInOut }); // Also increase current speed proportionally if not in collision recovery if (bot.currentSpeed >= bot.baseSpeed - 1) { tween(bot, { currentSpeed: newCurrentSpeed }, { duration: 1500, easing: tween.easeInOut }); } } // Remove bots that go off screen if (bot.lastY <= 2800 && bot.y > 2800) { bot.destroy(); botCars.splice(i, 1); continue; } // Check collision with player var currentIntersecting = bot.intersects(player); if (!bot.lastIntersecting && currentIntersecting) { LK.getSound('collision').play(); // Reduce player race speed on collision with bot cars raceSpeed = Math.max(12.0, raceSpeed - 3.0); // Reduce speed by 30 km/h, minimum 120 km/h // Add collision visual effects using tween var playerGraphics = player.children[0]; // Get the player car graphics var botGraphics = bot.children[0]; // Get the bot car graphics // Flash effect for player tween(playerGraphics, { tint: 0xff0000 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(playerGraphics, { tint: 0xffffff }, { duration: 300, easing: tween.easeIn }); } }); // Flash effect for bot tween(botGraphics, { tint: 0xff0000 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(botGraphics, { tint: 0xffffff }, { duration: 300, easing: tween.easeIn }); } }); // Shake effect for collision impact - move cars apart if (player.x < bot.x) { tween(player, { x: player.x - 40 }, { duration: 200, easing: tween.easeOut }); tween(bot, { x: bot.x + 30 }, { duration: 200, easing: tween.easeOut }); } else { tween(player, { x: player.x + 40 }, { duration: 200, easing: tween.easeOut }); tween(bot, { x: bot.x - 30 }, { duration: 200, easing: tween.easeOut }); } } bot.lastY = bot.y; bot.lastIntersecting = currentIntersecting; } // Update road lines for (var i = roadLines.length - 1; i >= 0; i--) { var line = roadLines[i]; if (line.lastY === undefined) { line.lastY = line.y; } // Remove lines that go off screen if (line.lastY <= 2800 && line.y > 2800) { line.destroy(); roadLines.splice(i, 1); continue; } line.lastY = line.y; } // Update track edges and check collisions for (var i = trackEdges.length - 1; i >= 0; i--) { var edge = trackEdges[i]; if (edge.lastY === undefined) { edge.lastY = edge.y; } // Check collision with player if (edge.intersects && edge.intersects(player)) { // Play collision sound LK.getSound('collision').play(); // Reduce player race speed on collision with track barriers raceSpeed = Math.max(12.0, raceSpeed - 4.0); // Reduce speed by 40 km/h, minimum 120 km/h // Add collision visual effects var playerGraphics = player.children[0]; // Get the player car graphics // Flash player car red to show collision tween(playerGraphics, { tint: 0xff0000 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(playerGraphics, { tint: 0xffffff }, { duration: 300, easing: tween.easeIn }); } }); // Bounce player away from barrier with enhanced collision effect if (edge.side === 'left') { // Hit left barrier, push player right tween(player, { x: player.x + 120 }, { duration: 250, easing: tween.bounceOut }); } else if (edge.side === 'right') { // Hit right barrier, push player left tween(player, { x: player.x - 120 }, { duration: 250, easing: tween.bounceOut }); } // Flash the barrier red to show collision tween(edge, { tint: 0xff0000 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(edge, { tint: 0xffffff }, { duration: 300, easing: tween.easeIn }); } }); } // Check collisions with bot cars for (var j = 0; j < botCars.length; j++) { var bot = botCars[j]; if (edge.intersects && edge.intersects(bot)) { // Reduce bot speed but keep within range (20-23.5) bot.currentSpeed = Math.max(20, bot.currentSpeed - 2); // Add collision visual effects var botGraphics = bot.children[0]; // Get the bot car graphics // Flash bot car red to show collision tween(botGraphics, { tint: 0xff0000 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(botGraphics, { tint: 0xffffff }, { duration: 300, easing: tween.easeIn }); } }); // Bounce bot away from barrier with enhanced collision effect if (edge.side === 'left') { // Hit left barrier, push bot right tween(bot, { x: bot.x + 100 }, { duration: 200, easing: tween.bounceOut }); } else if (edge.side === 'right') { // Hit right barrier, push bot left tween(bot, { x: bot.x - 100 }, { duration: 200, easing: tween.bounceOut }); } } } // Remove edges that go off screen and spawn new ones if (edge.lastY <= 2800 && edge.y > 2800) { edge.destroy(); trackEdges.splice(i, 1); continue; } edge.lastY = edge.y; } // Update finish lines for (var i = finishLines.length - 1; i >= 0; i--) { var finishLine = finishLines[i]; if (finishLine.lastY === undefined) { finishLine.lastY = finishLine.y; } // Remove finish lines that go off screen if (finishLine.lastY <= 2800 && finishLine.y > 2800) { finishLine.destroy(); finishLines.splice(i, 1); continue; } finishLine.lastY = finishLine.y; } // Spawn new track barriers - maintain continuous coverage with no gaps if (LK.ticks % 40 === 0) { // Spawn more frequently to ensure continuous coverage var barrierIndex = Math.floor(Math.random() * 5); // Find the topmost barrier position for each side to place new ones adjacent var leftTopY = -400; var rightTopY = -400; // Find the highest (lowest Y value) barrier on each side for (var k = 0; k < leftBarriers.length; k++) { if (leftBarriers[k].y < leftTopY) { leftTopY = leftBarriers[k].y; } } for (var k = 0; k < rightBarriers.length; k++) { if (rightBarriers[k].y < rightTopY) { rightTopY = rightBarriers[k].y; } } var leftBarrier = new TrackEdge(barrierIndex); leftBarrier.x = 150; // Position new barrier to be adjacent to the topmost barrier (accounting for barrier height) leftBarrier.y = leftTopY - 546; // Use barrier height to ensure no gap leftBarrier.side = 'left'; leftBarriers.push(leftBarrier); trackEdges.push(leftBarrier); game.addChild(leftBarrier); var rightBarrier = new TrackEdge(barrierIndex); rightBarrier.x = 1898; // Position new barrier to be adjacent to the topmost barrier (accounting for barrier height) rightBarrier.y = rightTopY - 546; // Use barrier height to ensure no gap rightBarrier.side = 'right'; rightBarriers.push(rightBarrier); trackEdges.push(rightBarrier); game.addChild(rightBarrier); // Remove barriers from arrays when they go off screen for (var k = leftBarriers.length - 1; k >= 0; k--) { if (leftBarriers[k].y > 2800) { leftBarriers.splice(k, 1); } } for (var k = rightBarriers.length - 1; k >= 0; k--) { if (rightBarriers[k].y > 2800) { rightBarriers.splice(k, 1); } } } // Simple position tracking - count how many active bot cars are ahead of player if (!raceFinished && raceStarted) { var botsAheadOfPlayer = 0; var positionChanged = false; // Count bot cars that are ahead of the player for (var i = 0; i < botCars.length; i++) { var bot = botCars[i]; if (!bot.hasFinished && bot.y < player.y) { botsAheadOfPlayer++; } } // Calculate new position: player position = bots ahead + 1 + finished bots var newPosition = botsAheadOfPlayer + 1; // Check if position changed if (newPosition !== position) { position = newPosition; positionChanged = true; // Add visual feedback for position change tween(positionTxt, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(positionTxt, { scaleX: 1.0, scaleY: 1.0 }, { duration: 200, easing: tween.easeIn }); } }); // Show position notification when position improves (lower number = better) if (positionChanged) { var positionNotification = new Text2('Position: ' + position, { size: 80, fill: 0x00FF00 }); positionNotification.anchor.set(0.5, 0.5); positionNotification.x = 1024; positionNotification.y = 1366; positionNotification.alpha = 0; game.addChild(positionNotification); // Animate position notification tween(positionNotification, { alpha: 1, scaleX: 1.5, scaleY: 1.5, y: 1200 }, { duration: 200, easing: tween.bounceOut, onFinish: function onFinish() { tween(positionNotification, { alpha: 0, y: 1000 }, { duration: 1000, easing: tween.easeIn, onFinish: function onFinish() { positionNotification.destroy(); } }); } }); } } positionTxt.setText('Position: ' + position + '/9'); } else if (raceFinished) { positionTxt.setText('Position: ' + finalPosition + '/9 - FINISHED'); } else { // Before race starts, show starting position positionTxt.setText('Position: 9/9'); } // Rain system - only active during race and if rain mode is enabled if (isRainMode && raceStarted) { // Spawn rain drops rainSpawnTimer++; if (rainSpawnTimer >= 3) { // Spawn rain drops every 3 frames for heavy rain rainSpawnTimer = 0; // Create multiple rain drops per spawn for dense rain effect for (var r = 0; r < 3; r++) { var rainDrop = new RainDrop(); rainDrop.x = Math.random() * 2200 - 100; // Spawn across full width plus margins rainDrop.y = -50; // Start above screen rainDrops.push(rainDrop); game.addChildAt(rainDrop, 1); // Add behind game elements but above road lines } } // Update and remove rain drops for (var i = rainDrops.length - 1; i >= 0; i--) { var drop = rainDrops[i]; if (drop.lastY === undefined) { drop.lastY = drop.y; } // Remove rain drops that go off screen if (drop.lastY <= 2800 && drop.y > 2800) { drop.destroy(); rainDrops.splice(i, 1); continue; } drop.lastY = drop.y; } } // Speed increases are now handled by the 10-second tween acceleration system // Remove this section to avoid conflicts with the new tween-based system };
===================================================================
--- original.js
+++ change.js
@@ -1,9 +1,8 @@
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
-var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
@@ -19,19 +18,19 @@
var speedVariations = [22,
// Fast aggressive bot
20.5,
// Medium-fast bot
- 22.5,
+ 23.5,
// Very fast bot (235 km/h max)
20,
// Slower cautious bot
- 21.5,
+ 22.5,
// Medium bot
- 23,
+ 23.5,
// Fastest bot (235 km/h max)
21,
// Medium-slow bot
- 22 // Fast bot
+ 23 // Fast bot
];
self.baseSpeed = speedVariations[carIndex % 8]; // Assign specific speed based on car index
self.currentSpeed = 0; // Start stationary until race begins
self.lanePosition = Math.floor(Math.random() * 3); // 0=left, 1=center, 2=right
@@ -288,180 +287,85 @@
return self;
});
var GameMenu = Container.expand(function () {
var self = Container.call(this);
- // Full screen menu background
+ // Menu background
var menuBg = self.attachAsset('menuBackground', {
anchorX: 0.5,
anchorY: 0.5
});
- menuBg.alpha = 1.0;
- menuBg.scaleX = 1.2;
- menuBg.scaleY = 1.2;
- // Header section
- var headerPanel = self.attachAsset('menuPanel', {
+ menuBg.alpha = 0.95;
+ // Menu panel
+ var menuPanel = self.attachAsset('menuPanel', {
anchorX: 0.5,
anchorY: 0.5
});
- headerPanel.y = -800;
- headerPanel.scaleX = 0.9;
- headerPanel.scaleY = 0.3;
- // Main title with enhanced styling
- var titleText = new Text2('FORMULA 1 RACING', {
- size: 85,
- fill: 0xFF0000
+ menuPanel.y = -100;
+ // Title
+ var titleText = new Text2('RACING CHAMPIONSHIP', {
+ size: 70,
+ fill: 0xFFD700
});
titleText.anchor.set(0.5, 0.5);
- titleText.y = -850;
+ titleText.y = -600;
self.addChild(titleText);
- var subtitleText = new Text2('RED BULL CHAMPIONSHIP', {
- size: 55,
- fill: 0xFFD700
- });
- subtitleText.anchor.set(0.5, 0.5);
- subtitleText.y = -750;
- self.addChild(subtitleText);
- // Game mode section
- var gameModePanel = self.attachAsset('menuPanel', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- gameModePanel.y = -450;
- gameModePanel.scaleX = 0.85;
- gameModePanel.scaleY = 0.4;
- var gameModeTitle = new Text2('RACE MODE', {
- size: 50,
- fill: 0x00AAFF
- });
- gameModeTitle.anchor.set(0.5, 0.5);
- gameModeTitle.y = -550;
- self.addChild(gameModeTitle);
- // Instructions with better formatting
- var instructionText = new Text2('• Drag to steer your Red Bull car\n• Complete 20 laps to finish the race\n• Avoid barriers and rival cars\n• Beat your opponents to win!', {
- size: 38,
+ // Instructions
+ var instructionText = new Text2('Drag to steer your car\nComplete 20 laps to win!\nAvoid barriers and other cars', {
+ size: 40,
fill: 0xFFFFFF,
- align: 'left'
+ align: 'center'
});
instructionText.anchor.set(0.5, 0.5);
instructionText.y = -400;
self.addChild(instructionText);
- // Car showcase section
- var carPanel = self.attachAsset('menuPanel', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- carPanel.y = -100;
- carPanel.scaleX = 0.8;
- carPanel.scaleY = 0.5;
- var carSectionTitle = new Text2('YOUR RED BULL CAR', {
- size: 45,
- fill: 0xFF4444
- });
- carSectionTitle.anchor.set(0.5, 0.5);
- carSectionTitle.y = -220;
- self.addChild(carSectionTitle);
- // Car selection display with enhanced presentation
+ // Car selection display
self.selectedCarIndex = 0;
var carPreview = self.attachAsset('playerCar', {
anchorX: 0.5,
anchorY: 0.5
});
- carPreview.y = -100;
- carPreview.scaleX = 1.2;
- carPreview.scaleY = 1.2;
- // Add car stats
- var carStatsText = new Text2('Max Speed: 250 km/h\nAcceleration: Professional\nHandling: Expert', {
- size: 32,
- fill: 0xCCCCCC,
- align: 'center'
- });
- carStatsText.anchor.set(0.5, 0.5);
- carStatsText.y = 20;
- self.addChild(carStatsText);
- // Race statistics section
- var statsPanel = self.attachAsset('menuPanel', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- statsPanel.y = 300;
- statsPanel.scaleX = 0.85;
- statsPanel.scaleY = 0.35;
- var statsTitle = new Text2('RACING STATISTICS', {
- size: 42,
- fill: 0x00FF88
- });
- statsTitle.anchor.set(0.5, 0.5);
- statsTitle.y = 200;
- self.addChild(statsTitle);
- // Best position tracking (enhanced)
- var bestPosition = storage.bestPosition || 'Not Set';
- var racesCompleted = storage.racesCompleted || 0;
- var totalWins = storage.totalWins || 0;
- var statsText = new Text2('Best Position: ' + bestPosition + '\nRaces Completed: ' + racesCompleted + '\nTotal Wins: ' + totalWins, {
+ carPreview.y = -150;
+ carPreview.scaleX = 0.8;
+ carPreview.scaleY = 0.8;
+ var carLabel = new Text2('Your Car', {
size: 35,
- fill: 0xFFFFFF,
- align: 'center'
+ fill: 0x00FF00
});
- statsText.anchor.set(0.5, 0.5);
- statsText.y = 280;
- self.addChild(statsText);
- // Enhanced start button
- var startButton = new MenuButton('start', 'START CHAMPIONSHIP', function () {
+ carLabel.anchor.set(0.5, 0.5);
+ carLabel.y = -50;
+ self.addChild(carLabel);
+ // Start button
+ var startButton = new MenuButton('start', 'START RACE', function () {
self.startRace();
});
- startButton.y = 450;
+ startButton.y = 200;
self.addChild(startButton);
- // Additional menu options
- var resetStatsButton = new MenuButton('carSelectButton', 'RESET STATS', function () {
- // Reset storage by removing the keys
- delete storage.bestPosition;
- delete storage.racesCompleted;
- delete storage.totalWins;
- // Update display
- statsText.setText('Best Position: Not Set\nRaces Completed: 0\nTotal Wins: 0');
+ // Rain mode toggle
+ self.rainMode = false;
+ var rainToggleButton = new MenuButton('carSelect', self.rainMode ? 'Rain: ON' : 'Rain: OFF', function () {
+ self.rainMode = !self.rainMode;
+ rainToggleButton.children[1].setText(self.rainMode ? 'Rain: ON' : 'Rain: OFF');
+ rainToggleButton.children[1].tint = self.rainMode ? 0x00FF00 : 0xFFFFFF;
});
- resetStatsButton.y = 570;
- resetStatsButton.scaleX = 0.8;
- resetStatsButton.scaleY = 0.8;
- self.addChild(resetStatsButton);
- // Version info
- var versionText = new Text2('Red Bull Racing Championship v1.0', {
- size: 25,
- fill: 0x888888
+ rainToggleButton.y = 100;
+ self.addChild(rainToggleButton);
+ // Best time display (placeholder)
+ var bestTimeText = new Text2('Best Position: Not Set', {
+ size: 30,
+ fill: 0xCCCCCC
});
- versionText.anchor.set(0.5, 0.5);
- versionText.y = 700;
- self.addChild(versionText);
- // Add subtle animations to menu elements
- tween(titleText, {
- scaleX: 1.1,
- scaleY: 1.1
- }, {
- duration: 2000,
- easing: tween.easeInOut,
- loop: true,
- yoyo: true
- });
- tween(carPreview, {
- rotation: 0.1
- }, {
- duration: 3000,
- easing: tween.easeInOut,
- loop: true,
- yoyo: true
- });
+ bestTimeText.anchor.set(0.5, 0.5);
+ bestTimeText.y = 350;
+ self.addChild(bestTimeText);
self.startRace = function () {
- // Update races completed
- var newRacesCompleted = (storage.racesCompleted || 0) + 1;
- storage.racesCompleted = newRacesCompleted;
- // Hide menu with enhanced animation
+ // Store rain mode setting globally
+ isRainMode = self.rainMode;
+ // Hide menu with animation
tween(self, {
alpha: 0,
- scaleX: 0.8,
- scaleY: 0.8,
- y: self.y - 300
+ y: self.y - 200
}, {
- duration: 1000,
+ duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
self.destroy();
// Start the race countdown
@@ -534,8 +438,29 @@
self.lastX = self.x;
};
return self;
});
+var RainDrop = Container.expand(function () {
+ var self = Container.call(this);
+ // Create a small white line for rain drop
+ var rainGraphics = LK.getAsset('roadLine', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.1,
+ scaleY: 0.3
+ });
+ rainGraphics.tint = 0x87CEEB; // Sky blue color for rain
+ rainGraphics.alpha = 0.7;
+ self.addChild(rainGraphics);
+ // Rain properties
+ self.speed = Math.random() * 15 + 20; // Random speed between 20-35
+ self.windEffect = Math.random() * 2 - 1; // Random wind effect
+ self.update = function () {
+ self.y += self.speed;
+ self.x += self.windEffect; // Add slight wind effect
+ };
+ return self;
+});
var RoadLine = Container.expand(function () {
var self = Container.call(this);
var lineGraphics = self.attachAsset('roadLine', {
anchorX: 0.5,
@@ -634,8 +559,18 @@
/****
* Game Code
****/
+// Function to update background color based on rain mode
+function updateBackgroundForRain() {
+ if (isRainMode && raceStarted) {
+ // Darker, more overcast background for rain
+ game.setBackgroundColor(0x1a1a2e);
+ } else {
+ // Normal background
+ game.setBackgroundColor(0x2d2d2d);
+ }
+}
// Game variables
var player;
var botCars = [];
var roadLines = [];
@@ -660,8 +595,12 @@
var raceStartSequence = false;
var startText = null;
var gameMenu = null;
var menuActive = true;
+// Rain mode variables
+var isRainMode = false;
+var rainDrops = [];
+var rainSpawnTimer = 0;
// Clean position tracking - start at 9th position
// Show menu first
gameMenu = new GameMenu();
gameMenu.x = 1024;
@@ -1027,18 +966,8 @@
duration: 800,
easing: tween.easeOut,
delay: 1200
});
- // Save statistics
- var currentBest = storage.bestPosition;
- if (!currentBest || finalPosition < parseInt(currentBest)) {
- storage.bestPosition = finalPosition.toString();
- }
- // Track wins (1st place finishes)
- if (finalPosition === 1) {
- var currentWins = storage.totalWins || 0;
- storage.totalWins = currentWins + 1;
- }
LK.setScore(900 - finalPosition * 100); // Higher score for better position
// Show you win after 4 seconds to allow time to see ranking
LK.setTimeout(function () {
LK.showYouWin();
@@ -1099,8 +1028,10 @@
});
}
});
raceStarted = true;
+ // Update background for rain mode
+ updateBackgroundForRain();
// Start 10-second race speed acceleration
if (!raceSpeedAccelerating) {
raceSpeedAccelerating = true;
var initialRaceSpeed = 8; // Starting race speed
@@ -1547,7 +1478,38 @@
} else {
// Before race starts, show starting position
positionTxt.setText('Position: 9/9');
}
+ // Rain system - only active during race and if rain mode is enabled
+ if (isRainMode && raceStarted) {
+ // Spawn rain drops
+ rainSpawnTimer++;
+ if (rainSpawnTimer >= 3) {
+ // Spawn rain drops every 3 frames for heavy rain
+ rainSpawnTimer = 0;
+ // Create multiple rain drops per spawn for dense rain effect
+ for (var r = 0; r < 3; r++) {
+ var rainDrop = new RainDrop();
+ rainDrop.x = Math.random() * 2200 - 100; // Spawn across full width plus margins
+ rainDrop.y = -50; // Start above screen
+ rainDrops.push(rainDrop);
+ game.addChildAt(rainDrop, 1); // Add behind game elements but above road lines
+ }
+ }
+ // Update and remove rain drops
+ for (var i = rainDrops.length - 1; i >= 0; i--) {
+ var drop = rainDrops[i];
+ if (drop.lastY === undefined) {
+ drop.lastY = drop.y;
+ }
+ // Remove rain drops that go off screen
+ if (drop.lastY <= 2800 && drop.y > 2800) {
+ drop.destroy();
+ rainDrops.splice(i, 1);
+ continue;
+ }
+ drop.lastY = drop.y;
+ }
+ }
// Speed increases are now handled by the 10-second tween acceleration system
// Remove this section to avoid conflicts with the new tween-based system
};
\ No newline at end of file
formula one race car 2d redbull vertical. In-Game asset. 2d. High contrast. No shadows
mclaren f1 race car vertical. In-Game asset. 2d. High contrast. No shadows
f1 grand prix barriers vertical 2d. In-Game asset. 2d. High contrast. No shadows
bird's-eye view of the F1 spectator crowd. In-Game asset. 2d. High contrast. No shadows
f1 mercedes car 2d vertical. In-Game asset. 2d. High contrast. No shadows