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
|
@ -7,27 +7,27 @@ import (
|
|||
const maxCircles = 64
|
||||
|
||||
type circleWave struct {
|
||||
Position raylib.Vector2
|
||||
Position rl.Vector2
|
||||
Radius float32
|
||||
Alpha float32
|
||||
Speed float32
|
||||
Color raylib.Color
|
||||
Color rl.Color
|
||||
}
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint) // NOTE: Try to enable MSAA 4X
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint) // NOTE: Try to enable MSAA 4X
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)")
|
||||
|
||||
raylib.InitAudioDevice()
|
||||
rl.InitAudioDevice()
|
||||
|
||||
colors := []raylib.Color{
|
||||
raylib.Orange, 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 := []rl.Color{
|
||||
rl.Orange, 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,
|
||||
}
|
||||
|
||||
circles := make([]circleWave, maxCircles)
|
||||
|
@ -36,47 +36,47 @@ func main() {
|
|||
c := circleWave{}
|
||||
|
||||
c.Alpha = 0
|
||||
c.Radius = float32(raylib.GetRandomValue(10, 40))
|
||||
c.Radius = float32(rl.GetRandomValue(10, 40))
|
||||
|
||||
x := raylib.GetRandomValue(int32(c.Radius), screenWidth-int32(c.Radius))
|
||||
y := raylib.GetRandomValue(int32(c.Radius), screenHeight-int32(c.Radius))
|
||||
c.Position = raylib.NewVector2(float32(x), float32(y))
|
||||
x := rl.GetRandomValue(int32(c.Radius), screenWidth-int32(c.Radius))
|
||||
y := rl.GetRandomValue(int32(c.Radius), screenHeight-int32(c.Radius))
|
||||
c.Position = rl.NewVector2(float32(x), float32(y))
|
||||
|
||||
c.Speed = float32(raylib.GetRandomValue(1, 100)) / 20000.0
|
||||
c.Color = colors[raylib.GetRandomValue(0, int32(len(colors)-1))]
|
||||
c.Speed = float32(rl.GetRandomValue(1, 100)) / 20000.0
|
||||
c.Color = colors[rl.GetRandomValue(0, int32(len(colors)-1))]
|
||||
|
||||
circles[i] = c
|
||||
}
|
||||
|
||||
xm := raylib.LoadMusicStream("mini1111.xm")
|
||||
raylib.PlayMusicStream(xm)
|
||||
xm := rl.LoadMusicStream("mini1111.xm")
|
||||
rl.PlayMusicStream(xm)
|
||||
|
||||
pause := false
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.UpdateMusicStream(xm) // Update music buffer with new stream data
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.UpdateMusicStream(xm) // Update music buffer with new stream data
|
||||
|
||||
// Restart music playing (stop and play)
|
||||
if raylib.IsKeyPressed(raylib.KeySpace) {
|
||||
raylib.StopMusicStream(xm)
|
||||
raylib.PlayMusicStream(xm)
|
||||
if rl.IsKeyPressed(rl.KeySpace) {
|
||||
rl.StopMusicStream(xm)
|
||||
rl.PlayMusicStream(xm)
|
||||
}
|
||||
|
||||
// Pause/Resume music playing
|
||||
if raylib.IsKeyPressed(raylib.KeyP) {
|
||||
if rl.IsKeyPressed(rl.KeyP) {
|
||||
pause = !pause
|
||||
|
||||
if pause {
|
||||
raylib.PauseMusicStream(xm)
|
||||
rl.PauseMusicStream(xm)
|
||||
} else {
|
||||
raylib.ResumeMusicStream(xm)
|
||||
rl.ResumeMusicStream(xm)
|
||||
}
|
||||
}
|
||||
|
||||
// Get timePlayed scaled to bar dimensions
|
||||
timePlayed := int32(raylib.GetMusicTimePlayed(xm)/raylib.GetMusicTimeLength(xm)*float32(screenWidth-40)) * 2
|
||||
timePlayed := int32(rl.GetMusicTimePlayed(xm)/rl.GetMusicTimeLength(xm)*float32(screenWidth-40)) * 2
|
||||
|
||||
// Color circles animation
|
||||
for i := maxCircles - 1; (i >= 0) && !pause; i-- {
|
||||
|
@ -89,33 +89,33 @@ func main() {
|
|||
|
||||
if circles[i].Alpha <= 0.0 {
|
||||
circles[i].Alpha = 0.0
|
||||
circles[i].Radius = float32(raylib.GetRandomValue(10, 40))
|
||||
circles[i].Position.X = float32(raylib.GetRandomValue(int32(circles[i].Radius), screenWidth-int32(circles[i].Radius)))
|
||||
circles[i].Position.Y = float32(raylib.GetRandomValue(int32(circles[i].Radius), screenHeight-int32(circles[i].Radius)))
|
||||
circles[i].Color = colors[raylib.GetRandomValue(0, 13)]
|
||||
circles[i].Speed = float32(raylib.GetRandomValue(1, 100)) / 20000.0
|
||||
circles[i].Radius = float32(rl.GetRandomValue(10, 40))
|
||||
circles[i].Position.X = float32(rl.GetRandomValue(int32(circles[i].Radius), screenWidth-int32(circles[i].Radius)))
|
||||
circles[i].Position.Y = float32(rl.GetRandomValue(int32(circles[i].Radius), screenHeight-int32(circles[i].Radius)))
|
||||
circles[i].Color = colors[rl.GetRandomValue(0, 13)]
|
||||
circles[i].Speed = float32(rl.GetRandomValue(1, 100)) / 20000.0
|
||||
}
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
for i := maxCircles - 1; i >= 0; i-- {
|
||||
raylib.DrawCircleV(circles[i].Position, float32(circles[i].Radius), raylib.Fade(circles[i].Color, circles[i].Alpha))
|
||||
rl.DrawCircleV(circles[i].Position, float32(circles[i].Radius), rl.Fade(circles[i].Color, circles[i].Alpha))
|
||||
}
|
||||
|
||||
// Draw time bar
|
||||
raylib.DrawRectangle(20, screenHeight-20-12, screenWidth-40, 12, raylib.LightGray)
|
||||
raylib.DrawRectangle(20, screenHeight-20-12, timePlayed, 12, raylib.Maroon)
|
||||
raylib.DrawRectangleLines(20, screenHeight-20-12, screenWidth-40, 12, raylib.Gray)
|
||||
rl.DrawRectangle(20, screenHeight-20-12, screenWidth-40, 12, rl.LightGray)
|
||||
rl.DrawRectangle(20, screenHeight-20-12, timePlayed, 12, rl.Maroon)
|
||||
rl.DrawRectangleLines(20, screenHeight-20-12, screenWidth-40, 12, rl.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadMusicStream(xm)
|
||||
rl.UnloadMusicStream(xm)
|
||||
|
||||
raylib.CloseAudioDevice()
|
||||
rl.CloseAudioDevice()
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -5,56 +5,56 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
raylib.InitWindow(800, 450, "raylib [audio] example - music playing (streaming)")
|
||||
raylib.InitAudioDevice()
|
||||
rl.InitWindow(800, 450, "raylib [audio] example - music playing (streaming)")
|
||||
rl.InitAudioDevice()
|
||||
|
||||
music := raylib.LoadMusicStream("guitar_noodling.ogg")
|
||||
music := rl.LoadMusicStream("guitar_noodling.ogg")
|
||||
pause := false
|
||||
|
||||
raylib.PlayMusicStream(music)
|
||||
rl.PlayMusicStream(music)
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.UpdateMusicStream(music) // Update music buffer with new stream data
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.UpdateMusicStream(music) // Update music buffer with new stream data
|
||||
|
||||
// Restart music playing (stop and play)
|
||||
if raylib.IsKeyPressed(raylib.KeySpace) {
|
||||
raylib.StopMusicStream(music)
|
||||
raylib.PlayMusicStream(music)
|
||||
if rl.IsKeyPressed(rl.KeySpace) {
|
||||
rl.StopMusicStream(music)
|
||||
rl.PlayMusicStream(music)
|
||||
}
|
||||
|
||||
// Pause/Resume music playing
|
||||
if raylib.IsKeyPressed(raylib.KeyP) {
|
||||
if rl.IsKeyPressed(rl.KeyP) {
|
||||
pause = !pause
|
||||
|
||||
if pause {
|
||||
raylib.PauseMusicStream(music)
|
||||
rl.PauseMusicStream(music)
|
||||
} else {
|
||||
raylib.ResumeMusicStream(music)
|
||||
rl.ResumeMusicStream(music)
|
||||
}
|
||||
}
|
||||
|
||||
// Get timePlayed scaled to bar dimensions (400 pixels)
|
||||
timePlayed := raylib.GetMusicTimePlayed(music) / raylib.GetMusicTimeLength(music) * 100 * 4
|
||||
timePlayed := rl.GetMusicTimePlayed(music) / rl.GetMusicTimeLength(music) * 100 * 4
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
raylib.DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, raylib.LightGray)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
rl.DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, rl.LightGray)
|
||||
|
||||
raylib.DrawRectangle(200, 200, 400, 12, raylib.LightGray)
|
||||
raylib.DrawRectangle(200, 200, int32(timePlayed), 12, raylib.Maroon)
|
||||
raylib.DrawRectangleLines(200, 200, 400, 12, raylib.Gray)
|
||||
rl.DrawRectangle(200, 200, 400, 12, rl.LightGray)
|
||||
rl.DrawRectangle(200, 200, int32(timePlayed), 12, rl.Maroon)
|
||||
rl.DrawRectangleLines(200, 200, 400, 12, rl.Gray)
|
||||
|
||||
raylib.DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, raylib.LightGray)
|
||||
raylib.DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, raylib.LightGray)
|
||||
rl.DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, rl.LightGray)
|
||||
rl.DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, rl.LightGray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadMusicStream(music) // Unload music stream buffers from RAM
|
||||
raylib.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
||||
rl.UnloadMusicStream(music) // Unload music stream buffers from RAM
|
||||
rl.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -12,34 +12,34 @@ const (
|
|||
)
|
||||
|
||||
func main() {
|
||||
raylib.InitWindow(800, 450, "raylib [audio] example - raw audio streaming")
|
||||
rl.InitWindow(800, 450, "raylib [audio] example - raw audio streaming")
|
||||
|
||||
raylib.InitAudioDevice()
|
||||
rl.InitAudioDevice()
|
||||
|
||||
// Init raw audio stream (sample rate: 22050, sample size: 32bit-float, channels: 1-mono)
|
||||
stream := raylib.InitAudioStream(22050, 32, 1)
|
||||
stream := rl.InitAudioStream(22050, 32, 1)
|
||||
|
||||
//// Fill audio stream with some samples (sine wave)
|
||||
data := make([]float32, maxSamples)
|
||||
|
||||
for i := 0; i < maxSamples; i++ {
|
||||
data[i] = float32(math.Sin(float64((2*raylib.Pi*float32(i))/2) * raylib.Deg2rad))
|
||||
data[i] = float32(math.Sin(float64((2*rl.Pi*float32(i))/2) * rl.Deg2rad))
|
||||
}
|
||||
|
||||
// NOTE: The generated MAX_SAMPLES do not fit to close a perfect loop
|
||||
// for that reason, there is a clip everytime audio stream is looped
|
||||
raylib.PlayAudioStream(stream)
|
||||
rl.PlayAudioStream(stream)
|
||||
|
||||
totalSamples := int32(maxSamples)
|
||||
samplesLeft := int32(totalSamples)
|
||||
|
||||
position := raylib.NewVector2(0, 0)
|
||||
position := rl.NewVector2(0, 0)
|
||||
|
||||
raylib.SetTargetFPS(30)
|
||||
rl.SetTargetFPS(30)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
// Refill audio stream if required
|
||||
if raylib.IsAudioBufferProcessed(stream) {
|
||||
if rl.IsAudioBufferProcessed(stream) {
|
||||
numSamples := int32(0)
|
||||
if samplesLeft >= maxSamplesPerUpdate {
|
||||
numSamples = maxSamplesPerUpdate
|
||||
|
@ -47,7 +47,7 @@ func main() {
|
|||
numSamples = samplesLeft
|
||||
}
|
||||
|
||||
raylib.UpdateAudioStream(stream, data[totalSamples-samplesLeft:], numSamples)
|
||||
rl.UpdateAudioStream(stream, data[totalSamples-samplesLeft:], numSamples)
|
||||
|
||||
samplesLeft -= numSamples
|
||||
|
||||
|
@ -57,25 +57,25 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
raylib.DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, raylib.LightGray)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
rl.DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, rl.LightGray)
|
||||
|
||||
// NOTE: Draw a part of the sine wave (only screen width)
|
||||
for i := 0; i < int(raylib.GetScreenWidth()); i++ {
|
||||
for i := 0; i < int(rl.GetScreenWidth()); i++ {
|
||||
position.X = float32(i)
|
||||
position.Y = 250 + 50*data[i]
|
||||
|
||||
raylib.DrawPixelV(position, raylib.Red)
|
||||
rl.DrawPixelV(position, rl.Red)
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseAudioStream(stream) // Close raw audio stream and delete buffers from RAM
|
||||
rl.CloseAudioStream(stream) // Close raw audio stream and delete buffers from RAM
|
||||
|
||||
raylib.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
||||
rl.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -5,37 +5,37 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
raylib.InitWindow(800, 450, "raylib [audio] example - sound loading and playing")
|
||||
rl.InitWindow(800, 450, "raylib [audio] example - sound loading and playing")
|
||||
|
||||
raylib.InitAudioDevice()
|
||||
rl.InitAudioDevice()
|
||||
|
||||
fxWav := raylib.LoadSound("weird.wav")
|
||||
fxOgg := raylib.LoadSound("tanatana.ogg")
|
||||
fxWav := rl.LoadSound("weird.wav")
|
||||
fxOgg := rl.LoadSound("tanatana.ogg")
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsKeyPressed(raylib.KeySpace) {
|
||||
raylib.PlaySound(fxWav)
|
||||
for !rl.WindowShouldClose() {
|
||||
if rl.IsKeyPressed(rl.KeySpace) {
|
||||
rl.PlaySound(fxWav)
|
||||
}
|
||||
if raylib.IsKeyPressed(raylib.KeyEnter) {
|
||||
raylib.PlaySound(fxOgg)
|
||||
if rl.IsKeyPressed(rl.KeyEnter) {
|
||||
rl.PlaySound(fxOgg)
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, raylib.LightGray)
|
||||
raylib.DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, raylib.LightGray)
|
||||
rl.DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, rl.LightGray)
|
||||
rl.DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, rl.LightGray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadSound(fxWav)
|
||||
raylib.UnloadSound(fxOgg)
|
||||
rl.UnloadSound(fxWav)
|
||||
rl.UnloadSound(fxOgg)
|
||||
|
||||
raylib.CloseAudioDevice()
|
||||
rl.CloseAudioDevice()
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [easings] example - easings")
|
||||
rl.SetConfigFlags(rl.FlagVsyncHint)
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [easings] example - easings")
|
||||
|
||||
currentTime := 0
|
||||
duration := float32(60)
|
||||
|
@ -19,7 +19,7 @@ func main() {
|
|||
finalPositionX := startPositionX * 3
|
||||
currentPositionX := startPositionX
|
||||
|
||||
ballPosition := raylib.NewVector2(startPositionX, float32(screenHeight)/2)
|
||||
ballPosition := rl.NewVector2(startPositionX, float32(screenHeight)/2)
|
||||
|
||||
comboActive := 0
|
||||
comboLastActive := 0
|
||||
|
@ -27,10 +27,10 @@ func main() {
|
|||
easingTypes := []string{"SineIn", "SineOut", "SineInOut", "BounceIn", "BounceOut", "BounceInOut", "BackIn", "BackOut", "BackInOut"}
|
||||
ease := easingTypes[comboActive]
|
||||
|
||||
//raylib.SetTargetFPS(60)
|
||||
//rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsKeyDown(raylib.KeyR) {
|
||||
for !rl.WindowShouldClose() {
|
||||
if rl.IsKeyDown(rl.KeyR) {
|
||||
currentTime = 0
|
||||
currentPositionX = startPositionX
|
||||
ballPosition.X = currentPositionX
|
||||
|
@ -71,18 +71,18 @@ func main() {
|
|||
currentTime++
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raygui.Label(raylib.NewRectangle(20, 20, 200, 20), "Easing Type:")
|
||||
comboActive = raygui.ComboBox(raylib.NewRectangle(20, 40, 200, 20), easingTypes, comboActive)
|
||||
raygui.Label(rl.NewRectangle(20, 20, 200, 20), "Easing Type:")
|
||||
comboActive = raygui.ComboBox(rl.NewRectangle(20, 40, 200, 20), easingTypes, comboActive)
|
||||
|
||||
raygui.Label(raylib.NewRectangle(20, 80, 200, 20), "Press R to reset")
|
||||
raygui.Label(rl.NewRectangle(20, 80, 200, 20), "Press R to reset")
|
||||
|
||||
raylib.DrawCircleV(ballPosition, 50, raylib.Maroon)
|
||||
rl.DrawCircleV(ballPosition, 50, rl.Maroon)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -35,20 +35,20 @@ const (
|
|||
|
||||
// Floppy type
|
||||
type Floppy struct {
|
||||
Position raylib.Vector2
|
||||
Position rl.Vector2
|
||||
}
|
||||
|
||||
// Pipe type
|
||||
type Pipe struct {
|
||||
Rec raylib.Rectangle
|
||||
Color raylib.Color
|
||||
Rec rl.Rectangle
|
||||
Color rl.Color
|
||||
Active bool
|
||||
}
|
||||
|
||||
// Particle type
|
||||
type Particle struct {
|
||||
Position raylib.Vector2
|
||||
Color raylib.Color
|
||||
Position rl.Vector2
|
||||
Color rl.Color
|
||||
Alpha float32
|
||||
Size float32
|
||||
Rotation float32
|
||||
|
@ -57,17 +57,17 @@ type Particle struct {
|
|||
|
||||
// Game type
|
||||
type Game struct {
|
||||
FxFlap raylib.Sound
|
||||
FxSlap raylib.Sound
|
||||
FxPoint raylib.Sound
|
||||
FxClick raylib.Sound
|
||||
FxFlap rl.Sound
|
||||
FxSlap rl.Sound
|
||||
FxPoint rl.Sound
|
||||
FxClick rl.Sound
|
||||
|
||||
TxSprites raylib.Texture2D
|
||||
TxSmoke raylib.Texture2D
|
||||
TxClouds raylib.Texture2D
|
||||
TxSprites rl.Texture2D
|
||||
TxSmoke rl.Texture2D
|
||||
TxClouds rl.Texture2D
|
||||
|
||||
CloudRec raylib.Rectangle
|
||||
FrameRec raylib.Rectangle
|
||||
CloudRec rl.Rectangle
|
||||
FrameRec rl.Rectangle
|
||||
|
||||
GameOver bool
|
||||
Dead bool
|
||||
|
@ -84,7 +84,7 @@ type Game struct {
|
|||
Particles []Particle
|
||||
|
||||
Pipes []Pipe
|
||||
PipesPos []raylib.Vector2
|
||||
PipesPos []rl.Vector2
|
||||
}
|
||||
|
||||
// NewGame - Start new game
|
||||
|
@ -95,7 +95,7 @@ func NewGame() (g Game) {
|
|||
|
||||
// On Android this sets callback function to be used for android_main
|
||||
func init() {
|
||||
raylib.SetCallbackFunc(main)
|
||||
rl.SetCallbackFunc(main)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -104,16 +104,16 @@ func main() {
|
|||
game.GameOver = true
|
||||
|
||||
// Initialize window
|
||||
raylib.InitWindow(screenWidth, screenHeight, "Floppy Gopher")
|
||||
rl.InitWindow(screenWidth, screenHeight, "Floppy Gopher")
|
||||
|
||||
// Initialize audio
|
||||
raylib.InitAudioDevice()
|
||||
rl.InitAudioDevice()
|
||||
|
||||
// NOTE: Textures and Sounds MUST be loaded after Window/Audio initialization
|
||||
game.Load()
|
||||
|
||||
// Limit FPS
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
// Main loop
|
||||
for !game.WindowShouldClose {
|
||||
|
@ -128,10 +128,10 @@ func main() {
|
|||
game.Unload()
|
||||
|
||||
// Close audio
|
||||
raylib.CloseAudioDevice()
|
||||
rl.CloseAudioDevice()
|
||||
|
||||
// Close window
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
|
||||
// Exit
|
||||
os.Exit(0)
|
||||
|
@ -141,37 +141,37 @@ func main() {
|
|||
func (g *Game) Init() {
|
||||
|
||||
// Gopher
|
||||
g.Floppy = Floppy{raylib.NewVector2(80, float32(screenHeight)/2-spriteSize/2)}
|
||||
g.Floppy = Floppy{rl.NewVector2(80, float32(screenHeight)/2-spriteSize/2)}
|
||||
|
||||
// Sprite rectangle
|
||||
g.FrameRec = raylib.NewRectangle(0, 0, spriteSize, spriteSize)
|
||||
g.FrameRec = rl.NewRectangle(0, 0, spriteSize, spriteSize)
|
||||
|
||||
// Cloud rectangle
|
||||
g.CloudRec = raylib.NewRectangle(0, 0, float32(screenWidth), float32(g.TxClouds.Height))
|
||||
g.CloudRec = rl.NewRectangle(0, 0, float32(screenWidth), float32(g.TxClouds.Height))
|
||||
|
||||
// Initialize particles
|
||||
g.Particles = make([]Particle, maxParticles)
|
||||
for i := 0; i < maxParticles; i++ {
|
||||
g.Particles[i].Position = raylib.NewVector2(0, 0)
|
||||
g.Particles[i].Color = raylib.RayWhite
|
||||
g.Particles[i].Position = rl.NewVector2(0, 0)
|
||||
g.Particles[i].Color = rl.RayWhite
|
||||
g.Particles[i].Alpha = 1.0
|
||||
g.Particles[i].Size = float32(raylib.GetRandomValue(1, 30)) / 20.0
|
||||
g.Particles[i].Rotation = float32(raylib.GetRandomValue(0, 360))
|
||||
g.Particles[i].Size = float32(rl.GetRandomValue(1, 30)) / 20.0
|
||||
g.Particles[i].Rotation = float32(rl.GetRandomValue(0, 360))
|
||||
g.Particles[i].Active = false
|
||||
}
|
||||
|
||||
// Pipes positions
|
||||
g.PipesPos = make([]raylib.Vector2, maxPipes)
|
||||
g.PipesPos = make([]rl.Vector2, maxPipes)
|
||||
for i := 0; i < maxPipes; i++ {
|
||||
g.PipesPos[i].X = float32(480 + 360*i)
|
||||
g.PipesPos[i].Y = -float32(raylib.GetRandomValue(0, 240))
|
||||
g.PipesPos[i].Y = -float32(rl.GetRandomValue(0, 240))
|
||||
}
|
||||
|
||||
// Pipes colors
|
||||
colors := []raylib.Color{
|
||||
raylib.Orange, raylib.Red, raylib.Gold, raylib.Lime,
|
||||
raylib.Violet, raylib.Brown, raylib.LightGray, raylib.Blue,
|
||||
raylib.Yellow, raylib.Green, raylib.Purple, raylib.Beige,
|
||||
colors := []rl.Color{
|
||||
rl.Orange, rl.Red, rl.Gold, rl.Lime,
|
||||
rl.Violet, rl.Brown, rl.LightGray, rl.Blue,
|
||||
rl.Yellow, rl.Green, rl.Purple, rl.Beige,
|
||||
}
|
||||
|
||||
// Pipes
|
||||
|
@ -181,7 +181,7 @@ func (g *Game) Init() {
|
|||
g.Pipes[i].Rec.Y = g.PipesPos[i/2].Y
|
||||
g.Pipes[i].Rec.Width = pipesWidth
|
||||
g.Pipes[i].Rec.Height = 550
|
||||
g.Pipes[i].Color = colors[raylib.GetRandomValue(0, int32(len(colors)-1))]
|
||||
g.Pipes[i].Color = colors[rl.GetRandomValue(0, int32(len(colors)-1))]
|
||||
|
||||
g.Pipes[i+1].Rec.X = g.PipesPos[i/2].X
|
||||
g.Pipes[i+1].Rec.Y = 1200 + g.PipesPos[i/2].Y - 550
|
||||
|
@ -203,35 +203,35 @@ func (g *Game) Init() {
|
|||
|
||||
// Load - Load resources
|
||||
func (g *Game) Load() {
|
||||
g.FxFlap = raylib.LoadSound("sounds/flap.wav")
|
||||
g.FxSlap = raylib.LoadSound("sounds/slap.wav")
|
||||
g.FxPoint = raylib.LoadSound("sounds/point.wav")
|
||||
g.FxClick = raylib.LoadSound("sounds/click.wav")
|
||||
g.TxSprites = raylib.LoadTexture("images/sprite.png")
|
||||
g.TxSmoke = raylib.LoadTexture("images/smoke.png")
|
||||
g.TxClouds = raylib.LoadTexture("images/clouds.png")
|
||||
g.FxFlap = rl.LoadSound("sounds/flap.wav")
|
||||
g.FxSlap = rl.LoadSound("sounds/slap.wav")
|
||||
g.FxPoint = rl.LoadSound("sounds/point.wav")
|
||||
g.FxClick = rl.LoadSound("sounds/click.wav")
|
||||
g.TxSprites = rl.LoadTexture("images/sprite.png")
|
||||
g.TxSmoke = rl.LoadTexture("images/smoke.png")
|
||||
g.TxClouds = rl.LoadTexture("images/clouds.png")
|
||||
}
|
||||
|
||||
// Unload - Unload resources
|
||||
func (g *Game) Unload() {
|
||||
raylib.UnloadSound(g.FxFlap)
|
||||
raylib.UnloadSound(g.FxSlap)
|
||||
raylib.UnloadSound(g.FxPoint)
|
||||
raylib.UnloadSound(g.FxClick)
|
||||
raylib.UnloadTexture(g.TxSprites)
|
||||
raylib.UnloadTexture(g.TxSmoke)
|
||||
raylib.UnloadTexture(g.TxClouds)
|
||||
rl.UnloadSound(g.FxFlap)
|
||||
rl.UnloadSound(g.FxSlap)
|
||||
rl.UnloadSound(g.FxPoint)
|
||||
rl.UnloadSound(g.FxClick)
|
||||
rl.UnloadTexture(g.TxSprites)
|
||||
rl.UnloadTexture(g.TxSmoke)
|
||||
rl.UnloadTexture(g.TxClouds)
|
||||
}
|
||||
|
||||
// Update - Update game
|
||||
func (g *Game) Update() {
|
||||
if raylib.WindowShouldClose() {
|
||||
if rl.WindowShouldClose() {
|
||||
g.WindowShouldClose = true
|
||||
}
|
||||
|
||||
if !g.GameOver {
|
||||
if raylib.IsKeyPressed(raylib.KeyP) || raylib.IsKeyPressed(raylib.KeyBack) {
|
||||
raylib.PlaySound(g.FxClick)
|
||||
if rl.IsKeyPressed(rl.KeyP) || rl.IsKeyPressed(rl.KeyBack) {
|
||||
rl.PlaySound(g.FxClick)
|
||||
|
||||
if runtime.GOOS == "android" && g.Pause {
|
||||
g.WindowShouldClose = true
|
||||
|
@ -259,8 +259,8 @@ func (g *Game) Update() {
|
|||
}
|
||||
|
||||
// Movement/Controls
|
||||
if raylib.IsKeyDown(raylib.KeySpace) || raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
||||
raylib.PlaySound(g.FxFlap)
|
||||
if rl.IsKeyDown(rl.KeySpace) || rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||
rl.PlaySound(g.FxFlap)
|
||||
|
||||
// Activate one particle every frame
|
||||
for i := 0; i < maxParticles; i++ {
|
||||
|
@ -315,11 +315,11 @@ func (g *Game) Update() {
|
|||
|
||||
// Check Collisions
|
||||
for i := 0; i < maxPipes*2; i++ {
|
||||
if raylib.CheckCollisionRecs(raylib.NewRectangle(g.Floppy.Position.X, g.Floppy.Position.Y, spriteSize, spriteSize), g.Pipes[i].Rec) {
|
||||
if rl.CheckCollisionRecs(rl.NewRectangle(g.Floppy.Position.X, g.Floppy.Position.Y, spriteSize, spriteSize), g.Pipes[i].Rec) {
|
||||
// OMG You killed Gopher you bastard!
|
||||
g.Dead = true
|
||||
|
||||
raylib.PlaySound(g.FxSlap)
|
||||
rl.PlaySound(g.FxSlap)
|
||||
} else if (g.PipesPos[i/2].X < g.Floppy.Position.X-spriteSize) && g.Pipes[i/2].Active && !g.GameOver {
|
||||
// Score point
|
||||
g.Score += 1
|
||||
|
@ -333,7 +333,7 @@ func (g *Game) Update() {
|
|||
g.HiScore = g.Score
|
||||
}
|
||||
|
||||
raylib.PlaySound(g.FxPoint)
|
||||
rl.PlaySound(g.FxPoint)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -351,17 +351,17 @@ func (g *Game) Update() {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
||||
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||
g.Pause = !g.Pause
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if raylib.IsKeyPressed(raylib.KeyEnter) || raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
||||
raylib.PlaySound(g.FxClick)
|
||||
if rl.IsKeyPressed(rl.KeyEnter) || rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||
rl.PlaySound(g.FxClick)
|
||||
|
||||
// Return of the Gopher!
|
||||
g.Init()
|
||||
} else if runtime.GOOS == "android" && raylib.IsKeyDown(raylib.KeyBack) {
|
||||
} else if runtime.GOOS == "android" && rl.IsKeyDown(rl.KeyBack) {
|
||||
g.WindowShouldClose = true
|
||||
}
|
||||
|
||||
|
@ -379,32 +379,32 @@ func (g *Game) Update() {
|
|||
|
||||
// Draw - Draw game
|
||||
func (g *Game) Draw() {
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.SkyBlue)
|
||||
rl.ClearBackground(rl.SkyBlue)
|
||||
|
||||
if !g.GameOver {
|
||||
// Draw clouds
|
||||
raylib.DrawTextureRec(g.TxClouds, g.CloudRec, raylib.NewVector2(0, float32(screenHeight-g.TxClouds.Height)), raylib.RayWhite)
|
||||
rl.DrawTextureRec(g.TxClouds, g.CloudRec, rl.NewVector2(0, float32(screenHeight-g.TxClouds.Height)), rl.RayWhite)
|
||||
|
||||
// Draw rotated clouds
|
||||
raylib.DrawTexturePro(g.TxClouds, raylib.NewRectangle(-g.CloudRec.X, 0, float32(g.TxClouds.Width), float32(g.TxClouds.Height)),
|
||||
raylib.NewRectangle(0, 0, float32(g.TxClouds.Width), float32(g.TxClouds.Height)), raylib.NewVector2(float32(g.TxClouds.Width), float32(g.TxClouds.Height)), 180, raylib.White)
|
||||
rl.DrawTexturePro(g.TxClouds, rl.NewRectangle(-g.CloudRec.X, 0, float32(g.TxClouds.Width), float32(g.TxClouds.Height)),
|
||||
rl.NewRectangle(0, 0, float32(g.TxClouds.Width), float32(g.TxClouds.Height)), rl.NewVector2(float32(g.TxClouds.Width), float32(g.TxClouds.Height)), 180, rl.White)
|
||||
|
||||
// Draw Gopher
|
||||
raylib.DrawTextureRec(g.TxSprites, g.FrameRec, g.Floppy.Position, raylib.RayWhite)
|
||||
rl.DrawTextureRec(g.TxSprites, g.FrameRec, g.Floppy.Position, rl.RayWhite)
|
||||
|
||||
// Draw active particles
|
||||
if !g.Dead {
|
||||
for i := 0; i < maxParticles; i++ {
|
||||
if g.Particles[i].Active {
|
||||
raylib.DrawTexturePro(
|
||||
rl.DrawTexturePro(
|
||||
g.TxSmoke,
|
||||
raylib.NewRectangle(0, 0, float32(g.TxSmoke.Width), float32(g.TxSmoke.Height)),
|
||||
raylib.NewRectangle(g.Particles[i].Position.X, g.Particles[i].Position.Y, float32(g.TxSmoke.Width)*g.Particles[i].Size, float32(g.TxSmoke.Height)*g.Particles[i].Size),
|
||||
raylib.NewVector2(float32(g.TxSmoke.Width)*g.Particles[i].Size/2, float32(g.TxSmoke.Height)*g.Particles[i].Size/2),
|
||||
rl.NewRectangle(0, 0, float32(g.TxSmoke.Width), float32(g.TxSmoke.Height)),
|
||||
rl.NewRectangle(g.Particles[i].Position.X, g.Particles[i].Position.Y, float32(g.TxSmoke.Width)*g.Particles[i].Size, float32(g.TxSmoke.Height)*g.Particles[i].Size),
|
||||
rl.NewVector2(float32(g.TxSmoke.Width)*g.Particles[i].Size/2, float32(g.TxSmoke.Height)*g.Particles[i].Size/2),
|
||||
g.Particles[i].Rotation,
|
||||
raylib.Fade(g.Particles[i].Color, g.Particles[i].Alpha),
|
||||
rl.Fade(g.Particles[i].Color, g.Particles[i].Alpha),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -412,41 +412,41 @@ func (g *Game) Draw() {
|
|||
|
||||
// Draw pipes
|
||||
for i := 0; i < maxPipes; i++ {
|
||||
raylib.DrawRectangle(int32(g.Pipes[i*2].Rec.X), int32(g.Pipes[i*2].Rec.Y), int32(g.Pipes[i*2].Rec.Width), int32(g.Pipes[i*2].Rec.Height), g.Pipes[i*2].Color)
|
||||
raylib.DrawRectangle(int32(g.Pipes[i*2+1].Rec.X), int32(g.Pipes[i*2+1].Rec.Y), int32(g.Pipes[i*2+1].Rec.Width), int32(g.Pipes[i*2+1].Rec.Height), g.Pipes[i*2].Color)
|
||||
rl.DrawRectangle(int32(g.Pipes[i*2].Rec.X), int32(g.Pipes[i*2].Rec.Y), int32(g.Pipes[i*2].Rec.Width), int32(g.Pipes[i*2].Rec.Height), g.Pipes[i*2].Color)
|
||||
rl.DrawRectangle(int32(g.Pipes[i*2+1].Rec.X), int32(g.Pipes[i*2+1].Rec.Y), int32(g.Pipes[i*2+1].Rec.Width), int32(g.Pipes[i*2+1].Rec.Height), g.Pipes[i*2].Color)
|
||||
|
||||
// Draw borders
|
||||
raylib.DrawRectangleLines(int32(g.Pipes[i*2].Rec.X), int32(g.Pipes[i*2].Rec.Y), int32(g.Pipes[i*2].Rec.Width), int32(g.Pipes[i*2].Rec.Height), raylib.Black)
|
||||
raylib.DrawRectangleLines(int32(g.Pipes[i*2+1].Rec.X), int32(g.Pipes[i*2+1].Rec.Y), int32(g.Pipes[i*2+1].Rec.Width), int32(g.Pipes[i*2+1].Rec.Height), raylib.Black)
|
||||
rl.DrawRectangleLines(int32(g.Pipes[i*2].Rec.X), int32(g.Pipes[i*2].Rec.Y), int32(g.Pipes[i*2].Rec.Width), int32(g.Pipes[i*2].Rec.Height), rl.Black)
|
||||
rl.DrawRectangleLines(int32(g.Pipes[i*2+1].Rec.X), int32(g.Pipes[i*2+1].Rec.Y), int32(g.Pipes[i*2+1].Rec.Width), int32(g.Pipes[i*2+1].Rec.Height), rl.Black)
|
||||
}
|
||||
|
||||
// Draw Super Flashing FX (one frame only)
|
||||
if g.SuperFX {
|
||||
raylib.DrawRectangle(0, 0, screenWidth, screenHeight, raylib.White)
|
||||
rl.DrawRectangle(0, 0, screenWidth, screenHeight, rl.White)
|
||||
g.SuperFX = false
|
||||
}
|
||||
|
||||
// Draw HI-SCORE
|
||||
raylib.DrawText(fmt.Sprintf("%02d", g.Score), 20, 20, 32, raylib.Black)
|
||||
raylib.DrawText(fmt.Sprintf("HI-SCORE: %02d", g.HiScore), 20, 64, 20, raylib.Black)
|
||||
rl.DrawText(fmt.Sprintf("%02d", g.Score), 20, 20, 32, rl.Black)
|
||||
rl.DrawText(fmt.Sprintf("HI-SCORE: %02d", g.HiScore), 20, 64, 20, rl.Black)
|
||||
|
||||
if g.Pause {
|
||||
// Draw PAUSED text
|
||||
raylib.DrawText("PAUSED", screenWidth/2-raylib.MeasureText("PAUSED", 24)/2, screenHeight/2-50, 20, raylib.Black)
|
||||
rl.DrawText("PAUSED", screenWidth/2-rl.MeasureText("PAUSED", 24)/2, screenHeight/2-50, 20, rl.Black)
|
||||
}
|
||||
} else {
|
||||
// Draw text
|
||||
raylib.DrawText("Floppy Gopher", raylib.GetScreenWidth()/2-raylib.MeasureText("Floppy Gopher", 40)/2, raylib.GetScreenHeight()/2-150, 40, raylib.RayWhite)
|
||||
rl.DrawText("Floppy Gopher", rl.GetScreenWidth()/2-rl.MeasureText("Floppy Gopher", 40)/2, rl.GetScreenHeight()/2-150, 40, rl.RayWhite)
|
||||
|
||||
if runtime.GOOS == "android" {
|
||||
raylib.DrawText("[TAP] TO PLAY", raylib.GetScreenWidth()/2-raylib.MeasureText("[TAP] TO PLAY", 20)/2, raylib.GetScreenHeight()/2-50, 20, raylib.Black)
|
||||
rl.DrawText("[TAP] TO PLAY", rl.GetScreenWidth()/2-rl.MeasureText("[TAP] TO PLAY", 20)/2, rl.GetScreenHeight()/2-50, 20, rl.Black)
|
||||
} else {
|
||||
raylib.DrawText("[ENTER] TO PLAY", raylib.GetScreenWidth()/2-raylib.MeasureText("[ENTER] TO PLAY", 20)/2, raylib.GetScreenHeight()/2-50, 20, raylib.Black)
|
||||
rl.DrawText("[ENTER] TO PLAY", rl.GetScreenWidth()/2-rl.MeasureText("[ENTER] TO PLAY", 20)/2, rl.GetScreenHeight()/2-50, 20, rl.Black)
|
||||
}
|
||||
|
||||
// Draw Gopher
|
||||
raylib.DrawTextureRec(g.TxSprites, g.FrameRec, raylib.NewVector2(float32(raylib.GetScreenWidth()/2-spriteSize/2), float32(raylib.GetScreenHeight()/2)), raylib.RayWhite)
|
||||
rl.DrawTextureRec(g.TxSprites, g.FrameRec, rl.NewVector2(float32(rl.GetScreenWidth()/2-spriteSize/2), float32(rl.GetScreenHeight()/2)), rl.RayWhite)
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ const (
|
|||
|
||||
// Cell type
|
||||
type Cell struct {
|
||||
Position raylib.Vector2
|
||||
Size raylib.Vector2
|
||||
Position rl.Vector2
|
||||
Size rl.Vector2
|
||||
Alive bool
|
||||
Next bool
|
||||
Visited bool
|
||||
|
@ -37,10 +37,10 @@ func main() {
|
|||
game := Game{}
|
||||
game.Init(false)
|
||||
|
||||
raylib.InitWindow(game.ScreenWidth, game.ScreenHeight, "Conway's Game of Life")
|
||||
raylib.SetTargetFPS(20)
|
||||
rl.InitWindow(game.ScreenWidth, game.ScreenHeight, "Conway's Game of Life")
|
||||
rl.SetTargetFPS(20)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
if game.Playing {
|
||||
game.Update()
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func main() {
|
|||
game.Draw()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
||||
// Init - Initialize game
|
||||
|
@ -70,8 +70,8 @@ func (g *Game) Init(clear bool) {
|
|||
for x := int32(0); x <= g.Cols; x++ {
|
||||
for y := int32(0); y <= g.Rows; y++ {
|
||||
g.Cells[x][y] = &Cell{}
|
||||
g.Cells[x][y].Position = raylib.NewVector2((float32(x) * squareSize), (float32(y)*squareSize)+1)
|
||||
g.Cells[x][y].Size = raylib.NewVector2(squareSize-1, squareSize-1)
|
||||
g.Cells[x][y].Position = rl.NewVector2((float32(x) * squareSize), (float32(y)*squareSize)+1)
|
||||
g.Cells[x][y].Size = rl.NewVector2(squareSize-1, squareSize-1)
|
||||
if rand.Float64() < 0.1 && clear == false {
|
||||
g.Cells[x][y].Alive = true
|
||||
}
|
||||
|
@ -82,19 +82,19 @@ func (g *Game) Init(clear bool) {
|
|||
// Input - Game input
|
||||
func (g *Game) Input() {
|
||||
// control
|
||||
if raylib.IsKeyPressed(raylib.KeyR) {
|
||||
if rl.IsKeyPressed(rl.KeyR) {
|
||||
g.Init(false)
|
||||
}
|
||||
if raylib.IsKeyPressed(raylib.KeyC) {
|
||||
if rl.IsKeyPressed(rl.KeyC) {
|
||||
g.Init(true)
|
||||
}
|
||||
if raylib.IsKeyDown(raylib.KeyRight) && !g.Playing {
|
||||
if rl.IsKeyDown(rl.KeyRight) && !g.Playing {
|
||||
g.Update()
|
||||
}
|
||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
||||
g.Click(raylib.GetMouseX(), raylib.GetMouseY())
|
||||
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||
g.Click(rl.GetMouseX(), rl.GetMouseY())
|
||||
}
|
||||
if raylib.IsKeyPressed(raylib.KeySpace) {
|
||||
if rl.IsKeyPressed(rl.KeySpace) {
|
||||
g.Playing = !g.Playing
|
||||
}
|
||||
|
||||
|
@ -165,36 +165,36 @@ func (g *Game) CountNeighbors(x, y int32) int {
|
|||
|
||||
// Draw - Draw game
|
||||
func (g *Game) Draw() {
|
||||
raylib.BeginDrawing()
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
// Draw cells
|
||||
for x := int32(0); x <= g.Cols; x++ {
|
||||
for y := int32(0); y <= g.Rows; y++ {
|
||||
if g.Cells[x][y].Alive {
|
||||
raylib.DrawRectangleV(g.Cells[x][y].Position, g.Cells[x][y].Size, raylib.Blue)
|
||||
rl.DrawRectangleV(g.Cells[x][y].Position, g.Cells[x][y].Size, rl.Blue)
|
||||
} else if g.Cells[x][y].Visited {
|
||||
raylib.DrawRectangleV(g.Cells[x][y].Position, g.Cells[x][y].Size, raylib.Color{R: 128, G: 177, B: 136, A: 255})
|
||||
rl.DrawRectangleV(g.Cells[x][y].Position, g.Cells[x][y].Size, rl.Color{R: 128, G: 177, B: 136, A: 255})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw grid lines
|
||||
for i := int32(0); i < g.Cols+1; i++ {
|
||||
raylib.DrawLineV(
|
||||
raylib.NewVector2(float32(squareSize*i), 0),
|
||||
raylib.NewVector2(float32(squareSize*i), float32(g.ScreenHeight)),
|
||||
raylib.LightGray,
|
||||
rl.DrawLineV(
|
||||
rl.NewVector2(float32(squareSize*i), 0),
|
||||
rl.NewVector2(float32(squareSize*i), float32(g.ScreenHeight)),
|
||||
rl.LightGray,
|
||||
)
|
||||
}
|
||||
|
||||
for i := int32(0); i < g.Rows+1; i++ {
|
||||
raylib.DrawLineV(
|
||||
raylib.NewVector2(0, float32(squareSize*i)),
|
||||
raylib.NewVector2(float32(g.ScreenWidth), float32(squareSize*i)),
|
||||
raylib.LightGray,
|
||||
rl.DrawLineV(
|
||||
rl.NewVector2(0, float32(squareSize*i)),
|
||||
rl.NewVector2(float32(g.ScreenWidth), float32(squareSize*i)),
|
||||
rl.LightGray,
|
||||
)
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
|
|
@ -11,18 +11,18 @@ const (
|
|||
|
||||
// Snake type
|
||||
type Snake struct {
|
||||
Position raylib.Vector2
|
||||
Size raylib.Vector2
|
||||
Speed raylib.Vector2
|
||||
Color raylib.Color
|
||||
Position rl.Vector2
|
||||
Size rl.Vector2
|
||||
Speed rl.Vector2
|
||||
Color rl.Color
|
||||
}
|
||||
|
||||
// Food type
|
||||
type Food struct {
|
||||
Position raylib.Vector2
|
||||
Size raylib.Vector2
|
||||
Position rl.Vector2
|
||||
Size rl.Vector2
|
||||
Active bool
|
||||
Color raylib.Color
|
||||
Color rl.Color
|
||||
}
|
||||
|
||||
// Game type
|
||||
|
@ -36,9 +36,9 @@ type Game struct {
|
|||
|
||||
Fruit Food
|
||||
Snake []Snake
|
||||
SnakePosition []raylib.Vector2
|
||||
SnakePosition []rl.Vector2
|
||||
AllowMove bool
|
||||
Offset raylib.Vector2
|
||||
Offset rl.Vector2
|
||||
CounterTail int
|
||||
}
|
||||
|
||||
|
@ -46,17 +46,17 @@ func main() {
|
|||
game := Game{}
|
||||
game.Init()
|
||||
|
||||
raylib.InitWindow(game.ScreenWidth, game.ScreenHeight, "sample game: snake")
|
||||
rl.InitWindow(game.ScreenWidth, game.ScreenHeight, "sample game: snake")
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
game.Update()
|
||||
|
||||
game.Draw()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
||||
// Init - Initialize game
|
||||
|
@ -71,58 +71,58 @@ func (g *Game) Init() {
|
|||
g.CounterTail = 1
|
||||
g.AllowMove = false
|
||||
|
||||
g.Offset = raylib.Vector2{}
|
||||
g.Offset = rl.Vector2{}
|
||||
g.Offset.X = float32(g.ScreenWidth % squareSize)
|
||||
g.Offset.Y = float32(g.ScreenHeight % squareSize)
|
||||
|
||||
g.Snake = make([]Snake, snakeLength)
|
||||
|
||||
for i := 0; i < snakeLength; i++ {
|
||||
g.Snake[i].Position = raylib.NewVector2(g.Offset.X/2, g.Offset.Y/2)
|
||||
g.Snake[i].Size = raylib.NewVector2(squareSize, squareSize)
|
||||
g.Snake[i].Speed = raylib.NewVector2(squareSize, 0)
|
||||
g.Snake[i].Position = rl.NewVector2(g.Offset.X/2, g.Offset.Y/2)
|
||||
g.Snake[i].Size = rl.NewVector2(squareSize, squareSize)
|
||||
g.Snake[i].Speed = rl.NewVector2(squareSize, 0)
|
||||
|
||||
if i == 0 {
|
||||
g.Snake[i].Color = raylib.DarkBlue
|
||||
g.Snake[i].Color = rl.DarkBlue
|
||||
} else {
|
||||
g.Snake[i].Color = raylib.Blue
|
||||
g.Snake[i].Color = rl.Blue
|
||||
}
|
||||
}
|
||||
|
||||
g.SnakePosition = make([]raylib.Vector2, snakeLength)
|
||||
g.SnakePosition = make([]rl.Vector2, snakeLength)
|
||||
|
||||
for i := 0; i < snakeLength; i++ {
|
||||
g.SnakePosition[i] = raylib.NewVector2(0.0, 0.0)
|
||||
g.SnakePosition[i] = rl.NewVector2(0.0, 0.0)
|
||||
}
|
||||
|
||||
g.Fruit.Size = raylib.NewVector2(squareSize, squareSize)
|
||||
g.Fruit.Color = raylib.SkyBlue
|
||||
g.Fruit.Size = rl.NewVector2(squareSize, squareSize)
|
||||
g.Fruit.Color = rl.SkyBlue
|
||||
g.Fruit.Active = false
|
||||
}
|
||||
|
||||
// Update - Update game
|
||||
func (g *Game) Update() {
|
||||
if !g.GameOver {
|
||||
if raylib.IsKeyPressed(raylib.KeyP) {
|
||||
if rl.IsKeyPressed('P') {
|
||||
g.Pause = !g.Pause
|
||||
}
|
||||
|
||||
if !g.Pause {
|
||||
// control
|
||||
if raylib.IsKeyPressed(raylib.KeyRight) && g.Snake[0].Speed.X == 0 && g.AllowMove {
|
||||
g.Snake[0].Speed = raylib.NewVector2(squareSize, 0)
|
||||
if rl.IsKeyPressed(rl.KeyRight) && g.Snake[0].Speed.X == 0 && g.AllowMove {
|
||||
g.Snake[0].Speed = rl.NewVector2(squareSize, 0)
|
||||
g.AllowMove = false
|
||||
}
|
||||
if raylib.IsKeyPressed(raylib.KeyLeft) && g.Snake[0].Speed.X == 0 && g.AllowMove {
|
||||
g.Snake[0].Speed = raylib.NewVector2(-squareSize, 0)
|
||||
if rl.IsKeyPressed(rl.KeyLeft) && g.Snake[0].Speed.X == 0 && g.AllowMove {
|
||||
g.Snake[0].Speed = rl.NewVector2(-squareSize, 0)
|
||||
g.AllowMove = false
|
||||
}
|
||||
if raylib.IsKeyPressed(raylib.KeyUp) && g.Snake[0].Speed.Y == 0 && g.AllowMove {
|
||||
g.Snake[0].Speed = raylib.NewVector2(0, -squareSize)
|
||||
if rl.IsKeyPressed(rl.KeyUp) && g.Snake[0].Speed.Y == 0 && g.AllowMove {
|
||||
g.Snake[0].Speed = rl.NewVector2(0, -squareSize)
|
||||
g.AllowMove = false
|
||||
}
|
||||
if raylib.IsKeyPressed(raylib.KeyDown) && g.Snake[0].Speed.Y == 0 && g.AllowMove {
|
||||
g.Snake[0].Speed = raylib.NewVector2(0, squareSize)
|
||||
if rl.IsKeyPressed(rl.KeyDown) && g.Snake[0].Speed.Y == 0 && g.AllowMove {
|
||||
g.Snake[0].Speed = rl.NewVector2(0, squareSize)
|
||||
g.AllowMove = false
|
||||
}
|
||||
|
||||
|
@ -159,16 +159,16 @@ func (g *Game) Update() {
|
|||
|
||||
if !g.Fruit.Active {
|
||||
g.Fruit.Active = true
|
||||
g.Fruit.Position = raylib.NewVector2(
|
||||
float32(raylib.GetRandomValue(0, (g.ScreenWidth/squareSize)-1)*squareSize+int32(g.Offset.X)/2),
|
||||
float32(raylib.GetRandomValue(0, (g.ScreenHeight/squareSize)-1)*squareSize+int32(g.Offset.Y)/2),
|
||||
g.Fruit.Position = rl.NewVector2(
|
||||
float32(rl.GetRandomValue(0, (g.ScreenWidth/squareSize)-1)*squareSize+int32(g.Offset.X)/2),
|
||||
float32(rl.GetRandomValue(0, (g.ScreenHeight/squareSize)-1)*squareSize+int32(g.Offset.Y)/2),
|
||||
)
|
||||
|
||||
for i := 0; i < g.CounterTail; i++ {
|
||||
for (g.Fruit.Position.X == g.Snake[i].Position.X) && (g.Fruit.Position.Y == g.Snake[i].Position.Y) {
|
||||
g.Fruit.Position = raylib.NewVector2(
|
||||
float32(raylib.GetRandomValue(0, (g.ScreenWidth/squareSize)-1)*squareSize),
|
||||
float32(raylib.GetRandomValue(0, (g.ScreenHeight/squareSize)-1)*squareSize),
|
||||
g.Fruit.Position = rl.NewVector2(
|
||||
float32(rl.GetRandomValue(0, (g.ScreenWidth/squareSize)-1)*squareSize),
|
||||
float32(rl.GetRandomValue(0, (g.ScreenHeight/squareSize)-1)*squareSize),
|
||||
)
|
||||
i = 0
|
||||
}
|
||||
|
@ -176,9 +176,9 @@ func (g *Game) Update() {
|
|||
}
|
||||
|
||||
// collision
|
||||
if raylib.CheckCollisionRecs(
|
||||
raylib.NewRectangle(g.Snake[0].Position.X, g.Snake[0].Position.Y, g.Snake[0].Size.X, g.Snake[0].Size.Y),
|
||||
raylib.NewRectangle(g.Fruit.Position.X, g.Fruit.Position.Y, g.Fruit.Size.X, g.Fruit.Size.Y),
|
||||
if rl.CheckCollisionRecs(
|
||||
rl.NewRectangle(g.Snake[0].Position.X, g.Snake[0].Position.Y, g.Snake[0].Size.X, g.Snake[0].Size.Y),
|
||||
rl.NewRectangle(g.Fruit.Position.X, g.Fruit.Position.Y, g.Fruit.Size.X, g.Fruit.Size.Y),
|
||||
) {
|
||||
g.Snake[g.CounterTail].Position = g.SnakePosition[g.CounterTail-1]
|
||||
g.CounterTail += 1
|
||||
|
@ -188,7 +188,7 @@ func (g *Game) Update() {
|
|||
g.FramesCounter++
|
||||
}
|
||||
} else {
|
||||
if raylib.IsKeyPressed(raylib.KeyEnter) {
|
||||
if rl.IsKeyPressed(rl.KeyEnter) {
|
||||
g.Init()
|
||||
g.GameOver = false
|
||||
}
|
||||
|
@ -197,42 +197,42 @@ func (g *Game) Update() {
|
|||
|
||||
// Draw - Draw game
|
||||
func (g *Game) Draw() {
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
if !g.GameOver {
|
||||
// Draw grid lines
|
||||
for i := int32(0); i < g.ScreenWidth/squareSize+1; i++ {
|
||||
raylib.DrawLineV(
|
||||
raylib.NewVector2(float32(squareSize*i)+g.Offset.X/2, g.Offset.Y/2),
|
||||
raylib.NewVector2(float32(squareSize*i)+g.Offset.X/2, float32(g.ScreenHeight)-g.Offset.Y/2),
|
||||
raylib.LightGray,
|
||||
rl.DrawLineV(
|
||||
rl.NewVector2(float32(squareSize*i)+g.Offset.X/2, g.Offset.Y/2),
|
||||
rl.NewVector2(float32(squareSize*i)+g.Offset.X/2, float32(g.ScreenHeight)-g.Offset.Y/2),
|
||||
rl.LightGray,
|
||||
)
|
||||
}
|
||||
|
||||
for i := int32(0); i < g.ScreenHeight/squareSize+1; i++ {
|
||||
raylib.DrawLineV(
|
||||
raylib.NewVector2(g.Offset.X/2, float32(squareSize*i)+g.Offset.Y/2),
|
||||
raylib.NewVector2(float32(g.ScreenWidth)-g.Offset.X/2, float32(squareSize*i)+g.Offset.Y/2),
|
||||
raylib.LightGray,
|
||||
rl.DrawLineV(
|
||||
rl.NewVector2(g.Offset.X/2, float32(squareSize*i)+g.Offset.Y/2),
|
||||
rl.NewVector2(float32(g.ScreenWidth)-g.Offset.X/2, float32(squareSize*i)+g.Offset.Y/2),
|
||||
rl.LightGray,
|
||||
)
|
||||
}
|
||||
|
||||
// Draw snake
|
||||
for i := 0; i < g.CounterTail; i++ {
|
||||
raylib.DrawRectangleV(g.Snake[i].Position, g.Snake[i].Size, g.Snake[i].Color)
|
||||
rl.DrawRectangleV(g.Snake[i].Position, g.Snake[i].Size, g.Snake[i].Color)
|
||||
}
|
||||
|
||||
// Draw fruit to pick
|
||||
raylib.DrawRectangleV(g.Fruit.Position, g.Fruit.Size, g.Fruit.Color)
|
||||
rl.DrawRectangleV(g.Fruit.Position, g.Fruit.Size, g.Fruit.Color)
|
||||
|
||||
if g.Pause {
|
||||
raylib.DrawText("GAME PAUSED", g.ScreenWidth/2-raylib.MeasureText("GAME PAUSED", 40)/2, g.ScreenHeight/2-40, 40, raylib.Gray)
|
||||
rl.DrawText("GAME PAUSED", g.ScreenWidth/2-rl.MeasureText("GAME PAUSED", 40)/2, g.ScreenHeight/2-40, 40, rl.Gray)
|
||||
}
|
||||
} else {
|
||||
raylib.DrawText("PRESS [ENTER] TO PLAY AGAIN", raylib.GetScreenWidth()/2-raylib.MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, raylib.GetScreenHeight()/2-50, 20, raylib.Gray)
|
||||
rl.DrawText("PRESS [ENTER] TO PLAY AGAIN", rl.GetScreenWidth()/2-rl.MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, rl.GetScreenHeight()/2-50, 20, rl.Gray)
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
||||
rl.SetConfigFlags(rl.FlagVsyncHint)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [gui] example - basic controls")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [gui] example - basic controls")
|
||||
|
||||
buttonToggle := true
|
||||
buttonClicked := false
|
||||
|
@ -33,9 +33,9 @@ func main() {
|
|||
|
||||
var inputText string
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
if buttonClicked {
|
||||
progressValue += 0.1
|
||||
if progressValue >= 1.1 {
|
||||
|
@ -43,50 +43,50 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.Beige)
|
||||
rl.ClearBackground(rl.Beige)
|
||||
|
||||
raygui.Label(raylib.NewRectangle(50, 50, 80, 20), "Label")
|
||||
raygui.Label(rl.NewRectangle(50, 50, 80, 20), "Label")
|
||||
|
||||
buttonClicked = raygui.Button(raylib.NewRectangle(50, 70, 80, 40), "Button")
|
||||
buttonClicked = raygui.Button(rl.NewRectangle(50, 70, 80, 40), "Button")
|
||||
|
||||
raygui.Label(raylib.NewRectangle(70, 140, 20, 20), "Checkbox")
|
||||
checkboxChecked = raygui.CheckBox(raylib.NewRectangle(50, 140, 20, 20), checkboxChecked)
|
||||
raygui.Label(rl.NewRectangle(70, 140, 20, 20), "Checkbox")
|
||||
checkboxChecked = raygui.CheckBox(rl.NewRectangle(50, 140, 20, 20), checkboxChecked)
|
||||
|
||||
raygui.Label(raylib.NewRectangle(50, 190, 200, 20), "ProgressBar")
|
||||
raygui.ProgressBar(raylib.NewRectangle(50, 210, 200, 20), progressValue)
|
||||
raygui.Label(raylib.NewRectangle(200+50+5, 210, 20, 20), fmt.Sprintf("%.1f", progressValue))
|
||||
raygui.Label(rl.NewRectangle(50, 190, 200, 20), "ProgressBar")
|
||||
raygui.ProgressBar(rl.NewRectangle(50, 210, 200, 20), progressValue)
|
||||
raygui.Label(rl.NewRectangle(200+50+5, 210, 20, 20), fmt.Sprintf("%.1f", progressValue))
|
||||
|
||||
raygui.Label(raylib.NewRectangle(50, 260, 200, 20), "Slider")
|
||||
sliderValue = raygui.Slider(raylib.NewRectangle(50, 280, 200, 20), sliderValue, 0, 100)
|
||||
raygui.Label(raylib.NewRectangle(200+50+5, 280, 20, 20), fmt.Sprintf("%.0f", sliderValue))
|
||||
raygui.Label(rl.NewRectangle(50, 260, 200, 20), "Slider")
|
||||
sliderValue = raygui.Slider(rl.NewRectangle(50, 280, 200, 20), sliderValue, 0, 100)
|
||||
raygui.Label(rl.NewRectangle(200+50+5, 280, 20, 20), fmt.Sprintf("%.0f", sliderValue))
|
||||
|
||||
buttonToggle = raygui.ToggleButton(raylib.NewRectangle(50, 350, 100, 40), "ToggleButton", buttonToggle)
|
||||
buttonToggle = raygui.ToggleButton(rl.NewRectangle(50, 350, 100, 40), "ToggleButton", buttonToggle)
|
||||
|
||||
raygui.Label(raylib.NewRectangle(500, 50, 200, 20), "ToggleGroup")
|
||||
toggleActive = raygui.ToggleGroup(raylib.NewRectangle(500, 70, 60, 30), toggleText, toggleActive)
|
||||
raygui.Label(rl.NewRectangle(500, 50, 200, 20), "ToggleGroup")
|
||||
toggleActive = raygui.ToggleGroup(rl.NewRectangle(500, 70, 60, 30), toggleText, toggleActive)
|
||||
|
||||
raygui.Label(raylib.NewRectangle(500, 120, 200, 20), "SliderBar")
|
||||
sliderBarValue = raygui.SliderBar(raylib.NewRectangle(500, 140, 200, 20), sliderBarValue, 0, 100)
|
||||
raygui.Label(raylib.NewRectangle(500+200+5, 140, 20, 20), fmt.Sprintf("%.0f", sliderBarValue))
|
||||
raygui.Label(rl.NewRectangle(500, 120, 200, 20), "SliderBar")
|
||||
sliderBarValue = raygui.SliderBar(rl.NewRectangle(500, 140, 200, 20), sliderBarValue, 0, 100)
|
||||
raygui.Label(rl.NewRectangle(500+200+5, 140, 20, 20), fmt.Sprintf("%.0f", sliderBarValue))
|
||||
|
||||
raygui.Label(raylib.NewRectangle(500, 190, 200, 20), "Spinner")
|
||||
spinnerValue = raygui.Spinner(raylib.NewRectangle(500, 210, 200, 20), spinnerValue, 0, 100)
|
||||
raygui.Label(rl.NewRectangle(500, 190, 200, 20), "Spinner")
|
||||
spinnerValue = raygui.Spinner(rl.NewRectangle(500, 210, 200, 20), spinnerValue, 0, 100)
|
||||
|
||||
raygui.Label(raylib.NewRectangle(500, 260, 200, 20), "ComboBox")
|
||||
comboActive = raygui.ComboBox(raylib.NewRectangle(500, 280, 200, 20), comboText, comboActive)
|
||||
raygui.Label(rl.NewRectangle(500, 260, 200, 20), "ComboBox")
|
||||
comboActive = raygui.ComboBox(rl.NewRectangle(500, 280, 200, 20), comboText, comboActive)
|
||||
|
||||
if comboLastActive != comboActive {
|
||||
raygui.LoadGuiStyle(fmt.Sprintf("styles/%s.style", comboText[comboActive]))
|
||||
comboLastActive = comboActive
|
||||
}
|
||||
|
||||
raygui.Label(raylib.NewRectangle(500, 330, 200, 20), "TextBox")
|
||||
inputText = raygui.TextBox(raylib.NewRectangle(500, 350, 200, 20), inputText)
|
||||
raygui.Label(rl.NewRectangle(500, 330, 200, 20), "TextBox")
|
||||
inputText = raygui.TextBox(rl.NewRectangle(500, 350, 200, 20), inputText)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,41 +8,41 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(5.0, 4.0, 5.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 2.0, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera := rl.Camera{}
|
||||
camera.Position = rl.NewVector3(5.0, 4.0, 5.0)
|
||||
camera.Target = rl.NewVector3(0.0, 2.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
|
||||
|
||||
bill := raylib.LoadTexture("billboard.png") // Our texture billboard
|
||||
billPosition := raylib.NewVector3(0.0, 2.0, 0.0) // Position where draw billboard
|
||||
bill := rl.LoadTexture("billboard.png") // Our texture billboard
|
||||
billPosition := rl.NewVector3(0.0, 2.0, 0.0) // Position where draw billboard
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
|
||||
rl.SetCameraMode(camera, rl.CameraOrbital) // Set an orbital 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.DrawBillboard(camera, bill, billPosition, 2.0, raylib.White)
|
||||
rl.DrawBillboard(camera, bill, billPosition, 2.0, rl.White)
|
||||
|
||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
||||
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
raylib.EndMode3D()
|
||||
rl.EndMode3D()
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(bill) // Unload texture
|
||||
rl.UnloadTexture(bill) // Unload texture
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,62 +8,62 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
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.Camera{}
|
||||
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
|
||||
|
||||
playerPosition := raylib.NewVector3(0.0, 1.0, 2.0)
|
||||
playerSize := raylib.NewVector3(1.0, 2.0, 1.0)
|
||||
playerColor := raylib.Green
|
||||
playerPosition := rl.NewVector3(0.0, 1.0, 2.0)
|
||||
playerSize := rl.NewVector3(1.0, 2.0, 1.0)
|
||||
playerColor := rl.Green
|
||||
|
||||
enemyBoxPos := raylib.NewVector3(-4.0, 1.0, 0.0)
|
||||
enemyBoxSize := raylib.NewVector3(2.0, 2.0, 2.0)
|
||||
enemyBoxPos := rl.NewVector3(-4.0, 1.0, 0.0)
|
||||
enemyBoxSize := rl.NewVector3(2.0, 2.0, 2.0)
|
||||
|
||||
enemySpherePos := raylib.NewVector3(4.0, 0.0, 0.0)
|
||||
enemySpherePos := rl.NewVector3(4.0, 0.0, 0.0)
|
||||
enemySphereSize := float32(1.5)
|
||||
|
||||
collision := false
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
// Update
|
||||
|
||||
// Move player
|
||||
if raylib.IsKeyDown(raylib.KeyRight) {
|
||||
if rl.IsKeyDown(rl.KeyRight) {
|
||||
playerPosition.X += 0.2
|
||||
} else if raylib.IsKeyDown(raylib.KeyLeft) {
|
||||
} else if rl.IsKeyDown(rl.KeyLeft) {
|
||||
playerPosition.X -= 0.2
|
||||
} else if raylib.IsKeyDown(raylib.KeyDown) {
|
||||
} else if rl.IsKeyDown(rl.KeyDown) {
|
||||
playerPosition.Z += 0.2
|
||||
} else if raylib.IsKeyDown(raylib.KeyUp) {
|
||||
} else if rl.IsKeyDown(rl.KeyUp) {
|
||||
playerPosition.Z -= 0.2
|
||||
}
|
||||
|
||||
collision = false
|
||||
|
||||
// Check collisions player vs enemy-box
|
||||
if raylib.CheckCollisionBoxes(
|
||||
raylib.NewBoundingBox(
|
||||
raylib.NewVector3(playerPosition.X-playerSize.X/2, playerPosition.Y-playerSize.Y/2, playerPosition.Z-playerSize.Z/2),
|
||||
raylib.NewVector3(playerPosition.X+playerSize.X/2, playerPosition.Y+playerSize.Y/2, playerPosition.Z+playerSize.Z/2)),
|
||||
raylib.NewBoundingBox(
|
||||
raylib.NewVector3(enemyBoxPos.X-enemyBoxSize.X/2, enemyBoxPos.Y-enemyBoxSize.Y/2, enemyBoxPos.Z-enemyBoxSize.Z/2),
|
||||
raylib.NewVector3(enemyBoxPos.X+enemyBoxSize.X/2, enemyBoxPos.Y+enemyBoxSize.Y/2, enemyBoxPos.Z+enemyBoxSize.Z/2)),
|
||||
if rl.CheckCollisionBoxes(
|
||||
rl.NewBoundingBox(
|
||||
rl.NewVector3(playerPosition.X-playerSize.X/2, playerPosition.Y-playerSize.Y/2, playerPosition.Z-playerSize.Z/2),
|
||||
rl.NewVector3(playerPosition.X+playerSize.X/2, playerPosition.Y+playerSize.Y/2, playerPosition.Z+playerSize.Z/2)),
|
||||
rl.NewBoundingBox(
|
||||
rl.NewVector3(enemyBoxPos.X-enemyBoxSize.X/2, enemyBoxPos.Y-enemyBoxSize.Y/2, enemyBoxPos.Z-enemyBoxSize.Z/2),
|
||||
rl.NewVector3(enemyBoxPos.X+enemyBoxSize.X/2, enemyBoxPos.Y+enemyBoxSize.Y/2, enemyBoxPos.Z+enemyBoxSize.Z/2)),
|
||||
) {
|
||||
collision = true
|
||||
}
|
||||
|
||||
// Check collisions player vs enemy-sphere
|
||||
if raylib.CheckCollisionBoxSphere(
|
||||
raylib.NewBoundingBox(
|
||||
raylib.NewVector3(playerPosition.X-playerSize.X/2, playerPosition.Y-playerSize.Y/2, playerPosition.Z-playerSize.Z/2),
|
||||
raylib.NewVector3(playerPosition.X+playerSize.X/2, playerPosition.Y+playerSize.Y/2, playerPosition.Z+playerSize.Z/2)),
|
||||
if rl.CheckCollisionBoxSphere(
|
||||
rl.NewBoundingBox(
|
||||
rl.NewVector3(playerPosition.X-playerSize.X/2, playerPosition.Y-playerSize.Y/2, playerPosition.Z-playerSize.Z/2),
|
||||
rl.NewVector3(playerPosition.X+playerSize.X/2, playerPosition.Y+playerSize.Y/2, playerPosition.Z+playerSize.Z/2)),
|
||||
enemySpherePos,
|
||||
enemySphereSize,
|
||||
) {
|
||||
|
@ -71,40 +71,40 @@ func main() {
|
|||
}
|
||||
|
||||
if collision {
|
||||
playerColor = raylib.Red
|
||||
playerColor = rl.Red
|
||||
} else {
|
||||
playerColor = raylib.Green
|
||||
playerColor = rl.Green
|
||||
}
|
||||
|
||||
// Draw
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.BeginMode3D(camera)
|
||||
rl.BeginMode3D(camera)
|
||||
|
||||
// Draw enemy-box
|
||||
raylib.DrawCube(enemyBoxPos, enemyBoxSize.X, enemyBoxSize.Y, enemyBoxSize.Z, raylib.Gray)
|
||||
raylib.DrawCubeWires(enemyBoxPos, enemyBoxSize.X, enemyBoxSize.Y, enemyBoxSize.Z, raylib.DarkGray)
|
||||
rl.DrawCube(enemyBoxPos, enemyBoxSize.X, enemyBoxSize.Y, enemyBoxSize.Z, rl.Gray)
|
||||
rl.DrawCubeWires(enemyBoxPos, enemyBoxSize.X, enemyBoxSize.Y, enemyBoxSize.Z, rl.DarkGray)
|
||||
|
||||
// Draw enemy-sphere
|
||||
raylib.DrawSphere(enemySpherePos, enemySphereSize, raylib.Gray)
|
||||
raylib.DrawSphereWires(enemySpherePos, enemySphereSize, 16, 16, raylib.DarkGray)
|
||||
rl.DrawSphere(enemySpherePos, enemySphereSize, rl.Gray)
|
||||
rl.DrawSphereWires(enemySpherePos, enemySphereSize, 16, 16, rl.DarkGray)
|
||||
|
||||
// Draw player
|
||||
raylib.DrawCubeV(playerPosition, playerSize, playerColor)
|
||||
rl.DrawCubeV(playerPosition, playerSize, playerColor)
|
||||
|
||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
||||
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
raylib.EndMode3D()
|
||||
rl.EndMode3D()
|
||||
|
||||
raylib.DrawText("Move player with cursors to collide", 220, 40, 20, raylib.Gray)
|
||||
rl.DrawText("Move player with cursors to collide", 220, 40, 20, rl.Gray)
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
rl.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,64 +8,64 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(16.0, 14.0, 16.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera := rl.Camera{}
|
||||
camera.Position = rl.NewVector3(16.0, 14.0, 16.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
|
||||
|
||||
image := raylib.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
|
||||
cubicmap := raylib.LoadTextureFromImage(image) // Convert image to texture to display (VRAM)
|
||||
image := rl.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
|
||||
cubicmap := rl.LoadTextureFromImage(image) // Convert image to texture to display (VRAM)
|
||||
|
||||
mesh := raylib.GenMeshCubicmap(*image, raylib.NewVector3(1.0, 1.0, 1.0))
|
||||
model := raylib.LoadModelFromMesh(mesh)
|
||||
mesh := rl.GenMeshCubicmap(*image, rl.NewVector3(1.0, 1.0, 1.0))
|
||||
model := rl.LoadModelFromMesh(mesh)
|
||||
|
||||
// NOTE: By default each cube is mapped to one part of texture atlas
|
||||
texture := raylib.LoadTexture("cubicmap_atlas.png") // Load map texture
|
||||
model.Material.Maps[raylib.MapDiffuse].Texture = texture // Set map diffuse texture
|
||||
texture := rl.LoadTexture("cubicmap_atlas.png") // Load map texture
|
||||
model.Material.Maps[rl.MapDiffuse].Texture = texture // Set map diffuse texture
|
||||
|
||||
mapPosition := raylib.NewVector3(-16.0, 0.0, -8.0) // Set model position
|
||||
mapPosition := rl.NewVector3(-16.0, 0.0, -8.0) // Set model position
|
||||
|
||||
raylib.UnloadImage(image) // Unload cubicmap image from RAM, already uploaded to VRAM
|
||||
rl.UnloadImage(image) // Unload cubicmap image from RAM, already uploaded to VRAM
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
|
||||
rl.SetCameraMode(camera, rl.CameraOrbital) // Set an orbital camera mode
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
// Update
|
||||
|
||||
raylib.UpdateCamera(&camera) // Update camera
|
||||
rl.UpdateCamera(&camera) // Update camera
|
||||
|
||||
// Draw
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.BeginMode3D(camera)
|
||||
rl.BeginMode3D(camera)
|
||||
|
||||
raylib.DrawModel(model, mapPosition, 1.0, raylib.White)
|
||||
rl.DrawModel(model, mapPosition, 1.0, rl.White)
|
||||
|
||||
raylib.EndMode3D()
|
||||
rl.EndMode3D()
|
||||
|
||||
raylib.DrawTextureEx(cubicmap, raylib.NewVector2(float32(screenWidth-cubicmap.Width*4-20), 20), 0.0, 4.0, raylib.White)
|
||||
raylib.DrawRectangleLines(screenWidth-cubicmap.Width*4-20, 20, cubicmap.Width*4, cubicmap.Height*4, raylib.Green)
|
||||
rl.DrawTextureEx(cubicmap, rl.NewVector2(float32(screenWidth-cubicmap.Width*4-20), 20), 0.0, 4.0, rl.White)
|
||||
rl.DrawRectangleLines(screenWidth-cubicmap.Width*4-20, 20, cubicmap.Width*4, cubicmap.Height*4, rl.Green)
|
||||
|
||||
raylib.DrawText("cubicmap image used to", 658, 90, 10, raylib.Gray)
|
||||
raylib.DrawText("generate map 3d model", 658, 104, 10, raylib.Gray)
|
||||
rl.DrawText("cubicmap image used to", 658, 90, 10, rl.Gray)
|
||||
rl.DrawText("generate map 3d model", 658, 104, 10, rl.Gray)
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
rl.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(cubicmap) // Unload cubicmap texture
|
||||
raylib.UnloadTexture(texture) // Unload map texture
|
||||
raylib.UnloadModel(model) // Unload map model
|
||||
rl.UnloadTexture(cubicmap) // Unload cubicmap texture
|
||||
rl.UnloadTexture(texture) // Unload map texture
|
||||
rl.UnloadModel(model) // Unload map model
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,45 +8,45 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
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.Camera{}
|
||||
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
|
||||
|
||||
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(raylib.NewVector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, raylib.Red)
|
||||
raylib.DrawCubeWires(raylib.NewVector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, raylib.Gold)
|
||||
raylib.DrawCubeWires(raylib.NewVector3(-4.0, 0.0, -2.0), 3.0, 6.0, 2.0, raylib.Maroon)
|
||||
rl.DrawCube(rl.NewVector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, rl.Red)
|
||||
rl.DrawCubeWires(rl.NewVector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, rl.Gold)
|
||||
rl.DrawCubeWires(rl.NewVector3(-4.0, 0.0, -2.0), 3.0, 6.0, 2.0, rl.Maroon)
|
||||
|
||||
raylib.DrawSphere(raylib.NewVector3(-1.0, 0.0, -2.0), 1.0, raylib.Green)
|
||||
raylib.DrawSphereWires(raylib.NewVector3(1.0, 0.0, 2.0), 2.0, 16, 16, raylib.Lime)
|
||||
rl.DrawSphere(rl.NewVector3(-1.0, 0.0, -2.0), 1.0, rl.Green)
|
||||
rl.DrawSphereWires(rl.NewVector3(1.0, 0.0, 2.0), 2.0, 16, 16, rl.Lime)
|
||||
|
||||
raylib.DrawCylinder(raylib.NewVector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, raylib.SkyBlue)
|
||||
raylib.DrawCylinderWires(raylib.NewVector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, raylib.DarkBlue)
|
||||
raylib.DrawCylinderWires(raylib.NewVector3(4.5, -1.0, 2.0), 1.0, 1.0, 2.0, 6, raylib.Brown)
|
||||
rl.DrawCylinder(rl.NewVector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, rl.SkyBlue)
|
||||
rl.DrawCylinderWires(rl.NewVector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, rl.DarkBlue)
|
||||
rl.DrawCylinderWires(rl.NewVector3(4.5, -1.0, 2.0), 1.0, 1.0, 2.0, 6, rl.Brown)
|
||||
|
||||
raylib.DrawCylinder(raylib.NewVector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, raylib.Gold)
|
||||
raylib.DrawCylinderWires(raylib.NewVector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, raylib.Pink)
|
||||
rl.DrawCylinder(rl.NewVector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, rl.Gold)
|
||||
rl.DrawCylinderWires(rl.NewVector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, rl.Pink)
|
||||
|
||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
||||
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
raylib.EndMode3D()
|
||||
rl.EndMode3D()
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
rl.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,58 +8,58 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(18.0, 16.0, 18.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera := rl.Camera{}
|
||||
camera.Position = rl.NewVector3(18.0, 16.0, 18.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
|
||||
|
||||
image := raylib.LoadImage("heightmap.png") // Load heightmap image (RAM)
|
||||
texture := raylib.LoadTextureFromImage(image) // Convert image to texture (VRAM)
|
||||
image := rl.LoadImage("heightmap.png") // Load heightmap image (RAM)
|
||||
texture := rl.LoadTextureFromImage(image) // Convert image to texture (VRAM)
|
||||
|
||||
mesh := raylib.GenMeshHeightmap(*image, raylib.NewVector3(16, 8, 16)) // Generate heightmap mesh (RAM and VRAM)
|
||||
model := raylib.LoadModelFromMesh(mesh) // Load model from generated mesh
|
||||
mesh := rl.GenMeshHeightmap(*image, rl.NewVector3(16, 8, 16)) // Generate heightmap mesh (RAM and VRAM)
|
||||
model := rl.LoadModelFromMesh(mesh) // Load model from generated mesh
|
||||
|
||||
model.Material.Maps[raylib.MapDiffuse].Texture = texture // Set map diffuse texture
|
||||
mapPosition := raylib.NewVector3(-8.0, 0.0, -8.0) // Set model position
|
||||
model.Material.Maps[rl.MapDiffuse].Texture = texture // Set map diffuse texture
|
||||
mapPosition := rl.NewVector3(-8.0, 0.0, -8.0) // Set model position
|
||||
|
||||
raylib.UnloadImage(image) // Unload heightmap image from RAM, already uploaded to VRAM
|
||||
rl.UnloadImage(image) // Unload heightmap image from RAM, already uploaded to VRAM
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
|
||||
rl.SetCameraMode(camera, rl.CameraOrbital) // Set an orbital camera mode
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
// Update
|
||||
|
||||
raylib.UpdateCamera(&camera) // Update camera
|
||||
rl.UpdateCamera(&camera) // Update camera
|
||||
|
||||
// Draw
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.BeginMode3D(camera)
|
||||
rl.BeginMode3D(camera)
|
||||
|
||||
raylib.DrawModel(model, mapPosition, 1.0, raylib.Red)
|
||||
rl.DrawModel(model, mapPosition, 1.0, rl.Red)
|
||||
|
||||
raylib.DrawGrid(20, 1.0)
|
||||
rl.DrawGrid(20, 1.0)
|
||||
|
||||
raylib.EndMode3D()
|
||||
rl.EndMode3D()
|
||||
|
||||
raylib.DrawTexture(texture, screenWidth-texture.Width-20, 20, raylib.White)
|
||||
raylib.DrawRectangleLines(screenWidth-texture.Width-20, 20, texture.Width, texture.Height, raylib.Green)
|
||||
rl.DrawTexture(texture, screenWidth-texture.Width-20, 20, rl.White)
|
||||
rl.DrawRectangleLines(screenWidth-texture.Width-20, 20, texture.Width, texture.Height, rl.Green)
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
rl.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture) // Unload map texture
|
||||
raylib.UnloadModel(model) // Unload map model
|
||||
rl.UnloadTexture(texture) // Unload map texture
|
||||
rl.UnloadModel(model) // Unload map model
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,45 +8,45 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(3.0, 3.0, 3.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 1.5, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera := rl.Camera{}
|
||||
camera.Position = rl.NewVector3(3.0, 3.0, 3.0)
|
||||
camera.Target = rl.NewVector3(0.0, 1.5, 0.0)
|
||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
|
||||
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
||||
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||
dwarf := rl.LoadModel("dwarf.obj") // Load OBJ model
|
||||
texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||
|
||||
dwarf.Material.Maps[raylib.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||
dwarf.Material.Maps[rl.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||
|
||||
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
|
||||
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.DrawModel(dwarf, position, 2.0, raylib.White) // Draw 3d model with texture
|
||||
rl.DrawModel(dwarf, position, 2.0, rl.White) // Draw 3d model with texture
|
||||
|
||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
||||
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
raylib.DrawGizmo(position) // Draw gizmo
|
||||
rl.DrawGizmo(position) // Draw gizmo
|
||||
|
||||
raylib.EndMode3D()
|
||||
rl.EndMode3D()
|
||||
|
||||
raylib.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
||||
rl.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, rl.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture) // Unload texture
|
||||
raylib.UnloadModel(dwarf) // Unload model
|
||||
rl.UnloadTexture(texture) // Unload texture
|
||||
rl.UnloadModel(dwarf) // Unload model
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -16,36 +16,36 @@ const (
|
|||
)
|
||||
|
||||
func init() {
|
||||
raylib.SetCallbackFunc(main)
|
||||
rl.SetCallbackFunc(main)
|
||||
}
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
||||
rl.SetConfigFlags(rl.FlagVsyncHint)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "Android example")
|
||||
rl.InitWindow(screenWidth, screenHeight, "Android example")
|
||||
|
||||
raylib.InitAudioDevice()
|
||||
rl.InitAudioDevice()
|
||||
|
||||
currentScreen := Logo
|
||||
windowShouldClose := false
|
||||
|
||||
texture := raylib.LoadTexture("raylib_logo.png") // Load texture (placed on assets folder)
|
||||
fx := raylib.LoadSound("coin.wav") // Load WAV audio file (placed on assets folder)
|
||||
ambient := raylib.LoadMusicStream("ambient.ogg") // Load music
|
||||
texture := rl.LoadTexture("raylib_logo.png") // Load texture (placed on assets folder)
|
||||
fx := rl.LoadSound("coin.wav") // Load WAV audio file (placed on assets folder)
|
||||
ambient := rl.LoadMusicStream("ambient.ogg") // Load music
|
||||
|
||||
raylib.PlayMusicStream(ambient)
|
||||
rl.PlayMusicStream(ambient)
|
||||
|
||||
framesCounter := 0 // Used to count frames
|
||||
|
||||
//raylib.SetTargetFPS(60)
|
||||
//rl.SetTargetFPS(60)
|
||||
|
||||
for !windowShouldClose {
|
||||
raylib.UpdateMusicStream(ambient)
|
||||
rl.UpdateMusicStream(ambient)
|
||||
|
||||
if runtime.GOOS == "android" && raylib.IsKeyDown(raylib.KeyBack) || raylib.WindowShouldClose() {
|
||||
if runtime.GOOS == "android" && rl.IsKeyDown(rl.KeyBack) || rl.WindowShouldClose() {
|
||||
windowShouldClose = true
|
||||
}
|
||||
|
||||
|
@ -60,64 +60,64 @@ func main() {
|
|||
break
|
||||
case Title:
|
||||
// Press enter to change to GamePlay screen
|
||||
if raylib.IsGestureDetected(raylib.GestureTap) {
|
||||
raylib.PlaySound(fx)
|
||||
if rl.IsGestureDetected(rl.GestureTap) {
|
||||
rl.PlaySound(fx)
|
||||
currentScreen = GamePlay
|
||||
}
|
||||
break
|
||||
case GamePlay:
|
||||
// Press enter to change to Ending screen
|
||||
if raylib.IsGestureDetected(raylib.GestureTap) {
|
||||
raylib.PlaySound(fx)
|
||||
if rl.IsGestureDetected(rl.GestureTap) {
|
||||
rl.PlaySound(fx)
|
||||
currentScreen = Ending
|
||||
}
|
||||
break
|
||||
case Ending:
|
||||
// Press enter to return to Title screen
|
||||
if raylib.IsGestureDetected(raylib.GestureTap) {
|
||||
raylib.PlaySound(fx)
|
||||
if rl.IsGestureDetected(rl.GestureTap) {
|
||||
rl.PlaySound(fx)
|
||||
currentScreen = Title
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
switch currentScreen {
|
||||
case Logo:
|
||||
raylib.DrawText("LOGO SCREEN", 20, 20, 40, raylib.LightGray)
|
||||
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
|
||||
raylib.DrawText("WAIT for 4 SECONDS...", 290, 400, 20, raylib.Gray)
|
||||
rl.DrawText("LOGO SCREEN", 20, 20, 40, rl.LightGray)
|
||||
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, rl.White)
|
||||
rl.DrawText("WAIT for 4 SECONDS...", 290, 400, 20, rl.Gray)
|
||||
break
|
||||
case Title:
|
||||
raylib.DrawRectangle(0, 0, screenWidth, screenHeight, raylib.Green)
|
||||
raylib.DrawText("TITLE SCREEN", 20, 20, 40, raylib.DarkGreen)
|
||||
raylib.DrawText("TAP SCREEN to JUMP to GAMEPLAY SCREEN", 160, 220, 20, raylib.DarkGreen)
|
||||
rl.DrawRectangle(0, 0, screenWidth, screenHeight, rl.Green)
|
||||
rl.DrawText("TITLE SCREEN", 20, 20, 40, rl.DarkGreen)
|
||||
rl.DrawText("TAP SCREEN to JUMP to GAMEPLAY SCREEN", 160, 220, 20, rl.DarkGreen)
|
||||
break
|
||||
case GamePlay:
|
||||
raylib.DrawRectangle(0, 0, screenWidth, screenHeight, raylib.Purple)
|
||||
raylib.DrawText("GAMEPLAY SCREEN", 20, 20, 40, raylib.Maroon)
|
||||
raylib.DrawText("TAP SCREEN to JUMP to ENDING SCREEN", 170, 220, 20, raylib.Maroon)
|
||||
rl.DrawRectangle(0, 0, screenWidth, screenHeight, rl.Purple)
|
||||
rl.DrawText("GAMEPLAY SCREEN", 20, 20, 40, rl.Maroon)
|
||||
rl.DrawText("TAP SCREEN to JUMP to ENDING SCREEN", 170, 220, 20, rl.Maroon)
|
||||
break
|
||||
case Ending:
|
||||
raylib.DrawRectangle(0, 0, screenWidth, screenHeight, raylib.Blue)
|
||||
raylib.DrawText("ENDING SCREEN", 20, 20, 40, raylib.DarkBlue)
|
||||
raylib.DrawText("TAP SCREEN to RETURN to TITLE SCREEN", 160, 220, 20, raylib.DarkBlue)
|
||||
rl.DrawRectangle(0, 0, screenWidth, screenHeight, rl.Blue)
|
||||
rl.DrawText("ENDING SCREEN", 20, 20, 40, rl.DarkBlue)
|
||||
rl.DrawText("TAP SCREEN to RETURN to TITLE SCREEN", 160, 220, 20, rl.DarkBlue)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadSound(fx) // Unload sound data
|
||||
raylib.UnloadMusicStream(ambient) // Unload music stream data
|
||||
raylib.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
||||
raylib.UnloadTexture(texture) // Unload texture data
|
||||
raylib.CloseWindow() // Close window
|
||||
rl.UnloadSound(fx) // Unload sound data
|
||||
rl.UnloadMusicStream(ambient) // Unload music stream data
|
||||
rl.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
||||
rl.UnloadTexture(texture) // Unload texture data
|
||||
rl.CloseWindow() // Close window
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
|
@ -8,33 +8,33 @@ import (
|
|||
|
||||
// Bunny type
|
||||
type Bunny struct {
|
||||
Position raylib.Vector2
|
||||
Speed raylib.Vector2
|
||||
Color raylib.Color
|
||||
Position rl.Vector2
|
||||
Speed rl.Vector2
|
||||
Color rl.Color
|
||||
}
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(1280)
|
||||
screenHeight := int32(960)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - Bunnymark")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - Bunnymark")
|
||||
|
||||
texture := raylib.LoadTexture("wabbit_alpha.png")
|
||||
texture := rl.LoadTexture("wabbit_alpha.png")
|
||||
|
||||
bunnies := make([]*Bunny, 0)
|
||||
bunniesCount := 0
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
|
||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
||||
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||
// Create more bunnies
|
||||
for i := 0; i < 100; i++ {
|
||||
b := &Bunny{}
|
||||
b.Position = raylib.GetMousePosition()
|
||||
b.Speed.X = float32(raylib.GetRandomValue(250, 500)) / 60.0
|
||||
b.Speed.Y = float32(raylib.GetRandomValue(250, 500)-500) / 60.0
|
||||
b.Position = rl.GetMousePosition()
|
||||
b.Speed.X = float32(rl.GetRandomValue(250, 500)) / 60.0
|
||||
b.Speed.Y = float32(rl.GetRandomValue(250, 500)-500) / 60.0
|
||||
|
||||
bunnies = append(bunnies, b)
|
||||
bunniesCount++
|
||||
|
@ -55,27 +55,27 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
for _, b := range bunnies {
|
||||
// NOTE: When internal QUADS batch limit is reached, a draw call is launched and
|
||||
// batching buffer starts being filled again; before launching the draw call,
|
||||
// updated vertex data from internal buffer is send to GPU... it seems it generates
|
||||
// a stall and consequently a frame drop, limiting number of bunnies drawn at 60 fps
|
||||
raylib.DrawTexture(texture, int32(b.Position.X), int32(b.Position.Y), raylib.RayWhite)
|
||||
rl.DrawTexture(texture, int32(b.Position.X), int32(b.Position.Y), rl.RayWhite)
|
||||
}
|
||||
|
||||
raylib.DrawRectangle(0, 0, screenWidth, 40, raylib.LightGray)
|
||||
raylib.DrawText("raylib bunnymark", 10, 10, 20, raylib.DarkGray)
|
||||
raylib.DrawText(fmt.Sprintf("bunnies: %d", bunniesCount), 400, 10, 20, raylib.Red)
|
||||
rl.DrawRectangle(0, 0, screenWidth, 40, rl.LightGray)
|
||||
rl.DrawText("raylib bunnymark", 10, 10, 20, rl.DarkGray)
|
||||
rl.DrawText(fmt.Sprintf("bunnies: %d", bunniesCount), 400, 10, 20, rl.Red)
|
||||
|
||||
raylib.DrawFPS(260, 10)
|
||||
rl.DrawFPS(260, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture)
|
||||
raylib.CloseWindow()
|
||||
rl.UnloadTexture(texture)
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -13,14 +13,14 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - resources loading")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - resources loading")
|
||||
|
||||
raylib.InitAudioDevice()
|
||||
rl.InitAudioDevice()
|
||||
|
||||
// OpenAsset() will also work on Android (reads files from assets/)
|
||||
reader, err := raylib.OpenAsset("data.rres")
|
||||
reader, err := rl.OpenAsset("data.rres")
|
||||
if err != nil {
|
||||
raylib.TraceLog(raylib.LogWarning, "[%s] rRES raylib resource file could not be opened: %v", "data.rres", err)
|
||||
rl.TraceLog(rl.LogWarning, "[%s] rRES raylib resource file could not be opened: %v", "data.rres", err)
|
||||
}
|
||||
|
||||
defer reader.Close()
|
||||
|
@ -30,67 +30,67 @@ func main() {
|
|||
//reader := bytes.NewReader(b)
|
||||
|
||||
res := rres.LoadResource(reader, 0, []byte("passwordpassword"))
|
||||
wav := raylib.LoadWaveEx(res.Data, int32(res.Param1), int32(res.Param2), int32(res.Param3), int32(res.Param4))
|
||||
snd := raylib.LoadSoundFromWave(wav)
|
||||
raylib.UnloadWave(wav)
|
||||
wav := rl.LoadWaveEx(res.Data, int32(res.Param1), int32(res.Param2), int32(res.Param3), int32(res.Param4))
|
||||
snd := rl.LoadSoundFromWave(wav)
|
||||
rl.UnloadWave(wav)
|
||||
|
||||
textures := make([]raylib.Texture2D, numTextures)
|
||||
textures := make([]rl.Texture2D, numTextures)
|
||||
for i := 0; i < numTextures; i++ {
|
||||
r := rres.LoadResource(reader, i+1, []byte("passwordpassword"))
|
||||
image := raylib.LoadImagePro(r.Data, int32(r.Param1), int32(r.Param2), raylib.PixelFormat(r.Param3))
|
||||
textures[i] = raylib.LoadTextureFromImage(image)
|
||||
raylib.UnloadImage(image)
|
||||
image := rl.LoadImagePro(r.Data, int32(r.Param1), int32(r.Param2), rl.PixelFormat(r.Param3))
|
||||
textures[i] = rl.LoadTextureFromImage(image)
|
||||
rl.UnloadImage(image)
|
||||
}
|
||||
|
||||
currentTexture := 0
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsKeyPressed(raylib.KeySpace) {
|
||||
raylib.PlaySound(snd)
|
||||
for !rl.WindowShouldClose() {
|
||||
if rl.IsKeyPressed(rl.KeySpace) {
|
||||
rl.PlaySound(snd)
|
||||
}
|
||||
|
||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
||||
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||
currentTexture = (currentTexture + 1) % numTextures // Cycle between the textures
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawTexture(textures[currentTexture], screenWidth/2-textures[currentTexture].Width/2, screenHeight/2-textures[currentTexture].Height/2, raylib.RayWhite)
|
||||
rl.DrawTexture(textures[currentTexture], screenWidth/2-textures[currentTexture].Width/2, screenHeight/2-textures[currentTexture].Height/2, rl.RayWhite)
|
||||
|
||||
raylib.DrawText("MOUSE LEFT BUTTON to CYCLE TEXTURES", 40, 410, 10, raylib.Gray)
|
||||
raylib.DrawText("SPACE to PLAY SOUND", 40, 430, 10, raylib.Gray)
|
||||
rl.DrawText("MOUSE LEFT BUTTON to CYCLE TEXTURES", 40, 410, 10, rl.Gray)
|
||||
rl.DrawText("SPACE to PLAY SOUND", 40, 430, 10, rl.Gray)
|
||||
|
||||
switch currentTexture {
|
||||
case 0:
|
||||
raylib.DrawText("GIF", 272, 70, 20, raylib.Gray)
|
||||
rl.DrawText("GIF", 272, 70, 20, rl.Gray)
|
||||
break
|
||||
case 1:
|
||||
raylib.DrawText("JPEG", 272, 70, 20, raylib.Gray)
|
||||
rl.DrawText("JPEG", 272, 70, 20, rl.Gray)
|
||||
break
|
||||
case 2:
|
||||
raylib.DrawText("PNG", 272, 70, 20, raylib.Gray)
|
||||
rl.DrawText("PNG", 272, 70, 20, rl.Gray)
|
||||
break
|
||||
case 3:
|
||||
raylib.DrawText("TGA", 272, 70, 20, raylib.Gray)
|
||||
rl.DrawText("TGA", 272, 70, 20, rl.Gray)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadSound(snd)
|
||||
rl.UnloadSound(snd)
|
||||
|
||||
for _, t := range textures {
|
||||
raylib.UnloadTexture(t)
|
||||
rl.UnloadTexture(t)
|
||||
}
|
||||
|
||||
raylib.CloseAudioDevice()
|
||||
rl.CloseAudioDevice()
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -3,19 +3,19 @@ package main
|
|||
import "github.com/gen2brain/raylib-go/raylib"
|
||||
|
||||
func main() {
|
||||
raylib.InitWindow(800, 450, "raylib [rpi] example - basic window")
|
||||
rl.InitWindow(800, 450, "raylib [rpi] 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()
|
||||
}
|
||||
|
|
|
@ -30,28 +30,28 @@ func (g *Game) Init() {
|
|||
// Update - Update game
|
||||
func (g *Game) Update() {
|
||||
// Keys 1-9 switch demos
|
||||
switch raylib.GetKeyPressed() {
|
||||
case raylib.KeyOne:
|
||||
switch rl.GetKeyPressed() {
|
||||
case rl.KeyOne:
|
||||
g.Demo1()
|
||||
case raylib.KeyTwo:
|
||||
case rl.KeyTwo:
|
||||
g.Demo2()
|
||||
case raylib.KeyThree:
|
||||
case rl.KeyThree:
|
||||
g.Demo3()
|
||||
case raylib.KeyFour:
|
||||
case rl.KeyFour:
|
||||
g.Demo4()
|
||||
case raylib.KeyFive:
|
||||
case rl.KeyFive:
|
||||
g.Demo5()
|
||||
case raylib.KeySix:
|
||||
case rl.KeySix:
|
||||
g.Demo6()
|
||||
case raylib.KeySeven:
|
||||
case rl.KeySeven:
|
||||
g.Demo7()
|
||||
case raylib.KeyEight:
|
||||
case rl.KeyEight:
|
||||
g.Demo8()
|
||||
case raylib.KeyNine:
|
||||
case rl.KeyNine:
|
||||
g.Demo9()
|
||||
}
|
||||
|
||||
g.TimeStep = float64(raylib.GetFrameTime())
|
||||
g.TimeStep = float64(rl.GetFrameTime())
|
||||
|
||||
// Physics steps calculations
|
||||
g.World.Step(g.TimeStep)
|
||||
|
@ -66,7 +66,7 @@ func (g *Game) Draw() {
|
|||
g.DrawJoint(j)
|
||||
}
|
||||
|
||||
raylib.DrawText("Use keys 1-9 to switch current demo", 20, 20, 10, raylib.RayWhite)
|
||||
rl.DrawText("Use keys 1-9 to switch current demo", 20, 20, 10, rl.RayWhite)
|
||||
}
|
||||
|
||||
// DrawBody - Draw body
|
||||
|
@ -83,10 +83,10 @@ func (g *Game) DrawBody(b *box2d.Body) {
|
|||
v3 := o.Add(S.MulV(x.Add(R.MulV(box2d.Vec2{h.X, h.Y}))))
|
||||
v4 := o.Add(S.MulV(x.Add(R.MulV(box2d.Vec2{-h.X, h.Y}))))
|
||||
|
||||
raylib.DrawLine(int32(v1.X), int32(v1.Y), int32(v2.X), int32(v2.Y), raylib.RayWhite)
|
||||
raylib.DrawLine(int32(v2.X), int32(v2.Y), int32(v3.X), int32(v3.Y), raylib.RayWhite)
|
||||
raylib.DrawLine(int32(v3.X), int32(v3.Y), int32(v4.X), int32(v4.Y), raylib.RayWhite)
|
||||
raylib.DrawLine(int32(v4.X), int32(v4.Y), int32(v1.X), int32(v1.Y), raylib.RayWhite)
|
||||
rl.DrawLine(int32(v1.X), int32(v1.Y), int32(v2.X), int32(v2.Y), rl.RayWhite)
|
||||
rl.DrawLine(int32(v2.X), int32(v2.Y), int32(v3.X), int32(v3.Y), rl.RayWhite)
|
||||
rl.DrawLine(int32(v3.X), int32(v3.Y), int32(v4.X), int32(v4.Y), rl.RayWhite)
|
||||
rl.DrawLine(int32(v4.X), int32(v4.Y), int32(v1.X), int32(v1.Y), rl.RayWhite)
|
||||
}
|
||||
|
||||
// DrawJoint - Draw joint
|
||||
|
@ -111,8 +111,8 @@ func (g *Game) DrawJoint(j *box2d.Joint) {
|
|||
x2 = o.Add(S.MulV(x2))
|
||||
p2 = o.Add(S.MulV(p2))
|
||||
|
||||
raylib.DrawLine(int32(x1.X), int32(x1.Y), int32(p1.X), int32(p1.Y), raylib.RayWhite)
|
||||
raylib.DrawLine(int32(x2.X), int32(x2.Y), int32(p2.X), int32(p2.Y), raylib.RayWhite)
|
||||
rl.DrawLine(int32(x1.X), int32(x1.Y), int32(p1.X), int32(p1.Y), rl.RayWhite)
|
||||
rl.DrawLine(int32(x2.X), int32(x2.Y), int32(p2.X), int32(p2.Y), rl.RayWhite)
|
||||
}
|
||||
|
||||
// Demo1 - Single box
|
||||
|
@ -489,25 +489,25 @@ func (g *Game) Demo9() {
|
|||
}
|
||||
|
||||
func main() {
|
||||
raylib.InitWindow(800, 450, "raylib [physics] example - box2d")
|
||||
rl.InitWindow(800, 450, "raylib [physics] example - box2d")
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
game := NewGame()
|
||||
|
||||
game.Demo1()
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.Black)
|
||||
rl.ClearBackground(rl.Black)
|
||||
|
||||
game.Update()
|
||||
|
||||
game.Draw()
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -1,163 +1,139 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
"github.com/jakecoffman/cp"
|
||||
|
||||
"github.com/vova616/chipmunk"
|
||||
"github.com/vova616/chipmunk/vect"
|
||||
)
|
||||
|
||||
var grabbableMaskBit uint = 1 << 31
|
||||
var grabFilter = cp.ShapeFilter{
|
||||
cp.NO_GROUP, grabbableMaskBit, grabbableMaskBit,
|
||||
const (
|
||||
ballRadius = 25
|
||||
ballMass = 1
|
||||
)
|
||||
|
||||
// Game type
|
||||
type Game struct {
|
||||
Space *chipmunk.Space
|
||||
Balls []*chipmunk.Shape
|
||||
StaticLines []*chipmunk.Shape
|
||||
|
||||
ticksToNextBall int
|
||||
}
|
||||
|
||||
func randUnitCircle() cp.Vector {
|
||||
v := cp.Vector{X: rand.Float64()*2.0 - 1.0, Y: rand.Float64()*2.0 - 1.0}
|
||||
if v.LengthSq() < 1.0 {
|
||||
return v
|
||||
}
|
||||
return randUnitCircle()
|
||||
// NewGame - Start new game
|
||||
func NewGame() (g Game) {
|
||||
g.Init()
|
||||
return
|
||||
}
|
||||
|
||||
var simpleTerrainVerts = []cp.Vector{
|
||||
{350.00, 425.07}, {336.00, 436.55}, {272.00, 435.39}, {258.00, 427.63}, {225.28, 420.00}, {202.82, 396.00},
|
||||
{191.81, 388.00}, {189.00, 381.89}, {173.00, 380.39}, {162.59, 368.00}, {150.47, 319.00}, {128.00, 311.55},
|
||||
{119.14, 286.00}, {126.84, 263.00}, {120.56, 227.00}, {141.14, 178.00}, {137.52, 162.00}, {146.51, 142.00},
|
||||
{156.23, 136.00}, {158.00, 118.27}, {170.00, 100.77}, {208.43, 84.00}, {224.00, 69.65}, {249.30, 68.00},
|
||||
{257.00, 54.77}, {363.00, 45.94}, {374.15, 54.00}, {386.00, 69.60}, {413.00, 70.73}, {456.00, 84.89},
|
||||
{468.09, 99.00}, {467.09, 123.00}, {464.92, 135.00}, {469.00, 141.03}, {497.00, 148.67}, {513.85, 180.00},
|
||||
{509.56, 223.00}, {523.51, 247.00}, {523.00, 277.00}, {497.79, 311.00}, {478.67, 348.00}, {467.90, 360.00},
|
||||
{456.76, 382.00}, {432.95, 389.00}, {417.00, 411.32}, {373.00, 433.19}, {361.00, 430.02}, {350.00, 425.07},
|
||||
// Init - Initialize game
|
||||
func (g *Game) Init() {
|
||||
g.createBodies()
|
||||
|
||||
g.ticksToNextBall = 10
|
||||
}
|
||||
|
||||
// creates a circle with random placement
|
||||
func addCircle(space *cp.Space, radius float64) {
|
||||
mass := radius * radius / 25.0
|
||||
body := space.AddBody(cp.NewBody(mass, cp.MomentForCircle(mass, 0, radius, cp.Vector{})))
|
||||
body.SetPosition(randUnitCircle().Mult(180))
|
||||
|
||||
shape := space.AddShape(cp.NewCircle(body, radius, cp.Vector{}))
|
||||
shape.SetElasticity(0)
|
||||
shape.SetFriction(0.9)
|
||||
}
|
||||
|
||||
// creates a simple terrain to contain bodies
|
||||
func simpleTerrain() *cp.Space {
|
||||
space := cp.NewSpace()
|
||||
space.Iterations = 10
|
||||
space.SetGravity(cp.Vector{0, -100})
|
||||
space.SetCollisionSlop(0.5)
|
||||
|
||||
offset := cp.Vector{X: -320, Y: -240}
|
||||
for i := 0; i < len(simpleTerrainVerts)-1; i++ {
|
||||
a := simpleTerrainVerts[i]
|
||||
b := simpleTerrainVerts[i+1]
|
||||
space.AddShape(cp.NewSegment(space.StaticBody, a.Add(offset), b.Add(offset), 0))
|
||||
// Update - Update game
|
||||
func (g *Game) Update() {
|
||||
g.ticksToNextBall--
|
||||
if g.ticksToNextBall == 0 {
|
||||
g.ticksToNextBall = rand.Intn(100) + 1
|
||||
g.addBall()
|
||||
}
|
||||
|
||||
return space
|
||||
// Physics steps calculations
|
||||
g.step(rl.GetFrameTime())
|
||||
}
|
||||
|
||||
// Draw - Draw game
|
||||
func (g *Game) Draw() {
|
||||
for i := range g.StaticLines {
|
||||
x := g.StaticLines[i].GetAsSegment().A.X
|
||||
y := g.StaticLines[i].GetAsSegment().A.Y
|
||||
|
||||
x2 := g.StaticLines[i].GetAsSegment().B.X
|
||||
y2 := g.StaticLines[i].GetAsSegment().B.Y
|
||||
|
||||
rl.DrawLine(int32(x), int32(y), int32(x2), int32(y2), rl.DarkBlue)
|
||||
}
|
||||
|
||||
for _, b := range g.Balls {
|
||||
pos := b.Body.Position()
|
||||
rl.DrawCircleLines(int32(pos.X), int32(pos.Y), float32(ballRadius), rl.DarkBlue)
|
||||
}
|
||||
}
|
||||
|
||||
// createBodies sets up the chipmunk space and static bodies
|
||||
func (g *Game) createBodies() {
|
||||
g.Space = chipmunk.NewSpace()
|
||||
g.Space.Gravity = vect.Vect{0, 900}
|
||||
|
||||
staticBody := chipmunk.NewBodyStatic()
|
||||
g.StaticLines = []*chipmunk.Shape{
|
||||
chipmunk.NewSegment(vect.Vect{250.0, 240.0}, vect.Vect{550.0, 280.0}, 0),
|
||||
chipmunk.NewSegment(vect.Vect{550.0, 280.0}, vect.Vect{550.0, 180.0}, 0),
|
||||
}
|
||||
|
||||
for _, segment := range g.StaticLines {
|
||||
segment.SetElasticity(0.6)
|
||||
staticBody.AddShape(segment)
|
||||
}
|
||||
|
||||
g.Space.AddBody(staticBody)
|
||||
}
|
||||
|
||||
// addBall adds ball to chipmunk space and body
|
||||
func (g *Game) addBall() {
|
||||
x := rand.Intn(600-200) + 200
|
||||
ball := chipmunk.NewCircle(vect.Vector_Zero, float32(ballRadius))
|
||||
ball.SetElasticity(0.95)
|
||||
|
||||
body := chipmunk.NewBody(vect.Float(ballMass), ball.Moment(float32(ballMass)))
|
||||
body.SetPosition(vect.Vect{vect.Float(x), 0.0})
|
||||
body.SetAngle(vect.Float(rand.Float32() * 2 * math.Pi))
|
||||
body.AddShape(ball)
|
||||
|
||||
g.Space.AddBody(body)
|
||||
g.Balls = append(g.Balls, ball)
|
||||
}
|
||||
|
||||
// step advances the physics engine and cleans up any balls that are off-screen
|
||||
func (g *Game) step(dt float32) {
|
||||
g.Space.Step(vect.Float(dt))
|
||||
|
||||
for i := 0; i < len(g.Balls); i++ {
|
||||
p := g.Balls[i].Body.Position()
|
||||
if p.Y < -100 {
|
||||
g.Space.RemoveBody(g.Balls[i].Body)
|
||||
g.Balls[i] = nil
|
||||
g.Balls = append(g.Balls[:i], g.Balls[i+1:]...)
|
||||
i-- // consider same index again
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
const width, height = 800, 450
|
||||
const physicsTickrate = 1.0 / 60.0
|
||||
rl.InitWindow(800, 450, "raylib [physics] example - chipmunk")
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
||||
raylib.InitWindow(width, height, "raylib [physics] example - chipmunk")
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
offset := raylib.Vector2{X: width / 2, Y: height / 2}
|
||||
// since the example ported from elsewhere, flip the camera 180 and offset to center it
|
||||
camera := raylib.NewCamera2D(offset, raylib.Vector2{}, 180, 1)
|
||||
game := NewGame()
|
||||
|
||||
space := simpleTerrain()
|
||||
for i := 0; i < 1000; i++ {
|
||||
addCircle(space, 5)
|
||||
}
|
||||
mouseBody := cp.NewKinematicBody()
|
||||
var mouse cp.Vector
|
||||
var mouseJoint *cp.Constraint
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.BeginDrawing()
|
||||
|
||||
var accumulator, dt float32
|
||||
lastTime := raylib.GetTime()
|
||||
for !raylib.WindowShouldClose() {
|
||||
// calculate dt
|
||||
now := raylib.GetTime()
|
||||
dt = now - lastTime
|
||||
lastTime = now
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
// update the mouse position
|
||||
mousePos := raylib.GetMousePosition()
|
||||
// alter the mouse coordinates based on the camera position, rotation
|
||||
mouse.X = float64(mousePos.X-camera.Offset.X) * -1
|
||||
mouse.Y = float64(mousePos.Y-camera.Offset.Y) * -1
|
||||
// smooth mouse movements to new position
|
||||
newPoint := mouseBody.Position().Lerp(mouse, 0.25)
|
||||
mouseBody.SetVelocityVector(newPoint.Sub(mouseBody.Position()).Mult(60.0))
|
||||
mouseBody.SetPosition(newPoint)
|
||||
game.Update()
|
||||
|
||||
// handle grabbing
|
||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
||||
result := space.PointQueryNearest(mouse, 5, grabFilter)
|
||||
if result.Shape != nil && result.Shape.Body().Mass() < cp.INFINITY {
|
||||
var nearest cp.Vector
|
||||
if result.Distance > 0 {
|
||||
nearest = result.Point
|
||||
} else {
|
||||
nearest = mouse
|
||||
}
|
||||
game.Draw()
|
||||
|
||||
// create a new constraint where the mouse is to draw the body towards the mouse
|
||||
body := result.Shape.Body()
|
||||
mouseJoint = cp.NewPivotJoint2(mouseBody, body, cp.Vector{}, body.WorldToLocal(nearest))
|
||||
mouseJoint.SetMaxForce(50000)
|
||||
mouseJoint.SetErrorBias(math.Pow(1.0-0.15, 60.0))
|
||||
space.AddConstraint(mouseJoint)
|
||||
}
|
||||
} else if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) && mouseJoint != nil {
|
||||
space.RemoveConstraint(mouseJoint)
|
||||
mouseJoint = nil
|
||||
}
|
||||
|
||||
// perform a fixed rate physics tick
|
||||
accumulator += dt
|
||||
for accumulator >= physicsTickrate {
|
||||
space.Step(physicsTickrate)
|
||||
accumulator -= physicsTickrate
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
raylib.BeginMode2D(camera)
|
||||
|
||||
// this is a generic way to iterate over the shapes in a space,
|
||||
// to avoid the type switch just keep a pointer to the shapes when they've been created
|
||||
space.EachShape(func(s *cp.Shape) {
|
||||
switch s.Class.(type) {
|
||||
case *cp.Segment:
|
||||
segment := s.Class.(*cp.Segment)
|
||||
a := segment.A()
|
||||
b := segment.B()
|
||||
raylib.DrawLineV(v(a), v(b), raylib.Black)
|
||||
case *cp.Circle:
|
||||
circle := s.Class.(*cp.Circle)
|
||||
pos := circle.Body().Position()
|
||||
raylib.DrawCircleV(v(pos), float32(circle.Radius()), raylib.Red)
|
||||
default:
|
||||
fmt.Println("unexpected shape", s.Class)
|
||||
}
|
||||
})
|
||||
|
||||
raylib.EndMode2D()
|
||||
raylib.DrawFPS(0, 0)
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
||||
|
||||
func v(v cp.Vector) raylib.Vector2 {
|
||||
return raylib.Vector2{X: float32(v.X), Y: float32(v.Y)}
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -9,46 +9,46 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
||||
raylib.InitWindow(screenWidth, screenHeight, "Physac [raylib] - physics demo")
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||
rl.InitWindow(screenWidth, screenHeight, "Physac [raylib] - physics demo")
|
||||
|
||||
// Physac logo drawing position
|
||||
logoX := screenWidth - raylib.MeasureText("Physac", 30) - 10
|
||||
logoX := screenWidth - rl.MeasureText("Physac", 30) - 10
|
||||
logoY := int32(15)
|
||||
|
||||
// Initialize physics and default physics bodies
|
||||
physics.Init()
|
||||
|
||||
// Create floor rectangle physics body
|
||||
floor := physics.NewBodyRectangle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)), 500, 100, 10)
|
||||
floor := physics.NewBodyRectangle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)), 500, 100, 10)
|
||||
floor.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
|
||||
// Create obstacle circle physics body
|
||||
circle := physics.NewBodyCircle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2), 45, 10)
|
||||
circle := physics.NewBodyCircle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2), 45, 10)
|
||||
circle.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
|
||||
// Update created physics objects
|
||||
physics.Update()
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeyR) { // Reset physics input
|
||||
if rl.IsKeyPressed(rl.KeyR) { // Reset physics input
|
||||
physics.Reset()
|
||||
|
||||
floor = physics.NewBodyRectangle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)), 500, 100, 10)
|
||||
floor = physics.NewBodyRectangle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)), 500, 100, 10)
|
||||
floor.Enabled = false
|
||||
|
||||
circle = physics.NewBodyCircle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2), 45, 10)
|
||||
circle = physics.NewBodyCircle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2), 45, 10)
|
||||
circle.Enabled = false
|
||||
}
|
||||
|
||||
// Physics body creation inputs
|
||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
||||
physics.NewBodyPolygon(raylib.GetMousePosition(), float32(raylib.GetRandomValue(20, 80)), int(raylib.GetRandomValue(3, 8)), 10)
|
||||
} else if raylib.IsMouseButtonPressed(raylib.MouseRightButton) {
|
||||
physics.NewBodyCircle(raylib.GetMousePosition(), float32(raylib.GetRandomValue(10, 45)), 10)
|
||||
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||
physics.NewBodyPolygon(rl.GetMousePosition(), float32(rl.GetRandomValue(20, 80)), int(rl.GetRandomValue(3, 8)), 10)
|
||||
} else if rl.IsMouseButtonPressed(rl.MouseRightButton) {
|
||||
physics.NewBodyCircle(rl.GetMousePosition(), float32(rl.GetRandomValue(10, 45)), 10)
|
||||
}
|
||||
|
||||
// Destroy falling physics bodies
|
||||
|
@ -58,11 +58,11 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.Black)
|
||||
rl.ClearBackground(rl.Black)
|
||||
|
||||
raylib.DrawFPS(screenWidth-90, screenHeight-30)
|
||||
rl.DrawFPS(screenWidth-90, screenHeight-30)
|
||||
|
||||
// Draw created physics bodies
|
||||
for i, body := range physics.GetBodies() {
|
||||
|
@ -79,21 +79,21 @@ func main() {
|
|||
|
||||
vertexB := body.GetShapeVertex(jj)
|
||||
|
||||
raylib.DrawLineV(vertexA, vertexB, raylib.Green) // Draw a line between two vertex positions
|
||||
rl.DrawLineV(vertexA, vertexB, rl.Green) // Draw a line between two vertex positions
|
||||
}
|
||||
}
|
||||
|
||||
raylib.DrawText("Left mouse button to create a polygon", 10, 10, 10, raylib.White)
|
||||
raylib.DrawText("Right mouse button to create a circle", 10, 25, 10, raylib.White)
|
||||
raylib.DrawText("Press 'R' to reset example", 10, 40, 10, raylib.White)
|
||||
rl.DrawText("Left mouse button to create a polygon", 10, 10, 10, rl.White)
|
||||
rl.DrawText("Right mouse button to create a circle", 10, 25, 10, rl.White)
|
||||
rl.DrawText("Press 'R' to reset example", 10, 40, 10, rl.White)
|
||||
|
||||
raylib.DrawText("Physac", logoX, logoY, 30, raylib.White)
|
||||
raylib.DrawText("Powered by", logoX+50, logoY-7, 10, raylib.White)
|
||||
rl.DrawText("Physac", logoX, logoY, 30, rl.White)
|
||||
rl.DrawText("Powered by", logoX+50, logoY-7, 10, rl.White)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
physics.Close() // Unitialize physics
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -9,67 +9,67 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
||||
raylib.InitWindow(screenWidth, screenHeight, "Physac [raylib] - physics friction")
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||
rl.InitWindow(screenWidth, screenHeight, "Physac [raylib] - physics friction")
|
||||
|
||||
// Physac logo drawing position
|
||||
logoX := screenWidth - raylib.MeasureText("Physac", 30) - 10
|
||||
logoX := screenWidth - rl.MeasureText("Physac", 30) - 10
|
||||
logoY := int32(15)
|
||||
|
||||
// Initialize physics and default physics bodies
|
||||
physics.Init()
|
||||
|
||||
// Create floor rectangle physics body
|
||||
floor := physics.NewBodyRectangle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)), float32(screenHeight), 100, 10)
|
||||
floor := physics.NewBodyRectangle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)), float32(screenHeight), 100, 10)
|
||||
floor.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
wall := physics.NewBodyRectangle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)*0.8), 10, 80, 10)
|
||||
wall := physics.NewBodyRectangle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)*0.8), 10, 80, 10)
|
||||
wall.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
|
||||
// Create left ramp physics body
|
||||
rectLeft := physics.NewBodyRectangle(raylib.NewVector2(25, float32(screenHeight)-5), 250, 250, 10)
|
||||
rectLeft := physics.NewBodyRectangle(rl.NewVector2(25, float32(screenHeight)-5), 250, 250, 10)
|
||||
rectLeft.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
rectLeft.SetRotation(30 * raylib.Deg2rad)
|
||||
rectLeft.SetRotation(30 * rl.Deg2rad)
|
||||
|
||||
// Create right ramp physics body
|
||||
rectRight := physics.NewBodyRectangle(raylib.NewVector2(float32(screenWidth)-25, float32(screenHeight)-5), 250, 250, 10)
|
||||
rectRight := physics.NewBodyRectangle(rl.NewVector2(float32(screenWidth)-25, float32(screenHeight)-5), 250, 250, 10)
|
||||
rectRight.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
rectRight.SetRotation(330 * raylib.Deg2rad)
|
||||
rectRight.SetRotation(330 * rl.Deg2rad)
|
||||
|
||||
// Create dynamic physics bodies
|
||||
bodyA := physics.NewBodyRectangle(raylib.NewVector2(35, float32(screenHeight)*0.6), 40, 40, 10)
|
||||
bodyA := physics.NewBodyRectangle(rl.NewVector2(35, float32(screenHeight)*0.6), 40, 40, 10)
|
||||
bodyA.StaticFriction = 0.1
|
||||
bodyA.DynamicFriction = 0.1
|
||||
bodyA.SetRotation(30 * raylib.Deg2rad)
|
||||
bodyA.SetRotation(30 * rl.Deg2rad)
|
||||
|
||||
bodyB := physics.NewBodyRectangle(raylib.NewVector2(float32(screenWidth)-35, float32(screenHeight)*0.6), 40, 40, 10)
|
||||
bodyB := physics.NewBodyRectangle(rl.NewVector2(float32(screenWidth)-35, float32(screenHeight)*0.6), 40, 40, 10)
|
||||
bodyB.StaticFriction = 1
|
||||
bodyB.DynamicFriction = 1
|
||||
bodyB.SetRotation(330 * raylib.Deg2rad)
|
||||
bodyB.SetRotation(330 * rl.Deg2rad)
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
// Physics steps calculations
|
||||
physics.Update()
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeyR) { // Reset physics input
|
||||
if rl.IsKeyPressed(rl.KeyR) { // Reset physics input
|
||||
// Reset dynamic physics bodies position, velocity and rotation
|
||||
bodyA.Position = raylib.NewVector2(35, float32(screenHeight)*0.6)
|
||||
bodyA.Velocity = raylib.NewVector2(0, 0)
|
||||
bodyA.Position = rl.NewVector2(35, float32(screenHeight)*0.6)
|
||||
bodyA.Velocity = rl.NewVector2(0, 0)
|
||||
bodyA.AngularVelocity = 0
|
||||
bodyA.SetRotation(30 * raylib.Deg2rad)
|
||||
bodyA.SetRotation(30 * rl.Deg2rad)
|
||||
|
||||
bodyB.Position = raylib.NewVector2(float32(screenWidth)-35, float32(screenHeight)*0.6)
|
||||
bodyB.Velocity = raylib.NewVector2(0, 0)
|
||||
bodyB.Position = rl.NewVector2(float32(screenWidth)-35, float32(screenHeight)*0.6)
|
||||
bodyB.Velocity = rl.NewVector2(0, 0)
|
||||
bodyB.AngularVelocity = 0
|
||||
bodyB.SetRotation(330 * raylib.Deg2rad)
|
||||
bodyB.SetRotation(330 * rl.Deg2rad)
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.Black)
|
||||
rl.ClearBackground(rl.Black)
|
||||
|
||||
raylib.DrawFPS(screenWidth-90, screenHeight-30)
|
||||
rl.DrawFPS(screenWidth-90, screenHeight-30)
|
||||
|
||||
// Draw created physics bodies
|
||||
bodiesCount := physics.GetBodiesCount()
|
||||
|
@ -89,25 +89,25 @@ func main() {
|
|||
|
||||
vertexB := body.GetShapeVertex(jj)
|
||||
|
||||
raylib.DrawLineV(vertexA, vertexB, raylib.Green) // Draw a line between two vertex positions
|
||||
rl.DrawLineV(vertexA, vertexB, rl.Green) // Draw a line between two vertex positions
|
||||
}
|
||||
}
|
||||
|
||||
raylib.DrawRectangle(0, screenHeight-49, screenWidth, 49, raylib.Black)
|
||||
rl.DrawRectangle(0, screenHeight-49, screenWidth, 49, rl.Black)
|
||||
|
||||
raylib.DrawText("Friction amount", (screenWidth-raylib.MeasureText("Friction amount", 30))/2, 75, 30, raylib.White)
|
||||
raylib.DrawText("0.1", int32(bodyA.Position.X)-raylib.MeasureText("0.1", 20)/2, int32(bodyA.Position.Y)-7, 20, raylib.White)
|
||||
raylib.DrawText("1", int32(bodyB.Position.X)-raylib.MeasureText("1", 20)/2, int32(bodyB.Position.Y)-7, 20, raylib.White)
|
||||
rl.DrawText("Friction amount", (screenWidth-rl.MeasureText("Friction amount", 30))/2, 75, 30, rl.White)
|
||||
rl.DrawText("0.1", int32(bodyA.Position.X)-rl.MeasureText("0.1", 20)/2, int32(bodyA.Position.Y)-7, 20, rl.White)
|
||||
rl.DrawText("1", int32(bodyB.Position.X)-rl.MeasureText("1", 20)/2, int32(bodyB.Position.Y)-7, 20, rl.White)
|
||||
|
||||
raylib.DrawText("Press 'R' to reset example", 10, 10, 10, raylib.White)
|
||||
rl.DrawText("Press 'R' to reset example", 10, 10, 10, rl.White)
|
||||
|
||||
raylib.DrawText("Physac", logoX, logoY, 30, raylib.White)
|
||||
raylib.DrawText("Powered by", logoX+50, logoY-7, 10, raylib.White)
|
||||
rl.DrawText("Physac", logoX, logoY, 30, rl.White)
|
||||
rl.DrawText("Powered by", logoX+50, logoY-7, 10, rl.White)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
physics.Close() // Unitialize physics
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -13,22 +13,22 @@ func main() {
|
|||
screenWidth := float32(800)
|
||||
screenHeight := float32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
||||
raylib.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - physics movement")
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||
rl.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - physics movement")
|
||||
|
||||
// Physac logo drawing position
|
||||
logoX := int32(screenWidth) - raylib.MeasureText("Physac", 30) - 10
|
||||
logoX := int32(screenWidth) - rl.MeasureText("Physac", 30) - 10
|
||||
logoY := int32(15)
|
||||
|
||||
// Initialize physics and default physics bodies
|
||||
physics.Init()
|
||||
|
||||
// Create floor and walls rectangle physics body
|
||||
floor := physics.NewBodyRectangle(raylib.NewVector2(screenWidth/2, screenHeight), screenWidth, 100, 10)
|
||||
platformLeft := physics.NewBodyRectangle(raylib.NewVector2(screenWidth*0.25, screenHeight*0.6), screenWidth*0.25, 10, 10)
|
||||
platformRight := physics.NewBodyRectangle(raylib.NewVector2(screenWidth*0.75, screenHeight*0.6), screenWidth*0.25, 10, 10)
|
||||
wallLeft := physics.NewBodyRectangle(raylib.NewVector2(-5, screenHeight/2), 10, screenHeight, 10)
|
||||
wallRight := physics.NewBodyRectangle(raylib.NewVector2(screenWidth+5, screenHeight/2), 10, screenHeight, 10)
|
||||
floor := physics.NewBodyRectangle(rl.NewVector2(screenWidth/2, screenHeight), screenWidth, 100, 10)
|
||||
platformLeft := physics.NewBodyRectangle(rl.NewVector2(screenWidth*0.25, screenHeight*0.6), screenWidth*0.25, 10, 10)
|
||||
platformRight := physics.NewBodyRectangle(rl.NewVector2(screenWidth*0.75, screenHeight*0.6), screenWidth*0.25, 10, 10)
|
||||
wallLeft := physics.NewBodyRectangle(rl.NewVector2(-5, screenHeight/2), 10, screenHeight, 10)
|
||||
wallRight := physics.NewBodyRectangle(rl.NewVector2(screenWidth+5, screenHeight/2), 10, screenHeight, 10)
|
||||
|
||||
// Disable dynamics to floor and walls physics bodies
|
||||
floor.Enabled = false
|
||||
|
@ -38,38 +38,38 @@ func main() {
|
|||
wallRight.Enabled = false
|
||||
|
||||
// Create movement physics body
|
||||
body := physics.NewBodyRectangle(raylib.NewVector2(screenWidth/2, screenHeight/2), 50, 50, 1)
|
||||
body := physics.NewBodyRectangle(rl.NewVector2(screenWidth/2, screenHeight/2), 50, 50, 1)
|
||||
body.FreezeOrient = true // Constrain body rotation to avoid little collision torque amounts
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
// Update created physics objects
|
||||
physics.Update()
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeyR) { // Reset physics input
|
||||
if rl.IsKeyPressed(rl.KeyR) { // Reset physics input
|
||||
// Reset movement physics body position, velocity and rotation
|
||||
body.Position = raylib.NewVector2(screenWidth/2, screenHeight/2)
|
||||
body.Velocity = raylib.NewVector2(0, 0)
|
||||
body.Position = rl.NewVector2(screenWidth/2, screenHeight/2)
|
||||
body.Velocity = rl.NewVector2(0, 0)
|
||||
body.SetRotation(0)
|
||||
}
|
||||
|
||||
// Physics body creation inputs
|
||||
if raylib.IsKeyDown(raylib.KeyRight) {
|
||||
if rl.IsKeyDown(rl.KeyRight) {
|
||||
body.Velocity.X = velocity
|
||||
} else if raylib.IsKeyDown(raylib.KeyLeft) {
|
||||
} else if rl.IsKeyDown(rl.KeyLeft) {
|
||||
body.Velocity.X = -velocity
|
||||
}
|
||||
|
||||
if raylib.IsKeyDown(raylib.KeyUp) && body.IsGrounded {
|
||||
if rl.IsKeyDown(rl.KeyUp) && body.IsGrounded {
|
||||
body.Velocity.Y = -velocity * 4
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.Black)
|
||||
rl.ClearBackground(rl.Black)
|
||||
|
||||
raylib.DrawFPS(int32(screenWidth)-90, int32(screenHeight)-30)
|
||||
rl.DrawFPS(int32(screenWidth)-90, int32(screenHeight)-30)
|
||||
|
||||
// Draw created physics bodies
|
||||
for i, body := range physics.GetBodies() {
|
||||
|
@ -86,20 +86,20 @@ func main() {
|
|||
|
||||
vertexB := body.GetShapeVertex(jj)
|
||||
|
||||
raylib.DrawLineV(vertexA, vertexB, raylib.Green) // Draw a line between two vertex positions
|
||||
rl.DrawLineV(vertexA, vertexB, rl.Green) // Draw a line between two vertex positions
|
||||
}
|
||||
}
|
||||
|
||||
raylib.DrawText("Use 'ARROWS' to move player", 10, 10, 10, raylib.White)
|
||||
raylib.DrawText("Press 'R' to reset example", 10, 30, 10, raylib.White)
|
||||
rl.DrawText("Use 'ARROWS' to move player", 10, 10, 10, rl.White)
|
||||
rl.DrawText("Press 'R' to reset example", 10, 30, 10, rl.White)
|
||||
|
||||
raylib.DrawText("Physac", logoX, logoY, 30, raylib.White)
|
||||
raylib.DrawText("Powered by", logoX+50, logoY-7, 10, raylib.White)
|
||||
rl.DrawText("Physac", logoX, logoY, 30, rl.White)
|
||||
rl.DrawText("Powered by", logoX+50, logoY-7, 10, rl.White)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
physics.Close() // Unitialize physics
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -13,50 +13,50 @@ func main() {
|
|||
screenWidth := float32(800)
|
||||
screenHeight := float32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
||||
raylib.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - physics restitution")
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||
rl.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - physics restitution")
|
||||
|
||||
// Physac logo drawing position
|
||||
logoX := int32(screenWidth) - raylib.MeasureText("Physac", 30) - 10
|
||||
logoX := int32(screenWidth) - rl.MeasureText("Physac", 30) - 10
|
||||
logoY := int32(15)
|
||||
|
||||
// Initialize physics and default physics bodies
|
||||
physics.Init()
|
||||
|
||||
// Create floor rectangle physics body
|
||||
floor := physics.NewBodyRectangle(raylib.NewVector2(screenWidth/2, screenHeight), screenWidth, 100, 10)
|
||||
floor := physics.NewBodyRectangle(rl.NewVector2(screenWidth/2, screenHeight), screenWidth, 100, 10)
|
||||
floor.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
floor.Restitution = 1
|
||||
|
||||
// Create circles physics body
|
||||
circleA := physics.NewBodyCircle(raylib.NewVector2(screenWidth*0.25, screenHeight/2), 30, 10)
|
||||
circleA := physics.NewBodyCircle(rl.NewVector2(screenWidth*0.25, screenHeight/2), 30, 10)
|
||||
circleA.Restitution = 0
|
||||
circleB := physics.NewBodyCircle(raylib.NewVector2(screenWidth*0.5, screenHeight/2), 30, 10)
|
||||
circleB := physics.NewBodyCircle(rl.NewVector2(screenWidth*0.5, screenHeight/2), 30, 10)
|
||||
circleB.Restitution = 0.5
|
||||
circleC := physics.NewBodyCircle(raylib.NewVector2(screenWidth*0.75, screenHeight/2), 30, 10)
|
||||
circleC := physics.NewBodyCircle(rl.NewVector2(screenWidth*0.75, screenHeight/2), 30, 10)
|
||||
circleC.Restitution = 1
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
// Update created physics objects
|
||||
physics.Update()
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeyR) { // Reset physics input
|
||||
if rl.IsKeyPressed(rl.KeyR) { // Reset physics input
|
||||
// Reset circles physics bodies position and velocity
|
||||
circleA.Position = raylib.NewVector2(screenWidth*0.25, screenHeight/2)
|
||||
circleA.Velocity = raylib.NewVector2(0, 0)
|
||||
circleB.Position = raylib.NewVector2(screenWidth*0.5, screenHeight/2)
|
||||
circleB.Velocity = raylib.NewVector2(0, 0)
|
||||
circleC.Position = raylib.NewVector2(screenWidth*0.75, screenHeight/2)
|
||||
circleC.Velocity = raylib.NewVector2(0, 0)
|
||||
circleA.Position = rl.NewVector2(screenWidth*0.25, screenHeight/2)
|
||||
circleA.Velocity = rl.NewVector2(0, 0)
|
||||
circleB.Position = rl.NewVector2(screenWidth*0.5, screenHeight/2)
|
||||
circleB.Velocity = rl.NewVector2(0, 0)
|
||||
circleC.Position = rl.NewVector2(screenWidth*0.75, screenHeight/2)
|
||||
circleC.Velocity = rl.NewVector2(0, 0)
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.Black)
|
||||
rl.ClearBackground(rl.Black)
|
||||
|
||||
raylib.DrawFPS(int32(screenWidth)-90, int32(screenHeight)-30)
|
||||
rl.DrawFPS(int32(screenWidth)-90, int32(screenHeight)-30)
|
||||
|
||||
// Draw created physics bodies
|
||||
for i, body := range physics.GetBodies() {
|
||||
|
@ -73,24 +73,24 @@ func main() {
|
|||
|
||||
vertexB := body.GetShapeVertex(jj)
|
||||
|
||||
raylib.DrawLineV(vertexA, vertexB, raylib.Green) // Draw a line between two vertex positions
|
||||
rl.DrawLineV(vertexA, vertexB, rl.Green) // Draw a line between two vertex positions
|
||||
}
|
||||
}
|
||||
|
||||
raylib.DrawText("Restitution amount", (int32(screenWidth)-raylib.MeasureText("Restitution amount", 30))/2, 75, 30, raylib.White)
|
||||
raylib.DrawText("0", int32(circleA.Position.X)-raylib.MeasureText("0", 20)/2, int32(circleA.Position.Y)-7, 20, raylib.White)
|
||||
raylib.DrawText("0.5", int32(circleB.Position.X)-raylib.MeasureText("0.5", 20)/2, int32(circleB.Position.Y)-7, 20, raylib.White)
|
||||
raylib.DrawText("1", int32(circleC.Position.X)-raylib.MeasureText("1", 20)/2, int32(circleC.Position.Y)-7, 20, raylib.White)
|
||||
rl.DrawText("Restitution amount", (int32(screenWidth)-rl.MeasureText("Restitution amount", 30))/2, 75, 30, rl.White)
|
||||
rl.DrawText("0", int32(circleA.Position.X)-rl.MeasureText("0", 20)/2, int32(circleA.Position.Y)-7, 20, rl.White)
|
||||
rl.DrawText("0.5", int32(circleB.Position.X)-rl.MeasureText("0.5", 20)/2, int32(circleB.Position.Y)-7, 20, rl.White)
|
||||
rl.DrawText("1", int32(circleC.Position.X)-rl.MeasureText("1", 20)/2, int32(circleC.Position.Y)-7, 20, rl.White)
|
||||
|
||||
raylib.DrawText("Press 'R' to reset example", 10, 10, 10, raylib.White)
|
||||
rl.DrawText("Press 'R' to reset example", 10, 10, 10, rl.White)
|
||||
|
||||
raylib.DrawText("Physac", logoX, logoY, 30, raylib.White)
|
||||
raylib.DrawText("Powered by", logoX+50, logoY-7, 10, raylib.White)
|
||||
rl.DrawText("Physac", logoX, logoY, 30, rl.White)
|
||||
rl.DrawText("Powered by", logoX+50, logoY-7, 10, rl.White)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
physics.Close() // Unitialize physics
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -13,11 +13,11 @@ func main() {
|
|||
screenWidth := float32(800)
|
||||
screenHeight := float32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
||||
raylib.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - body shatter")
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||
rl.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - body shatter")
|
||||
|
||||
// Physac logo drawing position
|
||||
logoX := int32(screenWidth) - raylib.MeasureText("Physac", 30) - 10
|
||||
logoX := int32(screenWidth) - rl.MeasureText("Physac", 30) - 10
|
||||
logoY := int32(15)
|
||||
|
||||
// Initialize physics and default physics bodies
|
||||
|
@ -25,30 +25,30 @@ func main() {
|
|||
physics.SetGravity(0, 0)
|
||||
|
||||
// Create random polygon physics body to shatter
|
||||
physics.NewBodyPolygon(raylib.NewVector2(screenWidth/2, screenHeight/2), float32(raylib.GetRandomValue(80, 200)), int(raylib.GetRandomValue(3, 8)), 10)
|
||||
physics.NewBodyPolygon(rl.NewVector2(screenWidth/2, screenHeight/2), float32(rl.GetRandomValue(80, 200)), int(rl.GetRandomValue(3, 8)), 10)
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
// Update created physics objects
|
||||
physics.Update()
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeyR) { // Reset physics input
|
||||
if rl.IsKeyPressed(rl.KeyR) { // Reset physics input
|
||||
physics.Reset()
|
||||
|
||||
// Create random polygon physics body to shatter
|
||||
physics.NewBodyPolygon(raylib.NewVector2(screenWidth/2, screenHeight/2), float32(raylib.GetRandomValue(80, 200)), int(raylib.GetRandomValue(3, 8)), 10)
|
||||
physics.NewBodyPolygon(rl.NewVector2(screenWidth/2, screenHeight/2), float32(rl.GetRandomValue(80, 200)), int(rl.GetRandomValue(3, 8)), 10)
|
||||
}
|
||||
|
||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
||||
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||
for _, b := range physics.GetBodies() {
|
||||
b.Shatter(raylib.GetMousePosition(), 10/b.InverseMass)
|
||||
b.Shatter(rl.GetMousePosition(), 10/b.InverseMass)
|
||||
}
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.Black)
|
||||
rl.ClearBackground(rl.Black)
|
||||
|
||||
// Draw created physics bodies
|
||||
for i, body := range physics.GetBodies() {
|
||||
|
@ -65,19 +65,19 @@ func main() {
|
|||
|
||||
vertexB := body.GetShapeVertex(jj)
|
||||
|
||||
raylib.DrawLineV(vertexA, vertexB, raylib.Green) // Draw a line between two vertex positions
|
||||
rl.DrawLineV(vertexA, vertexB, rl.Green) // Draw a line between two vertex positions
|
||||
}
|
||||
}
|
||||
|
||||
raylib.DrawText("Left mouse button in polygon area to shatter body\nPress 'R' to reset example", 10, 10, 10, raylib.White)
|
||||
rl.DrawText("Left mouse button in polygon area to shatter body\nPress 'R' to reset example", 10, 10, 10, rl.White)
|
||||
|
||||
raylib.DrawText("Physac", logoX, logoY, 30, raylib.White)
|
||||
raylib.DrawText("Powered by", logoX+50, logoY-7, 10, raylib.White)
|
||||
rl.DrawText("Physac", logoX, logoY, 30, rl.White)
|
||||
rl.DrawText("Powered by", logoX+50, logoY-7, 10, rl.White)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
physics.Close() // Unitialize physics
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,90 +8,90 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(3.0, 3.0, 3.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 1.5, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera := rl.Camera{}
|
||||
camera.Position = rl.NewVector3(3.0, 3.0, 3.0)
|
||||
camera.Target = rl.NewVector3(0.0, 1.5, 0.0)
|
||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
|
||||
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
||||
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||
dwarf := rl.LoadModel("dwarf.obj") // Load OBJ model
|
||||
texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||
|
||||
dwarf.Material.Maps[raylib.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||
dwarf.Material.Maps[rl.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||
|
||||
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
|
||||
shader := raylib.LoadShader("glsl330/base.vs", "glsl330/swirl.fs") // Load postpro shader
|
||||
shader := rl.LoadShader("glsl330/base.vs", "glsl330/swirl.fs") // Load postpro shader
|
||||
|
||||
// Get variable (uniform) location on the shader to connect with the program
|
||||
// NOTE: If uniform variable could not be found in the shader, function returns -1
|
||||
swirlCenterLoc := raylib.GetShaderLocation(shader, "center")
|
||||
swirlCenterLoc := rl.GetShaderLocation(shader, "center")
|
||||
|
||||
swirlCenter := make([]float32, 2)
|
||||
swirlCenter[0] = float32(screenWidth) / 2
|
||||
swirlCenter[1] = float32(screenHeight) / 2
|
||||
|
||||
// Create a RenderTexture2D to be used for render to texture
|
||||
target := raylib.LoadRenderTexture(screenWidth, screenHeight)
|
||||
target := rl.LoadRenderTexture(screenWidth, screenHeight)
|
||||
|
||||
// Setup orbital camera
|
||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
|
||||
rl.SetCameraMode(camera, rl.CameraOrbital) // Set an orbital camera mode
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
mousePosition := raylib.GetMousePosition()
|
||||
mousePosition := rl.GetMousePosition()
|
||||
|
||||
swirlCenter[0] = mousePosition.X
|
||||
swirlCenter[1] = float32(screenHeight) - mousePosition.Y
|
||||
|
||||
// Send new value to the shader to be used on drawing
|
||||
raylib.SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2)
|
||||
rl.SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2)
|
||||
|
||||
raylib.UpdateCamera(&camera) // Update camera
|
||||
rl.UpdateCamera(&camera) // Update camera
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.BeginTextureMode(target) // Enable drawing to texture
|
||||
rl.BeginTextureMode(target) // Enable drawing to texture
|
||||
|
||||
raylib.BeginMode3D(camera)
|
||||
rl.BeginMode3D(camera)
|
||||
|
||||
raylib.DrawModel(dwarf, position, 2.0, raylib.White) // Draw 3d model with texture
|
||||
rl.DrawModel(dwarf, position, 2.0, rl.White) // Draw 3d model with texture
|
||||
|
||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
||||
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
raylib.EndMode3D()
|
||||
rl.EndMode3D()
|
||||
|
||||
raylib.DrawText("TEXT DRAWN IN RENDER TEXTURE", 200, 10, 30, raylib.Red)
|
||||
rl.DrawText("TEXT DRAWN IN RENDER TEXTURE", 200, 10, 30, rl.Red)
|
||||
|
||||
raylib.EndTextureMode() // End drawing to texture (now we have a texture available for next passes)
|
||||
rl.EndTextureMode() // End drawing to texture (now we have a texture available for next passes)
|
||||
|
||||
raylib.BeginShaderMode(shader)
|
||||
rl.BeginShaderMode(shader)
|
||||
|
||||
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
||||
raylib.DrawTextureRec(target.Texture, raylib.NewRectangle(0, 0, float32(target.Texture.Width), float32(-target.Texture.Height)), raylib.NewVector2(0, 0), raylib.White)
|
||||
rl.DrawTextureRec(target.Texture, rl.NewRectangle(0, 0, float32(target.Texture.Width), float32(-target.Texture.Height)), rl.NewVector2(0, 0), rl.White)
|
||||
|
||||
raylib.EndShaderMode()
|
||||
rl.EndShaderMode()
|
||||
|
||||
raylib.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
||||
rl.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, rl.Gray)
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
rl.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadShader(shader) // Unload shader
|
||||
raylib.UnloadTexture(texture) // Unload texture
|
||||
raylib.UnloadModel(dwarf) // Unload model
|
||||
raylib.UnloadRenderTexture(target) // Unload render texture
|
||||
rl.UnloadShader(shader) // Unload shader
|
||||
rl.UnloadTexture(texture) // Unload texture
|
||||
rl.UnloadModel(dwarf) // Unload model
|
||||
rl.UnloadRenderTexture(target) // Unload render texture
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -10,57 +10,57 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(3.0, 3.0, 3.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 1.5, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera := rl.Camera{}
|
||||
camera.Position = rl.NewVector3(3.0, 3.0, 3.0)
|
||||
camera.Target = rl.NewVector3(0.0, 1.5, 0.0)
|
||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
|
||||
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
||||
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||
shader := raylib.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs") // Load model shader
|
||||
dwarf := rl.LoadModel("dwarf.obj") // Load OBJ model
|
||||
texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||
shader := rl.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs") // Load model shader
|
||||
|
||||
dwarf.Material.Shader = shader // Set shader effect to 3d model
|
||||
dwarf.Material.Maps[raylib.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||
dwarf.Material.Maps[rl.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||
|
||||
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraFree) // Set free camera mode
|
||||
rl.SetCameraMode(camera, rl.CameraFree) // Set 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
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.BeginMode3D(camera)
|
||||
rl.BeginMode3D(camera)
|
||||
|
||||
raylib.DrawModel(dwarf, position, 2.0, raylib.White) // Draw 3d model with texture
|
||||
rl.DrawModel(dwarf, position, 2.0, rl.White) // Draw 3d model with texture
|
||||
|
||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
||||
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
raylib.EndMode3D()
|
||||
rl.EndMode3D()
|
||||
|
||||
raylib.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
||||
rl.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, rl.Gray)
|
||||
|
||||
raylib.DrawText(fmt.Sprintf("Camera position: (%.2f, %.2f, %.2f)", camera.Position.X, camera.Position.Y, camera.Position.Z), 600, 20, 10, raylib.Black)
|
||||
raylib.DrawText(fmt.Sprintf("Camera target: (%.2f, %.2f, %.2f)", camera.Target.X, camera.Target.Y, camera.Target.Z), 600, 40, 10, raylib.Gray)
|
||||
rl.DrawText(fmt.Sprintf("Camera position: (%.2f, %.2f, %.2f)", camera.Position.X, camera.Position.Y, camera.Position.Z), 600, 20, 10, rl.Black)
|
||||
rl.DrawText(fmt.Sprintf("Camera target: (%.2f, %.2f, %.2f)", camera.Target.X, camera.Target.Y, camera.Target.Z), 600, 40, 10, rl.Gray)
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
rl.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadShader(shader) // Unload shader
|
||||
raylib.UnloadTexture(texture) // Unload texture
|
||||
raylib.UnloadModel(dwarf) // Unload model
|
||||
rl.UnloadShader(shader) // Unload shader
|
||||
rl.UnloadTexture(texture) // Unload texture
|
||||
rl.UnloadModel(dwarf) // Unload model
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -40,53 +40,53 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint | raylib.FlagVsyncHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint | rl.FlagVsyncHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(3.0, 3.0, 3.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 1.5, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera := rl.Camera{}
|
||||
camera.Position = rl.NewVector3(3.0, 3.0, 3.0)
|
||||
camera.Target = rl.NewVector3(0.0, 1.5, 0.0)
|
||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
|
||||
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
||||
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||
dwarf.Material.Maps[raylib.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||
dwarf := rl.LoadModel("dwarf.obj") // Load OBJ model
|
||||
texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||
dwarf.Material.Maps[rl.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||
|
||||
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
|
||||
// Load all postpro shaders
|
||||
// NOTE 1: All postpro shader use the base vertex shader (DEFAULT_VERTEX_SHADER)
|
||||
shaders := make([]raylib.Shader, MaxPostproShaders)
|
||||
shaders[FxGrayscale] = raylib.LoadShader("", "glsl330/grayscale.fs")
|
||||
shaders[FxPosterization] = raylib.LoadShader("", "glsl330/posterization.fs")
|
||||
shaders[FxDreamVision] = raylib.LoadShader("", "glsl330/dream_vision.fs")
|
||||
shaders[FxPixelizer] = raylib.LoadShader("", "glsl330/pixelizer.fs")
|
||||
shaders[FxCrossHatching] = raylib.LoadShader("", "glsl330/cross_hatching.fs")
|
||||
shaders[FxCrossStitching] = raylib.LoadShader("", "glsl330/cross_stitching.fs")
|
||||
shaders[FxPredatorView] = raylib.LoadShader("", "glsl330/predator.fs")
|
||||
shaders[FxScanlines] = raylib.LoadShader("", "glsl330/scanlines.fs")
|
||||
shaders[FxFisheye] = raylib.LoadShader("", "glsl330/fisheye.fs")
|
||||
shaders[FxSobel] = raylib.LoadShader("", "glsl330/sobel.fs")
|
||||
shaders[FxBlur] = raylib.LoadShader("", "glsl330/blur.fs")
|
||||
shaders[FxBloom] = raylib.LoadShader("", "glsl330/bloom.fs")
|
||||
shaders := make([]rl.Shader, MaxPostproShaders)
|
||||
shaders[FxGrayscale] = rl.LoadShader("", "glsl330/grayscale.fs")
|
||||
shaders[FxPosterization] = rl.LoadShader("", "glsl330/posterization.fs")
|
||||
shaders[FxDreamVision] = rl.LoadShader("", "glsl330/dream_vision.fs")
|
||||
shaders[FxPixelizer] = rl.LoadShader("", "glsl330/pixelizer.fs")
|
||||
shaders[FxCrossHatching] = rl.LoadShader("", "glsl330/cross_hatching.fs")
|
||||
shaders[FxCrossStitching] = rl.LoadShader("", "glsl330/cross_stitching.fs")
|
||||
shaders[FxPredatorView] = rl.LoadShader("", "glsl330/predator.fs")
|
||||
shaders[FxScanlines] = rl.LoadShader("", "glsl330/scanlines.fs")
|
||||
shaders[FxFisheye] = rl.LoadShader("", "glsl330/fisheye.fs")
|
||||
shaders[FxSobel] = rl.LoadShader("", "glsl330/sobel.fs")
|
||||
shaders[FxBlur] = rl.LoadShader("", "glsl330/blur.fs")
|
||||
shaders[FxBloom] = rl.LoadShader("", "glsl330/bloom.fs")
|
||||
|
||||
currentShader := FxGrayscale
|
||||
|
||||
// Create a RenderTexture2D to be used for render to texture
|
||||
target := raylib.LoadRenderTexture(screenWidth, screenHeight)
|
||||
target := rl.LoadRenderTexture(screenWidth, screenHeight)
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set free camera mode
|
||||
rl.SetCameraMode(camera, rl.CameraOrbital) // Set 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.IsKeyPressed(raylib.KeyRight) {
|
||||
if rl.IsKeyPressed(rl.KeyRight) {
|
||||
currentShader++
|
||||
} else if raylib.IsKeyPressed(raylib.KeyLeft) {
|
||||
} else if rl.IsKeyPressed(rl.KeyLeft) {
|
||||
currentShader--
|
||||
}
|
||||
|
||||
|
@ -96,51 +96,51 @@ func main() {
|
|||
currentShader = MaxPostproShaders - 1
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.BeginTextureMode(target) // Enable drawing to texture
|
||||
rl.BeginTextureMode(target) // Enable drawing to texture
|
||||
|
||||
raylib.BeginMode3D(camera)
|
||||
rl.BeginMode3D(camera)
|
||||
|
||||
raylib.DrawModel(dwarf, position, 2.0, raylib.White) // Draw 3d model with texture
|
||||
rl.DrawModel(dwarf, position, 2.0, rl.White) // Draw 3d model with texture
|
||||
|
||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
||||
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
raylib.EndMode3D()
|
||||
rl.EndMode3D()
|
||||
|
||||
raylib.EndTextureMode() // End drawing to texture (now we have a texture available for next passes)
|
||||
rl.EndTextureMode() // End drawing to texture (now we have a texture available for next passes)
|
||||
|
||||
// Render previously generated texture using selected postpro shader
|
||||
raylib.BeginShaderMode(shaders[currentShader])
|
||||
rl.BeginShaderMode(shaders[currentShader])
|
||||
|
||||
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
||||
raylib.DrawTextureRec(target.Texture, raylib.NewRectangle(0, 0, float32(target.Texture.Width), float32(-target.Texture.Height)), raylib.NewVector2(0, 0), raylib.White)
|
||||
rl.DrawTextureRec(target.Texture, rl.NewRectangle(0, 0, float32(target.Texture.Width), float32(-target.Texture.Height)), rl.NewVector2(0, 0), rl.White)
|
||||
|
||||
raylib.EndShaderMode()
|
||||
rl.EndShaderMode()
|
||||
|
||||
raylib.DrawRectangle(0, 9, 580, 30, raylib.Fade(raylib.LightGray, 0.7))
|
||||
rl.DrawRectangle(0, 9, 580, 30, rl.Fade(rl.LightGray, 0.7))
|
||||
|
||||
raylib.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, raylib.DarkGray)
|
||||
rl.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, rl.DarkGray)
|
||||
|
||||
raylib.DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, raylib.Black)
|
||||
raylib.DrawText(postproShaderText[currentShader], 330, 15, 20, raylib.Red)
|
||||
raylib.DrawText("< >", 540, 10, 30, raylib.DarkBlue)
|
||||
rl.DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, rl.Black)
|
||||
rl.DrawText(postproShaderText[currentShader], 330, 15, 20, rl.Red)
|
||||
rl.DrawText("< >", 540, 10, 30, rl.DarkBlue)
|
||||
|
||||
raylib.DrawFPS(700, 15)
|
||||
rl.DrawFPS(700, 15)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
// Unload all postpro shaders
|
||||
for i := 0; i < MaxPostproShaders; i++ {
|
||||
raylib.UnloadShader(shaders[i])
|
||||
rl.UnloadShader(shaders[i])
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture) // Unload texture
|
||||
raylib.UnloadModel(dwarf) // Unload model
|
||||
raylib.UnloadRenderTexture(target) // Unload render texture
|
||||
rl.UnloadTexture(texture) // Unload texture
|
||||
rl.UnloadModel(dwarf) // Unload model
|
||||
rl.UnloadRenderTexture(target) // Unload render texture
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,67 +8,67 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders")
|
||||
|
||||
fudesumi := raylib.LoadTexture("fudesumi.png")
|
||||
fudesumi := rl.LoadTexture("fudesumi.png")
|
||||
|
||||
// NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
|
||||
shader := raylib.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs")
|
||||
shader := rl.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs")
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
// Start drawing with default shader
|
||||
|
||||
raylib.DrawText("USING DEFAULT SHADER", 20, 40, 10, raylib.Red)
|
||||
rl.DrawText("USING DEFAULT SHADER", 20, 40, 10, rl.Red)
|
||||
|
||||
raylib.DrawCircle(80, 120, 35, raylib.DarkBlue)
|
||||
raylib.DrawCircleGradient(80, 220, 60, raylib.Green, raylib.SkyBlue)
|
||||
raylib.DrawCircleLines(80, 340, 80, raylib.DarkBlue)
|
||||
rl.DrawCircle(80, 120, 35, rl.DarkBlue)
|
||||
rl.DrawCircleGradient(80, 220, 60, rl.Green, rl.SkyBlue)
|
||||
rl.DrawCircleLines(80, 340, 80, rl.DarkBlue)
|
||||
|
||||
// Activate our custom shader to be applied on next shapes/textures drawings
|
||||
raylib.BeginShaderMode(shader)
|
||||
rl.BeginShaderMode(shader)
|
||||
|
||||
raylib.DrawText("USING CUSTOM SHADER", 190, 40, 10, raylib.Red)
|
||||
rl.DrawText("USING CUSTOM SHADER", 190, 40, 10, rl.Red)
|
||||
|
||||
raylib.DrawRectangle(250-60, 90, 120, 60, raylib.Red)
|
||||
raylib.DrawRectangleGradientH(250-90, 170, 180, 130, raylib.Maroon, raylib.Gold)
|
||||
raylib.DrawRectangleLines(250-40, 320, 80, 60, raylib.Orange)
|
||||
rl.DrawRectangle(250-60, 90, 120, 60, rl.Red)
|
||||
rl.DrawRectangleGradientH(250-90, 170, 180, 130, rl.Maroon, rl.Gold)
|
||||
rl.DrawRectangleLines(250-40, 320, 80, 60, rl.Orange)
|
||||
|
||||
// Activate our default shader for next drawings
|
||||
raylib.EndShaderMode()
|
||||
rl.EndShaderMode()
|
||||
|
||||
raylib.DrawText("USING DEFAULT SHADER", 370, 40, 10, raylib.Red)
|
||||
rl.DrawText("USING DEFAULT SHADER", 370, 40, 10, rl.Red)
|
||||
|
||||
raylib.DrawTriangle(raylib.NewVector2(430, 80),
|
||||
raylib.NewVector2(430-60, 150),
|
||||
raylib.NewVector2(430+60, 150), raylib.Violet)
|
||||
rl.DrawTriangle(rl.NewVector2(430, 80),
|
||||
rl.NewVector2(430-60, 150),
|
||||
rl.NewVector2(430+60, 150), rl.Violet)
|
||||
|
||||
raylib.DrawTriangleLines(raylib.NewVector2(430, 160),
|
||||
raylib.NewVector2(430-20, 230),
|
||||
raylib.NewVector2(430+20, 230), raylib.DarkBlue)
|
||||
rl.DrawTriangleLines(rl.NewVector2(430, 160),
|
||||
rl.NewVector2(430-20, 230),
|
||||
rl.NewVector2(430+20, 230), rl.DarkBlue)
|
||||
|
||||
raylib.DrawPoly(raylib.NewVector2(430, 320), 6, 80, 0, raylib.Brown)
|
||||
rl.DrawPoly(rl.NewVector2(430, 320), 6, 80, 0, rl.Brown)
|
||||
|
||||
// Activate our custom shader to be applied on next shapes/textures drawings
|
||||
raylib.BeginShaderMode(shader)
|
||||
rl.BeginShaderMode(shader)
|
||||
|
||||
raylib.DrawTexture(fudesumi, 500, -30, raylib.White) // Using custom shader
|
||||
rl.DrawTexture(fudesumi, 500, -30, rl.White) // Using custom shader
|
||||
|
||||
// Activate our default shader for next drawings
|
||||
raylib.EndShaderMode()
|
||||
rl.EndShaderMode()
|
||||
|
||||
raylib.DrawText("(c) Fudesumi sprite by Eiden Marsal", 380, screenHeight-20, 10, raylib.Gray)
|
||||
rl.DrawText("(c) Fudesumi sprite by Eiden Marsal", 380, screenHeight-20, 10, rl.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadShader(shader) // Unload shader
|
||||
raylib.UnloadTexture(fudesumi) // Unload texture
|
||||
rl.UnloadShader(shader) // Unload shader
|
||||
rl.UnloadTexture(fudesumi) // Unload texture
|
||||
|
||||
raylib.CloseWindow() // Close window and OpenGL context
|
||||
rl.CloseWindow() // Close window and OpenGL context
|
||||
}
|
||||
|
|
|
@ -8,38 +8,38 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing")
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawText("some basic shapes available on raylib", 20, 20, 20, raylib.DarkGray)
|
||||
rl.DrawText("some basic shapes available on raylib", 20, 20, 20, rl.DarkGray)
|
||||
|
||||
raylib.DrawLine(18, 42, screenWidth-18, 42, raylib.Black)
|
||||
rl.DrawLine(18, 42, screenWidth-18, 42, rl.Black)
|
||||
|
||||
raylib.DrawCircle(screenWidth/4, 120, 35, raylib.DarkBlue)
|
||||
raylib.DrawCircleGradient(screenWidth/4, 220, 60, raylib.Green, raylib.SkyBlue)
|
||||
raylib.DrawCircleLines(screenWidth/4, 340, 80, raylib.DarkBlue)
|
||||
rl.DrawCircle(screenWidth/4, 120, 35, rl.DarkBlue)
|
||||
rl.DrawCircleGradient(screenWidth/4, 220, 60, rl.Green, rl.SkyBlue)
|
||||
rl.DrawCircleLines(screenWidth/4, 340, 80, rl.DarkBlue)
|
||||
|
||||
raylib.DrawRectangle(screenWidth/4*2-60, 100, 120, 60, raylib.Red)
|
||||
raylib.DrawRectangleGradientH(screenWidth/4*2-90, 170, 180, 130, raylib.Maroon, raylib.Gold)
|
||||
raylib.DrawRectangleLines(screenWidth/4*2-40, 320, 80, 60, raylib.Orange)
|
||||
rl.DrawRectangle(screenWidth/4*2-60, 100, 120, 60, rl.Red)
|
||||
rl.DrawRectangleGradientH(screenWidth/4*2-90, 170, 180, 130, rl.Maroon, rl.Gold)
|
||||
rl.DrawRectangleLines(screenWidth/4*2-40, 320, 80, 60, rl.Orange)
|
||||
|
||||
raylib.DrawTriangle(raylib.NewVector2(float32(screenWidth)/4*3, 80),
|
||||
raylib.NewVector2(float32(screenWidth)/4*3-60, 150),
|
||||
raylib.NewVector2(float32(screenWidth)/4*3+60, 150), raylib.Violet)
|
||||
rl.DrawTriangle(rl.NewVector2(float32(screenWidth)/4*3, 80),
|
||||
rl.NewVector2(float32(screenWidth)/4*3-60, 150),
|
||||
rl.NewVector2(float32(screenWidth)/4*3+60, 150), rl.Violet)
|
||||
|
||||
raylib.DrawTriangleLines(raylib.NewVector2(float32(screenWidth)/4*3, 160),
|
||||
raylib.NewVector2(float32(screenWidth)/4*3-20, 230),
|
||||
raylib.NewVector2(float32(screenWidth)/4*3+20, 230), raylib.DarkBlue)
|
||||
rl.DrawTriangleLines(rl.NewVector2(float32(screenWidth)/4*3, 160),
|
||||
rl.NewVector2(float32(screenWidth)/4*3-20, 230),
|
||||
rl.NewVector2(float32(screenWidth)/4*3+20, 230), rl.DarkBlue)
|
||||
|
||||
raylib.DrawPoly(raylib.NewVector2(float32(screenWidth)/4*3, 320), 6, 80, 0, raylib.Brown)
|
||||
rl.DrawPoly(rl.NewVector2(float32(screenWidth)/4*3, 320), 6, 80, 0, rl.Brown)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -5,62 +5,62 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
raylib.InitWindow(800, 450, "raylib [shapes] example - raylib color palette")
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.InitWindow(800, 450, "raylib [shapes] example - raylib color palette")
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawText("raylib color palette", 28, 42, 20, raylib.Black)
|
||||
rl.DrawText("raylib color palette", 28, 42, 20, rl.Black)
|
||||
|
||||
raylib.DrawRectangle(26, 80, 100, 100, raylib.DarkGray)
|
||||
raylib.DrawRectangle(26, 188, 100, 100, raylib.Gray)
|
||||
raylib.DrawRectangle(26, 296, 100, 100, raylib.LightGray)
|
||||
raylib.DrawRectangle(134, 80, 100, 100, raylib.Maroon)
|
||||
raylib.DrawRectangle(134, 188, 100, 100, raylib.Red)
|
||||
raylib.DrawRectangle(134, 296, 100, 100, raylib.Pink)
|
||||
raylib.DrawRectangle(242, 80, 100, 100, raylib.Orange)
|
||||
raylib.DrawRectangle(242, 188, 100, 100, raylib.Gold)
|
||||
raylib.DrawRectangle(242, 296, 100, 100, raylib.Yellow)
|
||||
raylib.DrawRectangle(350, 80, 100, 100, raylib.DarkGreen)
|
||||
raylib.DrawRectangle(350, 188, 100, 100, raylib.Lime)
|
||||
raylib.DrawRectangle(350, 296, 100, 100, raylib.Green)
|
||||
raylib.DrawRectangle(458, 80, 100, 100, raylib.DarkBlue)
|
||||
raylib.DrawRectangle(458, 188, 100, 100, raylib.Blue)
|
||||
raylib.DrawRectangle(458, 296, 100, 100, raylib.SkyBlue)
|
||||
raylib.DrawRectangle(566, 80, 100, 100, raylib.DarkPurple)
|
||||
raylib.DrawRectangle(566, 188, 100, 100, raylib.Violet)
|
||||
raylib.DrawRectangle(566, 296, 100, 100, raylib.Purple)
|
||||
raylib.DrawRectangle(674, 80, 100, 100, raylib.DarkBrown)
|
||||
raylib.DrawRectangle(674, 188, 100, 100, raylib.Brown)
|
||||
raylib.DrawRectangle(674, 296, 100, 100, raylib.Beige)
|
||||
rl.DrawRectangle(26, 80, 100, 100, rl.DarkGray)
|
||||
rl.DrawRectangle(26, 188, 100, 100, rl.Gray)
|
||||
rl.DrawRectangle(26, 296, 100, 100, rl.LightGray)
|
||||
rl.DrawRectangle(134, 80, 100, 100, rl.Maroon)
|
||||
rl.DrawRectangle(134, 188, 100, 100, rl.Red)
|
||||
rl.DrawRectangle(134, 296, 100, 100, rl.Pink)
|
||||
rl.DrawRectangle(242, 80, 100, 100, rl.Orange)
|
||||
rl.DrawRectangle(242, 188, 100, 100, rl.Gold)
|
||||
rl.DrawRectangle(242, 296, 100, 100, rl.Yellow)
|
||||
rl.DrawRectangle(350, 80, 100, 100, rl.DarkGreen)
|
||||
rl.DrawRectangle(350, 188, 100, 100, rl.Lime)
|
||||
rl.DrawRectangle(350, 296, 100, 100, rl.Green)
|
||||
rl.DrawRectangle(458, 80, 100, 100, rl.DarkBlue)
|
||||
rl.DrawRectangle(458, 188, 100, 100, rl.Blue)
|
||||
rl.DrawRectangle(458, 296, 100, 100, rl.SkyBlue)
|
||||
rl.DrawRectangle(566, 80, 100, 100, rl.DarkPurple)
|
||||
rl.DrawRectangle(566, 188, 100, 100, rl.Violet)
|
||||
rl.DrawRectangle(566, 296, 100, 100, rl.Purple)
|
||||
rl.DrawRectangle(674, 80, 100, 100, rl.DarkBrown)
|
||||
rl.DrawRectangle(674, 188, 100, 100, rl.Brown)
|
||||
rl.DrawRectangle(674, 296, 100, 100, rl.Beige)
|
||||
|
||||
raylib.DrawText("DARKGRAY", 65, 166, 10, raylib.Black)
|
||||
raylib.DrawText("GRAY", 93, 274, 10, raylib.Black)
|
||||
raylib.DrawText("LIGHTGRAY", 61, 382, 10, raylib.Black)
|
||||
raylib.DrawText("MAROON", 186, 166, 10, raylib.Black)
|
||||
raylib.DrawText("RED", 208, 274, 10, raylib.Black)
|
||||
raylib.DrawText("PINK", 204, 382, 10, raylib.Black)
|
||||
raylib.DrawText("ORANGE", 295, 166, 10, raylib.Black)
|
||||
raylib.DrawText("GOLD", 310, 274, 10, raylib.Black)
|
||||
raylib.DrawText("YELLOW", 300, 382, 10, raylib.Black)
|
||||
raylib.DrawText("DARKGREEN", 382, 166, 10, raylib.Black)
|
||||
raylib.DrawText("LIME", 420, 274, 10, raylib.Black)
|
||||
raylib.DrawText("GREEN", 410, 382, 10, raylib.Black)
|
||||
raylib.DrawText("DARKBLUE", 498, 166, 10, raylib.Black)
|
||||
raylib.DrawText("BLUE", 526, 274, 10, raylib.Black)
|
||||
raylib.DrawText("SKYBLUE", 505, 382, 10, raylib.Black)
|
||||
raylib.DrawText("DARKPURPLE", 592, 166, 10, raylib.Black)
|
||||
raylib.DrawText("VIOLET", 621, 274, 10, raylib.Black)
|
||||
raylib.DrawText("PURPLE", 620, 382, 10, raylib.Black)
|
||||
raylib.DrawText("DARKBROWN", 705, 166, 10, raylib.Black)
|
||||
raylib.DrawText("BROWN", 733, 274, 10, raylib.Black)
|
||||
raylib.DrawText("BEIGE", 737, 382, 10, raylib.Black)
|
||||
rl.DrawText("DARKGRAY", 65, 166, 10, rl.Black)
|
||||
rl.DrawText("GRAY", 93, 274, 10, rl.Black)
|
||||
rl.DrawText("LIGHTGRAY", 61, 382, 10, rl.Black)
|
||||
rl.DrawText("MAROON", 186, 166, 10, rl.Black)
|
||||
rl.DrawText("RED", 208, 274, 10, rl.Black)
|
||||
rl.DrawText("PINK", 204, 382, 10, rl.Black)
|
||||
rl.DrawText("ORANGE", 295, 166, 10, rl.Black)
|
||||
rl.DrawText("GOLD", 310, 274, 10, rl.Black)
|
||||
rl.DrawText("YELLOW", 300, 382, 10, rl.Black)
|
||||
rl.DrawText("DARKGREEN", 382, 166, 10, rl.Black)
|
||||
rl.DrawText("LIME", 420, 274, 10, rl.Black)
|
||||
rl.DrawText("GREEN", 410, 382, 10, rl.Black)
|
||||
rl.DrawText("DARKBLUE", 498, 166, 10, rl.Black)
|
||||
rl.DrawText("BLUE", 526, 274, 10, rl.Black)
|
||||
rl.DrawText("SKYBLUE", 505, 382, 10, rl.Black)
|
||||
rl.DrawText("DARKPURPLE", 592, 166, 10, rl.Black)
|
||||
rl.DrawText("VIOLET", 621, 274, 10, rl.Black)
|
||||
rl.DrawText("PURPLE", 620, 382, 10, rl.Black)
|
||||
rl.DrawText("DARKBROWN", 705, 166, 10, rl.Black)
|
||||
rl.DrawText("BROWN", 733, 274, 10, rl.Black)
|
||||
rl.DrawText("BEIGE", 737, 382, 10, rl.Black)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,29 +8,29 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines")
|
||||
|
||||
start := raylib.NewVector2(0, 0)
|
||||
end := raylib.NewVector2(float32(screenWidth), float32(screenHeight))
|
||||
start := rl.NewVector2(0, 0)
|
||||
end := rl.NewVector2(float32(screenWidth), float32(screenHeight))
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
||||
start = raylib.GetMousePosition()
|
||||
} else if raylib.IsMouseButtonDown(raylib.MouseRightButton) {
|
||||
end = raylib.GetMousePosition()
|
||||
for !rl.WindowShouldClose() {
|
||||
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||
start = rl.GetMousePosition()
|
||||
} else if rl.IsMouseButtonDown(rl.MouseRightButton) {
|
||||
end = rl.GetMousePosition()
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, raylib.Gray)
|
||||
rl.DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, rl.Gray)
|
||||
|
||||
raylib.DrawLineBezier(start, end, 2.0, raylib.Red)
|
||||
rl.DrawLineBezier(start, end, 2.0, rl.Red)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,22 +8,22 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes")
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawRectangle(screenWidth/2-128, screenHeight/2-128, 256, 256, raylib.Black)
|
||||
raylib.DrawRectangle(screenWidth/2-112, screenHeight/2-112, 224, 224, raylib.RayWhite)
|
||||
raylib.DrawText("raylib", screenWidth/2-44, screenHeight/2+48, 50, raylib.Black)
|
||||
rl.DrawRectangle(screenWidth/2-128, screenHeight/2-128, 256, 256, rl.Black)
|
||||
rl.DrawRectangle(screenWidth/2-112, screenHeight/2-112, 224, 224, rl.RayWhite)
|
||||
rl.DrawText("raylib", screenWidth/2-44, screenHeight/2+48, 50, rl.Black)
|
||||
|
||||
raylib.DrawText("this is NOT a texture!", 350, 370, 10, raylib.Gray)
|
||||
rl.DrawText("this is NOT a texture!", 350, 370, 10, rl.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo animation")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo animation")
|
||||
|
||||
logoPositionX := screenWidth/2 - 128
|
||||
logoPositionY := screenHeight/2 - 128
|
||||
|
@ -25,9 +25,9 @@ func main() {
|
|||
state := 0 // Tracking animation states (State Machine)
|
||||
alpha := float32(1.0) // Useful for fading
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
if state == 0 { // State 0: Small box blinking
|
||||
framesCounter++
|
||||
|
||||
|
@ -66,7 +66,7 @@ func main() {
|
|||
}
|
||||
}
|
||||
} else if state == 4 { // State 4: Reset and Replay
|
||||
if raylib.IsKeyPressed(raylib.KeyR) {
|
||||
if rl.IsKeyPressed(rl.KeyR) {
|
||||
framesCounter = 0
|
||||
lettersCount = 0
|
||||
|
||||
|
@ -81,30 +81,30 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
if state == 0 {
|
||||
if (framesCounter/15)%2 == 0 {
|
||||
raylib.DrawRectangle(logoPositionX, logoPositionY, 16, 16, raylib.Black)
|
||||
rl.DrawRectangle(logoPositionX, logoPositionY, 16, 16, rl.Black)
|
||||
}
|
||||
} else if state == 1 {
|
||||
raylib.DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, raylib.Black)
|
||||
raylib.DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, raylib.Black)
|
||||
rl.DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, rl.Black)
|
||||
rl.DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, rl.Black)
|
||||
} else if state == 2 {
|
||||
raylib.DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, raylib.Black)
|
||||
raylib.DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, raylib.Black)
|
||||
rl.DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, rl.Black)
|
||||
rl.DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, rl.Black)
|
||||
|
||||
raylib.DrawRectangle(logoPositionX+240, logoPositionY, 16, rightSideRecHeight, raylib.Black)
|
||||
raylib.DrawRectangle(logoPositionX, logoPositionY+240, bottomSideRecWidth, 16, raylib.Black)
|
||||
rl.DrawRectangle(logoPositionX+240, logoPositionY, 16, rightSideRecHeight, rl.Black)
|
||||
rl.DrawRectangle(logoPositionX, logoPositionY+240, bottomSideRecWidth, 16, rl.Black)
|
||||
} else if state == 3 {
|
||||
raylib.DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, raylib.Fade(raylib.Black, alpha))
|
||||
raylib.DrawRectangle(logoPositionX, logoPositionY+16, 16, leftSideRecHeight-32, raylib.Fade(raylib.Black, alpha))
|
||||
rl.DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, rl.Fade(rl.Black, alpha))
|
||||
rl.DrawRectangle(logoPositionX, logoPositionY+16, 16, leftSideRecHeight-32, rl.Fade(rl.Black, alpha))
|
||||
|
||||
raylib.DrawRectangle(logoPositionX+240, logoPositionY+16, 16, rightSideRecHeight-32, raylib.Fade(raylib.Black, alpha))
|
||||
raylib.DrawRectangle(logoPositionX, logoPositionY+240, bottomSideRecWidth, 16, raylib.Fade(raylib.Black, alpha))
|
||||
rl.DrawRectangle(logoPositionX+240, logoPositionY+16, 16, rightSideRecHeight-32, rl.Fade(rl.Black, alpha))
|
||||
rl.DrawRectangle(logoPositionX, logoPositionY+240, bottomSideRecWidth, 16, rl.Fade(rl.Black, alpha))
|
||||
|
||||
raylib.DrawRectangle(screenWidth/2-112, screenHeight/2-112, 224, 224, raylib.Fade(raylib.RayWhite, alpha))
|
||||
rl.DrawRectangle(screenWidth/2-112, screenHeight/2-112, 224, 224, rl.Fade(rl.RayWhite, alpha))
|
||||
|
||||
text := "raylib"
|
||||
length := int32(len(text))
|
||||
|
@ -112,13 +112,13 @@ func main() {
|
|||
lettersCount = length
|
||||
}
|
||||
|
||||
raylib.DrawText(text[0:lettersCount], screenWidth/2-44, screenHeight/2+48, 50, raylib.Fade(raylib.Black, alpha))
|
||||
rl.DrawText(text[0:lettersCount], screenWidth/2-44, screenHeight/2+48, 50, rl.Fade(rl.Black, alpha))
|
||||
} else if state == 4 {
|
||||
raylib.DrawText("[R] REPLAY", 340, 200, 20, raylib.Gray)
|
||||
rl.DrawText("[R] REPLAY", 340, 200, 20, rl.Gray)
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,35 +8,35 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading")
|
||||
|
||||
msgBm := "THIS IS AN AngelCode SPRITE FONT"
|
||||
msgTtf := "THIS SPRITE FONT has been GENERATED from a TTF"
|
||||
|
||||
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||
fontBm := raylib.LoadFont("fonts/bmfont.fnt") // BMFont (AngelCode)
|
||||
fontTtf := raylib.LoadFont("fonts/pixantiqua.ttf") // TTF font
|
||||
fontBm := rl.LoadFont("fonts/bmfont.fnt") // BMFont (AngelCode)
|
||||
fontTtf := rl.LoadFont("fonts/pixantiqua.ttf") // TTF font
|
||||
|
||||
fontPosition := raylib.Vector2{}
|
||||
fontPosition := rl.Vector2{}
|
||||
|
||||
fontPosition.X = float32(screenWidth)/2 - raylib.MeasureTextEx(fontBm, msgBm, float32(fontBm.BaseSize), 0).X/2
|
||||
fontPosition.X = float32(screenWidth)/2 - rl.MeasureTextEx(fontBm, msgBm, float32(fontBm.BaseSize), 0).X/2
|
||||
fontPosition.Y = float32(screenHeight)/2 - float32(fontBm.BaseSize)/2 - 80
|
||||
|
||||
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.DrawTextEx(fontBm, msgBm, fontPosition, float32(fontBm.BaseSize), 0, raylib.Maroon)
|
||||
raylib.DrawTextEx(fontTtf, msgTtf, raylib.NewVector2(75.0, 240.0), float32(fontTtf.BaseSize)*0.8, 2, raylib.Lime)
|
||||
rl.DrawTextEx(fontBm, msgBm, fontPosition, float32(fontBm.BaseSize), 0, rl.Maroon)
|
||||
rl.DrawTextEx(fontTtf, msgTtf, rl.NewVector2(75.0, 240.0), float32(fontTtf.BaseSize)*0.8, 2, rl.Lime)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadFont(fontBm) // AngelCode Font unloading
|
||||
raylib.UnloadFont(fontTtf) // TTF Font unloading
|
||||
rl.UnloadFont(fontBm) // AngelCode Font unloading
|
||||
rl.UnloadFont(fontTtf) // TTF Font unloading
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -10,32 +10,32 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont unordered loading and drawing")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont unordered loading and drawing")
|
||||
|
||||
// NOTE: Using chars outside the [32..127] limits!
|
||||
// NOTE: If a character is not found in the font, it just renders a space
|
||||
msg := "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
|
||||
|
||||
// NOTE: Loaded font has an unordered list of characters (chars in the range 32..255)
|
||||
font := raylib.LoadFont("fonts/pixantiqua.fnt") // BMFont (AngelCode)
|
||||
font := rl.LoadFont("fonts/pixantiqua.fnt") // BMFont (AngelCode)
|
||||
|
||||
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("Font name: PixAntiqua", 40, 50, 20, raylib.Gray)
|
||||
raylib.DrawText(fmt.Sprintf("Font base size: %d", font.BaseSize), 40, 80, 20, raylib.Gray)
|
||||
raylib.DrawText(fmt.Sprintf("Font chars number: %d", font.CharsCount), 40, 110, 20, raylib.Gray)
|
||||
rl.DrawText("Font name: PixAntiqua", 40, 50, 20, rl.Gray)
|
||||
rl.DrawText(fmt.Sprintf("Font base size: %d", font.BaseSize), 40, 80, 20, rl.Gray)
|
||||
rl.DrawText(fmt.Sprintf("Font chars number: %d", font.CharsCount), 40, 110, 20, rl.Gray)
|
||||
|
||||
raylib.DrawTextEx(font, msg, raylib.NewVector2(40, 180), float32(font.BaseSize), 0, raylib.Maroon)
|
||||
rl.DrawTextEx(font, msg, rl.NewVector2(40, 180), float32(font.BaseSize), 0, rl.Maroon)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadFont(font) // AngelCode Font unloading
|
||||
rl.UnloadFont(font) // AngelCode Font unloading
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -10,29 +10,29 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - text formatting")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [text] example - text formatting")
|
||||
|
||||
score := 100020
|
||||
hiscore := 200450
|
||||
lives := 5
|
||||
|
||||
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(fmt.Sprintf("Score: %08d", score), 200, 80, 20, raylib.Red)
|
||||
rl.DrawText(fmt.Sprintf("Score: %08d", score), 200, 80, 20, rl.Red)
|
||||
|
||||
raylib.DrawText(fmt.Sprintf("HiScore: %08d", hiscore), 200, 120, 20, raylib.Green)
|
||||
rl.DrawText(fmt.Sprintf("HiScore: %08d", hiscore), 200, 120, 20, rl.Green)
|
||||
|
||||
raylib.DrawText(fmt.Sprintf("Lives: %02d", lives), 200, 160, 40, raylib.Blue)
|
||||
rl.DrawText(fmt.Sprintf("Lives: %02d", lives), 200, 160, 40, rl.Blue)
|
||||
|
||||
raylib.DrawText(fmt.Sprintf("Elapsed Time: %02.02f ms", raylib.GetFrameTime()*1000), 200, 220, 20, raylib.Black)
|
||||
rl.DrawText(fmt.Sprintf("Elapsed Time: %02.02f ms", rl.GetFrameTime()*1000), 200, 220, 20, rl.Black)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -10,17 +10,17 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts")
|
||||
|
||||
fonts := make([]raylib.Font, maxFonts)
|
||||
fonts[0] = raylib.LoadFont("fonts/alagard.png")
|
||||
fonts[1] = raylib.LoadFont("fonts/pixelplay.png")
|
||||
fonts[2] = raylib.LoadFont("fonts/mecha.png")
|
||||
fonts[3] = raylib.LoadFont("fonts/setback.png")
|
||||
fonts[4] = raylib.LoadFont("fonts/romulus.png")
|
||||
fonts[5] = raylib.LoadFont("fonts/pixantiqua.png")
|
||||
fonts[6] = raylib.LoadFont("fonts/alpha_beta.png")
|
||||
fonts[7] = raylib.LoadFont("fonts/jupiter_crash.png")
|
||||
fonts := make([]rl.Font, maxFonts)
|
||||
fonts[0] = rl.LoadFont("fonts/alagard.png")
|
||||
fonts[1] = rl.LoadFont("fonts/pixelplay.png")
|
||||
fonts[2] = rl.LoadFont("fonts/mecha.png")
|
||||
fonts[3] = rl.LoadFont("fonts/setback.png")
|
||||
fonts[4] = rl.LoadFont("fonts/romulus.png")
|
||||
fonts[5] = rl.LoadFont("fonts/pixantiqua.png")
|
||||
fonts[6] = rl.LoadFont("fonts/alpha_beta.png")
|
||||
fonts[7] = rl.LoadFont("fonts/jupiter_crash.png")
|
||||
|
||||
messages := []string{
|
||||
"ALAGARD FONT designed by Hewett Tsoi",
|
||||
|
@ -34,13 +34,13 @@ func main() {
|
|||
}
|
||||
|
||||
spacings := []float32{2, 4, 8, 4, 3, 4, 4, 1}
|
||||
positions := make([]raylib.Vector2, maxFonts)
|
||||
positions := make([]rl.Vector2, maxFonts)
|
||||
|
||||
var i int32
|
||||
for i = 0; i < maxFonts; i++ {
|
||||
x := screenWidth/2 - int32(raylib.MeasureTextEx(fonts[i], messages[i], float32(fonts[i].BaseSize*2), spacings[i]).X/2)
|
||||
x := screenWidth/2 - int32(rl.MeasureTextEx(fonts[i], messages[i], float32(fonts[i].BaseSize*2), spacings[i]).X/2)
|
||||
y := 60 + fonts[i].BaseSize + 45*i
|
||||
positions[i] = raylib.NewVector2(float32(x), float32(y))
|
||||
positions[i] = rl.NewVector2(float32(x), float32(y))
|
||||
}
|
||||
|
||||
// Small Y position corrections
|
||||
|
@ -48,27 +48,27 @@ func main() {
|
|||
positions[4].Y += 2
|
||||
positions[7].Y -= 8
|
||||
|
||||
colors := []raylib.Color{raylib.Maroon, raylib.Orange, raylib.DarkGreen, raylib.DarkBlue, raylib.DarkPurple, raylib.Lime, raylib.Gold, raylib.DarkBrown}
|
||||
colors := []rl.Color{rl.Maroon, rl.Orange, rl.DarkGreen, rl.DarkBlue, rl.DarkPurple, rl.Lime, rl.Gold, rl.DarkBrown}
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
raylib.DrawText("free fonts included with raylib", 250, 20, 20, raylib.DarkGray)
|
||||
raylib.DrawLine(220, 50, 590, 50, raylib.DarkGray)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
rl.DrawText("free fonts included with raylib", 250, 20, 20, rl.DarkGray)
|
||||
rl.DrawLine(220, 50, 590, 50, rl.DarkGray)
|
||||
|
||||
for i = 0; i < maxFonts; i++ {
|
||||
raylib.DrawTextEx(fonts[i], messages[i], positions[i], float32(fonts[i].BaseSize*2), spacings[i], colors[i])
|
||||
rl.DrawTextEx(fonts[i], messages[i], positions[i], float32(fonts[i].BaseSize*2), spacings[i], colors[i])
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
for i = 0; i < maxFonts; i++ {
|
||||
raylib.UnloadFont(fonts[i])
|
||||
rl.UnloadFont(fonts[i])
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,45 +8,45 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite fonts usage")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite fonts usage")
|
||||
|
||||
msg1 := "THIS IS A custom SPRITE FONT..."
|
||||
msg2 := "...and this is ANOTHER CUSTOM font..."
|
||||
msg3 := "...and a THIRD one! GREAT! :D"
|
||||
|
||||
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||
font1 := raylib.LoadFont("fonts/custom_mecha.png") // Font loading
|
||||
font2 := raylib.LoadFont("fonts/custom_alagard.png") // Font loading
|
||||
font3 := raylib.LoadFont("fonts/custom_jupiter_crash.png") // Font loading
|
||||
font1 := rl.LoadFont("fonts/custom_mecha.png") // Font loading
|
||||
font2 := rl.LoadFont("fonts/custom_alagard.png") // Font loading
|
||||
font3 := rl.LoadFont("fonts/custom_jupiter_crash.png") // Font loading
|
||||
|
||||
var fontPosition1, fontPosition2, fontPosition3 raylib.Vector2
|
||||
var fontPosition1, fontPosition2, fontPosition3 rl.Vector2
|
||||
|
||||
fontPosition1.X = float32(screenWidth)/2 - raylib.MeasureTextEx(font1, msg1, float32(font1.BaseSize), -3).X/2
|
||||
fontPosition1.X = float32(screenWidth)/2 - rl.MeasureTextEx(font1, msg1, float32(font1.BaseSize), -3).X/2
|
||||
fontPosition1.Y = float32(screenHeight)/2 - float32(font1.BaseSize)/2 - 80
|
||||
|
||||
fontPosition2.X = float32(screenWidth)/2 - raylib.MeasureTextEx(font2, msg2, float32(font2.BaseSize), -2).X/2
|
||||
fontPosition2.X = float32(screenWidth)/2 - rl.MeasureTextEx(font2, msg2, float32(font2.BaseSize), -2).X/2
|
||||
fontPosition2.Y = float32(screenHeight)/2 - float32(font2.BaseSize)/2 - 10
|
||||
|
||||
fontPosition3.X = float32(screenWidth)/2 - raylib.MeasureTextEx(font3, msg3, float32(font3.BaseSize), 2).X/2
|
||||
fontPosition3.X = float32(screenWidth)/2 - rl.MeasureTextEx(font3, msg3, float32(font3.BaseSize), 2).X/2
|
||||
fontPosition3.Y = float32(screenHeight)/2 - float32(font3.BaseSize)/2 + 50
|
||||
|
||||
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.DrawTextEx(font1, msg1, fontPosition1, float32(font1.BaseSize), -3, raylib.White)
|
||||
raylib.DrawTextEx(font2, msg2, fontPosition2, float32(font2.BaseSize), -2, raylib.White)
|
||||
raylib.DrawTextEx(font3, msg3, fontPosition3, float32(font3.BaseSize), 2, raylib.White)
|
||||
rl.DrawTextEx(font1, msg1, fontPosition1, float32(font1.BaseSize), -3, rl.White)
|
||||
rl.DrawTextEx(font2, msg2, fontPosition2, float32(font2.BaseSize), -2, rl.White)
|
||||
rl.DrawTextEx(font3, msg3, fontPosition3, float32(font3.BaseSize), 2, rl.White)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadFont(font1) // Font unloading
|
||||
raylib.UnloadFont(font2) // Font unloading
|
||||
raylib.UnloadFont(font3) // Font unloading
|
||||
rl.UnloadFont(font1) // Font unloading
|
||||
rl.UnloadFont(font2) // Font unloading
|
||||
rl.UnloadFont(font3) // Font unloading
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading")
|
||||
|
||||
msg := "TTF Font"
|
||||
|
||||
|
@ -19,94 +19,94 @@ func main() {
|
|||
fontChars := int32(0)
|
||||
|
||||
// TTF Font loading with custom generation parameters
|
||||
font := raylib.LoadFontEx("fonts/KAISG.ttf", 96, 0, &fontChars)
|
||||
font := rl.LoadFontEx("fonts/KAISG.ttf", 96, 0, &fontChars)
|
||||
|
||||
// Generate mipmap levels to use trilinear filtering
|
||||
// NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR
|
||||
raylib.GenTextureMipmaps(&font.Texture)
|
||||
rl.GenTextureMipmaps(&font.Texture)
|
||||
|
||||
fontSize := font.BaseSize
|
||||
fontPosition := raylib.NewVector2(40, float32(screenHeight)/2+50)
|
||||
textSize := raylib.Vector2{}
|
||||
fontPosition := rl.NewVector2(40, float32(screenHeight)/2+50)
|
||||
textSize := rl.Vector2{}
|
||||
|
||||
raylib.SetTextureFilter(font.Texture, raylib.FilterPoint)
|
||||
rl.SetTextureFilter(font.Texture, rl.FilterPoint)
|
||||
currentFontFilter := 0 // FilterPoint
|
||||
|
||||
count := int32(0)
|
||||
droppedFiles := make([]string, 0)
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
fontSize += raylib.GetMouseWheelMove() * 4.0
|
||||
fontSize += rl.GetMouseWheelMove() * 4.0
|
||||
|
||||
// Choose font texture filter method
|
||||
if raylib.IsKeyPressed(raylib.KeyOne) {
|
||||
raylib.SetTextureFilter(font.Texture, raylib.FilterPoint)
|
||||
if rl.IsKeyPressed(rl.KeyOne) {
|
||||
rl.SetTextureFilter(font.Texture, rl.FilterPoint)
|
||||
currentFontFilter = 0
|
||||
} else if raylib.IsKeyPressed(raylib.KeyTwo) {
|
||||
raylib.SetTextureFilter(font.Texture, raylib.FilterBilinear)
|
||||
} else if rl.IsKeyPressed(rl.KeyTwo) {
|
||||
rl.SetTextureFilter(font.Texture, rl.FilterBilinear)
|
||||
currentFontFilter = 1
|
||||
} else if raylib.IsKeyPressed(raylib.KeyThree) {
|
||||
} else if rl.IsKeyPressed(rl.KeyThree) {
|
||||
// NOTE: Trilinear filter won't be noticed on 2D drawing
|
||||
raylib.SetTextureFilter(font.Texture, raylib.FilterTrilinear)
|
||||
rl.SetTextureFilter(font.Texture, rl.FilterTrilinear)
|
||||
currentFontFilter = 2
|
||||
}
|
||||
|
||||
textSize = raylib.MeasureTextEx(font, msg, float32(fontSize), 0)
|
||||
textSize = rl.MeasureTextEx(font, msg, float32(fontSize), 0)
|
||||
|
||||
if raylib.IsKeyDown(raylib.KeyLeft) {
|
||||
if rl.IsKeyDown(rl.KeyLeft) {
|
||||
fontPosition.X -= 10
|
||||
} else if raylib.IsKeyDown(raylib.KeyRight) {
|
||||
} else if rl.IsKeyDown(rl.KeyRight) {
|
||||
fontPosition.X += 10
|
||||
}
|
||||
|
||||
// Load a dropped TTF file dynamically (at current fontSize)
|
||||
if raylib.IsFileDropped() {
|
||||
droppedFiles = raylib.GetDroppedFiles(&count)
|
||||
if rl.IsFileDropped() {
|
||||
droppedFiles = rl.GetDroppedFiles(&count)
|
||||
|
||||
if count == 1 { // Only support one ttf file dropped
|
||||
raylib.UnloadFont(font)
|
||||
font = raylib.LoadFontEx(droppedFiles[0], fontSize, 0, &fontChars)
|
||||
raylib.ClearDroppedFiles()
|
||||
rl.UnloadFont(font)
|
||||
font = rl.LoadFontEx(droppedFiles[0], fontSize, 0, &fontChars)
|
||||
rl.ClearDroppedFiles()
|
||||
}
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawText("Use mouse wheel to change font size", 20, 20, 10, raylib.Gray)
|
||||
raylib.DrawText("Use KEY_RIGHT and KEY_LEFT to move text", 20, 40, 10, raylib.Gray)
|
||||
raylib.DrawText("Use 1, 2, 3 to change texture filter", 20, 60, 10, raylib.Gray)
|
||||
raylib.DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, raylib.DarkGray)
|
||||
rl.DrawText("Use mouse wheel to change font size", 20, 20, 10, rl.Gray)
|
||||
rl.DrawText("Use KEY_RIGHT and KEY_LEFT to move text", 20, 40, 10, rl.Gray)
|
||||
rl.DrawText("Use 1, 2, 3 to change texture filter", 20, 60, 10, rl.Gray)
|
||||
rl.DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, rl.DarkGray)
|
||||
|
||||
raylib.DrawTextEx(font, msg, fontPosition, float32(fontSize), 0, raylib.Black)
|
||||
rl.DrawTextEx(font, msg, fontPosition, float32(fontSize), 0, rl.Black)
|
||||
|
||||
// TODO: It seems texSize measurement is not accurate due to chars offsets...
|
||||
//raylib.DrawRectangleLines(int32(fontPosition.X), int32(fontPosition.Y), int32(textSize.X), int32(textSize.Y), raylib.Red)
|
||||
//rl.DrawRectangleLines(int32(fontPosition.X), int32(fontPosition.Y), int32(textSize.X), int32(textSize.Y), rl.Red)
|
||||
|
||||
raylib.DrawRectangle(0, screenHeight-80, screenWidth, 80, raylib.LightGray)
|
||||
raylib.DrawText(fmt.Sprintf("Font size: %02.02f", float32(fontSize)), 20, screenHeight-50, 10, raylib.DarkGray)
|
||||
raylib.DrawText(fmt.Sprintf("Text size: [%02.02f, %02.02f]", textSize.X, textSize.Y), 20, screenHeight-30, 10, raylib.DarkGray)
|
||||
raylib.DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, raylib.Gray)
|
||||
rl.DrawRectangle(0, screenHeight-80, screenWidth, 80, rl.LightGray)
|
||||
rl.DrawText(fmt.Sprintf("Font size: %02.02f", float32(fontSize)), 20, screenHeight-50, 10, rl.DarkGray)
|
||||
rl.DrawText(fmt.Sprintf("Text size: [%02.02f, %02.02f]", textSize.X, textSize.Y), 20, screenHeight-30, 10, rl.DarkGray)
|
||||
rl.DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, rl.Gray)
|
||||
|
||||
if currentFontFilter == 0 {
|
||||
raylib.DrawText("POINT", 570, 400, 20, raylib.Black)
|
||||
rl.DrawText("POINT", 570, 400, 20, rl.Black)
|
||||
} else if currentFontFilter == 1 {
|
||||
raylib.DrawText("BILINEAR", 570, 400, 20, raylib.Black)
|
||||
rl.DrawText("BILINEAR", 570, 400, 20, rl.Black)
|
||||
} else if currentFontFilter == 2 {
|
||||
raylib.DrawText("TRILINEAR", 570, 400, 20, raylib.Black)
|
||||
rl.DrawText("TRILINEAR", 570, 400, 20, rl.Black)
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadFont(font) // Font unloading
|
||||
rl.UnloadFont(font) // Font unloading
|
||||
|
||||
raylib.ClearDroppedFiles() // Clear internal buffers
|
||||
rl.ClearDroppedFiles() // Clear internal buffers
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,24 +8,24 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - text writing anim")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [text] example - text writing anim")
|
||||
|
||||
message := "This sample illustrates a text writing\nanimation effect! Check it out! ;)"
|
||||
length := len(message)
|
||||
|
||||
framesCounter := 0
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
// Update
|
||||
if raylib.IsKeyDown(raylib.KeySpace) {
|
||||
if rl.IsKeyDown(rl.KeySpace) {
|
||||
framesCounter += 8
|
||||
} else {
|
||||
framesCounter++
|
||||
}
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeyEnter) {
|
||||
if rl.IsKeyPressed(rl.KeyEnter) {
|
||||
framesCounter = 0
|
||||
}
|
||||
|
||||
|
@ -34,17 +34,17 @@ func main() {
|
|||
}
|
||||
|
||||
// Draw
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawText(message[0:framesCounter/10], 210, 160, 20, raylib.Maroon)
|
||||
rl.DrawText(message[0:framesCounter/10], 210, 160, 20, rl.Maroon)
|
||||
|
||||
raylib.DrawText("PRESS [ENTER] to RESTART!", 240, 260, 20, raylib.LightGray)
|
||||
raylib.DrawText("PRESS [SPACE] to SPEED UP!", 239, 300, 20, raylib.LightGray)
|
||||
rl.DrawText("PRESS [ENTER] to RESTART!", 240, 260, 20, rl.LightGray)
|
||||
rl.DrawText("PRESS [SPACE] to SPEED UP!", 239, 300, 20, rl.LightGray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,42 +8,42 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
cat := raylib.LoadImage("cat.png") // Load image in CPU memory (RAM)
|
||||
raylib.ImageCrop(cat, raylib.NewRectangle(100, 10, 280, 380)) // Crop an image piece
|
||||
raylib.ImageFlipHorizontal(cat) // Flip cropped image horizontally
|
||||
raylib.ImageResize(cat, 150, 200) // Resize flipped-cropped image
|
||||
cat := rl.LoadImage("cat.png") // Load image in CPU memory (RAM)
|
||||
rl.ImageCrop(cat, rl.NewRectangle(100, 10, 280, 380)) // Crop an image piece
|
||||
rl.ImageFlipHorizontal(cat) // Flip cropped image horizontally
|
||||
rl.ImageResize(cat, 150, 200) // Resize flipped-cropped image
|
||||
|
||||
parrots := raylib.LoadImage("parrots.png") // Load image in CPU memory (RAM)
|
||||
parrots := rl.LoadImage("parrots.png") // Load image in CPU memory (RAM)
|
||||
|
||||
// Draw one image over the other with a scaling of 1.5f
|
||||
raylib.ImageDraw(parrots, cat, raylib.NewRectangle(0, 0, float32(cat.Width), float32(cat.Height)), raylib.NewRectangle(30, 40, float32(cat.Width)*1.5, float32(cat.Height)*1.5))
|
||||
raylib.ImageCrop(parrots, raylib.NewRectangle(0, 50, float32(parrots.Width), float32(parrots.Height-100))) // Crop resulting image
|
||||
rl.ImageDraw(parrots, cat, rl.NewRectangle(0, 0, float32(cat.Width), float32(cat.Height)), rl.NewRectangle(30, 40, float32(cat.Width)*1.5, float32(cat.Height)*1.5))
|
||||
rl.ImageCrop(parrots, rl.NewRectangle(0, 50, float32(parrots.Width), float32(parrots.Height-100))) // Crop resulting image
|
||||
|
||||
raylib.UnloadImage(cat) // Unload image from RAM
|
||||
rl.UnloadImage(cat) // Unload image from RAM
|
||||
|
||||
texture := raylib.LoadTextureFromImage(parrots) // Image converted to texture, uploaded to GPU memory (VRAM)
|
||||
raylib.UnloadImage(parrots) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||
texture := rl.LoadTextureFromImage(parrots) // Image converted to texture, uploaded to GPU memory (VRAM)
|
||||
rl.UnloadImage(parrots) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||
|
||||
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.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2-40, raylib.White)
|
||||
raylib.DrawRectangleLines(screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2-40, texture.Width, texture.Height, raylib.DarkGray)
|
||||
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2-40, rl.White)
|
||||
rl.DrawRectangleLines(screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2-40, texture.Width, texture.Height, rl.DarkGray)
|
||||
|
||||
raylib.DrawText("We are drawing only one texture from various images composed!", 240, 350, 10, raylib.DarkGray)
|
||||
raylib.DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, raylib.DarkGray)
|
||||
rl.DrawText("We are drawing only one texture from various images composed!", 240, 350, 10, rl.DarkGray)
|
||||
rl.DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, rl.DarkGray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture)
|
||||
rl.UnloadTexture(texture)
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -10,85 +10,85 @@ func main() {
|
|||
screenWidth := 800
|
||||
screenHeight := 450
|
||||
|
||||
raylib.InitWindow(int32(screenWidth), int32(screenHeight), "raylib [textures] example - procedural images generation")
|
||||
rl.InitWindow(int32(screenWidth), int32(screenHeight), "raylib [textures] example - procedural images generation")
|
||||
|
||||
verticalGradient := raylib.GenImageGradientV(screenWidth, screenHeight, raylib.Red, raylib.Blue)
|
||||
horizontalGradient := raylib.GenImageGradientH(screenWidth, screenHeight, raylib.Red, raylib.Blue)
|
||||
radialGradient := raylib.GenImageGradientRadial(screenWidth, screenHeight, 0, raylib.White, raylib.Black)
|
||||
checked := raylib.GenImageChecked(screenWidth, screenHeight, 32, 32, raylib.Red, raylib.Blue)
|
||||
whiteNoise := raylib.GenImageWhiteNoise(screenWidth, screenHeight, 0.5)
|
||||
perlinNoise := raylib.GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0)
|
||||
cellular := raylib.GenImageCellular(screenWidth, screenHeight, 32)
|
||||
verticalGradient := rl.GenImageGradientV(screenWidth, screenHeight, rl.Red, rl.Blue)
|
||||
horizontalGradient := rl.GenImageGradientH(screenWidth, screenHeight, rl.Red, rl.Blue)
|
||||
radialGradient := rl.GenImageGradientRadial(screenWidth, screenHeight, 0, rl.White, rl.Black)
|
||||
checked := rl.GenImageChecked(screenWidth, screenHeight, 32, 32, rl.Red, rl.Blue)
|
||||
whiteNoise := rl.GenImageWhiteNoise(screenWidth, screenHeight, 0.5)
|
||||
perlinNoise := rl.GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0)
|
||||
cellular := rl.GenImageCellular(screenWidth, screenHeight, 32)
|
||||
|
||||
textures := make([]raylib.Texture2D, numTextures)
|
||||
textures[0] = raylib.LoadTextureFromImage(verticalGradient)
|
||||
textures[1] = raylib.LoadTextureFromImage(horizontalGradient)
|
||||
textures[2] = raylib.LoadTextureFromImage(radialGradient)
|
||||
textures[3] = raylib.LoadTextureFromImage(checked)
|
||||
textures[4] = raylib.LoadTextureFromImage(whiteNoise)
|
||||
textures[5] = raylib.LoadTextureFromImage(perlinNoise)
|
||||
textures[6] = raylib.LoadTextureFromImage(cellular)
|
||||
textures := make([]rl.Texture2D, numTextures)
|
||||
textures[0] = rl.LoadTextureFromImage(verticalGradient)
|
||||
textures[1] = rl.LoadTextureFromImage(horizontalGradient)
|
||||
textures[2] = rl.LoadTextureFromImage(radialGradient)
|
||||
textures[3] = rl.LoadTextureFromImage(checked)
|
||||
textures[4] = rl.LoadTextureFromImage(whiteNoise)
|
||||
textures[5] = rl.LoadTextureFromImage(perlinNoise)
|
||||
textures[6] = rl.LoadTextureFromImage(cellular)
|
||||
|
||||
// Unload image data (CPU RAM)
|
||||
raylib.UnloadImage(verticalGradient)
|
||||
raylib.UnloadImage(horizontalGradient)
|
||||
raylib.UnloadImage(radialGradient)
|
||||
raylib.UnloadImage(checked)
|
||||
raylib.UnloadImage(whiteNoise)
|
||||
raylib.UnloadImage(perlinNoise)
|
||||
raylib.UnloadImage(cellular)
|
||||
rl.UnloadImage(verticalGradient)
|
||||
rl.UnloadImage(horizontalGradient)
|
||||
rl.UnloadImage(radialGradient)
|
||||
rl.UnloadImage(checked)
|
||||
rl.UnloadImage(whiteNoise)
|
||||
rl.UnloadImage(perlinNoise)
|
||||
rl.UnloadImage(cellular)
|
||||
|
||||
currentTexture := 0
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
||||
for !rl.WindowShouldClose() {
|
||||
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||
currentTexture = (currentTexture + 1) % numTextures // Cycle between the textures
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawTexture(textures[currentTexture], 0, 0, raylib.White)
|
||||
rl.DrawTexture(textures[currentTexture], 0, 0, rl.White)
|
||||
|
||||
raylib.DrawRectangle(30, 400, 325, 30, raylib.Fade(raylib.SkyBlue, 0.5))
|
||||
raylib.DrawRectangleLines(30, 400, 325, 30, raylib.Fade(raylib.White, 0.5))
|
||||
raylib.DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL TEXTURES", 40, 410, 10, raylib.White)
|
||||
rl.DrawRectangle(30, 400, 325, 30, rl.Fade(rl.SkyBlue, 0.5))
|
||||
rl.DrawRectangleLines(30, 400, 325, 30, rl.Fade(rl.White, 0.5))
|
||||
rl.DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL TEXTURES", 40, 410, 10, rl.White)
|
||||
|
||||
switch currentTexture {
|
||||
case 0:
|
||||
raylib.DrawText("VERTICAL GRADIENT", 560, 10, 20, raylib.RayWhite)
|
||||
rl.DrawText("VERTICAL GRADIENT", 560, 10, 20, rl.RayWhite)
|
||||
break
|
||||
case 1:
|
||||
raylib.DrawText("HORIZONTAL GRADIENT", 540, 10, 20, raylib.RayWhite)
|
||||
rl.DrawText("HORIZONTAL GRADIENT", 540, 10, 20, rl.RayWhite)
|
||||
break
|
||||
case 2:
|
||||
raylib.DrawText("RADIAL GRADIENT", 580, 10, 20, raylib.LightGray)
|
||||
rl.DrawText("RADIAL GRADIENT", 580, 10, 20, rl.LightGray)
|
||||
break
|
||||
case 3:
|
||||
raylib.DrawText("CHECKED", 680, 10, 20, raylib.RayWhite)
|
||||
rl.DrawText("CHECKED", 680, 10, 20, rl.RayWhite)
|
||||
break
|
||||
case 4:
|
||||
raylib.DrawText("WHITE NOISE", 640, 10, 20, raylib.Red)
|
||||
rl.DrawText("WHITE NOISE", 640, 10, 20, rl.Red)
|
||||
break
|
||||
case 5:
|
||||
raylib.DrawText("PERLIN NOISE", 630, 10, 20, raylib.RayWhite)
|
||||
rl.DrawText("PERLIN NOISE", 630, 10, 20, rl.RayWhite)
|
||||
break
|
||||
case 6:
|
||||
raylib.DrawText("CELLULAR", 670, 10, 20, raylib.RayWhite)
|
||||
rl.DrawText("CELLULAR", 670, 10, 20, rl.RayWhite)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
for _, t := range textures {
|
||||
raylib.UnloadTexture(t)
|
||||
rl.UnloadTexture(t)
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -11,57 +11,57 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from image.Image")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from image.Image")
|
||||
|
||||
r, err := os.Open("raylib_logo.png")
|
||||
if err != nil {
|
||||
raylib.TraceLog(raylib.LogError, err.Error())
|
||||
rl.TraceLog(rl.LogError, err.Error())
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
img, err := png.Decode(r)
|
||||
if err != nil {
|
||||
raylib.TraceLog(raylib.LogError, err.Error())
|
||||
rl.TraceLog(rl.LogError, err.Error())
|
||||
}
|
||||
|
||||
// Create raylib.Image from Go image.Image and create texture
|
||||
im := raylib.NewImageFromImage(img)
|
||||
texture := raylib.LoadTextureFromImage(im)
|
||||
// Create rl.Image from Go image.Image and create texture
|
||||
im := rl.NewImageFromImage(img)
|
||||
texture := rl.LoadTextureFromImage(im)
|
||||
|
||||
// Unload CPU (RAM) image data
|
||||
raylib.UnloadImage(im)
|
||||
rl.UnloadImage(im)
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsKeyPressed(raylib.KeyS) {
|
||||
rimg := raylib.GetTextureData(texture)
|
||||
for !rl.WindowShouldClose() {
|
||||
if rl.IsKeyPressed(rl.KeyS) {
|
||||
rimg := rl.GetTextureData(texture)
|
||||
|
||||
f, err := os.Create("image_saved.png")
|
||||
if err != nil {
|
||||
raylib.TraceLog(raylib.LogError, err.Error())
|
||||
rl.TraceLog(rl.LogError, err.Error())
|
||||
}
|
||||
|
||||
err = png.Encode(f, rimg.ToImage())
|
||||
if err != nil {
|
||||
raylib.TraceLog(raylib.LogError, err.Error())
|
||||
rl.TraceLog(rl.LogError, err.Error())
|
||||
}
|
||||
|
||||
f.Close()
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawText("PRESS S TO SAVE IMAGE FROM TEXTURE", 20, 20, 12, raylib.LightGray)
|
||||
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
|
||||
raylib.DrawText("this IS a texture loaded from an image.Image!", 285, 370, 10, raylib.Gray)
|
||||
rl.DrawText("PRESS S TO SAVE IMAGE FROM TEXTURE", 20, 20, 12, rl.LightGray)
|
||||
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, rl.White)
|
||||
rl.DrawText("this IS a texture loaded from an image.Image!", 285, 370, 10, rl.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture)
|
||||
rl.UnloadTexture(texture)
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,30 +8,30 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
image := raylib.LoadImage("raylib_logo.png") // Loaded in CPU memory (RAM)
|
||||
texture := raylib.LoadTextureFromImage(image) // Image converted to texture, GPU memory (VRAM)
|
||||
image := rl.LoadImage("raylib_logo.png") // Loaded in CPU memory (RAM)
|
||||
texture := rl.LoadTextureFromImage(image) // Image converted to texture, GPU memory (VRAM)
|
||||
|
||||
raylib.UnloadImage(image) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||
rl.UnloadImage(image) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||
|
||||
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.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
|
||||
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, rl.White)
|
||||
|
||||
raylib.DrawText("this IS a texture loaded from an image!", 300, 370, 10, raylib.Gray)
|
||||
rl.DrawText("this IS a texture loaded from an image!", 300, 370, 10, rl.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture)
|
||||
rl.UnloadTexture(texture)
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -33,31 +33,31 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing")
|
||||
|
||||
image := raylib.LoadImage("parrots.png") // Loaded in CPU memory (RAM)
|
||||
raylib.ImageFormat(image, raylib.UncompressedR8g8b8a8) // Format image to RGBA 32bit (required for texture update)
|
||||
texture := raylib.LoadTextureFromImage(image) // Image converted to texture, GPU memory (VRAM)
|
||||
image := rl.LoadImage("parrots.png") // Loaded in CPU memory (RAM)
|
||||
rl.ImageFormat(image, rl.UncompressedR8g8b8a8) // Format image to RGBA 32bit (required for texture update)
|
||||
texture := rl.LoadTextureFromImage(image) // Image converted to texture, GPU memory (VRAM)
|
||||
|
||||
currentProcess := None
|
||||
textureReload := false
|
||||
|
||||
selectRecs := make([]raylib.Rectangle, numProcesses)
|
||||
selectRecs := make([]rl.Rectangle, numProcesses)
|
||||
|
||||
for i := 0; i < numProcesses; i++ {
|
||||
selectRecs[i] = raylib.NewRectangle(40, 50+32*float32(i), 150, 30)
|
||||
selectRecs[i] = rl.NewRectangle(40, 50+32*float32(i), 150, 30)
|
||||
}
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsKeyPressed(raylib.KeyDown) {
|
||||
for !rl.WindowShouldClose() {
|
||||
if rl.IsKeyPressed(rl.KeyDown) {
|
||||
currentProcess++
|
||||
if currentProcess > 7 {
|
||||
currentProcess = 0
|
||||
}
|
||||
textureReload = true
|
||||
} else if raylib.IsKeyPressed(raylib.KeyUp) {
|
||||
} else if rl.IsKeyPressed(rl.KeyUp) {
|
||||
currentProcess--
|
||||
if currentProcess < 0 {
|
||||
currentProcess = 7
|
||||
|
@ -66,70 +66,70 @@ func main() {
|
|||
}
|
||||
|
||||
if textureReload {
|
||||
raylib.UnloadImage(image) // Unload current image data
|
||||
image = raylib.LoadImage("parrots.png") // Re-load image data
|
||||
rl.UnloadImage(image) // Unload current image data
|
||||
image = rl.LoadImage("parrots.png") // Re-load image data
|
||||
|
||||
// NOTE: Image processing is a costly CPU process to be done every frame,
|
||||
// If image processing is required in a frame-basis, it should be done
|
||||
// with a texture and by shaders
|
||||
switch currentProcess {
|
||||
case ColorGrayscale:
|
||||
raylib.ImageColorGrayscale(image)
|
||||
rl.ImageColorGrayscale(image)
|
||||
break
|
||||
case ColorTint:
|
||||
raylib.ImageColorTint(image, raylib.Green)
|
||||
rl.ImageColorTint(image, rl.Green)
|
||||
break
|
||||
case ColorInvert:
|
||||
raylib.ImageColorInvert(image)
|
||||
rl.ImageColorInvert(image)
|
||||
break
|
||||
case ColorContrast:
|
||||
raylib.ImageColorContrast(image, -40)
|
||||
rl.ImageColorContrast(image, -40)
|
||||
break
|
||||
case ColorBrightness:
|
||||
raylib.ImageColorBrightness(image, -80)
|
||||
rl.ImageColorBrightness(image, -80)
|
||||
break
|
||||
case FlipVertical:
|
||||
raylib.ImageFlipVertical(image)
|
||||
rl.ImageFlipVertical(image)
|
||||
break
|
||||
case FlipHorizontal:
|
||||
raylib.ImageFlipHorizontal(image)
|
||||
rl.ImageFlipHorizontal(image)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
pixels := raylib.GetImageData(image) // Get pixel data from image (RGBA 32bit)
|
||||
raylib.UpdateTexture(texture, pixels) // Update texture with new image data
|
||||
pixels := rl.GetImageData(image) // Get pixel data from image (RGBA 32bit)
|
||||
rl.UpdateTexture(texture, pixels) // Update texture with new image data
|
||||
|
||||
textureReload = false
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawText("IMAGE PROCESSING:", 40, 30, 10, raylib.DarkGray)
|
||||
rl.DrawText("IMAGE PROCESSING:", 40, 30, 10, rl.DarkGray)
|
||||
|
||||
// Draw rectangles
|
||||
for i := 0; i < numProcesses; i++ {
|
||||
if i == currentProcess {
|
||||
raylib.DrawRectangleRec(selectRecs[i], raylib.SkyBlue)
|
||||
raylib.DrawRectangleLines(int32(selectRecs[i].X), int32(selectRecs[i].Y), int32(selectRecs[i].Width), int32(selectRecs[i].Height), raylib.Blue)
|
||||
raylib.DrawText(processText[i], int32(selectRecs[i].X+selectRecs[i].Width/2)-raylib.MeasureText(processText[i], 10)/2, int32(selectRecs[i].Y)+11, 10, raylib.DarkBlue)
|
||||
rl.DrawRectangleRec(selectRecs[i], rl.SkyBlue)
|
||||
rl.DrawRectangleLines(int32(selectRecs[i].X), int32(selectRecs[i].Y), int32(selectRecs[i].Width), int32(selectRecs[i].Height), rl.Blue)
|
||||
rl.DrawText(processText[i], int32(selectRecs[i].X+selectRecs[i].Width/2)-rl.MeasureText(processText[i], 10)/2, int32(selectRecs[i].Y)+11, 10, rl.DarkBlue)
|
||||
} else {
|
||||
raylib.DrawRectangleRec(selectRecs[i], raylib.LightGray)
|
||||
raylib.DrawRectangleLines(int32(selectRecs[i].X), int32(selectRecs[i].Y), int32(selectRecs[i].Width), int32(selectRecs[i].Height), raylib.Gray)
|
||||
raylib.DrawText(processText[i], int32(selectRecs[i].X+selectRecs[i].Width/2)-raylib.MeasureText(processText[i], 10)/2, int32(selectRecs[i].Y)+11, 10, raylib.DarkGray)
|
||||
rl.DrawRectangleRec(selectRecs[i], rl.LightGray)
|
||||
rl.DrawRectangleLines(int32(selectRecs[i].X), int32(selectRecs[i].Y), int32(selectRecs[i].Width), int32(selectRecs[i].Height), rl.Gray)
|
||||
rl.DrawText(processText[i], int32(selectRecs[i].X+selectRecs[i].Width/2)-rl.MeasureText(processText[i], 10)/2, int32(selectRecs[i].Y)+11, 10, rl.DarkGray)
|
||||
}
|
||||
}
|
||||
|
||||
raylib.DrawTexture(texture, screenWidth-texture.Width-60, screenHeight/2-texture.Height/2, raylib.White)
|
||||
raylib.DrawRectangleLines(screenWidth-texture.Width-60, screenHeight/2-texture.Height/2, texture.Width, texture.Height, raylib.Black)
|
||||
rl.DrawTexture(texture, screenWidth-texture.Width-60, screenHeight/2-texture.Height/2, rl.White)
|
||||
rl.DrawRectangleLines(screenWidth-texture.Width-60, screenHeight/2-texture.Height/2, texture.Width, texture.Height, rl.Black)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture)
|
||||
rl.UnloadTexture(texture)
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,55 +8,55 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image text drawing")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image text drawing")
|
||||
|
||||
// TTF Font loading with custom generation parameters
|
||||
var fontChars int32
|
||||
font := raylib.LoadFontEx("fonts/KAISG.ttf", 64, 0, &fontChars)
|
||||
font := rl.LoadFontEx("fonts/KAISG.ttf", 64, 0, &fontChars)
|
||||
|
||||
parrots := raylib.LoadImage("parrots.png") // Load image in CPU memory (RAM)
|
||||
parrots := rl.LoadImage("parrots.png") // Load image in CPU memory (RAM)
|
||||
|
||||
// Draw over image using custom font
|
||||
raylib.ImageDrawTextEx(parrots, raylib.NewVector2(20, 20), font, "[Parrots font drawing]", float32(font.BaseSize), 0, raylib.White)
|
||||
rl.ImageDrawTextEx(parrots, rl.NewVector2(20, 20), font, "[Parrots font drawing]", float32(font.BaseSize), 0, rl.White)
|
||||
|
||||
texture := raylib.LoadTextureFromImage(parrots) // Image converted to texture, uploaded to GPU memory (VRAM)
|
||||
texture := rl.LoadTextureFromImage(parrots) // Image converted to texture, uploaded to GPU memory (VRAM)
|
||||
|
||||
raylib.UnloadImage(parrots) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||
rl.UnloadImage(parrots) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||
|
||||
position := raylib.NewVector2(float32(screenWidth)/2-float32(texture.Width)/2, float32(screenHeight)/2-float32(texture.Height)/2-20)
|
||||
position := rl.NewVector2(float32(screenWidth)/2-float32(texture.Width)/2, float32(screenHeight)/2-float32(texture.Height)/2-20)
|
||||
|
||||
showFont := false
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsKeyDown(raylib.KeySpace) {
|
||||
for !rl.WindowShouldClose() {
|
||||
if rl.IsKeyDown(rl.KeySpace) {
|
||||
showFont = true
|
||||
} else {
|
||||
showFont = false
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
if !showFont {
|
||||
// Draw texture with text already drawn inside
|
||||
raylib.DrawTextureV(texture, position, raylib.White)
|
||||
rl.DrawTextureV(texture, position, rl.White)
|
||||
|
||||
// Draw text directly using sprite font
|
||||
raylib.DrawTextEx(font, "[Parrots font drawing]", raylib.NewVector2(position.X+20, position.Y+20+280), float32(font.BaseSize), 0, raylib.White)
|
||||
rl.DrawTextEx(font, "[Parrots font drawing]", rl.NewVector2(position.X+20, position.Y+20+280), float32(font.BaseSize), 0, rl.White)
|
||||
} else {
|
||||
raylib.DrawTexture(font.Texture, screenWidth/2-font.Texture.Width/2, 50, raylib.Black)
|
||||
rl.DrawTexture(font.Texture, screenWidth/2-font.Texture.Width/2, 50, rl.Black)
|
||||
}
|
||||
|
||||
raylib.DrawText("PRESS SPACE to SEE USED SPRITEFONT ", 290, 420, 10, raylib.DarkGray)
|
||||
rl.DrawText("PRESS SPACE to SEE USED SPRITEFONT ", 290, 420, 10, rl.DarkGray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture)
|
||||
raylib.UnloadFont(font)
|
||||
rl.UnloadTexture(texture)
|
||||
rl.UnloadFont(font)
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,24 +8,24 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
texture := raylib.LoadTexture("raylib_logo.png")
|
||||
texture := rl.LoadTexture("raylib_logo.png")
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
|
||||
raylib.DrawText("this IS a texture!", 360, 370, 10, raylib.Gray)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, rl.White)
|
||||
rl.DrawText("this IS a texture!", 360, 370, 10, rl.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture)
|
||||
rl.UnloadTexture(texture)
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ const (
|
|||
)
|
||||
|
||||
type particle struct {
|
||||
Position raylib.Vector2
|
||||
Color raylib.Color
|
||||
Position rl.Vector2
|
||||
Color rl.Color
|
||||
Alpha float32
|
||||
Size float32
|
||||
Rotation float32
|
||||
|
@ -21,31 +21,31 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
//raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending")
|
||||
//rl.SetConfigFlags(rl.FlagVsyncHint)
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending")
|
||||
|
||||
// Particles pool, reuse them!
|
||||
mouseTail := make([]particle, maxParticles)
|
||||
|
||||
// Initialize particles
|
||||
for i := 0; i < maxParticles; i++ {
|
||||
mouseTail[i].Position = raylib.NewVector2(0, 0)
|
||||
mouseTail[i].Color = raylib.NewColor(byte(raylib.GetRandomValue(0, 255)), byte(raylib.GetRandomValue(0, 255)), byte(raylib.GetRandomValue(0, 255)), 255)
|
||||
mouseTail[i].Position = rl.NewVector2(0, 0)
|
||||
mouseTail[i].Color = rl.NewColor(byte(rl.GetRandomValue(0, 255)), byte(rl.GetRandomValue(0, 255)), byte(rl.GetRandomValue(0, 255)), 255)
|
||||
mouseTail[i].Alpha = 1.0
|
||||
mouseTail[i].Size = float32(raylib.GetRandomValue(1, 30)) / 20.0
|
||||
mouseTail[i].Rotation = float32(raylib.GetRandomValue(0, 360))
|
||||
mouseTail[i].Size = float32(rl.GetRandomValue(1, 30)) / 20.0
|
||||
mouseTail[i].Rotation = float32(rl.GetRandomValue(0, 360))
|
||||
mouseTail[i].Active = false
|
||||
}
|
||||
|
||||
gravity := float32(3.0)
|
||||
|
||||
smoke := raylib.LoadTexture("smoke.png")
|
||||
smoke := rl.LoadTexture("smoke.png")
|
||||
|
||||
blending := raylib.BlendAlpha
|
||||
blending := rl.BlendAlpha
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
// Update
|
||||
|
||||
// Activate one particle every frame and Update active particles
|
||||
|
@ -56,7 +56,7 @@ func main() {
|
|||
if !mouseTail[i].Active {
|
||||
mouseTail[i].Active = true
|
||||
mouseTail[i].Alpha = 1.0
|
||||
mouseTail[i].Position = raylib.GetMousePosition()
|
||||
mouseTail[i].Position = rl.GetMousePosition()
|
||||
i = maxParticles
|
||||
}
|
||||
}
|
||||
|
@ -74,50 +74,50 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeySpace) {
|
||||
if blending == raylib.BlendAlpha {
|
||||
blending = raylib.BlendAdditive
|
||||
if rl.IsKeyPressed(rl.KeySpace) {
|
||||
if blending == rl.BlendAlpha {
|
||||
blending = rl.BlendAdditive
|
||||
} else {
|
||||
blending = raylib.BlendAlpha
|
||||
blending = rl.BlendAlpha
|
||||
}
|
||||
}
|
||||
|
||||
// Draw
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.DarkGray)
|
||||
rl.ClearBackground(rl.DarkGray)
|
||||
|
||||
raylib.BeginBlendMode(blending)
|
||||
rl.BeginBlendMode(blending)
|
||||
|
||||
// Draw active particles
|
||||
for i := 0; i < maxParticles; i++ {
|
||||
if mouseTail[i].Active {
|
||||
raylib.DrawTexturePro(
|
||||
rl.DrawTexturePro(
|
||||
smoke,
|
||||
raylib.NewRectangle(0, 0, float32(smoke.Width), float32(smoke.Height)),
|
||||
raylib.NewRectangle(mouseTail[i].Position.X, mouseTail[i].Position.Y, float32(smoke.Width)*mouseTail[i].Size, float32(smoke.Height)*mouseTail[i].Size),
|
||||
raylib.NewVector2(float32(smoke.Width)*mouseTail[i].Size/2, float32(smoke.Height)*mouseTail[i].Size/2),
|
||||
rl.NewRectangle(0, 0, float32(smoke.Width), float32(smoke.Height)),
|
||||
rl.NewRectangle(mouseTail[i].Position.X, mouseTail[i].Position.Y, float32(smoke.Width)*mouseTail[i].Size, float32(smoke.Height)*mouseTail[i].Size),
|
||||
rl.NewVector2(float32(smoke.Width)*mouseTail[i].Size/2, float32(smoke.Height)*mouseTail[i].Size/2),
|
||||
mouseTail[i].Rotation,
|
||||
raylib.Fade(mouseTail[i].Color, mouseTail[i].Alpha),
|
||||
rl.Fade(mouseTail[i].Color, mouseTail[i].Alpha),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
raylib.EndBlendMode()
|
||||
rl.EndBlendMode()
|
||||
|
||||
raylib.DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, raylib.Black)
|
||||
rl.DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, rl.Black)
|
||||
|
||||
if blending == raylib.BlendAlpha {
|
||||
raylib.DrawText("ALPHA BLENDING", 290, screenHeight-40, 20, raylib.Black)
|
||||
if blending == rl.BlendAlpha {
|
||||
rl.DrawText("ALPHA BLENDING", 290, screenHeight-40, 20, rl.Black)
|
||||
} else {
|
||||
raylib.DrawText("ADDITIVE BLENDING", 280, screenHeight-40, 20, raylib.RayWhite)
|
||||
rl.DrawText("ADDITIVE BLENDING", 280, screenHeight-40, 20, rl.RayWhite)
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(smoke)
|
||||
rl.UnloadTexture(smoke)
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,56 +8,56 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
// Load RAW image data (384x512, 32bit RGBA, no file header)
|
||||
fudesumiRaw := raylib.LoadImageRaw("texture_formats/fudesumi.raw", 384, 512, raylib.UncompressedR8g8b8a8, 0)
|
||||
fudesumi := raylib.LoadTextureFromImage(fudesumiRaw) // Upload CPU (RAM) image to GPU (VRAM)
|
||||
raylib.UnloadImage(fudesumiRaw) // Unload CPU (RAM) image data
|
||||
fudesumiRaw := rl.LoadImageRaw("texture_formats/fudesumi.raw", 384, 512, rl.UncompressedR8g8b8a8, 0)
|
||||
fudesumi := rl.LoadTextureFromImage(fudesumiRaw) // Upload CPU (RAM) image to GPU (VRAM)
|
||||
rl.UnloadImage(fudesumiRaw) // Unload CPU (RAM) image data
|
||||
|
||||
// Generate a checked texture by code (1024x1024 pixels)
|
||||
width := 1024
|
||||
height := 1024
|
||||
|
||||
// Dynamic memory allocation to store pixels data (Color type)
|
||||
pixels := make([]raylib.Color, width*height)
|
||||
pixels := make([]rl.Color, width*height)
|
||||
|
||||
for y := 0; y < height; y++ {
|
||||
for x := 0; x < width; x++ {
|
||||
if ((x/32+y/32)/1)%2 == 0 {
|
||||
pixels[y*height+x] = raylib.Orange
|
||||
pixels[y*height+x] = rl.Orange
|
||||
} else {
|
||||
pixels[y*height+x] = raylib.Gold
|
||||
pixels[y*height+x] = rl.Gold
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load pixels data into an image structure and create texture
|
||||
checkedIm := raylib.LoadImageEx(pixels, int32(width), int32(height))
|
||||
checked := raylib.LoadTextureFromImage(checkedIm)
|
||||
raylib.UnloadImage(checkedIm) // Unload CPU (RAM) image data
|
||||
checkedIm := rl.LoadImageEx(pixels, int32(width), int32(height))
|
||||
checked := rl.LoadTextureFromImage(checkedIm)
|
||||
rl.UnloadImage(checkedIm) // Unload CPU (RAM) image data
|
||||
|
||||
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.DrawTexture(checked, screenWidth/2-checked.Width/2, screenHeight/2-checked.Height/2, raylib.Fade(raylib.White, 0.5))
|
||||
raylib.DrawTexture(fudesumi, 430, -30, raylib.White)
|
||||
rl.DrawTexture(checked, screenWidth/2-checked.Width/2, screenHeight/2-checked.Height/2, rl.Fade(rl.White, 0.5))
|
||||
rl.DrawTexture(fudesumi, 430, -30, rl.White)
|
||||
|
||||
raylib.DrawText("CHECKED TEXTURE ", 84, 100, 30, raylib.Brown)
|
||||
raylib.DrawText("GENERATED by CODE", 72, 164, 30, raylib.Brown)
|
||||
raylib.DrawText("and RAW IMAGE LOADING", 46, 226, 30, raylib.Brown)
|
||||
rl.DrawText("CHECKED TEXTURE ", 84, 100, 30, rl.Brown)
|
||||
rl.DrawText("GENERATED by CODE", 72, 164, 30, rl.Brown)
|
||||
rl.DrawText("and RAW IMAGE LOADING", 46, 226, 30, rl.Brown)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(fudesumi) // Texture unloading
|
||||
raylib.UnloadTexture(checked) // Texture unloading
|
||||
rl.UnloadTexture(fudesumi) // Texture unloading
|
||||
rl.UnloadTexture(checked) // Texture unloading
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -15,21 +15,21 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
scarfy := raylib.LoadTexture("scarfy.png") // Texture loading
|
||||
scarfy := rl.LoadTexture("scarfy.png") // Texture loading
|
||||
|
||||
position := raylib.NewVector2(350.0, 280.0)
|
||||
frameRec := raylib.NewRectangle(0, 0, float32(scarfy.Width/6), float32(scarfy.Height))
|
||||
position := rl.NewVector2(350.0, 280.0)
|
||||
frameRec := rl.NewRectangle(0, 0, float32(scarfy.Width/6), float32(scarfy.Height))
|
||||
currentFrame := float32(0)
|
||||
|
||||
framesCounter := 0
|
||||
framesSpeed := 8 // Number of spritesheet frames shown by second
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
framesCounter++
|
||||
|
||||
if framesCounter >= (60 / framesSpeed) {
|
||||
|
@ -43,9 +43,9 @@ func main() {
|
|||
frameRec.X = currentFrame * float32(scarfy.Width) / 6
|
||||
}
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeyRight) {
|
||||
if rl.IsKeyPressed(rl.KeyRight) {
|
||||
framesSpeed++
|
||||
} else if raylib.IsKeyPressed(raylib.KeyLeft) {
|
||||
} else if rl.IsKeyPressed(rl.KeyLeft) {
|
||||
framesSpeed--
|
||||
}
|
||||
|
||||
|
@ -55,33 +55,33 @@ func main() {
|
|||
framesSpeed = minFrameSpeed
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
raylib.DrawTexture(scarfy, 15, 40, raylib.White)
|
||||
raylib.DrawRectangleLines(15, 40, scarfy.Width, scarfy.Height, raylib.Lime)
|
||||
raylib.DrawRectangleLines(15+int32(frameRec.X), 40+int32(frameRec.Y), int32(frameRec.Width), int32(frameRec.Height), raylib.Red)
|
||||
rl.DrawTexture(scarfy, 15, 40, rl.White)
|
||||
rl.DrawRectangleLines(15, 40, scarfy.Width, scarfy.Height, rl.Lime)
|
||||
rl.DrawRectangleLines(15+int32(frameRec.X), 40+int32(frameRec.Y), int32(frameRec.Width), int32(frameRec.Height), rl.Red)
|
||||
|
||||
raylib.DrawText("FRAME SPEED: ", 165, 210, 10, raylib.DarkGray)
|
||||
raylib.DrawText(fmt.Sprintf("%02d FPS", framesSpeed), 575, 210, 10, raylib.DarkGray)
|
||||
raylib.DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, raylib.DarkGray)
|
||||
rl.DrawText("FRAME SPEED: ", 165, 210, 10, rl.DarkGray)
|
||||
rl.DrawText(fmt.Sprintf("%02d FPS", framesSpeed), 575, 210, 10, rl.DarkGray)
|
||||
rl.DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, rl.DarkGray)
|
||||
|
||||
for i := 0; i < maxFrameSpeed; i++ {
|
||||
if i < framesSpeed {
|
||||
raylib.DrawRectangle(int32(250+21*i), 205, 20, 20, raylib.Red)
|
||||
rl.DrawRectangle(int32(250+21*i), 205, 20, 20, rl.Red)
|
||||
}
|
||||
raylib.DrawRectangleLines(int32(250+21*i), 205, 20, 20, raylib.Maroon)
|
||||
rl.DrawRectangleLines(int32(250+21*i), 205, 20, 20, rl.Maroon)
|
||||
}
|
||||
|
||||
raylib.DrawTextureRec(scarfy, frameRec, position, raylib.White) // Draw part of the texture
|
||||
rl.DrawTextureRec(scarfy, frameRec, position, rl.White) // Draw part of the texture
|
||||
|
||||
raylib.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
||||
rl.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth-200, screenHeight-20, 10, rl.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(scarfy)
|
||||
rl.UnloadTexture(scarfy)
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,52 +8,52 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
scarfy := raylib.LoadTexture("scarfy.png") // Texture loading
|
||||
scarfy := rl.LoadTexture("scarfy.png") // Texture loading
|
||||
|
||||
frameWidth := float32(scarfy.Width) / 7
|
||||
frameHeight := float32(scarfy.Height)
|
||||
|
||||
// NOTE: Source rectangle (part of the texture to use for drawing)
|
||||
sourceRec := raylib.NewRectangle(0, 0, frameWidth, frameHeight)
|
||||
sourceRec := rl.NewRectangle(0, 0, frameWidth, frameHeight)
|
||||
|
||||
// NOTE: Destination rectangle (screen rectangle where drawing part of texture)
|
||||
destRec := raylib.NewRectangle(float32(screenWidth)/2, float32(screenHeight)/2, frameWidth*2, frameHeight*2)
|
||||
destRec := rl.NewRectangle(float32(screenWidth)/2, float32(screenHeight)/2, frameWidth*2, frameHeight*2)
|
||||
|
||||
// NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size
|
||||
origin := raylib.NewVector2(float32(frameWidth), float32(frameHeight))
|
||||
origin := rl.NewVector2(float32(frameWidth), float32(frameHeight))
|
||||
|
||||
rotation := float32(0)
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
// Update
|
||||
rotation++
|
||||
|
||||
// Draw
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
// NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw
|
||||
// sourceRec defines the part of the texture we use for drawing
|
||||
// destRec defines the rectangle where our texture part will fit (scaling it to fit)
|
||||
// origin defines the point of the texture used as reference for rotation and scaling
|
||||
// rotation defines the texture rotation (using origin as rotation point)
|
||||
raylib.DrawTexturePro(scarfy, sourceRec, destRec, origin, rotation, raylib.White)
|
||||
rl.DrawTexturePro(scarfy, sourceRec, destRec, origin, rotation, rl.White)
|
||||
|
||||
raylib.DrawLine(int32(destRec.X), 0, int32(destRec.X), screenHeight, raylib.Gray)
|
||||
raylib.DrawLine(0, int32(destRec.Y), screenWidth, int32(destRec.Y), raylib.Gray)
|
||||
rl.DrawLine(int32(destRec.X), 0, int32(destRec.X), screenHeight, rl.Gray)
|
||||
rl.DrawLine(0, int32(destRec.Y), screenWidth, int32(destRec.Y), rl.Gray)
|
||||
|
||||
raylib.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
||||
rl.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth-200, screenHeight-20, 10, rl.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(scarfy)
|
||||
rl.UnloadTexture(scarfy)
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
|
@ -8,32 +8,32 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image")
|
||||
|
||||
image := raylib.LoadImage("raylib_logo.png") // Load image data into CPU memory (RAM)
|
||||
texture := raylib.LoadTextureFromImage(image) // Image converted to texture, GPU memory (RAM -> VRAM)
|
||||
raylib.UnloadImage(image) // Unload image data from CPU memory (RAM)
|
||||
image := rl.LoadImage("raylib_logo.png") // Load image data into CPU memory (RAM)
|
||||
texture := rl.LoadTextureFromImage(image) // Image converted to texture, GPU memory (RAM -> VRAM)
|
||||
rl.UnloadImage(image) // Unload image data from CPU memory (RAM)
|
||||
|
||||
image = raylib.GetTextureData(texture) // Retrieve image data from GPU memory (VRAM -> RAM)
|
||||
raylib.UnloadTexture(texture) // Unload texture from GPU memory (VRAM)
|
||||
image = rl.GetTextureData(texture) // Retrieve image data from GPU memory (VRAM -> RAM)
|
||||
rl.UnloadTexture(texture) // Unload texture from GPU memory (VRAM)
|
||||
|
||||
texture = raylib.LoadTextureFromImage(image) // Recreate texture from retrieved image data (RAM -> VRAM)
|
||||
raylib.UnloadImage(image) // Unload retrieved image data from CPU memory (RAM)
|
||||
texture = rl.LoadTextureFromImage(image) // Recreate texture from retrieved image data (RAM -> VRAM)
|
||||
rl.UnloadImage(image) // Unload retrieved image data from CPU memory (RAM)
|
||||
|
||||
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.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
|
||||
raylib.DrawText("this IS a texture loaded from an image!", 300, 370, 10, raylib.Gray)
|
||||
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, rl.White)
|
||||
rl.DrawText("this IS a texture loaded from an image!", 300, 370, 10, rl.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture)
|
||||
rl.UnloadTexture(texture)
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue