Son aktivite 1751739830

a snake game that runs on the Myte playground !

Revizyon 5818cee11a0523d8b47ed773ede184b200808ed0

snake.nv Ham Playground
1|| 'INSTRUCTIONS' you can move using the WASD keys!
2
3'@include' (
4 lib/rpn.nv
5 lib/platforms/browser_dom.nv
6 lib/platforms/browser_game.nv
7)
8
9'snake' 200 200
10
11'' start a 400 by 400 game
12
13| '' game loop
14| ''
15 . check if w is pressed
16 . check if a is pressed
17 . check if s is pressed
18 . check if d is pressed
19 . draw background
20 . draw snake
21 . next frame
22
23| 'key pressed' w | 'vector' + 0 - 1
24| 'key pressed' a | 'vector' - 1 + 0
25| 'key pressed' s | 'vector' + 0 + 1
26| 'key pressed' d | 'vector' + 1 + 0
27| 'snake' $x $y 'vector' $1 $2 $3 $4
28| '' move snake '@rpn' ($y $4 $3 $x $2 $1)
29| '' move snake '@rpn data' ($x $y)
30| 'snake' $x $y
31
32| '' draw background | '@graphics' clear black
33
34| '' draw snake 'snake' $x $y?
35| '@graphics' draw square $x $y 10 green
36
37| '@graphics' draw square $x $y $size $color
38 '@@canvas context' $context?
39| '@js'
40 $context.fillStyle = $color;
41 $context.fillRect($x, $y, $size, $size);
42
43
44
45| '' start a $x by $y game
46| '@graphics' . canvas init canvas . set resolution $x $y
47 'DOM' ( <query canvas <style display = block margin = [1rem auto] > > )
48 '' game loop
49
50| '' next frame
51| '@js' window.requestAnimationFrame(nextFrame);
52
53|| '@js' const nextFrame = () => { f("", "game", "loop"); me.run(); }
54