boxbrawl/world/world.go

96 lines
1.7 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 = 3
JumpVelocity = 20
GroundWidth = 600
GroundHeight = 100
MaxDebug = 2
)
type AIType int
const (
AIStandard AIType = iota
AINone
AIMirror
AIBlock
)
var (
TPS = DefaultTPS
Fullscreen bool
DisableVsync bool
Headless bool // Run without using the display
ScreenWidth, ScreenHeight = 0, 0
CamX, CamY = 0, 0 // TODO currently static
StartMuted bool // Start with music muted.
LocalPort int
ConnectPromptVisible = true // When false, we are connected
ConnectPromptText string
ConnectPromptHost bool
ConnectPromptConfirmed bool
ConnectionActive bool
Debug int
WASM bool
CurrentPlayer = 1
Local bool // Playing against computer
AI AIType // AI configuration
Backend ggpo.Backend
)
// These variables are cached to prevent race conditions.
var (
Player1 component.Player
Player2 component.Player
Winner int
)
var TPSPresets = []int{1, 2, 4, 10, 30, 60, 120}
var PhysicsRects = []image.Rectangle{
image.Rect(-GroundWidth/2, 0, GroundWidth/2, -GroundHeight),
}
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))
}