chat (broken) and sounds

This commit is contained in:
Gnawmon 2024-04-25 18:44:29 +03:00
parent 373597a3c2
commit 63d037ad83
5 changed files with 50 additions and 14 deletions

View File

@ -15,4 +15,4 @@ echo '{"username":"'$USER'","color":"DEAD00"}' > account.json
## Credits
[guessy](./guessy4.ttf) is made by dottych
[guessy](./guessy4.ttf) and sounds are made by dottych

59
bf.go
View File

@ -4,6 +4,7 @@ import (
"fmt"
"strconv"
gui "github.com/gen2brain/raylib-go/raygui"
rl "github.com/gen2brain/raylib-go/raylib"
)
@ -11,16 +12,19 @@ const (
screenWidth = 1280
screenHeight = 720
ballRadius = 12
debug = false
debug = false
)
var (
ballpos = rl.Vector2{X: 400, Y: 225}
ballColor = rl.Black
speed = 3
squareSize = 100
squares = []rl.Vector2{{X: 640 - float32(squareSize), Y: 315}, {X: 640, Y: 315}, {X: 640 + float32(squareSize), Y: 315}, {X: 640, Y: 315 - float32(squareSize)}, {X: 640, Y: 315 - float32(squareSize)*2}}
paints = []paint{}
ballPos = rl.Vector2{X: 400, Y: 225}
cameraPos = rl.Vector2{}
ballColor = rl.Black
speed = 3
squareSize = 100
squares = []rl.Vector2{{X: 640 - float32(squareSize), Y: 315}, {X: 640, Y: 315}, {X: 640 + float32(squareSize), Y: 315}, {X: 640, Y: 315 - float32(squareSize)}, {X: 640, Y: 315 - float32(squareSize)*2}}
paints = []paint{}
chatBoxText = ""
inputText = ""
)
func main() {
@ -29,9 +33,15 @@ func main() {
ballColor = convertHex(userData["color"].(string))
rl.InitWindow(screenWidth, screenHeight, "balls offline")
guessy4 := rl.LoadFont("guessy4.ttf")
rl.InitAudioDevice()
guessy4 := rl.LoadFont("./assets/guessy4.ttf")
notification := rl.LoadSound("./assets/sound/Notification.ogg")
chatMessage := rl.LoadSound("./assets/sound/ChatMessage.ogg")
rl.SetTargetFPS(60)
gui.LoadStyle("bf.rgs")
chatBoxText = userData["username"].(string) + " joined the game."
rl.PlaySound(notification)
for !rl.WindowShouldClose() {
rl.BeginDrawing()
@ -39,12 +49,34 @@ func main() {
drawSquares()
drawPaint()
drawPosition(ballpos, rl.Vector2{X: 10, Y: screenHeight - 20}, guessy4)
drawBall(ballpos, ballColor, rl.White)
drawPosition(ballPos, rl.Vector2{X: 10, Y: screenHeight - 20}, guessy4)
drawBall(ballPos, ballColor, rl.White)
moveBall()
/*
for i := 0; i < screenHeight/10+1; i++ {
rl.DrawLineV(
rl.NewVector2(float32(squareSize*i), 0),
rl.NewVector2(float32(squareSize*i), float32(screenHeight)),
rl.LightGray,
)
}
drawTextShadow(userData["username"].(string), rl.Vector2{X: ballpos.X - ballRadius - 24, Y: ballpos.Y - ballRadius - 40}, guessy4)
for i := int32(0); i < screenWidth/10+1; i++ {
rl.DrawLineV(
rl.NewVector2(0, float32(squareSize)*float32(i)),
rl.NewVector2(float32(screenWidth), float32(squareSize)*float32(i)),
rl.LightGray,
)
}
*/
drawTextShadow(userData["username"].(string), rl.Vector2{X: ballPos.X - ballRadius - 24, Y: ballPos.Y - ballRadius - 40}, guessy4)
if rl.IsKeyPressed(rl.KeyEnter) && inputText != "" {
rl.PlaySound(chatMessage)
chatBoxText = chatBoxText + "\n" + userData["username"].(string) + ": " + inputText
inputText = ""
}
gui.TextBox(rl.NewRectangle(screenWidth-screenWidth/4, 0, screenWidth/4, 220), &chatBoxText, 100, false)
gui.TextBox(rl.NewRectangle(screenWidth-screenWidth/4, 220, screenWidth/4, 20), &inputText, 100, true)
rl.EndDrawing()
}
@ -79,7 +111,7 @@ func drawSquares() {
}
}
func draw() {
paintedPaint := paint{255, ballpos}
paintedPaint := paint{255, ballPos}
paints = append(paints, paintedPaint)
}
@ -125,6 +157,7 @@ func drawTextShadow(text string, textPos rl.Vector2, guessy4 rl.Font) {
}
func checkCollision(newPos rl.Vector2) bool {
return false
if debug {
rl.DrawLineV(newPos, rl.Vector2{X: newPos.X, Y: screenWidth * 2}, rl.Green)
rl.DrawLineV(newPos, rl.Vector2{X: newPos.X, Y: 0}, rl.Green)

1
go.mod
View File

@ -6,5 +6,6 @@ require github.com/gen2brain/raylib-go/raylib v0.0.0-20240418150228-9548fadb54e6
require (
github.com/ebitengine/purego v0.7.1 // indirect
github.com/gen2brain/raylib-go/raygui v0.0.0-20240421191056-278df68f40bb
golang.org/x/sys v0.19.0 // indirect
)

2
go.sum
View File

@ -1,5 +1,7 @@
github.com/ebitengine/purego v0.7.1 h1:6/55d26lG3o9VCZX8lping+bZcmShseiqlh2bnUDiPA=
github.com/ebitengine/purego v0.7.1/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/gen2brain/raylib-go/raygui v0.0.0-20240421191056-278df68f40bb h1:rL+CF2bsLRFjV/x/nRQTXVVFpsZzLXuRErMTsd6kVVs=
github.com/gen2brain/raylib-go/raygui v0.0.0-20240421191056-278df68f40bb/go.mod h1:Ra1zgJP7vnGst+STvzPPiVJhjicklFWONCz5nu6MnOM=
github.com/gen2brain/raylib-go/raylib v0.0.0-20240418150228-9548fadb54e6 h1:mNKFgLZIU0eEHKHjb7Uk9ZuSy65DdgmEf2xxum0Tof4=
github.com/gen2brain/raylib-go/raylib v0.0.0-20240418150228-9548fadb54e6/go.mod h1:P/hDjVwz/9fhR0ww3+umzDpDA7Bf7Tce4xNChHIEFqE=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=

Binary file not shown.