| 1 | import gg |
| 2 | |
| 3 | struct App { |
| 4 | mut: |
| 5 | x f64 = 100.0 |
| 6 | y f64 = 100.0 |
| 7 | } |
| 8 | |
| 9 | mut app := &App{} |
| 10 | gg.start( |
| 11 | window_title: 'Moving Square' |
| 12 | width: 640 |
| 13 | height: 480 |
| 14 | update_fn: fn [mut app] (dt f32, ctx &gg.Context) { |
| 15 | println(' frame: ${ctx.frame:6} | dt: ${dt:9.6f}s') |
| 16 | if ctx.pressed_keys[gg.KeyCode.right] { |
| 17 | app.x = app.x + 200 * dt |
| 18 | } |
| 19 | if ctx.pressed_keys[gg.KeyCode.left] { |
| 20 | app.x = app.x - 200 * dt |
| 21 | } |
| 22 | if ctx.pressed_keys[gg.KeyCode.down] { |
| 23 | app.y = app.y + 200 * dt |
| 24 | } |
| 25 | if ctx.pressed_keys[gg.KeyCode.up] { |
| 26 | app.y = app.y - 200 * dt |
| 27 | } |
| 28 | } |
| 29 | frame_fn: fn [mut app] (ctx &gg.Context) { |
| 30 | ctx.begin() |
| 31 | ctx.draw_rect_filled(int(app.x), int(app.y), 50, 50, gg.red) |
| 32 | ctx.end() |
| 33 | } |
| 34 | ) |
| 35 | |