🔬 These two blocks ARE the acceleration system—they only increase speed if a player holds their key. What happens if you remove the if-statements so planes ALWAYS accelerate even when no key is held?
if (player1IsAccelerating) {
airplane1Speed += accelerationRate;
airplane1Speed = min(airplane1Speed, maxSpeed); // Cap speed at maxSpeed
}
if (player2IsAccelerating) {
airplane2Speed += accelerationRate;
airplane2Speed = min(airplane2Speed, maxSpeed); // Cap speed at maxSpeed
}
🔬 These lines apply friction (drag) that slows planes down every frame. What happens if you increase frictionRate from 0.1 to 0.5 (you'd need to edit the global variable)? Will planes feel more sluggish or responsive?
// Apply friction to slow down airplanes
airplane1Speed -= frictionRate;
airplane1Speed = max(airplane1Speed, 0); // Speed cannot go below zero
airplane2Speed -= frictionRate;
airplane2Speed = max(airplane2Speed, 0); // Speed cannot go below zero
function draw() {
// --- Day-Night Cycle Logic ---
// Update dayProgress (loops from 0 to 1)
dayProgress += daySpeed;
if (dayProgress > 1) {
dayProgress = 0; // Loop back to morning/dawn
}
// Define colors for different times of day
let dawnTop = color(255, 180, 100); // Warm orange for dawn top
let dawnBottom = color(255, 220, 180); // Lighter orange for dawn horizon
let dayTop = color(100, 150, 255); // A medium blue for the top of the day sky
let dayBottom = color(200, 220, 255); // A lighter blue/white for the day horizon
let nightTop = color(20, 30, 80); // Dark blue for night top
let nightBottom = color(50, 60, 120); // Slightly lighter dark blue for night horizon
let currentSkyTopColor;
let currentSkyBottomColor;
if (dayProgress < 0.5) { // Morning to Day
// Transition from Dawn to Day colors
let inter = map(dayProgress, 0, 0.5, 0, 1);
currentSkyTopColor = lerpColor(dawnTop, dayTop, inter);
currentSkyBottomColor = lerpColor(dawnBottom, dayBottom, inter);
} else { // Day to Night
// Transition from Day to Night colors
let inter = map(dayProgress, 0.5, 1, 0, 1);
currentSkyTopColor = lerpColor(dayTop, nightTop, inter);
currentSkyBottomColor = lerpColor(dayBottom, nightBottom, inter);
}
// Draw the sky gradient using the current colors
setGradient(currentSkyTopColor, currentSkyBottomColor);
// --- Draw Airplane 1 (flying right) ---
push(); // Start an isolated drawing state
translate(airplane1X, height * 0.3); // Position the airplane horizontally and vertically
scale(airplaneSize1); // Scale its size
drawAirplaneShape(); // Draw the airplane shape
pop(); // Restore the previous drawing state
// --- Draw Airplane 2 (flying right) ---
push(); // Start another isolated drawing state
translate(airplane2X, height * 0.5); // Position Airplane 2
scale(airplaneSize2); // Scale its size (no flip, both fly right for the race)
drawAirplaneShape(); // Draw the airplane shape
pop(); // Restore the previous drawing state
// --- Game State Logic ---
if (isRacing) {
// Race is active - apply acceleration, friction, move planes, check winner
if (player1IsAccelerating) {
airplane1Speed += accelerationRate;
airplane1Speed = min(airplane1Speed, maxSpeed); // Cap speed at maxSpeed
}
if (player2IsAccelerating) {
airplane2Speed += accelerationRate;
airplane2Speed = min(airplane2Speed, maxSpeed); // Cap speed at maxSpeed
}
// Apply friction to slow down airplanes
airplane1Speed -= frictionRate;
airplane1Speed = max(airplane1Speed, 0); // Speed cannot go below zero
airplane2Speed -= frictionRate;
airplane2Speed = max(airplane2Speed, 0); // Speed cannot go below zero
// Move airplanes based on their current speeds
airplane1X += airplane1Speed;
airplane2X += airplane2Speed;
// Check for a winner
// The `winner === ""` check ensures only the first airplane to cross is declared the winner
if (airplane1X > width + 150 && winner === "") {
winner = "Player 1 Wins!";
isRacing = false; // Stop the race
} else if (airplane2X > width + 150 && winner === "") {
winner = "Player 2 Wins!";
isRacing = false; // Stop the race
}
} else {
// Race is not active - display instructions, countdown, or winner
fill(0); // Black text color
if (winner === "") {
// Pre-race idle state (instructions)
if (countdownTimer === 0) { // Countdown hasn't started yet
text("GO FLY AND WIN!", width / 2, height / 2 - 60); // Changed text here
textSize(24);
text(`Player 1: Press '${player1Key}' to accelerate`, width / 2, height / 2);
text(`Player 2: Press '${player2Key}' to accelerate`, width / 2, height / 2 + 30);
textSize(32); // Reset text size
} else {
// Countdown is active
textSize(100); // Larger text for countdown numbers
text(countdownValue, width / 2, height / 2);
textSize(32); // Reset text size for other messages
if (frameCount - countdownTimer >= countdownDuration) {
countdownValue--; // Decrement the countdown number
countdownTimer = frameCount; // Reset timer for the next number
if (countdownValue === 0) {
isRacing = true; // Start the race!
countdownTimer = 0; // Clear timer as countdown is over
}
}
}
} else {
// Post-race idle state (winner)
text(winner, width / 2, height / 2 - 30); // Display the winner
textSize(24);
text("Click to Race Again!", width / 2, height / 2 + 10); // Prompt to restart
textSize(32); // Reset text size for next race message
}
}
}