-
Notifications
You must be signed in to change notification settings - Fork 0
/
kdemo.html
64 lines (64 loc) · 1.65 KB
/
kdemo.html
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
<body></body>
<script src="https://unpkg.com/[email protected]/dist/kaboom.js"></script>
<script>
kaboom({
crisp: true,
background: "#000000",
focus: false
});
setGravity(300);
const level = addLevel([
"==========================",
"= =",
"= =",
"= ===== =",
"= @ =",
"= ^^ ============",
"=============== "
], {
tileWidth: 16,
tileHeight: 16,
pos: vec2(20, 20),
tiles: {
"@": () => [
rect(15, 31),
area(),
body({ jumpForce: 150, maxVelocity: 400 }),
anchor("bot"),
color("#ff0000"),
z(Infinity),
"player"
],
"^": () => [
rect(16, 16),
area(),
anchor("bot"),
color("#ffff00"),
"coin"
],
"=": () => [
rect(16, 16),
area(),
body({ isStatic: true }),
anchor("bot"),
color("#0000ff"),
"ground"
],
}
});
const player = level.get("player")[0];
// ?!? hacky ?!?
player.vel = vec2(0, -100);
onKeyDown("up", () => {
if (player.isGrounded()) {
player.jump();
}
});
const SPEED = 64;
onKeyDown("left", () => {
player.move(-SPEED, 0);
});
onKeyDown("right", () => {
player.move(SPEED, 0);
});
</script>