texturepacks and more i dont remember

This commit is contained in:
Gnawmon 2024-04-29 22:54:49 +03:00
parent 3ba85f3ebf
commit 4b3422288c
7 changed files with 134 additions and 106 deletions

View File

@ -8,11 +8,12 @@ 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'"}' > account.json
echo '{"username":"'$USER'","texture":"flat.png"}' > account.json
# or
echo '{"username":"'$USER'","color":"DEAD00"}' > account.json
echo '{"username":"'$USER'","color":"DEAD00","texture":"flat.png"}' > account.json
```
## Credits
[guessy](./guessy4.ttf) and sounds are made by dottych
[guessy](./guessy4.ttf), sounds, maps, flat texture pack and the original game are made by dottych
mertoalex for contributing code

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

131
bf.go
View File

@ -1,8 +1,8 @@
package main
import (
"fmt"
"math/rand"
"os"
"runtime"
"strconv"
@ -20,15 +20,17 @@ const (
)
var (
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 = ""
speed = 3
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
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 = []string{}
loadedTextures = []rl.Texture2D{}
walls = []rl.Vector2{}
)
func main() {
@ -51,9 +53,13 @@ func main() {
rl.PlaySound(notification)
rawMap, Error := os.ReadFile("./assets/maps/" + strconv.Itoa(rand.Intn(9)) + ".txt")
loadedMap = string(rawMap)
loadedMap = sliceMap(string(rawMap))
check(Error)
walls = getWalls(loadedMap)
loadedTextures = cropTexturePack("./assets/img/textures/" + userData["texture"].(string))
for !rl.WindowShouldClose() {
rl.BeginDrawing()
@ -96,36 +102,6 @@ func main() {
rl.CloseWindow()
}
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.R, uint8(paintI.time)))
continue
}
paints = removePaint(paints, index)
}
}
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()
@ -161,26 +137,6 @@ func drawTextShadow(text string, textPos rl.Vector2, font rl.Font) {
func checkCollision(newPos rl.Vector2) bool {
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 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
}
}
if newPos.X > float32(64*squareSize) {
return true
}
@ -196,18 +152,6 @@ 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]
@ -222,36 +166,19 @@ func convertHex(hex string) rl.Color {
return rl.NewColor(uint8(decimal), uint8(decimal2), uint8(decimal3), 255)
}
func drawMap(mapRaw string) {
func cropTexturePack(textureLocation string) []rl.Texture2D {
var textures []rl.Texture2D
var lines []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)
for i := 0; i < len(mapRaw); i += 64 {
end := i + 64
if end > len(mapRaw) {
end = len(mapRaw)
}
lines = append(lines, mapRaw[i:end])
croppedTexture := rl.LoadTextureFromImage(croppedImage)
rl.SetTextureFilter(croppedTexture, rl.FilterPoint)
textures = append(textures, croppedTexture)
}
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))
}
}
}
return textures
}

56
map.go Normal file
View File

@ -0,0 +1,56 @@
package main
import (
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 getWalls(slicedMap []string) []rl.Vector2 {
walls := []rl.Vector2{}
for y := range slicedMap {
for x := 0; x < len(slicedMap[y]); x++ {
switch slicedMap[y][x] {
case 51, 52:
walls = append(walls, rl.Vector2{X: float32(x), Y: float32(y)})
}
}
}
return walls
}

43
paint.go Normal file
View File

@ -0,0 +1,43 @@
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.R, 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:]...)
}