e
: The main div element representing onekos
: Object containing sprite positions for different states and directionsp
: Function to set the background position (sprite) of onekox
: Current x-position of onekoy
: Current y-position of onekom
: Current x-position of the mouse cursorv
: Current y-position of the mouse cursorf
: Frame count for animationi
: Idle time countera
: Current animation stater
: Frame counter for the current animationw
: Window inner widthh
: Window inner heightT
: Timestamp of the last frameS
: Speed of oneko's movementst
: Current state of oneko ("i", "a", or "c")af
: Frame counter for the alert staten
: Variable for x-distance between oneko and cursorc
: Variable for y-distance between oneko and cursord
: Distance between oneko and cursorg
: Variable for determining oneko's directionl
: Function to handle idle animationsu
: Main animation loop function
i
: Idlea
: Alerts1
: Scratch selfs2
: Scratch wall top (only at top boundary)s3
: Scratch wall bottom (only at bottom boundary)s4
: Scratch wall right (only at right boundary)s5
: Scratch wall left (only at left boundary)t
: Tiredz
: Sleeping
i
: Idle statea
: Alert statec
: Chase state
p(n, f)
: Sets the sprite for oneko based on the staten
and framef
l()
: Handles idle animations and state changes during idle timeu(t)
: Main animation loop, handling state transitions and movement
- oneko starts in the idle state at the top-left corner of the window.
- When the mouse moves, oneko enters the alert state for 6 frames.
- After the alert state, oneko chases the cursor.
- oneko returns to idle state when:
- It gets within 42 pixels of the cursor
- It reaches any window boundary
- During idle state, oneko may perform random animations:
- Sleeping (with a tired transition)
- Self scratching
- Wall scratching (only when exactly at a window boundary)
- Wall scratching animations are only triggered when oneko is exactly at the corresponding window boundary:
- Left boundary (x == 16): left wall scratch
- Top boundary (y == 16): top wall scratch
- Right boundary (x == window width - 16): right wall scratch
- Bottom boundary (y == window height - 16): bottom wall scratch`
e
: Function to simulate mouse events from touch events
e(e, t)
: Simulates a mouse move event from a touch evente
: The original touch eventt
: The touch point (t.touches[0])
- The script listens for 'touchmove' events only.
- Default behavior is prevented for all 'touchmove' events.
- Each 'touchmove' event is converted to a 'mousemove' event.
- The simulated 'mousemove' event uses event bubbling (bubbles:true) to ensure compatibility with the main oneko script.