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.

Read the controllerposition, speed, trigger
→
game.tick(dt, input)the rules update the state
→
Return eventssuch as nibble, bite, caught
→
The scene turns events intovibration, sound, text, graphics

State diagram

idle
Controller: quiet

Your controller

ready
state
idle
timer
–
fish
–
nibblesLeft
–
tension
–
progress
–
score
0
remaining (s)
120

The code running right now

fishingRules.js

Every 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 affected

This 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.

namepointsnibblesgap (s)window (s)pull

Three things you should be able to explain

  1. A state machine. this.state always holds exactly one value. tick uses if / else if to find the branch for the current state, which only checks whether it is time to move on.
  2. Countdown timers. Most states count down with this.timer -= dt and change state when the timer reaches 0. dt is how many seconds this frame took, about 1/72 s in a headset. The code never "waits"; it subtracts a little each frame.
  3. Rules and graphics are separate. tick never 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.