-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcore-input-keys.rkt
More file actions
executable file
·33 lines (23 loc) · 1.03 KB
/
core-input-keys.rkt
File metadata and controls
executable file
·33 lines (23 loc) · 1.03 KB
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
#!/usr/bin/env racket
#lang racket/base
;; https://github.com/raysan5/raylib/blob/master/examples/core/core_input_keys.c
(module+ main
(require raylib/2d/unsafe)
(define screen-width 800)
(define screen-height 450)
(InitWindow 800 450 "raylib [core] example - keyboard input")
(define ball-position (make-Vector2 (/ screen-width 2.0) (/ screen-height 2.0)))
(SetTargetFPS 60)
(let loop ()
(when (not (WindowShouldClose))
(when (IsKeyDown KEY_RIGHT) (set-Vector2-x! ball-position (+ (Vector2-x ball-position) 2)))
(when (IsKeyDown KEY_LEFT) (set-Vector2-x! ball-position (- (Vector2-x ball-position) 2)))
(when (IsKeyDown KEY_DOWN) (set-Vector2-y! ball-position (+ (Vector2-y ball-position) 2)))
(when (IsKeyDown KEY_UP) (set-Vector2-y! ball-position (- (Vector2-y ball-position) 2)))
(BeginDrawing)
(ClearBackground RAYWHITE)
(DrawText "move the ball with arrow keys" 10 10 20 DARKGRAY)
(DrawCircleV ball-position 50.0 MAROON)
(EndDrawing)
(loop)))
(CloseWindow))