HAPTIC FISHING / STUDY / LEVEL 1 OF 7
The life of
one fish.
The skeleton of the whole game is a state machine. At any moment the game is in exactly one state (waiting, a fish testing the bait, the bite, the fight…), and every frame it checks one thing: should it move to the next state? This page has no graphics and no headset. It runs the game's actual fishingRules.js, and buttons stand in for the controller.
State diagram
idleYour controller
ready- state
- idle
- timer
- –
- fish
- –
- nibblesLeft
- –
- tension
- –
- progress
- –
- score
- 0
- remaining (s)
- 120
The code running right now
fishingRules.jsEvery frame, the scene calls game.tick(dt, input). Inside tick, only the branch for the current state runs; it is highlighted below. When the state changes, the highlight moves with it.
Change the numbers yourself
only on this page; the game is not affectedThis is the game's fish table, FISH. Change a number and the next fish follows the new rule. For example, set the golden koi's window (seconds you get to strike after the bite) to 0.2, and you will barely have time to react.
| name | points | nibbles | gap (s) | window (s) | pull |
|---|
Three things you should be able to explain
- A state machine.
this.statealways holds exactly one value.tickusesif / else ifto find the branch for the current state, which only checks whether it is time to move on. - Countdown timers. Most states count down with
this.timer -= dtand change state when the timer reaches 0.dtis how many seconds this frame took, about 1/72 s in a headset. The code never "waits"; it subtracts a little each frame. - Rules and graphics are separate.
ticknever vibrates or draws anything. It only returns a list of events, such as{type:'bite'}. The real scene,fishing.js, receives them and vibrates the controller, plays sounds and updates the text. That is why this page can run the same rules without a headset.
Exercises: ① Choose "GOLDEN KOI" and strike while it is still tapping. Which event appears in the log, and which state does the game go back to? ② This time, after the bite, do not strike. Count how many seconds pass before it escapes, and compare with window in the fish table. ③ Hook a fish and hold reel without letting go. Watch tension climb until the line snaps.