-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
47 lines (41 loc) · 979 Bytes
/
example.js
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
const { start, color, createMap } = require("./index");
const { bitmaps } = require("./exported-animation.json");
// prettier-ignore
const map = createMap([
'cccccccccccccccc',
'c c',
'c c',
'c c',
'c c',
'c c',
'c c',
'cccccccccccccccc',
]);
start({
init: () => {
return { x: 1, y: 1 };
},
update: ({ x, y }, { pressed }) => {
if (pressed.down && !map.pget(x, y + 1)) {
y += 1;
}
if (pressed.up && y > 1 && !map.pget(x, y - 1)) {
y -= 1;
}
if (pressed.left && x > 1 && !map.pget(x - 1, y)) {
x -= 1;
}
if (pressed.right && !map.pget(x + 1, y)) {
x += 1;
}
return { x, y };
},
draw: (frame, { x, y }) => {
frame.bset(bitmaps[0]);
frame.mset(0, 0, map, 0);
frame.rect(6, 1, 15, 7, color.pink);
frame.fill(1, 1, 6, 7);
frame.pset(x, y, color.red);
frame.print("p", 2, 2, 7);
}
});