boxbrawl/world/world.go

67 lines
1.2 KiB
Go

package world
import (
"image"
"code.rocketnine.space/tslocum/boxbrawl/component"
"github.com/assemblaj/ggpo"
)
const (
DefaultTPS = 60
DefaultScreenWidth = 1280
DefaultScreenHeight = 720
InternalScreenWidth, InternalScreenHeight = 854, 480
Gravity = 6.0
GroundHeight = 100 // TODO
MaxDebug = 2
)
var (
TPS = DefaultTPS
ScreenWidth, ScreenHeight = 0, 0
CamX, CamY = 0, 0 // TODO currently static
LocalPort int
ConnectPromptVisible = true // When false, we are connected
ConnectPromptText string
ConnectPromptHost bool
ConnectPromptConfirmed bool
ConnectionActive bool
Debug = 1 // TODO
WASM bool
Player1 component.Player
Player2 component.Player
CurrentPlayer = 1
Backend ggpo.Backend
)
var TPSPresets = []int{1, 2, 4, 10, 30, 60, 120}
func GameCoordsToScreen(x, y float64) (int, int) {
return int(x) - CamX + (ScreenWidth / 2), -int(y) - CamY + (ScreenHeight - GroundHeight)
}
func GameRectToScreen(r image.Rectangle) image.Rectangle {
r = image.Rect(r.Min.X, -r.Min.Y, r.Max.X, -r.Max.Y)
return component.TranslateRect(r, -CamX+(ScreenWidth/2), -CamY+(ScreenHeight-GroundHeight))
}
func FloatRect(x1, y1, x2, y2 float64) image.Rectangle {
return image.Rect(int(x1), int(y1), int(x2), int(y2))
}