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
|
package djup
DELTA: f32 : 1.0 / 60.0
@(export = true)
sim_tick :: proc "c" (cur, next: ^Snapshot) {
if cur == nil || next == nil {
return
}
context = next.ctx^
next.tick = cur.tick + 1
copy(next.metadata, cur.metadata)
player_input_system(cur, next)
ball_movement_system(cur, next)
}
player_input_system :: proc(cur, next: ^Snapshot) {
for &e, id in soa_zip(m = cur.metadata, input = cur.player_inputs, ball = cur.balls) {
if e.m < {.Exists, .PlayerInput, .Ball} {
continue
}
PLAYER_ACCELERATION :: 1500
PLAYER_DRAG :: 2
acc :=
vec2_normal(e.input.direction) * PLAYER_ACCELERATION + e.ball.velocity * -PLAYER_DRAG
e.ball.velocity += acc * DELTA
next.player_inputs[id] = e.input
}
}
ball_movement_system :: proc(cur, next: ^Snapshot) {
for &e, id in soa_zip(m = cur.metadata, ball = cur.balls) {
if e.m < {.Exists, .Ball} {
continue
}
next.balls[id].position = e.ball.velocity * DELTA
next.balls[id].velocity = e.ball.velocity
}
}
|