-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.ts
85 lines (68 loc) · 1.58 KB
/
main_test.ts
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
import * as Valle from './mod.ts';
import { COLOR } from './mod.ts';
const app = new Valle.Application({
title: "Hello world",
height: 600,
width: 800
});
const context = app.context;
context.clearColor = [255,255,255]
let movementSpeed = 8;
const rect = new Valle.Rect();
rect.setSize(64, 64);
rect.color = COLOR.RED;
rect.position = {
x: rect.width / 2,
y: rect.height / 2
}
await context.draw(rect);
let gravity = 0.5;
let speed = 0.5;
let fallspeed = 0.5;
let y = gravity * speed / rect.height;
let falling = true;
let jumping = false;
app.on('update', async () => {
rect.setPosition({
y: y
})
if (rect.position.y > app.height - rect.height && jumping === false) {
falling = false;
}
if (falling === true && jumping === false) {
y += fallspeed;
console.log("Position : %s", y);
}
})
app.on('keyup', (e) => {
if (e.key === "Z") {
jumping = false;
}
});
app.on('keypress', (e) => {
if (e.key === "Z") {
jumping = true;
rect.position.y += 50
}
if (e.key === "X") {
rect.setSize((rect.position.x / 2) + rect.width + 1, (rect.position.y / 2) + rect.height + 1);
}
if (e.key === "D") {
let pos = rect.position.x + movementSpeed / 30 * 50;
rect.setPosition({
x: pos
});
} else if (e.key === "A") {
let pos = rect.position.x - movementSpeed / 30 * 50;
rect.setPosition({
x: pos
})
} else if (e.key === "S") {
let pos = rect.position.y + movementSpeed / 30 * 50;
rect.position.y = pos;
} else if (e.key === "W") {
let pos = rect.position.y - movementSpeed / 30 * 50;
rect.position.y = pos;
}
});
await app.run();