refactor: restructure the project
This commit is contained in:
2
languages/go/Makefile
Normal file
2
languages/go/Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
raylib_go: main.go
|
||||
go build -o raylib_go main.go
|
||||
8
languages/go/README.md
Normal file
8
languages/go/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Raylib in Go
|
||||
|
||||
## Quick start
|
||||
|
||||
```sh
|
||||
$ make
|
||||
$ ./raylib_go
|
||||
```
|
||||
BIN
languages/go/go_logo.png
Normal file
BIN
languages/go/go_logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
66
languages/go/main.go
Normal file
66
languages/go/main.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -I../raylib-5.5_linux_amd64/include
|
||||
#cgo LDFLAGS: -L../raylib-5.5_linux_amd64/lib -l:libraylib.a -lm
|
||||
#include <raylib.h>
|
||||
*/
|
||||
import "C"
|
||||
import "time"
|
||||
|
||||
const (
|
||||
windowWidth = 800
|
||||
windowHeight = 600
|
||||
logoHeight = 64
|
||||
logoSpeed = 300.0
|
||||
)
|
||||
|
||||
func main() {
|
||||
C.InitWindow(windowWidth, windowHeight, C.CString("Raylib in Go"))
|
||||
C.SetTargetFPS(60)
|
||||
C.SetRandomSeed(C.uint(time.Now().Unix()))
|
||||
|
||||
logoImage := C.LoadImage(C.CString("./go_logo.png"))
|
||||
C.ImageResize(&logoImage, logoImage.width*logoHeight/logoImage.height, logoHeight)
|
||||
logoTexture := C.LoadTextureFromImage(logoImage)
|
||||
C.UnloadImage(logoImage)
|
||||
|
||||
x := float32(C.GetRandomValue(0, windowWidth-C.int(logoTexture.width)))
|
||||
y := float32(C.GetRandomValue(0, windowHeight-C.int(logoTexture.height)))
|
||||
|
||||
dx := float32(logoSpeed)
|
||||
if C.GetRandomValue(0, 1) == 1 {
|
||||
dx = -dx
|
||||
}
|
||||
dy := float32(logoSpeed)
|
||||
if C.GetRandomValue(0, 1) == 1 {
|
||||
dy = -dy
|
||||
}
|
||||
|
||||
black := C.Color{0, 0, 0, 255}
|
||||
white := C.Color{255, 255, 255, 255}
|
||||
|
||||
for !bool(C.WindowShouldClose()) {
|
||||
deltaTime := float32(C.GetFrameTime())
|
||||
|
||||
x += dx * deltaTime
|
||||
y += dy * deltaTime
|
||||
|
||||
if x < 0 || x+float32(logoTexture.width) >= windowWidth-1 {
|
||||
dx *= -1
|
||||
x += dx * deltaTime
|
||||
}
|
||||
if y < 0 || y+float32(logoTexture.height) >= windowHeight-1 {
|
||||
dy *= -1
|
||||
y += dy * deltaTime
|
||||
}
|
||||
|
||||
C.BeginDrawing()
|
||||
C.ClearBackground(black)
|
||||
C.DrawTextureV(logoTexture, C.Vector2{x: C.float(x), y: C.float(y)}, white)
|
||||
C.EndDrawing()
|
||||
}
|
||||
|
||||
C.UnloadTexture(logoTexture)
|
||||
C.CloseWindow()
|
||||
}
|
||||
Reference in New Issue
Block a user