Update C sources, add new functions and rename package to

This commit is contained in:
Milan Nikolic 2018-10-08 18:56:34 +02:00
parent 391c25482d
commit 08aa518a46
156 changed files with 34542 additions and 19573 deletions

View file

@ -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)
}

View file

@ -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()
}

View file

@ -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()
}

View file

@ -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()
}