Documentation

Index

Constants

View Source
const (
	ScreenWidth  = 420
	ScreenHeight = 600
)

Variables

This section is empty.

Functions

func MoveTiles

func MoveTiles(tiles map[*Tile]struct{}, size int, dir Dir) bool

    MoveTiles moves tiles in the given tiles map if possible. MoveTiles returns true if there are tiles that are to move, otherwise false.

    When MoveTiles is called, all tiles must not be about to move.

    Types

    type Board

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

      Board represents the game board.

      func NewBoard

      func NewBoard(size int) (*Board, error)

        NewBoard generates a new Board with giving a size.

        func (*Board) Draw

        func (b *Board) Draw(boardImage *ebiten.Image)

          Draw draws the board to the given boardImage.

          func (*Board) Move

          func (b *Board) Move(dir Dir) error

            Move enqueues tile moving tasks.

            func (*Board) Size

            func (b *Board) Size() (int, int)

              Size returns the board size.

              func (*Board) Update

              func (b *Board) Update(input *Input) error

                Update updates the board state.

                type Dir

                type Dir int

                  Dir represents a direction.

                  const (
                  	DirUp Dir = iota
                  	DirRight
                  	DirDown
                  	DirLeft
                  )

                  func (Dir) String

                  func (d Dir) String() string

                    String returns a string representing the direction.

                    func (Dir) Vector

                    func (d Dir) Vector() (x, y int)

                      Vector returns a [-1, 1] value for each axis.

                      type Game

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

                        Game represents a game state.

                        func NewGame

                        func NewGame() (*Game, error)

                          NewGame generates a new Game object.

                          func (*Game) Draw

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

                            Draw draws the current game to the given screen.

                            func (*Game) Layout

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

                              Layout implements ebiten.Game's Layout.

                              func (*Game) Update

                              func (g *Game) Update() error

                                Update updates the current game state.

                                type Input

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

                                  Input represents the current key states.

                                  func NewInput

                                  func NewInput() *Input

                                    NewInput generates a new Input object.

                                    func (*Input) Dir

                                    func (i *Input) Dir() (Dir, bool)

                                      Dir returns a currently pressed direction. Dir returns false if no direction key is pressed.

                                      func (*Input) Update

                                      func (i *Input) Update()

                                        Update updates the current input states.

                                        type Tile

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

                                          Tile represents a tile information including TileData and animation states.

                                          func NewTile

                                          func NewTile(value int, x, y int) *Tile

                                            NewTile creates a new Tile object.

                                            func (*Tile) Draw

                                            func (t *Tile) Draw(boardImage *ebiten.Image)

                                              Draw draws the current tile to the given boardImage.

                                              func (*Tile) IsMoving

                                              func (t *Tile) IsMoving() bool

                                                IsMoving returns a boolean value indicating if the tile is animating.

                                                func (*Tile) NextPos

                                                func (t *Tile) NextPos() (int, int)

                                                  NextPos returns the tile's next position. NextPos is used only at testing so far.

                                                  func (*Tile) NextValue

                                                  func (t *Tile) NextValue() int

                                                    NextValue returns the tile's current value. NextValue is used only at testing so far.

                                                    func (*Tile) Pos

                                                    func (t *Tile) Pos() (int, int)

                                                      Pos returns the tile's current position. Pos is used only at testing so far.

                                                      func (*Tile) Update

                                                      func (t *Tile) Update() error

                                                        Update updates the tile's animation states.

                                                        func (*Tile) Value

                                                        func (t *Tile) Value() int

                                                          Value returns the tile's current value. Value is used only at testing so far.

                                                          type TileData

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

                                                            TileData represents a tile information like a value and a position.