Compare commits

..

1 Commits
main ... main

12 changed files with 128 additions and 203 deletions

View File

@ -8,15 +8,11 @@ To play first create an accounts.json, you can look example file [account.def.js
If you're on linux, you can do:
```bash
echo '{"username":"'$USER'","texture":"flat.png","cosmetic":"none"}' > account.json
echo '{"username":"'$USER'"}' > account.json
# or
echo '{"username":"'$USER'","color":"DEAD00","texture":"flat.png","cosmetic":"none"}' > account.json
echo '{"username":"'$USER'","color":"DEAD00"}' > account.json
```
## Credits
[guessy](./guessy4.ttf), sounds, maps, flat texture pack and the original game are made by dottych
mertoalex for contributing code
marioood for ash, jelly and monoworld texture packs
[guessy](./guessy4.ttf) and sounds are made by dottych

View File

@ -1,6 +1,4 @@
{
"username": "USERNAME HERE",
"color": "000000",
"texture": "flat.png",
"cosmetic":"none"
"color": "000000"
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 934 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 834 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

217
bf.go
View File

@ -1,8 +1,8 @@
package main
import (
"fmt"
"math/rand"
"os"
"runtime"
"strconv"
@ -12,29 +12,23 @@ import (
)
const (
screenWidth = 1280
screenHeight = 720
ballRadius = 10
squareSize = 110
debug = false
cosmeticResize = 4
screenWidth = 1280
screenHeight = 720
ballRadius = 12
squareSize = 128
debug = false
)
var (
speed = 200
ballPos = rl.Vector2{X: (squareSize * 64) / 2, Y: (squareSize * 64) / 2}
cameraPos = rl.Vector2{X: ballPos.X - screenWidth/2, Y: ballPos.Y - screenHeight/2}
ballColor = rl.Black
paints = []paint{}
chatBoxText = ""
inputText = ""
loadedMap = []string{}
loadedTextures = []rl.Texture2D{}
walls = []rl.Vector2{}
liquids = []rl.Vector2{}
cosmetic = rl.Texture2D{}
notification = rl.Sound{}
chatMessage = rl.Sound{}
speed = 3
ballPos = rl.Vector2{X: 4096, Y: 4096}
cameraPos = rl.Vector2{3500, 3800}
ballColor = rl.Black
squares = []rl.Vector2{{-200, 500}, {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 = ""
loadedMap = ""
)
func main() {
@ -49,27 +43,17 @@ func main() {
guessy := rl.LoadFont("./assets/font/guessy4.ttf")
carlito := rl.LoadFont("./assets/font/carlito.ttf")
notification = rl.LoadSound("./assets/sound/Notification.ogg")
chatMessage = rl.LoadSound("./assets/sound/ChatMessage.ogg")
notification := rl.LoadSound("./assets/sound/Notification.ogg")
chatMessage := rl.LoadSound("./assets/sound/ChatMessage.ogg")
gui.LoadStyle("./assets/bf.rgs")
chatBoxText = userData["username"].(string) + " joined the game."
rl.PlaySound(notification)
rawMap, Error := os.ReadFile("./assets/maps/" + strconv.Itoa(rand.Intn(9)) + ".txt")
loadedMap = sliceMap(string(rawMap))
loadedMap = string(rawMap)
check(Error)
walls = getBlocks(loadedMap, []int{51, 52})
liquids = getBlocks(loadedMap, []int{53})
cosmetic = loadCosmetic(userData)
loadedTextures = cropTexturePack("./assets/img/textures/" + userData["texture"].(string))
icon := rl.LoadImage("icon.png")
rl.SetWindowIcon(*icon)
for !rl.WindowShouldClose() {
rl.BeginDrawing()
@ -77,29 +61,25 @@ func main() {
drawMap(loadedMap)
drawPaint()
drawBall(ballPos, ballColor, rl.White, cosmetic)
drawBall(ballPos, ballColor, rl.White)
moveBall()
usernamePosisiton := rl.Vector2Subtract(ballPos, rl.Vector2{ballRadius + 24, ballRadius + 40})
usernamePosisiton = rl.Vector2Subtract(usernamePosisiton, cameraPos)
fpsText := "FPS: " + strconv.Itoa(int(rl.GetFPS()))
var spacing int = 21
drawTextShadow("Balls Offline", rl.Vector2{12, 5}, carlito, rl.White)
rl.DrawCircleV(rl.Vector2{135, 14}, 8, rl.NewColor(0, 255, 0, 255))
drawTextShadow(fpsText, rl.Vector2{155, 5}, carlito, rl.NewColor(0, 255, 0, 255))
rl.DrawLine(10, 33, 120, 33, rl.NewColor(221, 221, 221, 255))
drawTextShadow("Version: 1.0.0", rl.Vector2{10, float32(2*spacing + 1)}, carlito, rl.NewColor(168, 168, 252, 255))
drawTextShadow("Platform: "+runtime.GOOS, rl.Vector2{10, float32(3*spacing + 1)}, carlito, rl.NewColor(168, 168, 252, 255))
drawTextShadow("Client ID: none", rl.Vector2{10, float32(5*spacing + 1)}, carlito, rl.NewColor(221, 221, 221, 255))
drawTextShadow("Balls Offline", rl.Vector2{10, 5}, carlito)
rl.DrawLine(10, 33, 120, 33, rl.White)
drawTextShadow("Version: 0.0.0", rl.Vector2{10, float32(2*spacing + 1)}, carlito)
drawTextShadow("Platform: "+runtime.GOOS, rl.Vector2{10, float32(3*spacing + 1)}, carlito)
drawTextShadow("Client ID: none", rl.Vector2{10, float32(5*spacing + 1)}, carlito)
x := strconv.FormatFloat(float64(ballPos.X), 'f', -1, 64)[0:4]
y := strconv.FormatFloat(float64(ballPos.Y), 'f', -1, 64)[0:4]
x := strconv.FormatFloat(float64(ballPos.X), 'f', -1, 64)
y := strconv.FormatFloat(float64(ballPos.Y), 'f', -1, 64)
drawTextShadow("Position: "+x+" | "+y, rl.Vector2{10, float32(6*spacing + 1)}, carlito, rl.White)
drawTextShadow("Position: "+x+" | "+y, rl.Vector2{10, float32(6*spacing + 1)}, carlito)
drawTextShadow(userData["username"].(string), usernamePosisiton, guessy, rl.NewColor(221, 221, 221, 255))
drawTextShadow(userData["username"].(string), usernamePosisiton, guessy)
if rl.IsKeyPressed(rl.KeyEnter) && inputText != "" {
rl.PlaySound(chatMessage)
@ -116,65 +96,87 @@ func main() {
rl.CloseWindow()
}
func loadCosmetic(userData map[string]interface{}) rl.Texture2D {
if userData["costmetic"].(string) == "none" {
return rl.NewTexture2D(0, 0, 0, 0, 0)
func drawPaint() {
if debug {
t := strconv.Itoa(len(paints))
rl.DrawText(t, 10, 10, 40, rl.Black)
}
image := rl.LoadImage("./assets/img/cosmetics/" + userData["costmetic"].(string))
for index, paintI := range paints {
if len(paints) <= index {
continue
}
rl.ImageResizeNN(image, ballRadius*cosmeticResize, ballRadius*cosmeticResize)
if paintI.time > 1 {
paints[index] = paint{time: paintI.time - 1, location: paintI.location}
rl.DrawRectangleV(rl.Vector2Subtract(paintI.location, cameraPos), rl.Vector2{X: ballRadius - 2, Y: ballRadius - 2}, rl.NewColor(ballColor.R, ballColor.G, ballColor.R, uint8(paintI.time)))
continue
}
paints = removePaint(paints, index)
}
}
return rl.LoadTextureFromImage(image)
func drawSquares() {
for index, element := range squares {
debugLog(debug, fmt.Sprintln(index, element.X))
rl.DrawRectangleV(rl.Vector2{element.X - cameraPos.X, element.Y - cameraPos.Y}, rl.Vector2{X: float32(squareSize), Y: float32(squareSize)}, rl.LightGray)
}
}
func draw() {
paintedPaint := paint{255, ballPos}
paints = append(paints, paintedPaint)
}
func moveBall() {
if rl.IsKeyDown(rl.KeyLeftShift) {
draw()
}
ballSpeed := float32(speed) * rl.GetFrameTime()
if rl.IsKeyDown(rl.KeyRight) && !checkCollision(rl.Vector2{X: ballPos.X + ballSpeed, Y: ballPos.Y}) {
ballPos.X = ballPos.X + ballSpeed
cameraPos.X = cameraPos.X + ballSpeed
if rl.IsKeyDown(rl.KeyRight) && !checkCollision(rl.Vector2{X: ballPos.X + float32(speed), Y: ballPos.Y}) {
ballPos.X = ballPos.X + float32(speed)
cameraPos.X = cameraPos.X + float32(speed)
}
if rl.IsKeyDown(rl.KeyLeft) && !checkCollision(rl.Vector2{X: ballPos.X - ballSpeed, Y: ballPos.Y}) {
ballPos.X = ballPos.X - ballSpeed
cameraPos.X = cameraPos.X - ballSpeed
if rl.IsKeyDown(rl.KeyLeft) && !checkCollision(rl.Vector2{X: ballPos.X - float32(speed), Y: ballPos.Y}) {
ballPos.X = ballPos.X - float32(speed)
cameraPos.X = cameraPos.X - float32(speed)
}
if rl.IsKeyDown(rl.KeyUp) && !checkCollision(rl.Vector2{X: ballPos.X, Y: ballPos.Y - ballSpeed}) {
ballPos.Y = ballPos.Y - ballSpeed
cameraPos.Y = cameraPos.Y - ballSpeed
if rl.IsKeyDown(rl.KeyUp) && !checkCollision(rl.Vector2{X: ballPos.X, Y: ballPos.Y - float32(speed)}) {
ballPos.Y = ballPos.Y - float32(speed)
cameraPos.Y = cameraPos.Y - float32(speed)
}
if rl.IsKeyDown(rl.KeyDown) && !checkCollision(rl.Vector2{X: ballPos.X, Y: ballPos.Y + ballSpeed}) {
ballPos.Y = ballPos.Y + ballSpeed
cameraPos.Y = cameraPos.Y + ballSpeed
if rl.IsKeyDown(rl.KeyDown) && !checkCollision(rl.Vector2{X: ballPos.X, Y: ballPos.Y + float32(speed)}) {
ballPos.Y = ballPos.Y + float32(speed)
cameraPos.Y = cameraPos.Y + float32(speed)
}
}
func drawBall(pos rl.Vector2, color, outline rl.Color, ballCosmetic rl.Texture2D) {
func drawBall(pos rl.Vector2, color, outline rl.Color) {
rl.DrawCircleV(rl.Vector2Subtract(pos, cameraPos), ballRadius+1, outline)
rl.DrawCircleV(rl.Vector2Subtract(pos, cameraPos), ballRadius, color)
rl.DrawTextureV(ballCosmetic, rl.Vector2Subtract(rl.Vector2{pos.X - ballRadius*cosmeticResize/2, pos.Y - ballRadius*cosmeticResize/2}, cameraPos), rl.White)
}
func drawTextShadow(text string, textPos rl.Vector2, font rl.Font, color rl.Color) {
func drawTextShadow(text string, textPos rl.Vector2, font rl.Font) {
var textShadowPos rl.Vector2 = rl.Vector2{X: textPos.X + 2, Y: textPos.Y + 2}
rl.DrawTextEx(font, text, textShadowPos, 20, 1, rl.Black)
rl.DrawTextEx(font, text, textPos, 20, 1, color)
rl.DrawTextEx(font, text, textPos, 20, 1, rl.White)
}
func checkCollision(newPos rl.Vector2) bool {
for x := range liquids {
if rl.CheckCollisionPointRec(newPos, rl.NewRectangle(liquids[x].X*squareSize, liquids[x].Y*squareSize, squareSize, squareSize)) {
chatBoxText = chatBoxText + "\n" + "You've drowned!"
ballPos = rl.Vector2{X: (squareSize * 64) / 2, Y: (squareSize * 64) / 2}
cameraPos = rl.Vector2{X: ballPos.X - screenWidth/2, Y: ballPos.Y - screenHeight/2}
rl.PlaySound(chatMessage)
}
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)
rl.DrawLineV(newPos, rl.Vector2{X: 0, Y: newPos.Y}, rl.Green)
rl.DrawLineV(newPos, rl.Vector2{X: screenHeight * 2, Y: newPos.Y}, rl.Green)
}
for x := range walls {
if rl.CheckCollisionPointRec(newPos, rl.NewRectangle(walls[x].X*squareSize, walls[x].Y*squareSize, squareSize, squareSize)) {
for index, square := range squares {
if debug {
fmt.Println(index, square.X, rl.Vector2Distance(newPos, square))
rl.DrawLineV(newPos, square, rl.Purple)
}
if rl.CheckCollisionPointRec(newPos, rl.Rectangle{X: square.X, Y: square.Y, Width: float32(squareSize), Height: float32(squareSize)}) {
if debug {
rl.DrawText("colliding with obstacle", 10, 10, 40, rl.Black)
}
return true
}
}
@ -194,6 +196,18 @@ func checkCollision(newPos rl.Vector2) bool {
return false
}
type paint struct {
time float32
location rl.Vector2
}
func removePaint(slice []paint, index int) []paint {
if len(slice) <= 2 {
return make([]paint, 0)
}
return append(slice[:index], slice[index+1:]...)
}
func convertHex(hex string) rl.Color {
hex1 := hex[0:2]
hex2 := hex[2:4]
@ -208,19 +222,36 @@ func convertHex(hex string) rl.Color {
return rl.NewColor(uint8(decimal), uint8(decimal2), uint8(decimal3), 255)
}
func cropTexturePack(textureLocation string) []rl.Texture2D {
var textures []rl.Texture2D
func drawMap(mapRaw string) {
for i := 0; i < 6; i++ {
image := rl.LoadImage(textureLocation)
croppedImage := image
rl.ImageCrop(croppedImage, rl.NewRectangle(float32(i*32), 0, 32, 32))
rl.ImageResizeNN(croppedImage, squareSize, squareSize)
var lines []string
croppedTexture := rl.LoadTextureFromImage(croppedImage)
rl.SetTextureFilter(croppedTexture, rl.FilterPoint)
textures = append(textures, croppedTexture)
for i := 0; i < len(mapRaw); i += 64 {
end := i + 64
if end > len(mapRaw) {
end = len(mapRaw)
}
lines = append(lines, mapRaw[i:end])
}
return textures
for y := range lines {
for x := 0; x < len(lines[y]); x++ {
fmt.Println(lines[0][0])
switch lines[y][x] {
case 48: //air
case 49: //path
rl.DrawRectangleV(rl.Vector2{float32(x*squareSize) - cameraPos.X, float32(y*squareSize) - cameraPos.Y}, rl.Vector2{X: float32(squareSize), Y: float32(squareSize)}, rl.NewColor(133, 133, 133, 255))
case 50: //door
rl.DrawRectangleV(rl.Vector2{float32(x*squareSize) - cameraPos.X, float32(y*squareSize) - cameraPos.Y}, rl.Vector2{X: float32(squareSize), Y: float32(squareSize)}, rl.NewColor(112, 122, 112, 255))
case 51: //glass
rl.DrawRectangleV(rl.Vector2{float32(x*squareSize) - cameraPos.X, float32(y*squareSize) - cameraPos.Y}, rl.Vector2{X: float32(squareSize), Y: float32(squareSize)}, rl.NewColor(144, 144, 144, 255))
case 52: //wall
rl.DrawRectangleV(rl.Vector2{float32(x*squareSize) - cameraPos.X, float32(y*squareSize) - cameraPos.Y}, rl.Vector2{X: float32(squareSize), Y: float32(squareSize)}, rl.NewColor(170, 170, 170, 255))
case 53: //liquid
rl.DrawRectangleV(rl.Vector2{float32(x*squareSize) - cameraPos.X, float32(y*squareSize) - cameraPos.Y}, rl.Vector2{X: float32(squareSize), Y: float32(squareSize)}, rl.NewColor(205, 205, 205, 255))
}
}
}
}

57
map.go
View File

@ -1,57 +0,0 @@
package main
import (
"slices"
rl "github.com/gen2brain/raylib-go/raylib"
)
func sliceMap(mapLocation string) []string {
var lines []string
for i := 0; i < len(mapLocation); i += 64 {
end := i + 64
if end > len(mapLocation) {
end = len(mapLocation)
}
lines = append(lines, mapLocation[i:end])
}
return lines
}
func drawMap(slicedMap []string) {
for y := range slicedMap {
for x := 0; x < len(slicedMap[y]); x++ {
tilePositionX := int32(x*squareSize - int(cameraPos.X))
tilePositionY := int32(y*squareSize - int(cameraPos.Y))
rl.DrawTexture(loadedTextures[0], tilePositionX, tilePositionY, rl.White)
switch slicedMap[y][x] {
case 49: //path
rl.DrawTexture(loadedTextures[1], tilePositionX, tilePositionY, rl.White)
case 50: //door
rl.DrawTexture(loadedTextures[2], tilePositionX, tilePositionY, rl.White)
case 51: //glass
rl.DrawTexture(loadedTextures[3], tilePositionX, tilePositionY, rl.White)
case 52: //wall
rl.DrawTexture(loadedTextures[4], tilePositionX, tilePositionY, rl.White)
case 53: //liquid
rl.DrawTexture(loadedTextures[5], tilePositionX, tilePositionY, rl.White)
}
}
}
}
func getBlocks(slicedMap []string, blocks []int) []rl.Vector2 {
walls := []rl.Vector2{}
for y := range slicedMap {
for x := 0; x < len(slicedMap[y]); x++ {
if slices.Contains(blocks, int(slicedMap[y][x])) {
walls = append(walls, rl.Vector2{X: float32(x), Y: float32(y)})
}
}
}
return walls
}

View File

@ -1,43 +0,0 @@
package main
import (
"strconv"
rl "github.com/gen2brain/raylib-go/raylib"
)
type paint struct {
time float32
location rl.Vector2
}
func drawPaint() {
if debug {
t := strconv.Itoa(len(paints))
rl.DrawText(t, 10, 10, 40, rl.Black)
}
for index, paintI := range paints {
if len(paints) <= index {
continue
}
if paintI.time > 1 {
paints[index] = paint{time: paintI.time - 1, location: paintI.location}
rl.DrawRectangleV(rl.Vector2Subtract(paintI.location, cameraPos), rl.Vector2{X: ballRadius - 2, Y: ballRadius - 2}, rl.NewColor(ballColor.R, ballColor.G, ballColor.B, uint8(paintI.time)))
continue
}
paints = removePaint(paints, index)
}
}
func draw() {
paintedPaint := paint{255, ballPos}
paints = append(paints, paintedPaint)
}
func removePaint(slice []paint, index int) []paint {
if len(slice) <= 2 {
return make([]paint, 0)
}
return append(slice[:index], slice[index+1:]...)
}