boxbrawl/world/world.go

96 lines
1.7 KiB
Go
Raw Permalink Normal View History

2023-01-03 20:09:14 +00:00
package world
2023-01-05 20:16:01 +00:00
import (
2023-01-13 23:31:17 +00:00
"image"
2023-01-05 20:16:01 +00:00
"code.rocketnine.space/tslocum/boxbrawl/component"
2023-01-10 07:10:33 +00:00
"github.com/assemblaj/ggpo"
2023-01-05 20:16:01 +00:00
)
2023-01-03 20:09:14 +00:00
const (
2023-01-10 07:10:33 +00:00
DefaultTPS = 60
2023-01-03 20:09:14 +00:00
DefaultScreenWidth = 1280
DefaultScreenHeight = 720
2023-01-05 22:28:24 +00:00
InternalScreenWidth, InternalScreenHeight = 854, 480
2023-01-13 23:31:17 +00:00
Gravity = 3
2023-01-13 23:31:17 +00:00
2023-01-27 06:30:53 +00:00
JumpVelocity = 20
GroundWidth = 600
GroundHeight = 100
2023-02-01 17:13:31 +00:00
MaxDebug = 2
2023-01-03 20:09:14 +00:00
)
2023-01-27 23:18:59 +00:00
type AIType int
const (
2023-01-29 02:16:19 +00:00
AIStandard AIType = iota
2023-02-01 17:13:31 +00:00
AINone
2023-01-27 23:18:59 +00:00
AIMirror
AIBlock
)
2023-01-03 20:09:14 +00:00
var (
2023-01-10 07:10:33 +00:00
TPS = DefaultTPS
2023-01-29 02:16:19 +00:00
Fullscreen bool
DisableVsync bool
Headless bool // Run without using the display
2023-01-03 20:09:14 +00:00
ScreenWidth, ScreenHeight = 0, 0
2023-01-13 23:31:17 +00:00
CamX, CamY = 0, 0 // TODO currently static
2023-02-01 18:04:41 +00:00
StartMuted bool // Start with music muted.
LocalPort int
2023-01-10 07:10:33 +00:00
ConnectPromptVisible = true // When false, we are connected
2023-01-03 20:09:14 +00:00
ConnectPromptText string
ConnectPromptHost bool
2023-01-03 20:09:14 +00:00
ConnectPromptConfirmed bool
2023-01-10 07:10:33 +00:00
ConnectionActive bool
2023-01-03 20:09:14 +00:00
Debug int
WASM bool
2023-01-05 20:16:01 +00:00
2023-01-10 07:10:33 +00:00
CurrentPlayer = 1
2023-01-27 23:18:59 +00:00
Local bool // Playing against computer
AI AIType // AI configuration
2023-01-27 22:06:20 +00:00
2023-01-10 07:10:33 +00:00
Backend ggpo.Backend
2023-02-01 17:13:31 +00:00
)
2023-01-27 06:30:53 +00:00
2023-02-01 17:13:31 +00:00
// These variables are cached to prevent race conditions.
var (
2023-01-27 06:30:53 +00:00
Player1 component.Player
Player2 component.Player
Winner int
2023-01-03 20:09:14 +00:00
)
2023-01-13 23:31:17 +00:00
2023-01-19 00:41:13 +00:00
var TPSPresets = []int{1, 2, 4, 10, 30, 60, 120}
2023-01-27 06:30:53 +00:00
var PhysicsRects = []image.Rectangle{
image.Rect(-GroundWidth/2, 0, GroundWidth/2, -GroundHeight),
}
2023-01-13 23:31:17 +00:00
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 {
2023-01-19 00:41:13 +00:00
r = image.Rect(r.Min.X, -r.Min.Y, r.Max.X, -r.Max.Y)
2023-01-13 23:31:17 +00:00
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))
}