Update C sources, add new functions and rename package to
This commit is contained in:
parent
391c25482d
commit
08aa518a46
156 changed files with 34542 additions and 19573 deletions
|
@ -12,54 +12,54 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera")
|
||||
|
||||
player := raylib.NewRectangle(400, 280, 40, 40)
|
||||
player := rl.NewRectangle(400, 280, 40, 40)
|
||||
|
||||
buildings := make([]raylib.Rectangle, maxBuildings)
|
||||
buildColors := make([]raylib.Color, maxBuildings)
|
||||
buildings := make([]rl.Rectangle, maxBuildings)
|
||||
buildColors := make([]rl.Color, maxBuildings)
|
||||
|
||||
spacing := float32(0)
|
||||
|
||||
for i := 0; i < maxBuildings; i++ {
|
||||
r := raylib.Rectangle{}
|
||||
r.Width = float32(raylib.GetRandomValue(50, 200))
|
||||
r.Height = float32(raylib.GetRandomValue(100, 800))
|
||||
r := rl.Rectangle{}
|
||||
r.Width = float32(rl.GetRandomValue(50, 200))
|
||||
r.Height = float32(rl.GetRandomValue(100, 800))
|
||||
r.Y = float32(screenHeight) - 130 - r.Height
|
||||
r.X = -6000 + spacing
|
||||
|
||||
spacing += r.Width
|
||||
|
||||
c := raylib.NewColor(byte(raylib.GetRandomValue(200, 240)), byte(raylib.GetRandomValue(200, 240)), byte(raylib.GetRandomValue(200, 250)), byte(255))
|
||||
c := rl.NewColor(byte(rl.GetRandomValue(200, 240)), byte(rl.GetRandomValue(200, 240)), byte(rl.GetRandomValue(200, 250)), byte(255))
|
||||
|
||||
buildings[i] = r
|
||||
buildColors[i] = c
|
||||
}
|
||||
|
||||
camera := raylib.Camera2D{}
|
||||
camera.Target = raylib.NewVector2(float32(player.X+20), float32(player.Y+20))
|
||||
camera.Offset = raylib.NewVector2(0, 0)
|
||||
camera := rl.Camera2D{}
|
||||
camera.Target = rl.NewVector2(float32(player.X+20), float32(player.Y+20))
|
||||
camera.Offset = rl.NewVector2(0, 0)
|
||||
camera.Rotation = 0.0
|
||||
camera.Zoom = 1.0
|
||||
|
||||
raylib.SetTargetFPS(30)
|
||||
rl.SetTargetFPS(30)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsKeyDown(raylib.KeyRight) {
|
||||
for !rl.WindowShouldClose() {
|
||||
if rl.IsKeyDown(rl.KeyRight) {
|
||||
player.X += 2 // Player movement
|
||||
camera.Offset.X -= 2 // Camera displacement with player movement
|
||||
} else if raylib.IsKeyDown(raylib.KeyLeft) {
|
||||
} else if rl.IsKeyDown(rl.KeyLeft) {
|
||||
player.X -= 2 // Player movement
|
||||
camera.Offset.X += 2 // Camera displacement with player movement
|
||||
}
|
||||
|
||||
// Camera target follows player
|
||||
camera.Target = raylib.NewVector2(float32(player.X+20), float32(player.Y+20))
|
||||
camera.Target = rl.NewVector2(float32(player.X+20), float32(player.Y+20))
|
||||
|
||||
// Camera rotation controls
|
||||
if raylib.IsKeyDown(raylib.KeyA) {
|
||||
if rl.IsKeyDown(rl.KeyA) {
|
||||
camera.Rotation--
|
||||
} else if raylib.IsKeyDown(raylib.KeyS) {
|
||||
} else if rl.IsKeyDown(rl.KeyS) {
|
||||
camera.Rotation++
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ func main() {
|
|||
}
|
||||
|
||||
// Camera zoom controls
|
||||
camera.Zoom += float32(raylib.GetMouseWheelMove()) * 0.05
|
||||
camera.Zoom += float32(rl.GetMouseWheelMove()) * 0.05
|
||||
|
||||
if camera.Zoom > 3.0 {
|
||||
camera.Zoom = 3.0
|
||||
|
@ -80,48 +80,48 @@ func main() {
|
|||
}
|
||||
|
||||
// Camera reset (zoom and rotation)
|
||||
if raylib.IsKeyPressed(raylib.KeyR) {
|
||||
if rl.IsKeyPressed(rl.KeyR) {
|
||||
camera.Zoom = 1.0
|
||||
camera.Rotation = 0.0
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.BeginMode2D(camera)
|
||||
rl.BeginMode2D(camera)
|
||||
|
||||
raylib.DrawRectangle(-6000, 320, 13000, 8000, raylib.DarkGray)
|
||||
rl.DrawRectangle(-6000, 320, 13000, 8000, rl.DarkGray)
|
||||
|
||||
for i := 0; i < maxBuildings; i++ {
|
||||
raylib.DrawRectangleRec(buildings[i], buildColors[i])
|
||||
rl.DrawRectangleRec(buildings[i], buildColors[i])
|
||||
}
|
||||
|
||||
raylib.DrawRectangleRec(player, raylib.Red)
|
||||
rl.DrawRectangleRec(player, rl.Red)
|
||||
|
||||
raylib.DrawRectangle(int32(camera.Target.X), -500, 1, screenHeight*4, raylib.Green)
|
||||
raylib.DrawRectangle(-500, int32(camera.Target.Y), screenWidth*4, 1, raylib.Green)
|
||||
rl.DrawRectangle(int32(camera.Target.X), -500, 1, screenHeight*4, rl.Green)
|
||||
rl.DrawRectangle(-500, int32(camera.Target.Y), screenWidth*4, 1, rl.Green)
|
||||
|
||||
raylib.EndMode2D()
|
||||
rl.EndMode2D()
|
||||
|
||||
raylib.DrawText("SCREEN AREA", 640, 10, 20, raylib.Red)
|
||||
rl.DrawText("SCREEN AREA", 640, 10, 20, rl.Red)
|
||||
|
||||
raylib.DrawRectangle(0, 0, screenWidth, 5, raylib.Red)
|
||||
raylib.DrawRectangle(0, 5, 5, screenHeight-10, raylib.Red)
|
||||
raylib.DrawRectangle(screenWidth-5, 5, 5, screenHeight-10, raylib.Red)
|
||||
raylib.DrawRectangle(0, screenHeight-5, screenWidth, 5, raylib.Red)
|
||||
rl.DrawRectangle(0, 0, screenWidth, 5, rl.Red)
|
||||
rl.DrawRectangle(0, 5, 5, screenHeight-10, rl.Red)
|
||||
rl.DrawRectangle(screenWidth-5, 5, 5, screenHeight-10, rl.Red)
|
||||
rl.DrawRectangle(0, screenHeight-5, screenWidth, 5, rl.Red)
|
||||
|
||||
raylib.DrawRectangle(10, 10, 250, 113, raylib.Fade(raylib.SkyBlue, 0.5))
|
||||
raylib.DrawRectangleLines(10, 10, 250, 113, raylib.Blue)
|
||||
rl.DrawRectangle(10, 10, 250, 113, rl.Fade(rl.SkyBlue, 0.5))
|
||||
rl.DrawRectangleLines(10, 10, 250, 113, rl.Blue)
|
||||
|
||||
raylib.DrawText("Free 2d camera controls:", 20, 20, 10, raylib.Black)
|
||||
raylib.DrawText("- Right/Left to move Offset", 40, 40, 10, raylib.DarkGray)
|
||||
raylib.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, raylib.DarkGray)
|
||||
raylib.DrawText("- A / S to Rotate", 40, 80, 10, raylib.DarkGray)
|
||||
raylib.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, raylib.DarkGray)
|
||||
rl.DrawText("Free 2d camera controls:", 20, 20, 10, rl.Black)
|
||||
rl.DrawText("- Right/Left to move Offset", 40, 40, 10, rl.DarkGray)
|
||||
rl.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, rl.DarkGray)
|
||||
rl.DrawText("- A / S to Rotate", 40, 80, 10, rl.DarkGray)
|
||||
rl.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, rl.DarkGray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -9,61 +9,61 @@ const (
|
|||
)
|
||||
|
||||
func main() {
|
||||
raylib.InitWindow(800, 450, "raylib [core] example - 3d camera first person")
|
||||
rl.InitWindow(800, 450, "raylib [core] example - 3d camera first person")
|
||||
|
||||
camera := raylib.Camera3D{}
|
||||
camera.Position = raylib.NewVector3(4.0, 2.0, 4.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 1.8, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera := rl.Camera3D{}
|
||||
camera.Position = rl.NewVector3(4.0, 2.0, 4.0)
|
||||
camera.Target = rl.NewVector3(0.0, 1.8, 0.0)
|
||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 60.0
|
||||
camera.Type = raylib.CameraPerspective
|
||||
camera.Type = rl.CameraPerspective
|
||||
|
||||
// Generates some random columns
|
||||
heights := make([]float32, maxColumns)
|
||||
positions := make([]raylib.Vector3, maxColumns)
|
||||
colors := make([]raylib.Color, maxColumns)
|
||||
positions := make([]rl.Vector3, maxColumns)
|
||||
colors := make([]rl.Color, maxColumns)
|
||||
|
||||
for i := 0; i < maxColumns; i++ {
|
||||
heights[i] = float32(raylib.GetRandomValue(1, 12))
|
||||
positions[i] = raylib.NewVector3(float32(raylib.GetRandomValue(-15, 15)), heights[i]/2, float32(raylib.GetRandomValue(-15, 15)))
|
||||
colors[i] = raylib.NewColor(uint8(raylib.GetRandomValue(20, 255)), uint8(raylib.GetRandomValue(10, 55)), 30, 255)
|
||||
heights[i] = float32(rl.GetRandomValue(1, 12))
|
||||
positions[i] = rl.NewVector3(float32(rl.GetRandomValue(-15, 15)), heights[i]/2, float32(rl.GetRandomValue(-15, 15)))
|
||||
colors[i] = rl.NewColor(uint8(rl.GetRandomValue(20, 255)), uint8(rl.GetRandomValue(10, 55)), 30, 255)
|
||||
}
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraFirstPerson) // Set a first person camera mode
|
||||
rl.SetCameraMode(camera, rl.CameraFirstPerson) // Set a first person camera mode
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.UpdateCamera(&camera) // Update camera
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.UpdateCamera(&camera) // Update camera
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.BeginMode3D(camera)
|
||||
rl.BeginMode3D(camera)
|
||||
|
||||
raylib.DrawPlane(raylib.NewVector3(0.0, 0.0, 0.0), raylib.NewVector2(32.0, 32.0), raylib.LightGray) // Draw ground
|
||||
raylib.DrawCube(raylib.NewVector3(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, raylib.Blue) // Draw a blue wall
|
||||
raylib.DrawCube(raylib.NewVector3(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, raylib.Lime) // Draw a green wall
|
||||
raylib.DrawCube(raylib.NewVector3(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, raylib.Gold) // Draw a yellow wall
|
||||
rl.DrawPlane(rl.NewVector3(0.0, 0.0, 0.0), rl.NewVector2(32.0, 32.0), rl.LightGray) // Draw ground
|
||||
rl.DrawCube(rl.NewVector3(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Blue) // Draw a blue wall
|
||||
rl.DrawCube(rl.NewVector3(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Lime) // Draw a green wall
|
||||
rl.DrawCube(rl.NewVector3(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, rl.Gold) // Draw a yellow wall
|
||||
|
||||
// Draw some cubes around
|
||||
for i := 0; i < maxColumns; i++ {
|
||||
raylib.DrawCube(positions[i], 2.0, heights[i], 2.0, colors[i])
|
||||
raylib.DrawCubeWires(positions[i], 2.0, heights[i], 2.0, raylib.Maroon)
|
||||
rl.DrawCube(positions[i], 2.0, heights[i], 2.0, colors[i])
|
||||
rl.DrawCubeWires(positions[i], 2.0, heights[i], 2.0, rl.Maroon)
|
||||
}
|
||||
|
||||
raylib.EndMode3D()
|
||||
rl.EndMode3D()
|
||||
|
||||
raylib.DrawRectangle(10, 10, 220, 70, raylib.Fade(raylib.SkyBlue, 0.5))
|
||||
raylib.DrawRectangleLines(10, 10, 220, 70, raylib.Blue)
|
||||
rl.DrawRectangle(10, 10, 220, 70, rl.Fade(rl.SkyBlue, 0.5))
|
||||
rl.DrawRectangleLines(10, 10, 220, 70, rl.Blue)
|
||||
|
||||
raylib.DrawText("First person camera default controls:", 20, 20, 10, raylib.Black)
|
||||
raylib.DrawText("- Move with keys: W, A, S, D", 40, 40, 10, raylib.DarkGray)
|
||||
raylib.DrawText("- Mouse move to look around", 40, 60, 10, raylib.DarkGray)
|
||||
rl.DrawText("First person camera default controls:", 20, 20, 10, rl.Black)
|
||||
rl.DrawText("- Move with keys: W, A, S, D", 40, 40, 10, rl.DarkGray)
|
||||
rl.DrawText("- Mouse move to look around", 40, 60, 10, rl.DarkGray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -5,53 +5,53 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
raylib.InitWindow(800, 450, "raylib [core] example - 3d camera free")
|
||||
rl.InitWindow(800, 450, "raylib [core] example - 3d camera free")
|
||||
|
||||
camera := raylib.Camera3D{}
|
||||
camera.Position = raylib.NewVector3(10.0, 10.0, 10.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera := rl.Camera3D{}
|
||||
camera.Position = rl.NewVector3(10.0, 10.0, 10.0)
|
||||
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
camera.Type = raylib.CameraPerspective
|
||||
camera.Type = rl.CameraPerspective
|
||||
|
||||
cubePosition := raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
cubePosition := rl.NewVector3(0.0, 0.0, 0.0)
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraFree) // Set a free camera mode
|
||||
rl.SetCameraMode(camera, rl.CameraFree) // Set a free camera mode
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.UpdateCamera(&camera) // Update camera
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.UpdateCamera(&camera) // Update camera
|
||||
|
||||
if raylib.IsKeyDown(raylib.KeyZ) {
|
||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
if rl.IsKeyDown(rl.KeyZ) {
|
||||
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.BeginMode3D(camera)
|
||||
rl.BeginMode3D(camera)
|
||||
|
||||
raylib.DrawCube(cubePosition, 2.0, 2.0, 2.0, raylib.Red)
|
||||
raylib.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, raylib.Maroon)
|
||||
rl.DrawCube(cubePosition, 2.0, 2.0, 2.0, rl.Red)
|
||||
rl.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, rl.Maroon)
|
||||
|
||||
raylib.DrawGrid(10, 1.0)
|
||||
rl.DrawGrid(10, 1.0)
|
||||
|
||||
raylib.EndMode3D()
|
||||
rl.EndMode3D()
|
||||
|
||||
raylib.DrawRectangle(10, 10, 320, 133, raylib.Fade(raylib.SkyBlue, 0.5))
|
||||
raylib.DrawRectangleLines(10, 10, 320, 133, raylib.Blue)
|
||||
rl.DrawRectangle(10, 10, 320, 133, rl.Fade(rl.SkyBlue, 0.5))
|
||||
rl.DrawRectangleLines(10, 10, 320, 133, rl.Blue)
|
||||
|
||||
raylib.DrawText("Free camera default controls:", 20, 20, 10, raylib.Black)
|
||||
raylib.DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, raylib.DarkGray)
|
||||
raylib.DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, raylib.DarkGray)
|
||||
raylib.DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, raylib.DarkGray)
|
||||
raylib.DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, raylib.DarkGray)
|
||||
raylib.DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, raylib.DarkGray)
|
||||
rl.DrawText("Free camera default controls:", 20, 20, 10, rl.Black)
|
||||
rl.DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, rl.DarkGray)
|
||||
rl.DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, rl.DarkGray)
|
||||
rl.DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, rl.DarkGray)
|
||||
rl.DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, rl.DarkGray)
|
||||
rl.DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, rl.DarkGray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -5,39 +5,39 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
raylib.InitWindow(800, 450, "raylib [core] example - 3d mode")
|
||||
rl.InitWindow(800, 450, "raylib [core] example - 3d mode")
|
||||
|
||||
camera := raylib.Camera3D{}
|
||||
camera.Position = raylib.NewVector3(0.0, 10.0, 10.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera := rl.Camera3D{}
|
||||
camera.Position = rl.NewVector3(0.0, 10.0, 10.0)
|
||||
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
camera.Type = raylib.CameraPerspective
|
||||
camera.Type = rl.CameraPerspective
|
||||
|
||||
cubePosition := raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
cubePosition := rl.NewVector3(0.0, 0.0, 0.0)
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.BeginMode3D(camera)
|
||||
rl.BeginMode3D(camera)
|
||||
|
||||
raylib.DrawCube(cubePosition, 2.0, 2.0, 2.0, raylib.Red)
|
||||
raylib.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, raylib.Maroon)
|
||||
rl.DrawCube(cubePosition, 2.0, 2.0, 2.0, rl.Red)
|
||||
rl.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, rl.Maroon)
|
||||
|
||||
raylib.DrawGrid(10, 1.0)
|
||||
rl.DrawGrid(10, 1.0)
|
||||
|
||||
raylib.EndMode3D()
|
||||
rl.EndMode3D()
|
||||
|
||||
raylib.DrawText("Welcome to the third dimension!", 10, 40, 20, raylib.DarkGray)
|
||||
rl.DrawText("Welcome to the third dimension!", 10, 40, 20, rl.DarkGray)
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
rl.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,70 +8,71 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking")
|
||||
|
||||
camera := raylib.Camera3D{}
|
||||
camera.Position = raylib.NewVector3(10.0, 10.0, 10.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera := rl.Camera3D{}
|
||||
camera.Position = rl.NewVector3(10.0, 10.0, 10.0)
|
||||
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
camera.Type = raylib.CameraPerspective
|
||||
camera.Type = rl.CameraPerspective
|
||||
|
||||
cubePosition := raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
cubeSize := raylib.NewVector3(2.0, 2.0, 2.0)
|
||||
cubePosition := rl.NewVector3(0.0, 1.0, 0.0)
|
||||
cubeSize := rl.NewVector3(2.0, 2.0, 2.0)
|
||||
|
||||
var ray raylib.Ray
|
||||
var ray rl.Ray
|
||||
|
||||
collision := false
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraFree) // Set a free camera mode
|
||||
rl.SetCameraMode(camera, rl.CameraFree) // Set a free camera mode
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.UpdateCamera(&camera) // Update camera
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.UpdateCamera(&camera) // Update camera
|
||||
|
||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
||||
ray = raylib.GetMouseRay(raylib.GetMousePosition(), camera)
|
||||
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||
// NOTE: This function is NOT WORKING properly!
|
||||
ray = rl.GetMouseRay(rl.GetMousePosition(), camera)
|
||||
|
||||
// Check collision between ray and box
|
||||
min := raylib.NewVector3(cubePosition.X-cubeSize.X/2, cubePosition.Y-cubeSize.Y/2, cubePosition.Z-cubeSize.Z/2)
|
||||
max := raylib.NewVector3(cubePosition.X+cubeSize.X/2, cubePosition.Y+cubeSize.Y/2, cubePosition.Z+cubeSize.Z/2)
|
||||
collision = raylib.CheckCollisionRayBox(ray, raylib.NewBoundingBox(min, max))
|
||||
min := rl.NewVector3(cubePosition.X-cubeSize.X/2, cubePosition.Y-cubeSize.Y/2, cubePosition.Z-cubeSize.Z/2)
|
||||
max := rl.NewVector3(cubePosition.X+cubeSize.X/2, cubePosition.Y+cubeSize.Y/2, cubePosition.Z+cubeSize.Z/2)
|
||||
collision = rl.CheckCollisionRayBox(ray, rl.NewBoundingBox(min, max))
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.BeginMode3D(camera)
|
||||
rl.BeginMode3D(camera)
|
||||
|
||||
if collision {
|
||||
raylib.DrawCube(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, raylib.Red)
|
||||
raylib.DrawCubeWires(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, raylib.Maroon)
|
||||
rl.DrawCube(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, rl.Red)
|
||||
rl.DrawCubeWires(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, rl.Maroon)
|
||||
|
||||
raylib.DrawCubeWires(cubePosition, cubeSize.X+0.2, cubeSize.Y+0.2, cubeSize.Z+0.2, raylib.Green)
|
||||
rl.DrawCubeWires(cubePosition, cubeSize.X+0.2, cubeSize.Y+0.2, cubeSize.Z+0.2, rl.Green)
|
||||
} else {
|
||||
raylib.DrawCube(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, raylib.Gray)
|
||||
raylib.DrawCubeWires(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, raylib.DarkGray)
|
||||
rl.DrawCube(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, rl.Gray)
|
||||
rl.DrawCubeWires(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, rl.DarkGray)
|
||||
}
|
||||
|
||||
raylib.DrawRay(ray, raylib.Maroon)
|
||||
rl.DrawRay(ray, rl.Maroon)
|
||||
|
||||
raylib.DrawGrid(10, 1.0)
|
||||
rl.DrawGrid(10, 1.0)
|
||||
|
||||
raylib.EndMode3D()
|
||||
rl.EndMode3D()
|
||||
|
||||
raylib.DrawText("Try selecting the box with mouse!", 240, 10, 20, raylib.DarkGray)
|
||||
rl.DrawText("Try selecting the box with mouse!", 240, 10, 20, rl.DarkGray)
|
||||
|
||||
if collision {
|
||||
raylib.DrawText("BOX SELECTED", (screenWidth-raylib.MeasureText("BOX SELECTED", 30))/2, int32(float32(screenHeight)*0.1), 30, raylib.Green)
|
||||
rl.DrawText("BOX SELECTED", (screenWidth-rl.MeasureText("BOX SELECTED", 30))/2, int32(float32(screenHeight)*0.1), 30, rl.Green)
|
||||
}
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
rl.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -3,20 +3,20 @@ package main
|
|||
import "github.com/gen2brain/raylib-go/raylib"
|
||||
|
||||
func main() {
|
||||
raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
||||
raylib.InitWindow(800, 450, "raylib [core] example - basic window")
|
||||
rl.SetConfigFlags(rl.FlagVsyncHint)
|
||||
rl.InitWindow(800, 450, "raylib [core] example - basic window")
|
||||
|
||||
//raylib.SetTargetFPS(60)
|
||||
//rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawText("Congrats! You created your first window!", 190, 200, 20, raylib.LightGray)
|
||||
rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.LightGray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -5,19 +5,19 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
raylib.InitWindow(800, 450, "raylib [core] example - color selection (collision detection)")
|
||||
rl.InitWindow(800, 450, "raylib [core] example - color selection (collision detection)")
|
||||
|
||||
colors := [21]raylib.Color{
|
||||
raylib.DarkGray, raylib.Maroon, raylib.Orange, raylib.DarkGreen, raylib.DarkBlue, raylib.DarkPurple,
|
||||
raylib.DarkBrown, raylib.Gray, raylib.Red, raylib.Gold, raylib.Lime, raylib.Blue, raylib.Violet, raylib.Brown,
|
||||
raylib.LightGray, raylib.Pink, raylib.Yellow, raylib.Green, raylib.SkyBlue, raylib.Purple, raylib.Beige,
|
||||
colors := [21]rl.Color{
|
||||
rl.DarkGray, rl.Maroon, rl.Orange, rl.DarkGreen, rl.DarkBlue, rl.DarkPurple,
|
||||
rl.DarkBrown, rl.Gray, rl.Red, rl.Gold, rl.Lime, rl.Blue, rl.Violet, rl.Brown,
|
||||
rl.LightGray, rl.Pink, rl.Yellow, rl.Green, rl.SkyBlue, rl.Purple, rl.Beige,
|
||||
}
|
||||
|
||||
colorsRecs := make([]raylib.Rectangle, 21) // Rectangles array
|
||||
colorsRecs := make([]rl.Rectangle, 21) // Rectangles array
|
||||
|
||||
// Fills colorsRecs data (for every rectangle)
|
||||
for i := 0; i < 21; i++ {
|
||||
r := raylib.Rectangle{}
|
||||
r := rl.Rectangle{}
|
||||
r.X = float32(20 + 100*(i%7) + 10*(i%7))
|
||||
r.Y = float32(60 + 100*(i/7) + 10*(i/7))
|
||||
r.Width = 100
|
||||
|
@ -28,18 +28,18 @@ func main() {
|
|||
|
||||
selected := make([]bool, 21) // Selected rectangles indicator
|
||||
|
||||
mousePoint := raylib.Vector2{}
|
||||
mousePoint := rl.Vector2{}
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
mousePoint = raylib.GetMousePosition()
|
||||
for !rl.WindowShouldClose() {
|
||||
mousePoint = rl.GetMousePosition()
|
||||
|
||||
for i := 0; i < 21; i++ { // Iterate along all the rectangles
|
||||
if raylib.CheckCollisionPointRec(mousePoint, colorsRecs[i]) {
|
||||
if rl.CheckCollisionPointRec(mousePoint, colorsRecs[i]) {
|
||||
colors[i].A = 120
|
||||
|
||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
||||
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||
selected[i] = !selected[i]
|
||||
}
|
||||
} else {
|
||||
|
@ -47,24 +47,24 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
for i := 0; i < 21; i++ { // Draw all rectangles
|
||||
raylib.DrawRectangleRec(colorsRecs[i], colors[i])
|
||||
rl.DrawRectangleRec(colorsRecs[i], colors[i])
|
||||
|
||||
// Draw four rectangles around selected rectangle
|
||||
if selected[i] {
|
||||
raylib.DrawRectangle(int32(colorsRecs[i].X), int32(colorsRecs[i].Y), 100, 10, raylib.RayWhite) // Square top rectangle
|
||||
raylib.DrawRectangle(int32(colorsRecs[i].X), int32(colorsRecs[i].Y), 10, 100, raylib.RayWhite) // Square left rectangle
|
||||
raylib.DrawRectangle(int32(colorsRecs[i].X+90), int32(colorsRecs[i].Y), 10, 100, raylib.RayWhite) // Square right rectangle
|
||||
raylib.DrawRectangle(int32(colorsRecs[i].X), int32(colorsRecs[i].Y)+90, 100, 10, raylib.RayWhite) // Square bottom rectangle
|
||||
rl.DrawRectangle(int32(colorsRecs[i].X), int32(colorsRecs[i].Y), 100, 10, rl.RayWhite) // Square top rectangle
|
||||
rl.DrawRectangle(int32(colorsRecs[i].X), int32(colorsRecs[i].Y), 10, 100, rl.RayWhite) // Square left rectangle
|
||||
rl.DrawRectangle(int32(colorsRecs[i].X+90), int32(colorsRecs[i].Y), 10, 100, rl.RayWhite) // Square right rectangle
|
||||
rl.DrawRectangle(int32(colorsRecs[i].X), int32(colorsRecs[i].Y)+90, 100, 10, rl.RayWhite) // Square bottom rectangle
|
||||
}
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,43 +8,43 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files")
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
count := int32(0)
|
||||
var droppedFiles []string
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsFileDropped() {
|
||||
droppedFiles = raylib.GetDroppedFiles(&count)
|
||||
for !rl.WindowShouldClose() {
|
||||
if rl.IsFileDropped() {
|
||||
droppedFiles = rl.GetDroppedFiles(&count)
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
if count == 0 {
|
||||
raylib.DrawText("Drop your files to this window!", 100, 40, 20, raylib.DarkGray)
|
||||
rl.DrawText("Drop your files to this window!", 100, 40, 20, rl.DarkGray)
|
||||
} else {
|
||||
raylib.DrawText("Dropped files:", 100, 40, 20, raylib.DarkGray)
|
||||
rl.DrawText("Dropped files:", 100, 40, 20, rl.DarkGray)
|
||||
|
||||
for i := int32(0); i < count; i++ {
|
||||
if i%2 == 0 {
|
||||
raylib.DrawRectangle(0, int32(85+40*i), screenWidth, 40, raylib.Fade(raylib.LightGray, 0.5))
|
||||
rl.DrawRectangle(0, int32(85+40*i), screenWidth, 40, rl.Fade(rl.LightGray, 0.5))
|
||||
} else {
|
||||
raylib.DrawRectangle(0, int32(85+40*i), screenWidth, 40, raylib.Fade(raylib.LightGray, 0.3))
|
||||
rl.DrawRectangle(0, int32(85+40*i), screenWidth, 40, rl.Fade(rl.LightGray, 0.3))
|
||||
}
|
||||
|
||||
raylib.DrawText(droppedFiles[i], 120, int32(100+i*40), 10, raylib.Gray)
|
||||
rl.DrawText(droppedFiles[i], 120, int32(100), 10, rl.Gray)
|
||||
}
|
||||
|
||||
raylib.DrawText("Drop new files...", 100, int32(150+count*40), 20, raylib.DarkGray)
|
||||
rl.DrawText("Drop new files...", 100, int32(150), 20, rl.DarkGray)
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.ClearDroppedFiles()
|
||||
rl.ClearDroppedFiles()
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -12,47 +12,47 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - gestures detection")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - gestures detection")
|
||||
|
||||
touchPosition := raylib.NewVector2(0, 0)
|
||||
touchArea := raylib.NewRectangle(220, 10, float32(screenWidth)-230, float32(screenHeight)-20)
|
||||
touchPosition := rl.NewVector2(0, 0)
|
||||
touchArea := rl.NewRectangle(220, 10, float32(screenWidth)-230, float32(screenHeight)-20)
|
||||
|
||||
gestureStrings := make([]string, 0)
|
||||
|
||||
currentGesture := raylib.GestureNone
|
||||
lastGesture := raylib.GestureNone
|
||||
currentGesture := rl.GestureNone
|
||||
lastGesture := rl.GestureNone
|
||||
|
||||
//raylib.SetGesturesEnabled(uint32(raylib.GestureHold | raylib.GestureDrag)) // Enable only some gestures to be detected
|
||||
//rl.SetGesturesEnabled(uint32(rl.GestureHold | rl.GestureDrag)) // Enable only some gestures to be detected
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
lastGesture = currentGesture
|
||||
currentGesture = raylib.GetGestureDetected()
|
||||
touchPosition = raylib.GetTouchPosition(0)
|
||||
currentGesture = rl.GetGestureDetected()
|
||||
touchPosition = rl.GetTouchPosition(0)
|
||||
|
||||
if raylib.CheckCollisionPointRec(touchPosition, touchArea) && currentGesture != raylib.GestureNone {
|
||||
if rl.CheckCollisionPointRec(touchPosition, touchArea) && currentGesture != rl.GestureNone {
|
||||
if currentGesture != lastGesture {
|
||||
switch currentGesture {
|
||||
case raylib.GestureTap:
|
||||
case rl.GestureTap:
|
||||
gestureStrings = append(gestureStrings, "GESTURE TAP")
|
||||
case raylib.GestureDoubletap:
|
||||
case rl.GestureDoubletap:
|
||||
gestureStrings = append(gestureStrings, "GESTURE DOUBLETAP")
|
||||
case raylib.GestureHold:
|
||||
case rl.GestureHold:
|
||||
gestureStrings = append(gestureStrings, "GESTURE HOLD")
|
||||
case raylib.GestureDrag:
|
||||
case rl.GestureDrag:
|
||||
gestureStrings = append(gestureStrings, "GESTURE DRAG")
|
||||
case raylib.GestureSwipeRight:
|
||||
case rl.GestureSwipeRight:
|
||||
gestureStrings = append(gestureStrings, "GESTURE SWIPE RIGHT")
|
||||
case raylib.GestureSwipeLeft:
|
||||
case rl.GestureSwipeLeft:
|
||||
gestureStrings = append(gestureStrings, "GESTURE SWIPE LEFT")
|
||||
case raylib.GestureSwipeUp:
|
||||
case rl.GestureSwipeUp:
|
||||
gestureStrings = append(gestureStrings, "GESTURE SWIPE UP")
|
||||
case raylib.GestureSwipeDown:
|
||||
case rl.GestureSwipeDown:
|
||||
gestureStrings = append(gestureStrings, "GESTURE SWIPE DOWN")
|
||||
case raylib.GesturePinchIn:
|
||||
case rl.GesturePinchIn:
|
||||
gestureStrings = append(gestureStrings, "GESTURE PINCH IN")
|
||||
case raylib.GesturePinchOut:
|
||||
case rl.GesturePinchOut:
|
||||
gestureStrings = append(gestureStrings, "GESTURE PINCH OUT")
|
||||
}
|
||||
|
||||
|
@ -62,38 +62,38 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawRectangleRec(touchArea, raylib.Gray)
|
||||
raylib.DrawRectangle(225, 15, screenWidth-240, screenHeight-30, raylib.RayWhite)
|
||||
rl.DrawRectangleRec(touchArea, rl.Gray)
|
||||
rl.DrawRectangle(225, 15, screenWidth-240, screenHeight-30, rl.RayWhite)
|
||||
|
||||
raylib.DrawText("GESTURES TEST AREA", screenWidth-270, screenHeight-40, 20, raylib.Fade(raylib.Gray, 0.5))
|
||||
rl.DrawText("GESTURES TEST AREA", screenWidth-270, screenHeight-40, 20, rl.Fade(rl.Gray, 0.5))
|
||||
|
||||
for i := 0; i < len(gestureStrings); i++ {
|
||||
if i%2 == 0 {
|
||||
raylib.DrawRectangle(10, int32(30+20*i), 200, 20, raylib.Fade(raylib.LightGray, 0.5))
|
||||
rl.DrawRectangle(10, int32(30+20*i), 200, 20, rl.Fade(rl.LightGray, 0.5))
|
||||
} else {
|
||||
raylib.DrawRectangle(10, int32(30+20*i), 200, 20, raylib.Fade(raylib.LightGray, 0.3))
|
||||
rl.DrawRectangle(10, int32(30+20*i), 200, 20, rl.Fade(rl.LightGray, 0.3))
|
||||
}
|
||||
|
||||
if i < len(gestureStrings)-1 {
|
||||
raylib.DrawText(gestureStrings[i], 35, int32(36+20*i), 10, raylib.DarkGray)
|
||||
rl.DrawText(gestureStrings[i], 35, int32(36+20*i), 10, rl.DarkGray)
|
||||
} else {
|
||||
raylib.DrawText(gestureStrings[i], 35, int32(36+20*i), 10, raylib.Maroon)
|
||||
rl.DrawText(gestureStrings[i], 35, int32(36+20*i), 10, rl.Maroon)
|
||||
}
|
||||
}
|
||||
|
||||
raylib.DrawRectangleLines(10, 29, 200, screenHeight-50, raylib.Gray)
|
||||
raylib.DrawText("DETECTED GESTURES", 50, 15, 10, raylib.Gray)
|
||||
rl.DrawRectangleLines(10, 29, 200, screenHeight-50, rl.Gray)
|
||||
rl.DrawText("DETECTED GESTURES", 50, 15, 10, rl.Gray)
|
||||
|
||||
if currentGesture != raylib.GestureNone {
|
||||
raylib.DrawCircleV(touchPosition, 30, raylib.Maroon)
|
||||
if currentGesture != rl.GestureNone {
|
||||
rl.DrawCircleV(touchPosition, 30, rl.Maroon)
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -12,190 +12,190 @@ const (
|
|||
)
|
||||
|
||||
func main() {
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint) // Set MSAA 4X hint before windows creation
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint) // Set MSAA 4X hint before windows creation
|
||||
|
||||
raylib.InitWindow(800, 450, "raylib [core] example - gamepad input")
|
||||
rl.InitWindow(800, 450, "raylib [core] example - gamepad input")
|
||||
|
||||
texPs3Pad := raylib.LoadTexture("ps3.png")
|
||||
texXboxPad := raylib.LoadTexture("xbox.png")
|
||||
texPs3Pad := rl.LoadTexture("ps3.png")
|
||||
texXboxPad := rl.LoadTexture("xbox.png")
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
if raylib.IsGamepadAvailable(raylib.GamepadPlayer1) {
|
||||
raylib.DrawText(fmt.Sprintf("GP1: %s", raylib.GetGamepadName(raylib.GamepadPlayer1)), 10, 10, 10, raylib.Black)
|
||||
if rl.IsGamepadAvailable(rl.GamepadPlayer1) {
|
||||
rl.DrawText(fmt.Sprintf("GP1: %s", rl.GetGamepadName(rl.GamepadPlayer1)), 10, 10, 10, rl.Black)
|
||||
|
||||
if raylib.IsGamepadName(raylib.GamepadPlayer1, xbox360NameID) {
|
||||
raylib.DrawTexture(texXboxPad, 0, 0, raylib.DarkGray)
|
||||
if rl.IsGamepadName(rl.GamepadPlayer1, xbox360NameID) {
|
||||
rl.DrawTexture(texXboxPad, 0, 0, rl.DarkGray)
|
||||
|
||||
// Draw buttons: xbox home
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonHome) {
|
||||
raylib.DrawCircle(394, 89, 19, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonHome) {
|
||||
rl.DrawCircle(394, 89, 19, rl.Red)
|
||||
}
|
||||
|
||||
// Draw buttons: basic
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonStart) {
|
||||
raylib.DrawCircle(436, 150, 9, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonStart) {
|
||||
rl.DrawCircle(436, 150, 9, rl.Red)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonSelect) {
|
||||
raylib.DrawCircle(352, 150, 9, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonSelect) {
|
||||
rl.DrawCircle(352, 150, 9, rl.Red)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonX) {
|
||||
raylib.DrawCircle(501, 151, 15, raylib.Blue)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonX) {
|
||||
rl.DrawCircle(501, 151, 15, rl.Blue)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonA) {
|
||||
raylib.DrawCircle(536, 187, 15, raylib.Lime)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonA) {
|
||||
rl.DrawCircle(536, 187, 15, rl.Lime)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonB) {
|
||||
raylib.DrawCircle(572, 151, 15, raylib.Maroon)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonB) {
|
||||
rl.DrawCircle(572, 151, 15, rl.Maroon)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonY) {
|
||||
raylib.DrawCircle(536, 115, 15, raylib.Gold)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonY) {
|
||||
rl.DrawCircle(536, 115, 15, rl.Gold)
|
||||
}
|
||||
|
||||
// Draw buttons: d-pad
|
||||
raylib.DrawRectangle(317, 202, 19, 71, raylib.Black)
|
||||
raylib.DrawRectangle(293, 228, 69, 19, raylib.Black)
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonUp) {
|
||||
raylib.DrawRectangle(317, 202, 19, 26, raylib.Red)
|
||||
rl.DrawRectangle(317, 202, 19, 71, rl.Black)
|
||||
rl.DrawRectangle(293, 228, 69, 19, rl.Black)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonUp) {
|
||||
rl.DrawRectangle(317, 202, 19, 26, rl.Red)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonDown) {
|
||||
raylib.DrawRectangle(317, 202+45, 19, 26, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonDown) {
|
||||
rl.DrawRectangle(317, 202+45, 19, 26, rl.Red)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonLeft) {
|
||||
raylib.DrawRectangle(292, 228, 25, 19, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonLeft) {
|
||||
rl.DrawRectangle(292, 228, 25, 19, rl.Red)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonRight) {
|
||||
raylib.DrawRectangle(292+44, 228, 26, 19, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonRight) {
|
||||
rl.DrawRectangle(292+44, 228, 26, 19, rl.Red)
|
||||
}
|
||||
|
||||
// Draw buttons: left-right back
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonLb) {
|
||||
raylib.DrawCircle(259, 61, 20, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonLb) {
|
||||
rl.DrawCircle(259, 61, 20, rl.Red)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonRb) {
|
||||
raylib.DrawCircle(536, 61, 20, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonRb) {
|
||||
rl.DrawCircle(536, 61, 20, rl.Red)
|
||||
}
|
||||
|
||||
// Draw axis: left joystick
|
||||
raylib.DrawCircle(259, 152, 39, raylib.Black)
|
||||
raylib.DrawCircle(259, 152, 34, raylib.LightGray)
|
||||
raylib.DrawCircle(int32(259+(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadXboxAxisLeftX)*20)),
|
||||
int32(152-(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadXboxAxisLeftY)*20)), 25, raylib.Black)
|
||||
rl.DrawCircle(259, 152, 39, rl.Black)
|
||||
rl.DrawCircle(259, 152, 34, rl.LightGray)
|
||||
rl.DrawCircle(int32(259+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisLeftX)*20)),
|
||||
int32(152-(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisLeftY)*20)), 25, rl.Black)
|
||||
|
||||
// Draw axis: right joystick
|
||||
raylib.DrawCircle(461, 237, 38, raylib.Black)
|
||||
raylib.DrawCircle(461, 237, 33, raylib.LightGray)
|
||||
raylib.DrawCircle(int32(461+(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadXboxAxisRightX)*20)),
|
||||
int32(237-(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadXboxAxisRightY)*20)), 25, raylib.Black)
|
||||
rl.DrawCircle(461, 237, 38, rl.Black)
|
||||
rl.DrawCircle(461, 237, 33, rl.LightGray)
|
||||
rl.DrawCircle(int32(461+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisRightX)*20)),
|
||||
int32(237-(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisRightY)*20)), 25, rl.Black)
|
||||
|
||||
// Draw axis: left-right triggers
|
||||
raylib.DrawRectangle(170, 30, 15, 70, raylib.Gray)
|
||||
raylib.DrawRectangle(604, 30, 15, 70, raylib.Gray)
|
||||
raylib.DrawRectangle(170, 30, 15, int32(((1.0+raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadXboxAxisLt))/2.0)*70), raylib.Red)
|
||||
raylib.DrawRectangle(604, 30, 15, int32(((1.0+raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadXboxAxisRt))/2.0)*70), raylib.Red)
|
||||
rl.DrawRectangle(170, 30, 15, 70, rl.Gray)
|
||||
rl.DrawRectangle(604, 30, 15, 70, rl.Gray)
|
||||
rl.DrawRectangle(170, 30, 15, int32(((1.0+rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisLt))/2.0)*70), rl.Red)
|
||||
rl.DrawRectangle(604, 30, 15, int32(((1.0+rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisRt))/2.0)*70), rl.Red)
|
||||
|
||||
} else if raylib.IsGamepadName(raylib.GamepadPlayer1, ps3NameID) {
|
||||
raylib.DrawTexture(texPs3Pad, 0, 0, raylib.DarkGray)
|
||||
} else if rl.IsGamepadName(rl.GamepadPlayer1, ps3NameID) {
|
||||
rl.DrawTexture(texPs3Pad, 0, 0, rl.DarkGray)
|
||||
|
||||
// Draw buttons: ps
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonPs) {
|
||||
raylib.DrawCircle(396, 222, 13, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonPs) {
|
||||
rl.DrawCircle(396, 222, 13, rl.Red)
|
||||
}
|
||||
|
||||
// Draw buttons: basic
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonSelect) {
|
||||
raylib.DrawRectangle(328, 170, 32, 13, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonSelect) {
|
||||
rl.DrawRectangle(328, 170, 32, 13, rl.Red)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonStart) {
|
||||
raylib.DrawTriangle(raylib.NewVector2(436, 168), raylib.NewVector2(436, 185), raylib.NewVector2(464, 177), raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonStart) {
|
||||
rl.DrawTriangle(rl.NewVector2(436, 168), rl.NewVector2(436, 185), rl.NewVector2(464, 177), rl.Red)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonTriangle) {
|
||||
raylib.DrawCircle(557, 144, 13, raylib.Lime)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonTriangle) {
|
||||
rl.DrawCircle(557, 144, 13, rl.Lime)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonCircle) {
|
||||
raylib.DrawCircle(586, 173, 13, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonCircle) {
|
||||
rl.DrawCircle(586, 173, 13, rl.Red)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonCross) {
|
||||
raylib.DrawCircle(557, 203, 13, raylib.Violet)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonCross) {
|
||||
rl.DrawCircle(557, 203, 13, rl.Violet)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonSquare) {
|
||||
raylib.DrawCircle(527, 173, 13, raylib.Pink)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonSquare) {
|
||||
rl.DrawCircle(527, 173, 13, rl.Pink)
|
||||
}
|
||||
|
||||
// Draw buttons: d-pad
|
||||
raylib.DrawRectangle(225, 132, 24, 84, raylib.Black)
|
||||
raylib.DrawRectangle(195, 161, 84, 25, raylib.Black)
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonUp) {
|
||||
raylib.DrawRectangle(225, 132, 24, 29, raylib.Red)
|
||||
rl.DrawRectangle(225, 132, 24, 84, rl.Black)
|
||||
rl.DrawRectangle(195, 161, 84, 25, rl.Black)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonUp) {
|
||||
rl.DrawRectangle(225, 132, 24, 29, rl.Red)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonDown) {
|
||||
raylib.DrawRectangle(225, 132+54, 24, 30, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonDown) {
|
||||
rl.DrawRectangle(225, 132+54, 24, 30, rl.Red)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonLeft) {
|
||||
raylib.DrawRectangle(195, 161, 30, 25, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonLeft) {
|
||||
rl.DrawRectangle(195, 161, 30, 25, rl.Red)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonRight) {
|
||||
raylib.DrawRectangle(195+54, 161, 30, 25, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonRight) {
|
||||
rl.DrawRectangle(195+54, 161, 30, 25, rl.Red)
|
||||
}
|
||||
|
||||
// Draw buttons: left-right back buttons
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonL1) {
|
||||
raylib.DrawCircle(239, 82, 20, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonL1) {
|
||||
rl.DrawCircle(239, 82, 20, rl.Red)
|
||||
}
|
||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonR1) {
|
||||
raylib.DrawCircle(557, 82, 20, raylib.Red)
|
||||
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonR1) {
|
||||
rl.DrawCircle(557, 82, 20, rl.Red)
|
||||
}
|
||||
|
||||
// Draw axis: left joystick
|
||||
raylib.DrawCircle(319, 255, 35, raylib.Black)
|
||||
raylib.DrawCircle(319, 255, 31, raylib.LightGray)
|
||||
raylib.DrawCircle(int32(319+(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadPs3AxisLeftX)*20)),
|
||||
int32(255+(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadPs3AxisLeftY)*20)), 25, raylib.Black)
|
||||
rl.DrawCircle(319, 255, 35, rl.Black)
|
||||
rl.DrawCircle(319, 255, 31, rl.LightGray)
|
||||
rl.DrawCircle(int32(319+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisLeftX)*20)),
|
||||
int32(255+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisLeftY)*20)), 25, rl.Black)
|
||||
|
||||
// Draw axis: right joystick
|
||||
raylib.DrawCircle(475, 255, 35, raylib.Black)
|
||||
raylib.DrawCircle(475, 255, 31, raylib.LightGray)
|
||||
raylib.DrawCircle(int32(475+(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadPs3AxisRightX)*20)),
|
||||
int32(255+(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadPs3AxisRightY)*20)), 25, raylib.Black)
|
||||
rl.DrawCircle(475, 255, 35, rl.Black)
|
||||
rl.DrawCircle(475, 255, 31, rl.LightGray)
|
||||
rl.DrawCircle(int32(475+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisRightX)*20)),
|
||||
int32(255+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisRightY)*20)), 25, rl.Black)
|
||||
|
||||
// Draw axis: left-right triggers
|
||||
raylib.DrawRectangle(169, 48, 15, 70, raylib.Gray)
|
||||
raylib.DrawRectangle(611, 48, 15, 70, raylib.Gray)
|
||||
raylib.DrawRectangle(169, 48, 15, int32(((1.0-raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadPs3AxisL2))/2.0)*70), raylib.Red)
|
||||
raylib.DrawRectangle(611, 48, 15, int32(((1.0-raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadPs3AxisR2))/2.0)*70), raylib.Red)
|
||||
rl.DrawRectangle(169, 48, 15, 70, rl.Gray)
|
||||
rl.DrawRectangle(611, 48, 15, 70, rl.Gray)
|
||||
rl.DrawRectangle(169, 48, 15, int32(((1.0-rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisL2))/2.0)*70), rl.Red)
|
||||
rl.DrawRectangle(611, 48, 15, int32(((1.0-rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisR2))/2.0)*70), rl.Red)
|
||||
} else {
|
||||
raylib.DrawText("- GENERIC GAMEPAD -", 280, 180, 20, raylib.Gray)
|
||||
rl.DrawText("- GENERIC GAMEPAD -", 280, 180, 20, rl.Gray)
|
||||
|
||||
// TODO: Draw generic gamepad
|
||||
}
|
||||
|
||||
raylib.DrawText(fmt.Sprintf("DETECTED AXIS [%d]:", raylib.GetGamepadAxisCount(raylib.GamepadPlayer1)), 10, 50, 10, raylib.Maroon)
|
||||
rl.DrawText(fmt.Sprintf("DETECTED AXIS [%d]:", rl.GetGamepadAxisCount(rl.GamepadPlayer1)), 10, 50, 10, rl.Maroon)
|
||||
|
||||
for i := int32(0); i < raylib.GetGamepadAxisCount(raylib.GamepadPlayer1); i++ {
|
||||
raylib.DrawText(fmt.Sprintf("AXIS %d: %.02f", i, raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, i)), 20, 70+20*i, 10, raylib.DarkGray)
|
||||
for i := int32(0); i < rl.GetGamepadAxisCount(rl.GamepadPlayer1); i++ {
|
||||
rl.DrawText(fmt.Sprintf("AXIS %d: %.02f", i, rl.GetGamepadAxisMovement(rl.GamepadPlayer1, i)), 20, 70+20*i, 10, rl.DarkGray)
|
||||
}
|
||||
|
||||
if raylib.GetGamepadButtonPressed() != -1 {
|
||||
raylib.DrawText(fmt.Sprintf("DETECTED BUTTON: %d", raylib.GetGamepadButtonPressed()), 10, 430, 10, raylib.Red)
|
||||
if rl.GetGamepadButtonPressed() != -1 {
|
||||
rl.DrawText(fmt.Sprintf("DETECTED BUTTON: %d", rl.GetGamepadButtonPressed()), 10, 430, 10, rl.Red)
|
||||
} else {
|
||||
raylib.DrawText("DETECTED BUTTON: NONE", 10, 430, 10, raylib.Gray)
|
||||
rl.DrawText("DETECTED BUTTON: NONE", 10, 430, 10, rl.Gray)
|
||||
}
|
||||
} else {
|
||||
raylib.DrawText("GP1: NOT DETECTED", 10, 10, 10, raylib.Gray)
|
||||
rl.DrawText("GP1: NOT DETECTED", 10, 10, 10, rl.Gray)
|
||||
|
||||
raylib.DrawTexture(texXboxPad, 0, 0, raylib.LightGray)
|
||||
rl.DrawTexture(texXboxPad, 0, 0, rl.LightGray)
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texPs3Pad)
|
||||
raylib.UnloadTexture(texXboxPad)
|
||||
rl.UnloadTexture(texPs3Pad)
|
||||
rl.UnloadTexture(texXboxPad)
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,34 +8,34 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input")
|
||||
|
||||
ballPosition := raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2)
|
||||
ballPosition := rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2)
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsKeyDown(raylib.KeyRight) {
|
||||
for !rl.WindowShouldClose() {
|
||||
if rl.IsKeyDown(rl.KeyRight) {
|
||||
ballPosition.X += 0.8
|
||||
}
|
||||
if raylib.IsKeyDown(raylib.KeyLeft) {
|
||||
if rl.IsKeyDown(rl.KeyLeft) {
|
||||
ballPosition.X -= 0.8
|
||||
}
|
||||
if raylib.IsKeyDown(raylib.KeyUp) {
|
||||
if rl.IsKeyDown(rl.KeyUp) {
|
||||
ballPosition.Y -= 0.8
|
||||
}
|
||||
if raylib.IsKeyDown(raylib.KeyDown) {
|
||||
if rl.IsKeyDown(rl.KeyDown) {
|
||||
ballPosition.Y += 0.8
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawText("move the ball with arrow keys", 10, 10, 20, raylib.DarkGray)
|
||||
raylib.DrawCircleV(ballPosition, 50, raylib.Maroon)
|
||||
rl.DrawText("move the ball with arrow keys", 10, 10, 20, rl.DarkGray)
|
||||
rl.DrawCircleV(ballPosition, 50, rl.Maroon)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -5,31 +5,31 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
raylib.InitWindow(800, 450, "raylib [core] example - mouse input")
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.InitWindow(800, 450, "raylib [core] example - mouse input")
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
ballColor := raylib.DarkBlue
|
||||
ballColor := rl.DarkBlue
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
ballPosition := raylib.GetMousePosition()
|
||||
for !rl.WindowShouldClose() {
|
||||
ballPosition := rl.GetMousePosition()
|
||||
|
||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
||||
ballColor = raylib.Maroon
|
||||
} else if raylib.IsMouseButtonPressed(raylib.MouseMiddleButton) {
|
||||
ballColor = raylib.Lime
|
||||
} else if raylib.IsMouseButtonPressed(raylib.MouseRightButton) {
|
||||
ballColor = raylib.DarkBlue
|
||||
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||
ballColor = rl.Maroon
|
||||
} else if rl.IsMouseButtonPressed(rl.MouseMiddleButton) {
|
||||
ballColor = rl.Lime
|
||||
} else if rl.IsMouseButtonPressed(rl.MouseRightButton) {
|
||||
ballColor = rl.DarkBlue
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
raylib.DrawCircleV(ballPosition, 40, ballColor)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
rl.DrawCircleV(ballPosition, 40, ballColor)
|
||||
|
||||
raylib.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, raylib.DarkGray)
|
||||
rl.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.DarkGray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -10,27 +10,27 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse wheel")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse wheel")
|
||||
|
||||
boxPositionY := screenHeight/2 - 40
|
||||
scrollSpeed := int32(4) // Scrolling speed in pixels
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
boxPositionY -= raylib.GetMouseWheelMove() * scrollSpeed
|
||||
for !rl.WindowShouldClose() {
|
||||
boxPositionY -= rl.GetMouseWheelMove() * scrollSpeed
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawRectangle(screenWidth/2-40, boxPositionY, 80, 80, raylib.Maroon)
|
||||
rl.DrawRectangle(screenWidth/2-40, boxPositionY, 80, 80, rl.Maroon)
|
||||
|
||||
raylib.DrawText("Use mouse wheel to move the square up and down!", 10, 10, 20, raylib.Gray)
|
||||
raylib.DrawText(fmt.Sprintf("Box position Y: %d", boxPositionY), 10, 40, 20, raylib.LightGray)
|
||||
rl.DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, rl.Gray)
|
||||
rl.DrawText(fmt.Sprintf("Box position Y: %d", boxPositionY), 10, 40, 20, rl.LightGray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -7,32 +7,32 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
raylib.InitWindow(800, 450, "raylib [core] example - generate random values")
|
||||
rl.InitWindow(800, 450, "raylib [core] example - generate random values")
|
||||
|
||||
framesCounter := 0 // Variable used to count frames
|
||||
randValue := raylib.GetRandomValue(-8, 5) // Get a random integer number between -8 and 5 (both included)
|
||||
randValue := rl.GetRandomValue(-8, 5) // Get a random integer number between -8 and 5 (both included)
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
framesCounter++
|
||||
|
||||
// Every two seconds (120 frames) a new random value is generated
|
||||
if ((framesCounter / 120) % 2) == 1 {
|
||||
randValue = raylib.GetRandomValue(-8, 5)
|
||||
randValue = rl.GetRandomValue(-8, 5)
|
||||
framesCounter = 0
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, raylib.Maroon)
|
||||
rl.DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, rl.Maroon)
|
||||
|
||||
raylib.DrawText(fmt.Sprintf("%d", randValue), 360, 180, 80, raylib.LightGray)
|
||||
rl.DrawText(fmt.Sprintf("%d", randValue), 360, 180, 80, rl.LightGray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -12,47 +12,47 @@ const (
|
|||
)
|
||||
|
||||
func main() {
|
||||
raylib.InitWindow(800, 450, "raylib [core] example - storage save/load values")
|
||||
rl.InitWindow(800, 450, "raylib [core] example - storage save/load values")
|
||||
|
||||
score := int32(0)
|
||||
hiscore := int32(0)
|
||||
|
||||
framesCounter := 0
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsKeyPressed(raylib.KeyR) {
|
||||
score = raylib.GetRandomValue(1000, 2000)
|
||||
hiscore = raylib.GetRandomValue(2000, 4000)
|
||||
for !rl.WindowShouldClose() {
|
||||
if rl.IsKeyPressed(rl.KeyR) {
|
||||
score = rl.GetRandomValue(1000, 2000)
|
||||
hiscore = rl.GetRandomValue(2000, 4000)
|
||||
}
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeyEnter) {
|
||||
raylib.StorageSaveValue(storageScore, score)
|
||||
raylib.StorageSaveValue(storageHiscore, hiscore)
|
||||
} else if raylib.IsKeyPressed(raylib.KeySpace) {
|
||||
if rl.IsKeyPressed(rl.KeyEnter) {
|
||||
rl.StorageSaveValue(storageScore, score)
|
||||
rl.StorageSaveValue(storageHiscore, hiscore)
|
||||
} else if rl.IsKeyPressed(rl.KeySpace) {
|
||||
// NOTE: If requested position could not be found, value 0 is returned
|
||||
score = raylib.StorageLoadValue(storageScore)
|
||||
hiscore = raylib.StorageLoadValue(storageHiscore)
|
||||
score = rl.StorageLoadValue(storageScore)
|
||||
hiscore = rl.StorageLoadValue(storageHiscore)
|
||||
}
|
||||
|
||||
framesCounter++
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawText(fmt.Sprintf("SCORE: %d", score), 280, 130, 40, raylib.Maroon)
|
||||
raylib.DrawText(fmt.Sprintf("HI-SCORE: %d", hiscore), 210, 200, 50, raylib.Black)
|
||||
rl.DrawText(fmt.Sprintf("SCORE: %d", score), 280, 130, 40, rl.Maroon)
|
||||
rl.DrawText(fmt.Sprintf("HI-SCORE: %d", hiscore), 210, 200, 50, rl.Black)
|
||||
|
||||
raylib.DrawText(fmt.Sprintf("frames: %d", framesCounter), 10, 10, 20, raylib.Lime)
|
||||
rl.DrawText(fmt.Sprintf("frames: %d", framesCounter), 10, 10, 20, rl.Lime)
|
||||
|
||||
raylib.DrawText("Press R to generate random numbers", 220, 40, 20, raylib.LightGray)
|
||||
raylib.DrawText("Press ENTER to SAVE values", 250, 310, 20, raylib.LightGray)
|
||||
raylib.DrawText("Press SPACE to LOAD values", 252, 350, 20, raylib.LightGray)
|
||||
rl.DrawText("Press R to generate random numbers", 220, 40, 20, rl.LightGray)
|
||||
rl.DrawText("Press ENTER to SAVE values", 250, 310, 20, rl.LightGray)
|
||||
rl.DrawText("Press SPACE to LOAD values", 252, 350, 20, rl.LightGray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -5,50 +5,54 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
hmd := raylib.GetVrDeviceInfo(raylib.HmdOculusRiftCv1) // Oculus Rift CV1
|
||||
raylib.InitWindow(int32(hmd.HScreenSize), int32(hmd.VScreenSize), "raylib [core] example - vr simulator")
|
||||
screenWidth := int32(1080)
|
||||
screenHeight := int32(600)
|
||||
|
||||
// NOTE: screenWidth/screenHeight should match VR device aspect ratio
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - vr simulator")
|
||||
|
||||
// NOTE: default device (simulator)
|
||||
raylib.InitVrSimulator(hmd) // Init VR device
|
||||
rl.InitVrSimulator(rl.GetVrDeviceInfo(rl.HmdOculusRiftCv1)) // Init VR device (Oculus Rift CV1)
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(5.0, 2.0, 5.0) // Camera position
|
||||
camera.Target = raylib.NewVector3(0.0, 2.0, 0.0) // Camera looking at point
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0) // Camera up vector (rotation towards target)
|
||||
camera := rl.Camera{}
|
||||
camera.Position = rl.NewVector3(5.0, 2.0, 5.0) // Camera position
|
||||
camera.Target = rl.NewVector3(0.0, 2.0, 0.0) // Camera looking at point
|
||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0) // Camera up vector (rotation towards target)
|
||||
camera.Fovy = 60.0 // Camera field-of-view Y
|
||||
|
||||
cubePosition := raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
cubePosition := rl.NewVector3(0.0, 0.0, 0.0)
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraFirstPerson) // Set first person camera mode
|
||||
rl.SetCameraMode(camera, rl.CameraFirstPerson) // Set first person camera mode
|
||||
|
||||
raylib.SetTargetFPS(90)
|
||||
rl.SetTargetFPS(90)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.UpdateCamera(&camera) // Update camera (simulator mode)
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.UpdateCamera(&camera) // Update camera (simulator mode)
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.BeginVrDrawing()
|
||||
rl.BeginVrDrawing()
|
||||
|
||||
raylib.BeginMode3D(camera)
|
||||
rl.BeginMode3D(camera)
|
||||
|
||||
raylib.DrawCube(cubePosition, 2.0, 2.0, 2.0, raylib.Red)
|
||||
raylib.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, raylib.Maroon)
|
||||
rl.DrawCube(cubePosition, 2.0, 2.0, 2.0, rl.Red)
|
||||
rl.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, rl.Maroon)
|
||||
|
||||
raylib.DrawGrid(40, 1.0)
|
||||
rl.DrawGrid(40, 1.0)
|
||||
|
||||
raylib.EndMode3D()
|
||||
rl.EndMode3D()
|
||||
|
||||
raylib.EndVrDrawing()
|
||||
rl.EndVrDrawing()
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
rl.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseVrSimulator() // Close VR simulator
|
||||
rl.CloseVrSimulator() // Close VR simulator
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,45 +8,45 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(10.0, 10.0, 10.0) // Camera position
|
||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0) // Camera looking at point
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0) // Camera up vector (rotation towards target)
|
||||
camera := rl.Camera{}
|
||||
camera.Position = rl.NewVector3(10.0, 10.0, 10.0) // Camera position
|
||||
camera.Target = rl.NewVector3(0.0, 0.0, 0.0) // Camera looking at point
|
||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0) // Camera up vector (rotation towards target)
|
||||
camera.Fovy = 45.0 // Camera field-of-view Y
|
||||
|
||||
cubePosition := raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
cubeScreenPosition := raylib.Vector2{}
|
||||
cubePosition := rl.NewVector3(0.0, 0.0, 0.0)
|
||||
cubeScreenPosition := rl.Vector2{}
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraFree) // Set a free camera mode
|
||||
rl.SetCameraMode(camera, rl.CameraFree) // Set a free camera mode
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.UpdateCamera(&camera) // Update camera
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.UpdateCamera(&camera) // Update camera
|
||||
|
||||
// Calculate cube screen space position (with a little offset to be in top)
|
||||
cubeScreenPosition = raylib.GetWorldToScreen(raylib.NewVector3(cubePosition.X, cubePosition.Y+2.5, cubePosition.Z), camera)
|
||||
cubeScreenPosition = rl.GetWorldToScreen(rl.NewVector3(cubePosition.X, cubePosition.Y+2.5, cubePosition.Z), camera)
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.BeginMode3D(camera)
|
||||
rl.BeginMode3D(camera)
|
||||
|
||||
raylib.DrawCube(cubePosition, 2.0, 2.0, 2.0, raylib.Red)
|
||||
raylib.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, raylib.Maroon)
|
||||
rl.DrawCube(cubePosition, 2.0, 2.0, 2.0, rl.Red)
|
||||
rl.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, rl.Maroon)
|
||||
|
||||
raylib.DrawGrid(10, 1.0)
|
||||
rl.DrawGrid(10, 1.0)
|
||||
|
||||
raylib.EndMode3D()
|
||||
rl.EndMode3D()
|
||||
|
||||
raylib.DrawText("Enemy: 100 / 100", int32(cubeScreenPosition.X)-raylib.MeasureText("Enemy: 100 / 100", 20)/2, int32(cubeScreenPosition.Y), 20, raylib.Black)
|
||||
raylib.DrawText("Text is always on top of the cube", (screenWidth-raylib.MeasureText("Text is always on top of the cube", 20))/2, 25, 20, raylib.Gray)
|
||||
rl.DrawText("Enemy: 100 / 100", int32(cubeScreenPosition.X)-rl.MeasureText("Enemy: 100 / 100", 20)/2, int32(cubeScreenPosition.Y), 20, rl.Black)
|
||||
rl.DrawText("Text is always on top of the cube", (screenWidth-rl.MeasureText("Text is always on top of the cube", 20))/2, 25, 20, rl.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue