@dithrkit/sdk 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/package.json +5 -5
- package/templates/platformer.js +206 -28
- package/templates/platformer.ts +177 -29
- package/types/dithr.d.ts +18 -1
package/README.md
CHANGED
|
@@ -51,6 +51,7 @@ module.exports = [
|
|
|
51
51
|
|
|
52
52
|
## Documentation
|
|
53
53
|
|
|
54
|
+
- [Getting Started](https://github.com/dithrkit/dithr/blob/main/docs/getting-started.md)
|
|
54
55
|
- [API Reference](https://github.com/dithrkit/dithr/blob/main/docs/api-reference.md)
|
|
55
56
|
- [Cart Format](https://github.com/dithrkit/dithr/blob/main/docs/cart-format.md)
|
|
56
57
|
- [Architecture](https://github.com/dithrkit/dithr/blob/main/docs/architecture.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dithrkit/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "SDK and CLI for the dithr fantasy console",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "dithrkit",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"esbuild": "^0.24.0"
|
|
45
45
|
},
|
|
46
46
|
"optionalDependencies": {
|
|
47
|
-
"@dithrkit/win32-x64": "0.1.
|
|
48
|
-
"@dithrkit/linux-x64": "0.1.
|
|
49
|
-
"@dithrkit/darwin-arm64": "0.1.
|
|
50
|
-
"@dithrkit/wasm": "0.1.
|
|
47
|
+
"@dithrkit/win32-x64": "0.1.6",
|
|
48
|
+
"@dithrkit/linux-x64": "0.1.6",
|
|
49
|
+
"@dithrkit/darwin-arm64": "0.1.6",
|
|
50
|
+
"@dithrkit/wasm": "0.1.6"
|
|
51
51
|
}
|
|
52
52
|
}
|
package/templates/platformer.js
CHANGED
|
@@ -1,53 +1,231 @@
|
|
|
1
|
-
// Platformer template —
|
|
1
|
+
// Platformer template — tile-based collision with acceleration physics
|
|
2
|
+
//
|
|
3
|
+
// Demonstrates:
|
|
4
|
+
// - Acceleration-based horizontal movement with run button
|
|
5
|
+
// - Variable-height jump (hold jump to go higher)
|
|
6
|
+
// - Tile-based collision with a simple level
|
|
7
|
+
// - Coyote time (jump grace period after leaving a ledge)
|
|
8
|
+
// - Collectible coins
|
|
9
|
+
//
|
|
10
|
+
// Extend this by adding enemies, more tile types, scrolling, etc.
|
|
2
11
|
|
|
3
|
-
|
|
4
|
-
|
|
12
|
+
const TILE = 8;
|
|
13
|
+
const MAP_W = 40; // level width in tiles
|
|
14
|
+
const MAP_H = 23; // level height in tiles (fits 180px)
|
|
15
|
+
|
|
16
|
+
// Physics
|
|
17
|
+
const WALK_ACCEL = 0.046875;
|
|
18
|
+
const SKID_DECEL = 0.15;
|
|
19
|
+
const RELEASE_DECEL = 0.046875;
|
|
20
|
+
const WALK_MAX = 0.75;
|
|
21
|
+
const RUN_MAX = 1.3;
|
|
22
|
+
const JUMP_VEL = -2.6;
|
|
23
|
+
const GRAV_HOLD = 0.11;
|
|
24
|
+
const GRAV_RELEASE = 0.375;
|
|
25
|
+
const MAX_FALL = 2.25;
|
|
26
|
+
const COYOTE_TICKS = 4;
|
|
27
|
+
|
|
28
|
+
// Tile types
|
|
29
|
+
const T_EMPTY = 0;
|
|
30
|
+
const T_SOLID = 1;
|
|
31
|
+
const T_COIN = 2;
|
|
32
|
+
|
|
33
|
+
let tiles = [];
|
|
34
|
+
let px = 16;
|
|
35
|
+
let py = 0;
|
|
5
36
|
let vx = 0;
|
|
6
37
|
let vy = 0;
|
|
7
38
|
let grounded = false;
|
|
39
|
+
let facing = 1;
|
|
40
|
+
let jumping = false;
|
|
41
|
+
let coyote = 0;
|
|
42
|
+
let score = 0;
|
|
43
|
+
|
|
44
|
+
function solidAt(cx, cy) {
|
|
45
|
+
if (cx < 0 || cy < 0 || cx >= MAP_W || cy >= MAP_H) return true;
|
|
46
|
+
return tiles[cy * MAP_W + cx] === T_SOLID;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function tileAt(cx, cy) {
|
|
50
|
+
if (cx < 0 || cy < 0 || cx >= MAP_W || cy >= MAP_H) return T_SOLID;
|
|
51
|
+
return tiles[cy * MAP_W + cx];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function setTile(cx, cy, v) {
|
|
55
|
+
if (cx >= 0 && cy >= 0 && cx < MAP_W && cy < MAP_H) tiles[cy * MAP_W + cx] = v;
|
|
56
|
+
}
|
|
8
57
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
58
|
+
function buildLevel() {
|
|
59
|
+
tiles = [];
|
|
60
|
+
for (let i = 0; i < MAP_W * MAP_H; ++i) tiles.push(T_EMPTY);
|
|
61
|
+
|
|
62
|
+
const floor = MAP_H - 2;
|
|
63
|
+
|
|
64
|
+
// Ground with a couple of gaps
|
|
65
|
+
for (let x = 0; x < MAP_W; ++x) {
|
|
66
|
+
if ((x >= 12 && x <= 14) || (x >= 26 && x <= 28)) continue;
|
|
67
|
+
for (let y = floor; y < MAP_H; ++y) setTile(x, y, T_SOLID);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Platforms
|
|
71
|
+
for (let x = 8; x <= 12; ++x) setTile(x, floor - 4, T_SOLID);
|
|
72
|
+
for (let x = 18; x <= 22; ++x) setTile(x, floor - 5, T_SOLID);
|
|
73
|
+
for (let x = 30; x <= 35; ++x) setTile(x, floor - 4, T_SOLID);
|
|
74
|
+
|
|
75
|
+
// Coins
|
|
76
|
+
for (let x = 9; x <= 11; ++x) setTile(x, floor - 5, T_COIN);
|
|
77
|
+
for (let x = 19; x <= 21; ++x) setTile(x, floor - 6, T_COIN);
|
|
78
|
+
for (let x = 31; x <= 34; ++x) setTile(x, floor - 5, T_COIN);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function collideX() {
|
|
82
|
+
const left = math.flr(px / TILE);
|
|
83
|
+
const right = math.flr((px + 5) / TILE);
|
|
84
|
+
const top = math.flr(py / TILE);
|
|
85
|
+
const bot = math.flr((py + 6) / TILE);
|
|
86
|
+
for (let ty = top; ty <= bot; ++ty) {
|
|
87
|
+
if (solidAt(left, ty)) {
|
|
88
|
+
px = (left + 1) * TILE;
|
|
89
|
+
vx = 0;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (solidAt(right, ty)) {
|
|
93
|
+
px = right * TILE - 6;
|
|
94
|
+
vx = 0;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function collideY() {
|
|
101
|
+
const left = math.flr(px / TILE);
|
|
102
|
+
const right = math.flr((px + 5) / TILE);
|
|
103
|
+
const top = math.flr(py / TILE);
|
|
104
|
+
const bot = math.flr((py + 6) / TILE);
|
|
105
|
+
grounded = false;
|
|
106
|
+
if (vy < 0) {
|
|
107
|
+
for (let tx = left; tx <= right; ++tx) {
|
|
108
|
+
if (solidAt(tx, top)) {
|
|
109
|
+
py = (top + 1) * TILE;
|
|
110
|
+
vy = 0;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
for (let tx = left; tx <= right; ++tx) {
|
|
116
|
+
if (solidAt(tx, bot)) {
|
|
117
|
+
py = bot * TILE - 7;
|
|
118
|
+
vy = 0;
|
|
119
|
+
grounded = true;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
13
124
|
|
|
14
125
|
function _init() {
|
|
15
|
-
|
|
126
|
+
buildLevel();
|
|
127
|
+
py = (MAP_H - 4) * TILE;
|
|
16
128
|
}
|
|
17
129
|
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
vx *= FRICTION;
|
|
130
|
+
function _fixedUpdate(_dt) {
|
|
131
|
+
const running = input.btn("run");
|
|
132
|
+
const maxSpd = running ? RUN_MAX : WALK_MAX;
|
|
133
|
+
const accel = WALK_ACCEL;
|
|
23
134
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
135
|
+
if (input.btn("left") && !input.btn("right")) {
|
|
136
|
+
facing = -1;
|
|
137
|
+
vx = vx > 0 ? vx - SKID_DECEL : math.max(vx - accel, -maxSpd);
|
|
138
|
+
} else if (input.btn("right") && !input.btn("left")) {
|
|
139
|
+
facing = 1;
|
|
140
|
+
vx = vx < 0 ? vx + SKID_DECEL : math.min(vx + accel, maxSpd);
|
|
141
|
+
} else {
|
|
142
|
+
if (vx > 0) {
|
|
143
|
+
vx -= RELEASE_DECEL;
|
|
144
|
+
if (vx < 0) vx = 0;
|
|
145
|
+
} else if (vx < 0) {
|
|
146
|
+
vx += RELEASE_DECEL;
|
|
147
|
+
if (vx > 0) vx = 0;
|
|
148
|
+
}
|
|
28
149
|
}
|
|
29
150
|
|
|
30
|
-
//
|
|
31
|
-
vy +=
|
|
151
|
+
// Variable-height gravity
|
|
152
|
+
if (jumping && input.btn("jump") && vy < 0) vy += GRAV_HOLD;
|
|
153
|
+
else {
|
|
154
|
+
vy += GRAV_RELEASE;
|
|
155
|
+
jumping = false;
|
|
156
|
+
}
|
|
157
|
+
if (vy > MAX_FALL) vy = MAX_FALL;
|
|
32
158
|
|
|
33
|
-
// Simple floor collision at y = 140
|
|
34
159
|
px += vx;
|
|
160
|
+
collideX();
|
|
35
161
|
py += vy;
|
|
36
|
-
|
|
37
|
-
|
|
162
|
+
collideY();
|
|
163
|
+
if (px < 0) {
|
|
164
|
+
px = 0;
|
|
165
|
+
vx = 0;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (grounded) coyote = COYOTE_TICKS;
|
|
169
|
+
else if (coyote > 0) coyote--;
|
|
170
|
+
|
|
171
|
+
if (coyote > 0 && input.btnp("jump")) {
|
|
172
|
+
vy = JUMP_VEL;
|
|
173
|
+
jumping = true;
|
|
174
|
+
coyote = 0;
|
|
175
|
+
grounded = false;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Collect coins
|
|
179
|
+
const cx1 = math.flr(px / TILE);
|
|
180
|
+
const cx2 = math.flr((px + 5) / TILE);
|
|
181
|
+
const cy1 = math.flr(py / TILE);
|
|
182
|
+
const cy2 = math.flr((py + 6) / TILE);
|
|
183
|
+
for (let ty = cy1; ty <= cy2; ++ty) {
|
|
184
|
+
for (let tx = cx1; tx <= cx2; ++tx) {
|
|
185
|
+
if (tileAt(tx, ty) === T_COIN) {
|
|
186
|
+
setTile(tx, ty, T_EMPTY);
|
|
187
|
+
score += 10;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Respawn if fallen
|
|
193
|
+
if (py > MAP_H * TILE + 16) {
|
|
194
|
+
px = 16;
|
|
195
|
+
py = (MAP_H - 4) * TILE;
|
|
196
|
+
vx = 0;
|
|
38
197
|
vy = 0;
|
|
39
|
-
grounded = true;
|
|
40
198
|
}
|
|
41
199
|
}
|
|
42
200
|
|
|
43
201
|
function _draw() {
|
|
44
|
-
gfx.cls(
|
|
202
|
+
gfx.cls(12);
|
|
45
203
|
|
|
46
|
-
// Draw
|
|
47
|
-
|
|
204
|
+
// Draw tiles
|
|
205
|
+
for (let ty = 0; ty < MAP_H; ++ty) {
|
|
206
|
+
for (let tx = 0; tx < MAP_W; ++tx) {
|
|
207
|
+
const t = tileAt(tx, ty);
|
|
208
|
+
const x = tx * TILE;
|
|
209
|
+
const y = ty * TILE;
|
|
210
|
+
if (t === T_SOLID) {
|
|
211
|
+
gfx.rectfill(x, y, x + 7, y + 7, 4);
|
|
212
|
+
gfx.line(x, y, x + 7, y, 15);
|
|
213
|
+
} else if (t === T_COIN) {
|
|
214
|
+
const r = 2 + math.abs(math.sin(sys.time() * 4));
|
|
215
|
+
gfx.circfill(x + 4, y + 4, r, 10);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
48
219
|
|
|
49
220
|
// Draw player
|
|
50
|
-
|
|
221
|
+
const ipx = math.flr(px);
|
|
222
|
+
const ipy = math.flr(py);
|
|
223
|
+
gfx.rectfill(ipx, ipy + 2, ipx + 5, ipy + 6, 8);
|
|
224
|
+
gfx.rectfill(ipx + 1, ipy, ipx + 4, ipy + 2, 15);
|
|
225
|
+
gfx.line(ipx, ipy, ipx + 5, ipy, 8);
|
|
226
|
+
gfx.pset(facing > 0 ? ipx + 3 : ipx + 2, ipy + 1, 0);
|
|
51
227
|
|
|
52
|
-
|
|
228
|
+
// HUD
|
|
229
|
+
gfx.print("score: " + score, 4, 4, 7);
|
|
230
|
+
gfx.print("arrows: move z: jump x: run", 4, 170, 5);
|
|
53
231
|
}
|
package/templates/platformer.ts
CHANGED
|
@@ -1,53 +1,201 @@
|
|
|
1
|
-
// Platformer template —
|
|
1
|
+
// Platformer template — tile-based collision with acceleration physics
|
|
2
|
+
//
|
|
3
|
+
// Demonstrates:
|
|
4
|
+
// - Acceleration-based horizontal movement with run button
|
|
5
|
+
// - Variable-height jump (hold jump to go higher)
|
|
6
|
+
// - Tile-based collision with a simple level
|
|
7
|
+
// - Coyote time (jump grace period after leaving a ledge)
|
|
8
|
+
// - Collectible coins
|
|
9
|
+
//
|
|
10
|
+
// Extend this by adding enemies, more tile types, scrolling, etc.
|
|
2
11
|
|
|
3
|
-
|
|
4
|
-
|
|
12
|
+
const TILE = 8;
|
|
13
|
+
const MAP_W = 40; // level width in tiles
|
|
14
|
+
const MAP_H = 23; // level height in tiles (fits 180px)
|
|
15
|
+
|
|
16
|
+
// Physics
|
|
17
|
+
const WALK_ACCEL = 0.046875;
|
|
18
|
+
const SKID_DECEL = 0.15;
|
|
19
|
+
const RELEASE_DECEL = 0.046875;
|
|
20
|
+
const WALK_MAX = 0.75;
|
|
21
|
+
const RUN_MAX = 1.3;
|
|
22
|
+
const JUMP_VEL = -2.6;
|
|
23
|
+
const GRAV_HOLD = 0.11;
|
|
24
|
+
const GRAV_RELEASE = 0.375;
|
|
25
|
+
const MAX_FALL = 2.25;
|
|
26
|
+
const COYOTE_TICKS = 4;
|
|
27
|
+
|
|
28
|
+
// Tile types
|
|
29
|
+
const T_EMPTY = 0;
|
|
30
|
+
const T_SOLID = 1;
|
|
31
|
+
const T_COIN = 2;
|
|
32
|
+
|
|
33
|
+
let tiles: number[] = [];
|
|
34
|
+
let px = 16;
|
|
35
|
+
let py = 0;
|
|
5
36
|
let vx = 0;
|
|
6
37
|
let vy = 0;
|
|
7
38
|
let grounded = false;
|
|
39
|
+
let facing = 1;
|
|
40
|
+
let jumping = false;
|
|
41
|
+
let coyote = 0;
|
|
42
|
+
let score = 0;
|
|
43
|
+
|
|
44
|
+
function solidAt(cx: number, cy: number): boolean {
|
|
45
|
+
if (cx < 0 || cy < 0 || cx >= MAP_W || cy >= MAP_H) return true;
|
|
46
|
+
return tiles[cy * MAP_W + cx] === T_SOLID;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function tileAt(cx: number, cy: number): number {
|
|
50
|
+
if (cx < 0 || cy < 0 || cx >= MAP_W || cy >= MAP_H) return T_SOLID;
|
|
51
|
+
return tiles[cy * MAP_W + cx];
|
|
52
|
+
}
|
|
8
53
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
54
|
+
function setTile(cx: number, cy: number, v: number): void {
|
|
55
|
+
if (cx >= 0 && cy >= 0 && cx < MAP_W && cy < MAP_H)
|
|
56
|
+
tiles[cy * MAP_W + cx] = v;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function buildLevel(): void {
|
|
60
|
+
tiles = [];
|
|
61
|
+
for (let i = 0; i < MAP_W * MAP_H; ++i) tiles.push(T_EMPTY);
|
|
62
|
+
|
|
63
|
+
const floor = MAP_H - 2;
|
|
64
|
+
|
|
65
|
+
// Ground with a couple of gaps
|
|
66
|
+
for (let x = 0; x < MAP_W; ++x) {
|
|
67
|
+
if ((x >= 12 && x <= 14) || (x >= 26 && x <= 28)) continue;
|
|
68
|
+
for (let y = floor; y < MAP_H; ++y) setTile(x, y, T_SOLID);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Platforms
|
|
72
|
+
for (let x = 8; x <= 12; ++x) setTile(x, floor - 4, T_SOLID);
|
|
73
|
+
for (let x = 18; x <= 22; ++x) setTile(x, floor - 5, T_SOLID);
|
|
74
|
+
for (let x = 30; x <= 35; ++x) setTile(x, floor - 4, T_SOLID);
|
|
75
|
+
|
|
76
|
+
// Coins
|
|
77
|
+
for (let x = 9; x <= 11; ++x) { setTile(x, floor - 5, T_COIN); score--; }
|
|
78
|
+
for (let x = 19; x <= 21; ++x) { setTile(x, floor - 6, T_COIN); score--; }
|
|
79
|
+
for (let x = 31; x <= 34; ++x) { setTile(x, floor - 5, T_COIN); score--; }
|
|
80
|
+
score = 0; // reset — we just needed to count
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function collideX(): void {
|
|
84
|
+
const left = math.flr(px / TILE);
|
|
85
|
+
const right = math.flr((px + 5) / TILE);
|
|
86
|
+
const top = math.flr(py / TILE);
|
|
87
|
+
const bot = math.flr((py + 6) / TILE);
|
|
88
|
+
for (let ty = top; ty <= bot; ++ty) {
|
|
89
|
+
if (solidAt(left, ty)) { px = (left + 1) * TILE; vx = 0; return; }
|
|
90
|
+
if (solidAt(right, ty)) { px = right * TILE - 6; vx = 0; return; }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function collideY(): void {
|
|
95
|
+
const left = math.flr(px / TILE);
|
|
96
|
+
const right = math.flr((px + 5) / TILE);
|
|
97
|
+
const top = math.flr(py / TILE);
|
|
98
|
+
const bot = math.flr((py + 6) / TILE);
|
|
99
|
+
grounded = false;
|
|
100
|
+
if (vy < 0) {
|
|
101
|
+
for (let tx = left; tx <= right; ++tx) {
|
|
102
|
+
if (solidAt(tx, top)) { py = (top + 1) * TILE; vy = 0; return; }
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
for (let tx = left; tx <= right; ++tx) {
|
|
106
|
+
if (solidAt(tx, bot)) { py = bot * TILE - 7; vy = 0; grounded = true; return; }
|
|
107
|
+
}
|
|
108
|
+
}
|
|
13
109
|
|
|
14
110
|
export function _init(): void {
|
|
15
|
-
|
|
111
|
+
buildLevel();
|
|
112
|
+
py = (MAP_H - 4) * TILE;
|
|
16
113
|
}
|
|
17
114
|
|
|
18
|
-
export function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
vx *= FRICTION;
|
|
115
|
+
export function _fixedUpdate(_dt: number): void {
|
|
116
|
+
const running = input.btn('run');
|
|
117
|
+
const maxSpd = running ? RUN_MAX : WALK_MAX;
|
|
118
|
+
const accel = WALK_ACCEL;
|
|
23
119
|
|
|
24
|
-
|
|
25
|
-
|
|
120
|
+
if (input.btn('left') && !input.btn('right')) {
|
|
121
|
+
facing = -1;
|
|
122
|
+
vx = vx > 0 ? vx - SKID_DECEL : math.max(vx - accel, -maxSpd);
|
|
123
|
+
} else if (input.btn('right') && !input.btn('left')) {
|
|
124
|
+
facing = 1;
|
|
125
|
+
vx = vx < 0 ? vx + SKID_DECEL : math.min(vx + accel, maxSpd);
|
|
126
|
+
} else {
|
|
127
|
+
if (vx > 0) { vx -= RELEASE_DECEL; if (vx < 0) vx = 0; }
|
|
128
|
+
else if (vx < 0) { vx += RELEASE_DECEL; if (vx > 0) vx = 0; }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Variable-height gravity
|
|
132
|
+
if (jumping && input.btn('jump') && vy < 0) vy += GRAV_HOLD;
|
|
133
|
+
else { vy += GRAV_RELEASE; jumping = false; }
|
|
134
|
+
if (vy > MAX_FALL) vy = MAX_FALL;
|
|
135
|
+
|
|
136
|
+
px += vx; collideX();
|
|
137
|
+
py += vy; collideY();
|
|
138
|
+
if (px < 0) { px = 0; vx = 0; }
|
|
139
|
+
|
|
140
|
+
if (grounded) coyote = COYOTE_TICKS;
|
|
141
|
+
else if (coyote > 0) coyote--;
|
|
142
|
+
|
|
143
|
+
if (coyote > 0 && input.btnp('jump')) {
|
|
26
144
|
vy = JUMP_VEL;
|
|
145
|
+
jumping = true;
|
|
146
|
+
coyote = 0;
|
|
27
147
|
grounded = false;
|
|
28
148
|
}
|
|
29
149
|
|
|
30
|
-
//
|
|
31
|
-
|
|
150
|
+
// Collect coins
|
|
151
|
+
const cx1 = math.flr(px / TILE);
|
|
152
|
+
const cx2 = math.flr((px + 5) / TILE);
|
|
153
|
+
const cy1 = math.flr(py / TILE);
|
|
154
|
+
const cy2 = math.flr((py + 6) / TILE);
|
|
155
|
+
for (let ty = cy1; ty <= cy2; ++ty) {
|
|
156
|
+
for (let tx = cx1; tx <= cx2; ++tx) {
|
|
157
|
+
if (tileAt(tx, ty) === T_COIN) {
|
|
158
|
+
setTile(tx, ty, T_EMPTY);
|
|
159
|
+
score += 10;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
32
163
|
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
py = 140;
|
|
38
|
-
vy = 0;
|
|
39
|
-
grounded = true;
|
|
164
|
+
// Respawn if fallen
|
|
165
|
+
if (py > MAP_H * TILE + 16) {
|
|
166
|
+
px = 16; py = (MAP_H - 4) * TILE;
|
|
167
|
+
vx = 0; vy = 0;
|
|
40
168
|
}
|
|
41
169
|
}
|
|
42
170
|
|
|
43
171
|
export function _draw(): void {
|
|
44
|
-
gfx.cls(
|
|
172
|
+
gfx.cls(12);
|
|
45
173
|
|
|
46
|
-
// Draw
|
|
47
|
-
|
|
174
|
+
// Draw tiles
|
|
175
|
+
for (let ty = 0; ty < MAP_H; ++ty) {
|
|
176
|
+
for (let tx = 0; tx < MAP_W; ++tx) {
|
|
177
|
+
const t = tileAt(tx, ty);
|
|
178
|
+
const x = tx * TILE;
|
|
179
|
+
const y = ty * TILE;
|
|
180
|
+
if (t === T_SOLID) {
|
|
181
|
+
gfx.rectfill(x, y, x + 7, y + 7, 4);
|
|
182
|
+
gfx.line(x, y, x + 7, y, 15);
|
|
183
|
+
} else if (t === T_COIN) {
|
|
184
|
+
const r = 2 + math.abs(math.sin(sys.time() * 4));
|
|
185
|
+
gfx.circfill(x + 4, y + 4, r, 10);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
48
189
|
|
|
49
190
|
// Draw player
|
|
50
|
-
|
|
191
|
+
const ipx = math.flr(px);
|
|
192
|
+
const ipy = math.flr(py);
|
|
193
|
+
gfx.rectfill(ipx, ipy + 2, ipx + 5, ipy + 6, 8);
|
|
194
|
+
gfx.rectfill(ipx + 1, ipy, ipx + 4, ipy + 2, 15);
|
|
195
|
+
gfx.line(ipx, ipy, ipx + 5, ipy, 8);
|
|
196
|
+
gfx.pset(facing > 0 ? ipx + 3 : ipx + 2, ipy + 1, 0);
|
|
51
197
|
|
|
52
|
-
|
|
198
|
+
// HUD
|
|
199
|
+
gfx.print(`score: ${score}`, 4, 4, 7);
|
|
200
|
+
gfx.print('arrows: move z: jump x: run', 4, 170, 5);
|
|
53
201
|
}
|
package/types/dithr.d.ts
CHANGED
|
@@ -54,6 +54,10 @@ interface DithrSynthSfx {
|
|
|
54
54
|
speed: number;
|
|
55
55
|
loopStart: number;
|
|
56
56
|
loopEnd: number;
|
|
57
|
+
envAttack: number;
|
|
58
|
+
envDecay: number;
|
|
59
|
+
envSustain: number;
|
|
60
|
+
envRelease: number;
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
interface DithrTweenHandle {
|
|
@@ -102,6 +106,7 @@ interface DithrGfx {
|
|
|
102
106
|
|
|
103
107
|
// Sprites
|
|
104
108
|
spr(idx?: number, x?: number, y?: number, w?: number, h?: number, flip_x?: boolean, flip_y?: boolean): void;
|
|
109
|
+
sprBatch(data: Int32Array, count?: number): void;
|
|
105
110
|
sspr(sx?: number, sy?: number, sw?: number, sh?: number, dx?: number, dy?: number, dw?: number, dh?: number): void;
|
|
106
111
|
sprRot(idx?: number, x?: number, y?: number, angle?: number, cx?: number, cy?: number): void;
|
|
107
112
|
sprAffine(idx?: number, x?: number, y?: number, origin_x?: number, origin_y?: number, rot_x?: number, rot_y?: number): void;
|
|
@@ -615,6 +620,13 @@ interface DithrUi {
|
|
|
615
620
|
// tween — Tweening Engine
|
|
616
621
|
// ---------------------------------------------------------------------------
|
|
617
622
|
|
|
623
|
+
interface DithrTweenStepConfig {
|
|
624
|
+
from: number;
|
|
625
|
+
to: number;
|
|
626
|
+
dur: number;
|
|
627
|
+
ease?: string;
|
|
628
|
+
}
|
|
629
|
+
|
|
618
630
|
interface DithrTween {
|
|
619
631
|
start(from: number, to: number, dur: number, ease?: string, delay?: number): DithrTweenHandle;
|
|
620
632
|
tick(dt: number): void;
|
|
@@ -623,6 +635,11 @@ interface DithrTween {
|
|
|
623
635
|
cancel(handle_or_id: DithrTweenHandle | number): void;
|
|
624
636
|
cancelAll(): void;
|
|
625
637
|
ease(t: number, name: string): number;
|
|
638
|
+
sequence(steps: DithrTweenStepConfig[]): DithrTweenHandle;
|
|
639
|
+
parallel(steps: DithrTweenStepConfig[]): DithrTweenHandle;
|
|
640
|
+
seqVal(handle_or_id: DithrTweenHandle | number): number;
|
|
641
|
+
seqDone(handle_or_id: DithrTweenHandle | number): boolean;
|
|
642
|
+
seqCancel(handle_or_id: DithrTweenHandle | number): void;
|
|
626
643
|
}
|
|
627
644
|
|
|
628
645
|
// ---------------------------------------------------------------------------
|
|
@@ -642,7 +659,7 @@ interface DithrCam {
|
|
|
642
659
|
|
|
643
660
|
interface DithrSynth {
|
|
644
661
|
// Definitions
|
|
645
|
-
set(idx: number, notes: DithrSynthNote[], speed?: number, loopStart?: number, loopEnd?: number): boolean;
|
|
662
|
+
set(idx: number, notes: DithrSynthNote[], speed?: number, loopStart?: number, loopEnd?: number, envAttack?: number, envDecay?: number, envSustain?: number, envRelease?: number): boolean;
|
|
646
663
|
get(idx: number): DithrSynthSfx | undefined;
|
|
647
664
|
count(): number;
|
|
648
665
|
|