@dithrkit/sdk 0.1.0
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/bin/dithrkit.js +4 -0
- package/configs/eslint.config.js +96 -0
- package/configs/tsconfig.base.json +13 -0
- package/lib/binary.js +33 -0
- package/lib/build-helper.js +82 -0
- package/lib/cli.js +91 -0
- package/lib/commands/build.js +74 -0
- package/lib/commands/create.js +235 -0
- package/lib/commands/dev.js +145 -0
- package/lib/commands/export.js +164 -0
- package/lib/commands/run.js +83 -0
- package/lib/commands/serve.js +165 -0
- package/lib/commands/watch.js +447 -0
- package/lib/packager.js +159 -0
- package/package.json +52 -0
- package/templates/blank.js +14 -0
- package/templates/blank.ts +14 -0
- package/templates/platformer.js +53 -0
- package/templates/platformer.ts +53 -0
- package/templates/shell.html +77 -0
- package/types/dithr.d.ts +700 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Platformer template — simple gravity + tile collision
|
|
2
|
+
|
|
3
|
+
let px = 64;
|
|
4
|
+
let py = 64;
|
|
5
|
+
let vx = 0;
|
|
6
|
+
let vy = 0;
|
|
7
|
+
let grounded = false;
|
|
8
|
+
|
|
9
|
+
const GRAVITY = 0.4;
|
|
10
|
+
const JUMP_VEL = -5.0;
|
|
11
|
+
const MOVE_SPD = 2.0;
|
|
12
|
+
const FRICTION = 0.8;
|
|
13
|
+
|
|
14
|
+
function _init() {
|
|
15
|
+
gfx.cls(0);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _update(dt) {
|
|
19
|
+
// Horizontal movement
|
|
20
|
+
if (input.btn("left")) vx -= MOVE_SPD;
|
|
21
|
+
if (input.btn("right")) vx += MOVE_SPD;
|
|
22
|
+
vx *= FRICTION;
|
|
23
|
+
|
|
24
|
+
// Jump
|
|
25
|
+
if (grounded && input.btnp("jump")) {
|
|
26
|
+
vy = JUMP_VEL;
|
|
27
|
+
grounded = false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Gravity
|
|
31
|
+
vy += GRAVITY;
|
|
32
|
+
|
|
33
|
+
// Simple floor collision at y = 140
|
|
34
|
+
px += vx;
|
|
35
|
+
py += vy;
|
|
36
|
+
if (py >= 140) {
|
|
37
|
+
py = 140;
|
|
38
|
+
vy = 0;
|
|
39
|
+
grounded = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function _draw() {
|
|
44
|
+
gfx.cls(1);
|
|
45
|
+
|
|
46
|
+
// Draw ground
|
|
47
|
+
gfx.rectfill(0, 148, sys.width() - 1, 180, 3);
|
|
48
|
+
|
|
49
|
+
// Draw player
|
|
50
|
+
gfx.rectfill(math.flr(px), math.flr(py), math.flr(px) + 8, math.flr(py) + 8, 11);
|
|
51
|
+
|
|
52
|
+
gfx.print("arrows/wasd: move z/space: jump", 4, 4, 7);
|
|
53
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Platformer template — simple gravity + tile collision
|
|
2
|
+
|
|
3
|
+
let px = 64;
|
|
4
|
+
let py = 64;
|
|
5
|
+
let vx = 0;
|
|
6
|
+
let vy = 0;
|
|
7
|
+
let grounded = false;
|
|
8
|
+
|
|
9
|
+
const GRAVITY = 0.4;
|
|
10
|
+
const JUMP_VEL = -5.0;
|
|
11
|
+
const MOVE_SPD = 2.0;
|
|
12
|
+
const FRICTION = 0.8;
|
|
13
|
+
|
|
14
|
+
export function _init(): void {
|
|
15
|
+
gfx.cls(0);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function _update(dt: number): void {
|
|
19
|
+
// Horizontal movement
|
|
20
|
+
if (input.btn('left')) vx -= MOVE_SPD;
|
|
21
|
+
if (input.btn('right')) vx += MOVE_SPD;
|
|
22
|
+
vx *= FRICTION;
|
|
23
|
+
|
|
24
|
+
// Jump
|
|
25
|
+
if (grounded && input.btnp('jump')) {
|
|
26
|
+
vy = JUMP_VEL;
|
|
27
|
+
grounded = false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Gravity
|
|
31
|
+
vy += GRAVITY;
|
|
32
|
+
|
|
33
|
+
// Simple floor collision at y = 140
|
|
34
|
+
px += vx;
|
|
35
|
+
py += vy;
|
|
36
|
+
if (py >= 140) {
|
|
37
|
+
py = 140;
|
|
38
|
+
vy = 0;
|
|
39
|
+
grounded = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function _draw(): void {
|
|
44
|
+
gfx.cls(1);
|
|
45
|
+
|
|
46
|
+
// Draw ground
|
|
47
|
+
gfx.rectfill(0, 148, sys.width() - 1, 180, 3);
|
|
48
|
+
|
|
49
|
+
// Draw player
|
|
50
|
+
gfx.rectfill(math.flr(px), math.flr(py), math.flr(px) + 8, math.flr(py) + 8, 11);
|
|
51
|
+
|
|
52
|
+
gfx.print('arrows/wasd: move z/space: jump', 4, 4, 7);
|
|
53
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
|
6
|
+
<title>dithr</title>
|
|
7
|
+
<style>
|
|
8
|
+
html, body {
|
|
9
|
+
margin: 0; padding: 0; width: 100%; height: 100%;
|
|
10
|
+
background: #111; overflow: hidden;
|
|
11
|
+
}
|
|
12
|
+
canvas#canvas {
|
|
13
|
+
display: block; margin: auto;
|
|
14
|
+
image-rendering: pixelated;
|
|
15
|
+
image-rendering: crisp-edges;
|
|
16
|
+
}
|
|
17
|
+
#splash {
|
|
18
|
+
position: fixed; inset: 0; display: flex; align-items: center;
|
|
19
|
+
justify-content: center; flex-direction: column;
|
|
20
|
+
background: #111; color: #aaa; font: 1rem monospace;
|
|
21
|
+
z-index: 10; cursor: pointer;
|
|
22
|
+
}
|
|
23
|
+
#splash.hidden { display: none; }
|
|
24
|
+
#progress-bar {
|
|
25
|
+
width: 200px; height: 4px; background: #333; margin-top: 12px;
|
|
26
|
+
border-radius: 2px; overflow: hidden;
|
|
27
|
+
}
|
|
28
|
+
#progress-fill {
|
|
29
|
+
width: 0%; height: 100%; background: #6cf; transition: width 0.2s;
|
|
30
|
+
}
|
|
31
|
+
#touch-start {
|
|
32
|
+
display: none; margin-top: 16px; color: #ccc; font-size: 0.9rem;
|
|
33
|
+
}
|
|
34
|
+
</style>
|
|
35
|
+
</head>
|
|
36
|
+
<body>
|
|
37
|
+
<div id="splash">
|
|
38
|
+
<div>loading…</div>
|
|
39
|
+
<div id="progress-bar"><div id="progress-fill"></div></div>
|
|
40
|
+
<div id="touch-start">tap to start</div>
|
|
41
|
+
</div>
|
|
42
|
+
<canvas id="canvas" oncontextmenu="event.preventDefault()" tabindex="-1"></canvas>
|
|
43
|
+
|
|
44
|
+
<script>
|
|
45
|
+
var Module = {
|
|
46
|
+
canvas: document.getElementById("canvas"),
|
|
47
|
+
setStatus: function(text) {
|
|
48
|
+
// Emscripten calls this with "Downloading data... (x/y)" or ""
|
|
49
|
+
var m = text.match(/(\d+)\/(\d+)/);
|
|
50
|
+
var fill = document.getElementById("progress-fill");
|
|
51
|
+
if (m) {
|
|
52
|
+
var pct = (parseInt(m[1]) / parseInt(m[2]) * 100).toFixed(0);
|
|
53
|
+
if (fill) fill.style.width = pct + "%";
|
|
54
|
+
} else if (text === "") {
|
|
55
|
+
// Loading complete
|
|
56
|
+
if (fill) fill.style.width = "100%";
|
|
57
|
+
var splash = document.getElementById("splash");
|
|
58
|
+
if ("ontouchstart" in window) {
|
|
59
|
+
document.getElementById("touch-start").style.display = "block";
|
|
60
|
+
splash.addEventListener("click", function() {
|
|
61
|
+
splash.classList.add("hidden");
|
|
62
|
+
});
|
|
63
|
+
splash.addEventListener("touchend", function() {
|
|
64
|
+
splash.classList.add("hidden");
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
splash.classList.add("hidden");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
</script>
|
|
73
|
+
|
|
74
|
+
{{{ SCRIPT }}}
|
|
75
|
+
|
|
76
|
+
</body>
|
|
77
|
+
</html>
|