pong

package
v0.0.0-...-000ac03 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InitBallVelocity = 5.0
	InitPaddleSpeed  = 10.0
	SpeedUpdateCount = 6
	SpeedIncrement   = 0.5
)
View Source
const (
	WindowWidth  = 800
	WindowHeight = 600
)
View Source
const (
	InitPaddleWidth  = 20
	InitPaddleHeight = 100
	InitPaddleShift  = 50
)
View Source
const (
	InitBallRadius = 10.0
)

Variables

View Source
var (
	BgColor  = color.Black
	ObjColor = color.RGBA{120, 226, 160, 255}
)
View Source
var (
	ArcadeFont      font.Face
	SmallArcadeFont font.Face
)

Functions

func DrawBigText

func DrawBigText(state GameState, color color.Color, screen *ebiten.Image)

func DrawCaption

func DrawCaption(state GameState, color color.Color, screen *ebiten.Image)

func InitFonts

func InitFonts()

func IsKeyJustPressed

func IsKeyJustPressed(action UserAction, key ebiten.Key) bool

func IsKeyJustReleased

func IsKeyJustReleased(action UserAction, key ebiten.Key) bool

func ListenAndServe

func ListenAndServe(g *Game)

Types

type Ball

type Ball struct {
	Position
	Radius    float32
	XVelocity float32
	YVelocity float32
}

Ball is a pong ball

func (*Ball) Draw

func (b *Ball) Draw(screen *ebiten.Image)

func (*Ball) GetBallState

func (b *Ball) GetBallState() Ball

func (*Ball) Update

func (b *Ball) Update(leftPaddle *Paddle, rightPaddle *Paddle)

type CloseResponse

type CloseResponse struct {
	Placeholder string
	TryAgain    bool
}

type Connections

type Connections = map[net.Conn]PlayerConnection

type Game

type Game struct {
	State    GameState
	Ball     *Ball
	Player1  *Paddle
	Player2  *Paddle
	Rally    int
	Level    int
	MaxScore int
	Ws       Connections
	// contains filtered or unexported fields
}

func NewGame

func NewGame() *Game
	g.player1.
}

NewGame creates an initializes a new game

func (*Game) Draw

func (g *Game) Draw(screen *ebiten.Image) error

Draw updates the game screen elements drawn

func (*Game) Layout

func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int)

// Layout sets the screen layout

func (*Game) Update

func (g *Game) Update(screen *ebiten.Image) error

func (*Game) UpdateGameState

func (g *Game) UpdateGameState(action UserAction) error

type GameState

type GameState byte
const (
	StartState GameState = iota
	PlayState
	GameOverState
)

type KeyAction

type KeyAction int
const (
	KeyPressed  KeyAction = iota
	KeyReleased           = 1
)

type Paddle

type Paddle struct {
	Position
	Score  int
	Speed  float32
	Width  int
	Height int
	Up     ebiten.Key
	Down   ebiten.Key

	PlayerName string
	// contains filtered or unexported fields
}

Paddle is a pong paddle

func (*Paddle) AiUpdate

func (p *Paddle) AiUpdate(b *Ball)

func (*Paddle) Draw

func (p *Paddle) Draw(screen *ebiten.Image)

func (*Paddle) GetPlayerState

func (p *Paddle) GetPlayerState() Paddle

func (*Paddle) Update

func (p *Paddle) Update(action UserAction)

type PlayerConnection

type PlayerConnection struct {
	Connection *net.Conn
	// contains filtered or unexported fields
}

type Position

type Position struct {
	X, Y float32
}

Position is a set of coordinates in 2-D plan

func GetCenter

func GetCenter() Position

GetCenter returns the center position on screen

type StateResponse

type StateResponse struct {
	State    GameState
	Ball     *Ball
	Player1  *Paddle
	Player2  *Paddle
	Rally    int
	Level    int
	MaxScore int
	KeyPads  []ebiten.Key
}

type UserAction

type UserAction struct {
	Key    ebiten.Key `json:"key"`
	Action KeyAction  `json:"action"`
}

Jump to

Keyboard shortcuts

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