From df56b0237ee21a8d9ca7a9a476344510c828d223 Mon Sep 17 00:00:00 2001 From: silva guimaraes Date: Thu, 27 Jul 2023 12:36:01 -0300 Subject: [PATCH] suporte para shaders --- main.go | 84 ++++++++++++++++++++++++++++++++++++++++++++++-------- windows.sh | 3 ++ 2 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 windows.sh diff --git a/main.go b/main.go index c88fd50..3519f71 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "math" + // "path" "strconv" rl "github.com/gen2brain/raylib-go/raylib" @@ -28,6 +29,7 @@ type game struct { bullets []*bullet score int gameSpeed float32 // 1 = velocidade normal + backgroundColor rl.Color } type bullet struct { @@ -267,6 +269,7 @@ func (e *enemy) update(g *game, index int) { e.health -= bullet.dmg g.removeBullet(idx) enemyColor = rl.White + g.backgroundColor = rl.NewColor(20, 20, 20, 255) } if e.health <= 0 { @@ -348,7 +351,7 @@ func (p *player) checkHit(g *game) { // fmt.Println(distance) if distance < p.hitBoxRadius { - fmt.Println("hit!") + // fmt.Println("hit!") } } } @@ -390,8 +393,13 @@ func (p *player) update(g *game) { func main() { - state := &game{arenaWidth: 450, arenaHeight: 700, interfaceWidth: 300, gameSpeed: 1} - + state := &game{ + arenaWidth: 450, + arenaHeight: 700, + interfaceWidth: 300, + gameSpeed: 1, + backgroundColor: rl.NewColor(0, 0, 0, 100), + } player := player{ pos: rl.Vector2{ X: float32(state.arenaWidth) / 2, @@ -404,10 +412,21 @@ func main() { hitBoxRadius: 5, } - rl.SetTraceLog(rl.LogWarning | rl.LogDebug) + // rl.SetTraceLog(rl.LogWarning | rl.LogDebug) + + rl.SetConfigFlags(rl.FlagMsaa4xHint) rl.InitWindow(state.arenaWidth + state.interfaceWidth, state.arenaHeight, "danmaku") rl.SetTargetFPS(60) + + // shader_path := path.Join("shaders", "trails.glsl") + // shader := rl.LoadShader("", shader_path) + // timeShaderLocation := rl.GetShaderLocation(shader, "time") + // target := rl.LoadRenderTexture( + // state.arenaWidth + state.interfaceWidth, + // state.arenaHeight, + // ) + state.enemies = []*enemy{ { pos: rl.Vector2{X: 200, Y: 200}, @@ -436,11 +455,10 @@ func main() { for ; !rl.WindowShouldClose(); state.frame += state.gameSpeed { rl.BeginDrawing() - rl.ClearBackground(rl.Black) - rl.DrawText("danmaku babe bullet shoot shoot", 20, 20, 20, rl.DarkGray) - rl.DrawLine(18, 42, state.arenaWidth-18, 42, rl.Black) - rl.DrawFPS(0, 0) + // rl.BeginTextureMode(target) + rl.ClearBackground(state.backgroundColor) + state.backgroundColor = rl.Black player.update(state) @@ -456,10 +474,6 @@ func main() { state.arenaWidth, 0, state.interfaceWidth, state.arenaHeight, rl.NewColor(0, 33, 59, 255), ) - currectScore += (state.score - currectScore) / 11 - rl.DrawText(strconv.Itoa(currectScore), state.arenaWidth, 0, 50, rl.White) - - rl.DrawText(strconv.Itoa(len(state.bullets)), state.arenaWidth, 50, 50, rl.White) if player.focusMode { state.gameSpeed = 0.3 @@ -467,6 +481,52 @@ func main() { state.gameSpeed = 1 } + // rl.EndTextureMode() + + // { // shaders + // if rl.IsKeyPressed(rl.KeyF2) { + // shader = rl.LoadShader("", shader_path) + // fmt.Println("reloaded shader") + // } + // + // rl.SetShaderValue( + // shader, timeShaderLocation, []float32{float32(rl.GetTime())}, + // rl.ShaderUniformFloat, + // ) + // rl.BeginShaderMode(shader) + // // NOTE: Render texture must be y-flipped due to default + // // OpenGL coordinates (left-bottom) + // rl.DrawTextureRec( + // target.Texture, + // rl.NewRectangle( + // 0, 0, float32(target.Texture.Width), float32(-target.Texture.Height), + // ), + // rl.NewVector2(0, 0), rl.White, + // ) + // + // rl.EndShaderMode() + // } + + { // UI + currectScore += (state.score - currectScore) / 11 + rl.DrawText(strconv.Itoa(currectScore), state.arenaWidth, 0, 50, rl.White) + + rl.DrawText( + strconv.Itoa(len(state.bullets)), state.arenaWidth, 50, 50, rl.White, + ) + + rl.DrawText( + fmt.Sprintf("%f", state.frame), state.arenaWidth, 100, 50, rl.White, + ) + rl.DrawText( + fmt.Sprintf("%d", int(state.frame)), state.arenaWidth, 150, 50, rl.White, + ) + rl.DrawText("danmaku babe bullet shoot shoot", 20, 20, 20, rl.DarkGray) + rl.DrawLine(18, 42, state.arenaWidth-18, 42, rl.Black) + rl.DrawFPS(0, 0) + } + + rl.EndDrawing() } diff --git a/windows.sh b/windows.sh new file mode 100644 index 0000000..f3ece73 --- /dev/null +++ b/windows.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 CGO_LDFLAGS="-static-libgcc -static -lpthread" go build