-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
55 lines (48 loc) · 1.29 KB
/
Copy pathmain.go
File metadata and controls
55 lines (48 loc) · 1.29 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Using the raylib library to move a ball with the arrow keys.
//
// Usage:
//
// make example name=input
// ./build/input
//
// Source: https://github.com/raysan5/raylib/blob/master/examples/core/core_input_keys.c
package main
import (
"solod.dev/raylib/libraylib"
"solod.dev/so/c"
)
var _ c.Int // for implicit int -> c.Int conversion
const (
screenWidth = 800
screenHeight = 450
ballSpeed = 2.0
ballRadius = 50.0
)
func main() {
libraylib.InitWindow(screenWidth, screenHeight, "raylib - keyboard input")
defer libraylib.CloseWindow()
ball := libraylib.Vector2{X: screenWidth / 2, Y: screenHeight / 2}
libraylib.SetTargetFPS(60)
// Loop until the user closes the window.
for !libraylib.WindowShouldClose() {
// Move the ball.
if libraylib.IsKeyDown(libraylib.KEY_RIGHT) {
ball.X += ballSpeed
}
if libraylib.IsKeyDown(libraylib.KEY_LEFT) {
ball.X -= ballSpeed
}
if libraylib.IsKeyDown(libraylib.KEY_UP) {
ball.Y -= ballSpeed
}
if libraylib.IsKeyDown(libraylib.KEY_DOWN) {
ball.Y += ballSpeed
}
// Draw the scene.
libraylib.BeginDrawing()
libraylib.ClearBackground(libraylib.RAYWHITE)
libraylib.DrawText("move the ball with arrow keys", 10, 10, 20, libraylib.DARKGRAY)
libraylib.DrawCircleV(ball, ballRadius, libraylib.MAROON)
libraylib.EndDrawing()
}
}