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()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue