forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coding_demo_1_linked_sprites.js
123 lines (118 loc) 路 1.99 KB
/
coding_demo_1_linked_sprites.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
@title: Coding Demo 1 - Linked sprites
@author: Leonard (Omay)
Important code at bottom
Movement code
*/
const playertop = "a";
const playerbot = "b";
const wall = "c";
setLegend(
[ playertop, bitmap`
................
......00000.....
..00000....0....
.00........00...
.0..........0...
.0..0....00.0...
.0..00...00.0...
.0..00.......0..
.00..........0..
..0..........0..
..0...0...0..0..
..0...00.00..0..
..00...000..00..
....00...0000...
......000.......
......000.......`],
[ playerbot, bitmap`
......000.......
.....000000.....
....00000000....
...0000000000...
...0000000000...
...0.00000000...
...0.000000.0...
...0.000000.0...
...0.000000.0...
.....000000.0...
......0..00.....
.....00..00.....
.....0...0......
.....0...00.....
.....0....0.....
....00....00....`],
[ wall, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`]
);
setSolids([playertop, playerbot, wall]);
setPushables({
[playertop]:[playerbot]
});
let level = 0;
const levels = [
map`
a........
b........
..c.c.c..
..c.c....
.........
....c.c..
..c.c.c..`,
];
setMap(levels[level]);
onInput("w", () => {
let top = getFirst(playertop);
let bot = getFirst(playerbot);
top.y -= 1
bot.y = top.y+1;
if(bot.y !== top.y+1){
top.y += 1
bot.y = top.y+1;
}
});
onInput("a", () => {
let top = getFirst(playertop);
let bot = getFirst(playerbot);
top.x -= 1
bot.x = top.x;
if(bot.x !== top.x){
top.x += 1
bot.x = top.x;
}
});
onInput("s", () => {
let top = getFirst(playertop);
let bot = getFirst(playerbot);
top.y += 1
bot.y = top.y+1;
if(bot.y !== top.y+1){
top.y -= 1
bot.y = top.y+1;
}
});
onInput("d", () => {
let top = getFirst(playertop);
let bot = getFirst(playerbot);
top.x += 1
bot.x = top.x;
if(bot.x !== top.x){
top.x -= 1
bot.x = top.x;
}
});