diff options
Diffstat (limited to 'lib/systems.odin')
| -rw-r--r-- | lib/systems.odin | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/systems.odin b/lib/systems.odin new file mode 100644 index 0000000..288bd01 --- /dev/null +++ b/lib/systems.odin @@ -0,0 +1,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 + } +} |
