-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (41 loc) · 1.35 KB
/
Copy pathmain.go
File metadata and controls
50 lines (41 loc) · 1.35 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
// Using the raymath vector functions to bounce a ball around the window.
//
// Usage:
//
// ./build/vector
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
radius = 30
)
func main() {
libraylib.InitWindow(screenWidth, screenHeight, "raylib - vector math")
defer libraylib.CloseWindow()
pos := libraylib.Vector2{X: screenWidth / 2, Y: screenHeight / 2}
speed := libraylib.Vector2{X: 320, Y: 240}
libraylib.SetTargetFPS(60)
// Loop until the user closes the window.
for !libraylib.WindowShouldClose() {
// Move the ball by speed * elapsed time.
dt := libraylib.GetFrameTime()
pos = libraylib.Vector2Add(pos, libraylib.Vector2Scale(speed, dt))
// Reflect off the walls the ball has reached.
if pos.X-radius <= 0 || pos.X+radius >= screenWidth {
speed = libraylib.Vector2Reflect(speed, libraylib.Vector2{X: 1, Y: 0})
}
if pos.Y-radius <= 0 || pos.Y+radius >= screenHeight {
speed = libraylib.Vector2Reflect(speed, libraylib.Vector2{X: 0, Y: 1})
}
libraylib.BeginDrawing()
libraylib.ClearBackground(libraylib.RAYWHITE)
libraylib.DrawCircleV(pos, radius, libraylib.MAROON)
libraylib.DrawText("Vector2Add, Vector2Scale and Vector2Reflect from raymath.h", 20, 20, 20, libraylib.DARKGRAY)
libraylib.EndDrawing()
}
}