beats
array
Stores an array of beat objects, each with x, y, and time properties. Updated as beats are added by Tone.js and removed when hit or missed.
let beats = [];
beatSpeed
number
Controls how many pixels beats move downward each frame. Higher values make the game faster.
let beatSpeed = 5;
hitZoneY
number
Y-coordinate of the red hit zone line. Set to height - 100 so the zone is near the bottom.
let hitZoneY;
beatSize
number
The diameter of beat circles in pixels. Affects both visual size and hit zone radius.
let beatSize = 40;
score
number
Tracks the player's current score. Increases by 10 for each perfect hit.
let score = 0;
health
number
Tracks the player's remaining chances to miss. Decreases by 1 on each miss; game ends when it reaches 0.
let health = 5;
gameStarted
boolean
Game state flag: true = playing, false = start screen. Controls which screen is drawn.
let gameStarted = false;
gameOver
boolean
Game state flag: true = game over screen, false = still playing. Controls which screen is drawn.
let gameOver = false;
crowd
array
Array of crowd objects, each with x, y, size, alpha, and type. Rendered on the game over screen.
let crowd = [];
crowdDensity
number
Number of crowd elements to generate. Controls how full the crowd appears.
let crowdDensity = 150;
crowdCoverProgress
number
Tracks animation progress of crowd covering the screen (0 to 1). Controls crowd position and opacity.
let crowdCoverProgress = 0;
crowdCoverSpeed
number
How quickly the crowd animates upward to cover the screen on game over.
let crowdCoverSpeed = 0.005;
gameFont
object
Stores the loaded font for all text rendering. Loaded in preload().
let gameFont;
synth
object
Tone.js PolySynth object that plays audio sounds for beats and hits.
let synth;
beatLoop
object
Tone.js Loop object that schedules beat creation at precise musical intervals.
let beatLoop;
pattern
array
Array of 1s and 0s representing the rhythm pattern. 1 = beat, 0 = rest.
let pattern = [1, 0, 1, 0, 1, 1, 0, 1];
patternIndex
number
Current position in the rhythm pattern. Increments each beat and loops at the end.
let patternIndex = 0;
feedbackText
string
Text to display as feedback (PERFECT!, MISS!, TOO EARLY/LATE!). Fades out each frame.
let feedbackText = '';
feedbackAlpha
number
Opacity of feedback text (0-255). Decreases by 5 each frame to create a fade-out effect.
let feedbackAlpha = 0;
feedbackX
number
Horizontal position of feedback text. Set to the x-coordinate of the hit or missed beat.
let feedbackX;
feedbackY
number
Vertical position of feedback text. Set to just above the hit zone.
let feedbackY;
lossCount
number
Tracks how many times the player has lost. Determines which crowd type (person, dog, water) appears.
let lossCount = 0;
peopleEmojis
array
Array of people and celebration emojis used for the first crowd appearance.
const peopleEmojis = ['🧑🤝🧑', '👨👩👧👦', ...];
dogEmojis
array
Array of dog emojis used for the second crowd appearance (after first loss).
const dogEmojis = ['🐕', '🐶', ...];
waterEmojis
array
Array of water and animal emojis used for the third crowd appearance (after second loss).
const waterEmojis = ['🌊', '💧', ...];