pong

package
v0.0.0-...-170af22 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const MoveCmd cg.CommandName = "move"

Clients send the move command to the server to signal a direction change of their paddle.

View Source
const PositionsEvent cg.EventName = "positions"

The positions event is sent to all players to tell them the positions of all objects in the game.

View Source
const ScoreEvent cg.EventName = "score"

The score event is sent to all players when a player scores a point.

View Source
const StartEvent cg.EventName = "start"

Is sent once the game starts.

Variables

This section is empty.

Functions

This section is empty.

Types

type Direction

type Direction string
const (
	DirectionNone Direction = "none"
	DirectionUp   Direction = "up"
	DirectionDown Direction = "down"
)

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 {
}

type MoveCmdData

type MoveCmdData struct {
	// The direction of the paddle movement.
	Direction Direction `json:"direction"`
}

type PositionsEventData

type PositionsEventData struct {
	// The position of the ball.
	Ball Rectangle `json:"ball"`
	// The position of left paddle.
	PaddleLeft Rectangle `json:"paddle_left"`
	// The position of right paddle.
	PaddleRight Rectangle `json:"paddle_right"`
}

type Rectangle

type Rectangle struct {
	X      float64 `json:"x"`
	Y      float64 `json:"y"`
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
}

type ScoreEventData

type ScoreEventData struct {
	// The score of the left player.
	PlayerLeft int `json:"player_left"`
	// The score of the right player.
	PlayerRight int `json:"player_right"`
}

type Side

type Side string
const (
	SideLeft  Side = "left"
	SideRight Side = "right"
)

type StartEventData

type StartEventData struct {
	// The side of the player.
	Side Side `json:"side"`
}

Jump to

Keyboard shortcuts

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