hoverrace

package
v0.0.0-...-2ed38d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const CheckpointsEvent cg.EventName = "checkpoints"

The `checkpoints` event contains all of the remaining checkpoints.

View Source
const ControlCmd cg.CommandName = "control"

The `control` command allows you to change your throttle level and direction. **NOTE:** These values are targets. The hovercraft needs some time to reach the desired values.

View Source
const CountdownEvent cg.EventName = "countdown"

The `countdown` counts down from 5. When the value reaches 0 a `start` event will be sent instead of the `countdown` event.

View Source
const FinishedPlayersEvent cg.EventName = "finished_players"

The `finished_players` event contains a list of players that have finished the race.

View Source
const HovercraftsEvent cg.EventName = "hovercrafts"

The `hovercraft` event tells all clients where all the hovercrafts are and how they are moving.

View Source
const InProgressEvent cg.EventName = "in_progress"

The `in_progress` event is sent to sockets which connect to the game while it's running.

View Source
const RaceOverEvent cg.EventName = "race_over"

The `race_over` event is sent when all players finished the game or the time runs out.

View Source
const ReadyCmd cg.CommandName = "ready"

Send the `ready` command to the server when you think the game should begin.

View Source
const ReadyPlayersEvent cg.EventName = "ready_players"

The `ready_players` event contains a list of all players which are ready.

View Source
const StartEvent cg.EventName = "start"

The `start` event is sent when the race begins. The game begins once at least 2 players have joined and all players have sent the `ready` event.

Variables

This section is empty.

Functions

func AngleDifference

func AngleDifference(a, b float64) float64

func NormalizeAngle

func NormalizeAngle(degrees float64) float64

func ToDegrees

func ToDegrees(radians float64) float64

func ToRadians

func ToRadians(degrees float64) float64

Types

type CheckpointsEventData

type CheckpointsEventData struct {
	// The positions of all the remaining checkpoints.
	Checkpoints []Vec `json:"checkpoints"`
	// The position of the finish line.
	FinishLine Vec `json:"finish_line"`
}

type ControlCmdData

type ControlCmdData struct {
	// Thrust level between -1 and 1.
	Thrust float64 `json:"thrust"`
	// The angle in degrees the hovercraft should be facing (right = 0°, up = 90°, left = 180°, down = -90°).
	Angle float64 `json:"angle"`
}

type CountdownEventData

type CountdownEventData struct {
	// The current value of the countdown (5-1).
	Value int `json:"value"`
}

type FinishedPlayer

type FinishedPlayer struct {
	// The ID of the player.
	Id string `json:"id"`
	// The place, the player has reached.
	Place int `json:"place"`
	// The amount of time in milliseconds the player needed to finish the race.
	Duration int64 `json:"duration"`
}

`finished_player` represents an entry in the final ranking.

type FinishedPlayersEventData

type FinishedPlayersEventData struct {
	// A list of players that have finished the race sorted by their placement.
	Players []FinishedPlayer `json:"players"`
}

type Game

type Game struct {
	// contains filtered or unexported fields
}

func NewGame

func NewGame(cgGame *cg.Game, config GameConfig) *Game

func (*Game) Run

func (g *Game) Run()

type GameConfig

type GameConfig struct {
	// The speed at which the thrust level reacts to user input. default = 1
	ThrottleSpeed float64 `json:"throttle_speed"`
	// The speed at which hovercrafts turn. default = 220
	TurnSpeed float64 `json:"turn_speed"`
	// The maximum acceleration of hovercrafts. default = 5
	MaxAcceleration float64 `json:"max_acceleration"`
	// The maximum velocity of hovercrafts. default = 20
	MaxVelocity float64 `json:"max_velocity"`
	// The amount of checkpoints per game. default = 10
	CheckpointCount int `json:"checkpoint_count"`
	// The time in seconds that a game is allowed to last. default = infinite
	Timeout int `json:"timeout"`
}

type Hovercraft

type Hovercraft struct {
	// The position of the center of the hovercraft.
	Pos Vec `json:"pos"`
	// The current velocity of the hovercraft.
	Velocity Vec `json:"velocity"`
	// The current thrust level of the hovercraft.
	Thrust float64 `json:"thrust"`
	// The angle in degrees the hovercraft is facing (right = 0°, up = 90°, left = 180°, down = -90°).
	Angle float64 `json:"angle"`
	// The amount of reached checkpoints.
	Checkpoints int `json:"checkpoints"`
}

A hovercraft is a circle with a diameter of 1 unit.

type HovercraftsEventData

type HovercraftsEventData struct {
	// All hovercrafts mapped to their respective player IDs.
	Hovercrafts map[string]Hovercraft `json:"hovercrafts"`
	// The time in UNIX milliseconds when this event occured.
	Time int64 `json:"time"`
}

type InProgressEventData

type InProgressEventData struct {
}

type Player

type Player struct {
	// contains filtered or unexported fields
}

type RaceOverEventData

type RaceOverEventData struct {
	// The players that have finished the game before the time ran out.
	FinishedPlayers []FinishedPlayer `json:"finished_players"`
	// The IDs of the players that have not finished the game before the time ran out.
	UnfinishedPlayers []string `json:"unfinished_players"`
}

type ReadyCmdData

type ReadyCmdData struct {
}

type ReadyPlayersEventData

type ReadyPlayersEventData struct {
	// A list of all ready players.
	Players []string `json:"players"`
	// True if all players in the game are ready.
	Everyone bool `json:"everyone"`
}

type StartEventData

type StartEventData struct {
}

type Vec

type Vec struct {
	// left to right
	X float64 `json:"x"`
	// bottom to top
	Y float64 `json:"y"`
}

One unit equals the width of the hovercrafts and checkpoints.

func VecFromAngle

func VecFromAngle(degrees float64) Vec

func (Vec) Add

func (v Vec) Add(other Vec) Vec

func (Vec) AngleTo

func (v Vec) AngleTo(other Vec) float64

func (Vec) Magnitude

func (v Vec) Magnitude() float64

func (Vec) MagnitudeSquared

func (v Vec) MagnitudeSquared() float64

func (Vec) Mul

func (v Vec) Mul(scalar float64) Vec

func (Vec) Normalize

func (v Vec) Normalize() Vec

func (Vec) Sub

func (v Vec) Sub(other Vec) Vec

func (Vec) ToAngle

func (v Vec) ToAngle() float64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL