pkg

package
v0.0.0-...-f8da68a Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetImg

func GetImg(filename string, size int) *ebiten.Image

Types

type Ball

type Ball struct {
	Position
	XSpeed      float32
	YSpeed      float32
	Width       int
	Height      int
	Image       *ebiten.Image
	Impressions []Impression

	UpdateBall chan Position
}

func NewBall

func NewBall(w, h int, position Position) *Ball

func (*Ball) Remote

func (b *Ball) Remote()

type Font

type Font struct {
	H1, H2, Text, SmallText, TinyText                     text.Face
	H1Size, H2Size, TextSize, SmallTextSize, TinyTextSize int
	AvailableFonts                                        map[string]*text.GoTextFaceSource
}

func NewFont

func NewFont() Font

type FontText

type FontText struct {
	Text     string
	Font     text.Face
	FontSize int
	Color    color.Color
}

type Game

type Game struct {
	*GameState

	GameMode GameMode

	Title    FontText
	Subtitle FontText
	Screen   Screen

	PlayerL *Player
	PlayerR *Player
	Ball    *Ball

	Win Win

	Debug bool
}

func NewGame

func NewGame(mode GameMode, debug bool) *Game

func (*Game) EndSet

func (g *Game) EndSet(player Player)

EndSet updates parameters of the current set

func (Game) IsLocal

func (g Game) IsLocal() bool

func (Game) IsRemoteClient

func (g Game) IsRemoteClient() bool

func (Game) IsRemoteServer

func (g Game) IsRemoteServer() bool

func (Game) Looser

func (g Game) Looser() *Player

Looser gets the looser of the game

func (Game) Mark

func (g Game) Mark(player *Player)

Mark increments the player's winner score and the another player to {win=false}

func (Game) MaxXSpeedSet

func (g Game) MaxXSpeedSet() float32

MaxXSpeedSet returns the max x speed of the sets

func (*Game) ResetGame

func (g *Game) ResetGame()

ResetGame initializes a new Game

func (*Game) StartNewSet

func (g *Game) StartNewSet()

StartNewSet initializes a new set

func (Game) Winner

func (g Game) Winner() *Player

Winner gets the winner if there is one

type GameMode

type GameMode int
const (
	LocalMode GameMode = iota
	RemoteClientMode
	RemoteServerMode
)

type GameState

type GameState struct {
	*ResumeGameState

	CurrentState State
	Reset        Reset
}

type Impression

type Impression struct {
	Position
	Image ebiten.Image
}

type Options

type Options struct {
	Color color.Color
	Up    ebiten.Key
	Down  ebiten.Key
}

Options is an options (shortcuts, color, etc...)

type Paddle

type Paddle struct {
	Position
	Speed          float32
	Width          int
	Height         int
	Image          *ebiten.Image
	CurrentPressed ebiten.Key
}

func NewPaddle

func NewPaddle(w, h int, position Position) *Paddle

type Player

type Player struct {
	*PlayerState

	Name          string
	Side          PlayerSide
	Paddle        *Paddle
	Options       Options
	UpdatePaddleY chan float32
}

Player is a player with a paddle and options

func NewPlayer

func NewPlayer(name string, side PlayerSide, p *Paddle, options Options) *Player

func (*Player) Hit

func (p *Player) Hit(ball Ball) bool

func (*Player) Mark

func (p *Player) Mark()

func (*Player) Remote

func (p *Player) Remote()

type PlayerSide

type PlayerSide int

PlayerSide is an enum that represents the position of the player on the screen (LEFT or RIGHT)

const (
	PlayerLeft PlayerSide = iota
	PlayerRight
)

func (PlayerSide) String

func (p PlayerSide) String() string

type PlayerState

type PlayerState struct {
	Score int
	Win   bool
}

Player is a player with a paddle and options

type Position

type Position struct {
	X float32 `json:"x"`
	Y float32 `json:"y"`
}

Position is a set of coordinates in 2-D plan

type Reset

type Reset struct {
	Ball Ball
}

type ResumeGameState

type ResumeGameState struct {
	Max   int
	Count int
}

type Screen

type Screen struct {
	Width, Height, RemoteExtendZoneW int
	XLeft, XRight, YBottom, YTop     float32
	AvailableColors                  map[string]color.Color
	Font                             Font
}

func (Screen) GameZoneHeight

func (s Screen) GameZoneHeight() int

func (Screen) GameZoneWidth

func (s Screen) GameZoneWidth() int

func (Screen) GameZoneXCenter

func (s Screen) GameZoneXCenter() int

func (Screen) GameZoneYCenter

func (s Screen) GameZoneYCenter() int

type Set

type Set struct {
	StartTime     time.Time
	EndTime       time.Time
	PlayerLScore  int
	PlayerRScore  int
	PlayerSideWin PlayerSide
	XSpeed        float32
}

func (Set) Duration

func (s Set) Duration() string

func (Set) HasWin

func (s Set) HasWin(player Player) bool

func (Set) Speed

func (s Set) Speed() float32

func (Set) SpeedFormat

func (s Set) SpeedFormat() string

type State

type State int
const (
	PauseGame State = iota
	PlayerLLostBall
	PlayerRLostBall
	PlayGame
	ResumeGame
	StartGame
	WinGame
)

func ToState

func ToState(s string) State

func (State) PlayerLostBall

func (s State) PlayerLostBall() bool

func (State) String

func (s State) String() string

type Win

type Win struct {
	Sets         []*Set
	Score        int
	SetScore     int
	SetGapWScore int
}

Jump to

Keyboard shortcuts

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