-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhello.gr
74 lines (63 loc) · 1.8 KB
/
hello.gr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module Main
include "runtime/unsafe/wasmi32"
include "bytes"
include "./grainboy"
@unsafe @externalName("GRAINBOY_INPUT")
provide let input = Grainboy.input
@unsafe
let mut i = 0n
@unsafe
let mut playerX = 210n
@unsafe
let mut playerY = 100n
@unsafe
provide let run = () => {
from WasmI32 use { (+), (-), (*), (/), remS as (%) }
let mut y = 4n
Grainboy.text(8n, y, L, 0xffffffffn, "Welcome to Grainboy!")
y += 16n
Grainboy.text(8n, y, M, 0xffffffffn, "You can draw shapes:")
y += 16n
Grainboy.rect(8n, y, 16n, 16n, 0xffff00ffn)
Grainboy.circ(32n, y, 16n, 0xff00ffffn)
y += 32n
Grainboy.text(8n, y, M, 0xffffffffn, "You can draw sprites:")
y += 16n
Grainboy.sprite(8n, y, 16n, 16n, i / 10n % 9n * 16n, 0n)
Grainboy.sprite(32n, y, 16n, 16n, i / 10n % 9n * 16n, 16n)
y += 32n
Grainboy.text(8n, y, M, 0xffffffffn, "You can draw text:")
y += 16n
Grainboy.text(8n, y, S, 0xffffffffn, "small")
Grainboy.text(33n, y, M, 0xffffffffn, " / medium")
Grainboy.text(79n, y, L, 0xffffffffn, " / large")
y += 8n
Grainboy.text(i % 256n, i % 144n, M, 0xffffffffn, "hello, world!")
y = 4n
Grainboy.rect(180n, 0n, 76n, 144n, 0x222222ffn)
Grainboy.text(184n, y, M, 0xffffffffn, "What's next?")
y += 12n
Grainboy.text(184n, y, S, 0xffffffffn, "- Fix blending issues")
y += 8n
Grainboy.text(184n, y, S, 0xffffffffn, "- Run on web")
y += 8n
Grainboy.text(184n, y, S, 0xffffffffn, "- Demo games")
y += 8n
Grainboy.text(184n, y, S, 0xffffffffn, "- mouse/touch")
y += 8n
let gamepad = Grainboy.gamepad(0n)
if (gamepad.up == Pressed) {
playerY -= 1n
}
if (gamepad.down == Pressed) {
playerY += 1n
}
if (gamepad.left == Pressed) {
playerX -= 1n
}
if (gamepad.right == Pressed) {
playerX += 1n
}
Grainboy.rect(playerX, playerY, 16n, 16n, 0xffffffffn)
i += 1n
}