forked from gnawmon/ballsoffline
first comit
This commit is contained in:
parent
b9e391d955
commit
14a97915e3
|
@ -21,3 +21,7 @@
|
|||
# Go workspace file
|
||||
go.work
|
||||
|
||||
__*
|
||||
epic_music.ogg
|
||||
bf
|
||||
bf.exe
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# ballsoffline
|
||||
|
||||
a game inspired by balls online
|
||||
a game inspired by balls online
|
||||
|
||||
guessy is made by dottych
|
|
@ -0,0 +1,143 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
screenWidth = 1280
|
||||
screenHeight = 720
|
||||
ballRadius = 12
|
||||
debug = false
|
||||
)
|
||||
|
||||
var (
|
||||
ballpos = rl.Vector2{X: 400, Y: 225}
|
||||
speed = 3
|
||||
squareSize = 100
|
||||
squares = [5]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}}
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "balls offline")
|
||||
guessy4 := rl.LoadFont("guessy4.ttf")
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.NewColor(128, 128, 128, 255))
|
||||
|
||||
for index, element := range squares {
|
||||
if debug {
|
||||
fmt.Println(index, element.X)
|
||||
}
|
||||
|
||||
rl.DrawRectangleV(element, rl.Vector2{X: float32(squareSize), Y: float32(squareSize)}, rl.LightGray)
|
||||
}
|
||||
|
||||
drawPosition(ballpos, rl.Vector2{X: 10, Y: screenHeight - 20}, guessy4)
|
||||
drawBall(ballpos, rl.Black, rl.White)
|
||||
moveBall()
|
||||
|
||||
drawTextShadow("your name", rl.Vector2{X: ballpos.X - ballRadius - 24, Y: ballpos.Y - ballRadius - 40}, guessy4)
|
||||
|
||||
rl.EndDrawing()
|
||||
|
||||
}
|
||||
|
||||
rl.CloseAudioDevice()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
||||
func moveBall() {
|
||||
if rl.IsKeyDown(rl.KeyS) {
|
||||
speed += 2
|
||||
}
|
||||
if rl.IsKeyDown(rl.KeyRight) {
|
||||
if !checkIfWall(rl.Vector2{X: ballpos.X + float32(speed), Y: ballpos.Y}) {
|
||||
ballpos.X = ballpos.X + float32(speed)
|
||||
}
|
||||
}
|
||||
if rl.IsKeyDown(rl.KeyLeft) {
|
||||
if !checkIfWall(rl.Vector2{X: ballpos.X - float32(speed), Y: ballpos.Y}) {
|
||||
ballpos.X = ballpos.X - float32(speed)
|
||||
}
|
||||
}
|
||||
if rl.IsKeyDown(rl.KeyUp) {
|
||||
if !checkIfWall(rl.Vector2{X: ballpos.X, Y: ballpos.Y - float32(speed)}) {
|
||||
ballpos.Y = ballpos.Y - float32(speed)
|
||||
}
|
||||
}
|
||||
if rl.IsKeyDown(rl.KeyDown) {
|
||||
if !checkIfWall(rl.Vector2{X: ballpos.X, Y: ballpos.Y + float32(speed)}) {
|
||||
ballpos.Y = ballpos.Y + float32(speed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func drawBall(pos rl.Vector2, color, outline rl.Color) {
|
||||
rl.DrawCircleV(pos, ballRadius+1, outline)
|
||||
rl.DrawCircleV(pos, ballRadius, color)
|
||||
}
|
||||
|
||||
func drawPosition(pos, textPos rl.Vector2, guessy4 rl.Font) {
|
||||
|
||||
x := strconv.FormatFloat(float64(pos.X), 'f', -1, 64)
|
||||
y := strconv.FormatFloat(float64(pos.Y), 'f', -1, 64)
|
||||
|
||||
drawTextShadow("X:"+x, textPos, guessy4)
|
||||
drawTextShadow("Y:"+y, rl.Vector2Add(textPos, rl.Vector2{X: 90, Y: 0}), guessy4)
|
||||
}
|
||||
|
||||
func drawTextShadow(text string, textPos rl.Vector2, guessy4 rl.Font) {
|
||||
var textShadowPos rl.Vector2 = rl.Vector2{X: textPos.X + 2, Y: textPos.Y + 2}
|
||||
rl.DrawTextEx(guessy4, text, textShadowPos, 20, 1, rl.Black)
|
||||
rl.DrawTextEx(guessy4, text, textPos, 20, 1, rl.White)
|
||||
}
|
||||
|
||||
func checkIfWall(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 {
|
||||
square = rl.Vector2{X: square.X + float32(squareSize)/2, Y: square.Y + float32(squareSize)/2}
|
||||
|
||||
if debug {
|
||||
fmt.Println(index, square.X, rl.Vector2Distance(newPos, square))
|
||||
rl.DrawLineV(newPos, square, rl.Purple)
|
||||
}
|
||||
mininumDistance := float32(squareSize)/2 + 12
|
||||
if rl.Vector2Distance(newPos, square) < mininumDistance {
|
||||
distanceString := strconv.FormatFloat(float64(rl.Vector2Distance(newPos, square)), 'f', -1, 32)
|
||||
distanceReqString := strconv.FormatFloat(float64(mininumDistance), 'f', -1, 32)
|
||||
|
||||
if debug {
|
||||
rl.DrawText(distanceString+"<"+distanceReqString, 10, 10, 40, rl.Black)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if newPos.X > screenWidth-12 {
|
||||
return true
|
||||
}
|
||||
if newPos.X < 12 {
|
||||
return true
|
||||
}
|
||||
if newPos.Y < 12 {
|
||||
return true
|
||||
}
|
||||
if newPos.Y > screenHeight-12 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
module ballsoffline
|
||||
|
||||
go 1.22.2
|
||||
|
||||
require (
|
||||
github.com/ebitengine/purego v0.7.1 // indirect
|
||||
github.com/gen2brain/raylib-go/raygui v0.0.0-20240418150228-9548fadb54e6 // indirect
|
||||
github.com/gen2brain/raylib-go/raylib v0.0.0-20240418150228-9548fadb54e6
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
)
|
|
@ -0,0 +1,8 @@
|
|||
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/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=
|
||||
github.com/gen2brain/raylib-go/raylib v0.0.0-20240421191056-278df68f40bb h1:2CdDr/LfDc9uLOW/+3ffSM5Ia7xZZMgjC6UmP7KTjRw=
|
||||
github.com/gen2brain/raylib-go/raylib v0.0.0-20240421191056-278df68f40bb/go.mod h1:P/hDjVwz/9fhR0ww3+umzDpDA7Bf7Tce4xNChHIEFqE=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
Binary file not shown.
Loading…
Reference in New Issue