Ostatnio aktywny 1751739830

a snake game that runs on the Myte playground !

Rewizja d5a014d4a656921ca3d7f4086e29e4b6c6a7e217

snake.nv Surowy Playground
1| 'INSTRUCTIONS' | ~~
2 you can move using the WASD keys !
3
4|| '@include' (
5 https://gist.casuallyblue.dev/autumn/056799f483464c668e0a6a2d9db099df/raw/HEAD/game.nv
6 https://gist.casuallyblue.dev/autumn/e1c6774f800249be87a94240042135db/raw/HEAD/reduce.nv
7)
8
9'snake' 11 4
10'direction' down
11'movement speed' 6
12'timer' 0
13'cell size' 16
14'grid size' 23
15
16'' start game
17
18| '' start game 'cell size' $cell? 'grid size' $grid?
19| '' (@reduce @main =
20 start a { $cell $grid * } by { $cell $grid * } game .)
21
22| '' game loop
23| '' check if w is pressed
24 '' check if a is pressed
25 '' check if s is pressed
26 '' check if d is pressed
27 '' update movement timer
28 '' draw background
29 '' draw snake
30 '' next frame
31
32| 'key pressed' w 'direction' $_ | 'direction' up
33| 'key pressed' a 'direction' $_ | 'direction' left
34| 'key pressed' s 'direction' $_ | 'direction' down
35| 'key pressed' d 'direction' $_ | 'direction' right
36
37| '' move 'direction' up? | 'vector' + 0 - 1
38| '' move 'direction' left? | 'vector' - 1 + 0
39| '' move 'direction' down? | 'vector' + 0 + 1
40| '' move 'direction' right? | 'vector' + 1 + 0
41| 'snake' $x $y 'vector' $1 $2 $3 $4 'grid size' $size?
42| '' (@reduce snake = { $x $2 $1 0 $size 1 - wrap }
43 { $y $4 $3 0 $size 1 - wrap } .)
44
45| '' update movement timer 'movement speed' $speed? 'timer' $speed
46| '' move 'timer' 0
47
48| '' update movement timer 'timer' $time
49| '' (@reduce timer = { $time 1 + } .)
50
51| '' draw background
52| '@graphics' clear black
53
54| '' draw snake 'pixel_position' $x $y 'cell size' $size?
55| '@graphics' draw square $x $y $size #F75AFF
56
57| '' draw snake? 'snake' $x $y?
58| '' convert $x $y to pixel position
59
60| '@graphics' draw square $x $y $size $color '@@canvas context' $c?
61| '@js' $c.fillStyle = $color;
62 $c.fillRect($x, $y, $size, $size);
63
64| '' convert $x $y to pixel position 'cell size' $scalar?
65| '' (@reduce pixel_position = { $x $scalar * } { $y $scalar * } .)
66