[title: "Player Class"] ← Back to index

Handles all gameplay logic including note processing and scoring

[heading: "Description"]

Core gameplay class that processes player input, evaluates timing judgements against chart notes, and manages all runtime game state including scoring, health, combo, and accuracy. Delegates visual rendering to ChartRenderer while handling the logic layer of gameplay. Serves as the base class for FirstPlayer and SecondPlayer.

[heading: "Key Features"] [list] * Note input processing and judgement evaluation * Score, combo, health, and accuracy tracking * Hold and roll note management * Skill system integration [/list] [heading: "Constructor"] [table header] [ Parameter | Type | Description ] [ scene | Phaser.Scene | The Phaser game scene this player belongs to ] [ playerSide | string | Player position: "center", "left", or "right" ] [ settings | Object | Gameplay configuration overrides ] [/table] [heading: "Properties"] [table header] [ Property | Type | Description ] [ scene | Object | The gameplay scene this player belongs to ] [ playerSide | string | Lane position of this player ("center", "left" or "right") ] [ gamepad | Object | Gamepad assigned to this player ] [ hud | Object | HUD container this player renders into ] [ renderer | ChartRenderer | Handles all visual chart rendering ] [ notes | Array | Chart note data for this difficulty ] [ bpmChanges | Array | BPM change markers from the chart ] [ stops | Array | Stop events from the chart ] [ autoplay | boolean | Whether AI auto-play is active ] [ autoplayActiveHolds | Set | Hold notes being held by the autoplay AI ] [ keymap | Object | Mapping of action names to column indices ] [ inputStates | Array<boolean> | Current press state for each column ] [ lastInputStates | Array<boolean> | Press state for each column on the previous frame ] [ activeHolds | Object | Active hold notes keyed by column index ] [ heldColumns | Set | Columns currently being held ] [ judgementHistory | Array | History of all judgements received ] [ lastNoteCheckBeats | Array | Last checked beat for each column ] [ score | number | Current accumulated score ] [ combo | number | Current consecutive hit streak ] [ maxCombo | number | Highest combo achieved this game ] [ maxHealth | number | Maximum health capacity ] [ health | number | Current player health ] [ previousHealth | number | Health value before the latest change ] [ timingStory | Array | Record of timing measurements for each judgement ] [ HOLD_FORGIVENESS | number | Seconds of leeway tolerated for hold notes ] [ ROLL_FORGIVENESS | number | Seconds of leeway tolerated for roll notes ] [ ROLL_REQUIRED_INTERVALS | number | Interval between required roll taps in seconds ] [ judgementCounts | Object | Count of each judgement type received ] [ totalNotes | number | Total note count for accuracy calculation ] [ accuracy | number | Current accuracy percentage (0-100) ] [ gameOver | boolean | Whether the game has ended ] [ skillSystem | Object | Reference to the active skill system ] [ perfectStreak | number | Consecutive marvelous/perfect hits ] [ comboShieldActive | boolean | Whether the combo shield skill is active ] [ receptors | Array | Receptor sprites for each column ] [ judgementText | Object | Sprite that displays the last judgement result ] [ comboText | Object | Text showing the current combo count ] [ scoreText | Object | Text showing the current score ] [ healthText | Object | Text showing the current health ] [ lifebarStart | Object | Left anchor sprite of the lifebar ] [ lifebarMiddle | Object | Stretching middle sprite of the lifebar ] [ lifebarEnd | Object | Right anchor sprite of the lifebar ] [ accuracyBar | Object | Accuracy bar sprite ] [ HEALTH_X | number | X position of the health bar ] [ HEALTH_WIDTH | number | Width of the variable area of the health bar ] [ ACCURACY_BAR_WIDTH | number | Width of the accuracy bar ] [/table] [heading: "Methods"] [table header] [ Method | Parameters | Description ] [ calculateTotalNotes | () | Counts the total number of hittable notes in the chart for accuracy calculation. Called once during initialization to set the baseline for accuracy scoring. ] [ findClosestNote | (column, beat, noteTypes, searchRangeSeconds) | Finds the nearest unhit note in a given column within a time range. Used by input handling and auto-play to identify which note to judge. ] [ processNoteIfInWindow | (note, currentTime, column, callback) | Checks if a note falls within the judgement window and triggers the callback. Prevents double-judging the same note by tracking last checked beats per column. ] [ autoPlay | () | AI auto-play logic that simulates perfect inputs for all notes. Processes regular notes and holds automatically each frame when enabled. ] [ handleInput | (column, isKeyDown) | Core input handler that processes key press and release events. Routes to regular note checking, hold start/release, and roll tapping logic. ] [ checkRegularNotes | (column, now, beat) | Checks if a regular tap note was hit within the judgement window. ] [ checkMines | (column, now, beat) | Checks if the player is holding a column with a mine note at the judgement line. Mines damage the player when held at the same position. ] [ triggerMine | (mineNote) | Applies damage and breaks combo when a mine note is triggered. Respects mine damage multiplier from the skill system. ] [ checkHoldStart | (column, now, beat) | Checks if a hold or roll note should begin based on current timing. Initializes the hold tracking state for the column. ] [ checkHoldRelease | (column, now) | Handles key release during an active hold note. Applies forgiveness window before marking the hold as inactive. ] [ getAdjustedJudgementWindows | () | Returns judgement windows modified by skill system multipliers. ] [ getHoldForgiveness | () | Returns hold note forgiveness duration with skill system modifier. ] [ getRollForgiveness | () | Returns roll note tap forgiveness duration with skill system modifier. ] [ getJudgement | (timeDelta) | Evaluates the timing delta against adjusted judgement windows. Updates the perfect streak counter and records to timing history. ] [ processJudgement | (note, judgement, column, type) | Processes a judgement result by updating score, combo, health, and accuracy. Applies skill system modifiers including score multipliers, health gains, combo shields, and judgement conversions. ] [ getMaxHealth | () | Returns maximum health including skill system bonuses. ] [ getNoteSpeedMultiplier | () | Returns note speed multiplier combined with skill system modifiers. ] [ updateAccuracy | () | Recalculates accuracy as a weighted percentage of achieved vs possible score. Updates the accuracy bar in the HUD. ] [ updateUI | () | Updates the HUD display with current combo, score, and pulsing effects. ] [ getScoreRating | () | Returns a letter grade based on current accuracy. ] [ showJudgementText | (judgement, column, type) | Displays the judgement text with color, animation, and optional receptor pulse. Freeze judgements show as smaller floating text near the receptor. ] [ getComboColor | (combo) | Returns a color that transitions from white to yellow as combo increases. ] [ onSkillHpRegen | (amount) | Callback for skill system health regeneration. ] [ onComboShield | () | Activates the combo shield, converting the next miss into a non-combo-breaking boo. ] [ render | () | Renders the chart by delegating to ChartRenderer with current active holds. Called each frame to update note positions and visual elements. ] [ update | () | Main gameplay loop called each frame. Processes input, updates holds, checks skill activations, and manages health. Handles both manual input and auto-play modes. ] [ destroy | () | Cleans up all renderer resources and sprite groups. ] [/table] [heading: "Example Usage (Modding)"] [codeblock javascript] // Creating a Player instance directly const player = new Player(game.state.getCurrentState(), "left", { speedMod: "C-MOD", scrollDirection: "falling", noteSpeedMult: 1.5 }); player.update(); console.log(player.score, player.combo, player.accuracy); [/codeblock] [footer: "© Retora 2026"]