| 'INSTRUCTIONS' | ~~ you can move using the WASD keys ! || '@include' ( https://gist.casuallyblue.dev/autumn/056799f483464c668e0a6a2d9db099df/raw/HEAD/game.nv https://gist.casuallyblue.dev/autumn/e1c6774f800249be87a94240042135db/raw/HEAD/reduce.nv ) 'snake' 11 4 'direction' down 'movement speed' 6 'timer' 0 'cell size' 16 'grid size' 23 '' start game | '' start game 'cell size' $cell? 'grid size' $grid? | '' (@reduce @main = start a { $cell $grid * } by { $cell $grid * } game .) | '' game loop | '' check if w is pressed '' check if a is pressed '' check if s is pressed '' check if d is pressed '' update movement timer '' draw background '' draw snake '' next frame | 'key pressed' w 'direction' $_ | 'direction' up | 'key pressed' a 'direction' $_ | 'direction' left | 'key pressed' s 'direction' $_ | 'direction' down | 'key pressed' d 'direction' $_ | 'direction' right | '' move 'direction' up? | 'vector' + 0 - 1 | '' move 'direction' left? | 'vector' - 1 + 0 | '' move 'direction' down? | 'vector' + 0 + 1 | '' move 'direction' right? | 'vector' + 1 + 0 | 'snake' $x $y 'vector' $1 $2 $3 $4 'grid size' $size? | '' (@reduce snake = { $x $2 $1 0 $size 1 - wrap } { $y $4 $3 0 $size 1 - wrap } .) | '' update movement timer 'movement speed' $speed? 'timer' $speed | '' move 'timer' 0 | '' update movement timer 'timer' $time | '' (@reduce timer = { $time 1 + } .) | '' draw background | '@graphics' clear black | '' draw snake 'pixel_position' $x $y 'cell size' $size? | '@graphics' draw square $x $y $size #F75AFF | '' draw snake? 'snake' $x $y? | '' convert $x $y to pixel position | '@graphics' draw square $x $y $size $color '@@canvas context' $c? | '@js' $c.fillStyle = $color; $c.fillRect($x, $y, $size, $size); | '' convert $x $y to pixel position 'cell size' $scalar? | '' (@reduce pixel_position = { $x $scalar * } { $y $scalar * } .)