engine

package
v0.0.0-...-171b251 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2016 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultStateOptions = StateOptions{
	Width:  640,
	Height: 480,
	FPS:    60,
}

DefaultStateOptions are the options used if NewState is passed nil.

Functions

This section is empty.

Types

type Anim

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

Anim is an animated image. An Anim can also be a static image by simply having a single frame. An Anim is normally initialized by a State.

func (*Anim) Copy

func (anim *Anim) Copy() *Anim

Copy returns a new Anim which references the same image in memory.

func (*Anim) Frames

func (anim *Anim) Frames() int

Frames returns the number of frames in the animation.

func (*Anim) Image

func (anim *Anim) Image() (screen.Texture, image.Rectangle)

func (*Anim) Size

func (anim *Anim) Size() image.Point

Size returns the size of one frame of the animation.

func (*Anim) Start

func (anim *Anim) Start(delay time.Duration, loop bool)

Start starts the animation, delaying by the specified amount between frames. If the animation has already been started, it adjusts the delay of the running animation.

If loop is true, then the animation will loop; otherwise, it will stop the animation on the last frame. If the animation is already running, loop has no effect.

func (*Anim) Stop

func (anim *Anim) Stop()

Stop stops the running animation. If the animation isn't currently running, it does nothing.

type Imager

type Imager interface {
	// Image returns a texture and a clipping rectangle.
	Image() (screen.Texture, image.Rectangle)
}

Imager is a type that can represent itself as a piece of a texture.

type InvalidFrameWidthError

type InvalidFrameWidthError struct {
	ImageW int
	FrameW int
}

func (InvalidFrameWidthError) Error

func (err InvalidFrameWidthError) Error() string

type Room

type Room interface {
	Enter()
	Update()
}

Room represents a room of the game. This can be almost anything, from a menu, to a level, to credits.

type State

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

State is the main struct of the engine. It keeps track of pretty much everything, as well as running the actual game.

func NewState

func NewState() *State

NewState initializes a new state.

func (*State) AddRoom

func (s *State) AddRoom(name string, room Room)

AddRoom adds a room to the game, or overwrites an existing room if one named name already exists.

func (State) Bounds

func (s State) Bounds() image.Rectangle

Bounds returns the screen's bounds.

func (State) Draw

func (s State) Draw(img Imager, dst image.Point)

Draw draws an image onto the screen at the specified point.

func (*State) EnterRoom

func (s *State) EnterRoom(name string)

EnterRoom switches to the room named name, calling its Enter() method.

func (State) Fill

func (s State) Fill(r image.Rectangle, c color.Color)

Fill fills r with c on the screen.

func (State) Frame

func (s State) Frame() int

Frame returns the current frame of the game, with 0 being the initial frame.

func (*State) KeyDown

func (s *State) KeyDown(code key.Code) bool

KeyDown returns whether or not a specific key is currently being held down.

func (*State) KeyPress

func (s *State) KeyPress(code key.Code) bool

KeyPress returns true the first time it is called after the key represented by code is pressed, but returns false for that key until the key is released and then pressed again.

func (State) LoadAnim

func (s State) LoadAnim(r io.Reader, frameW int) (*Anim, error)

LoadAnim loads an animation from r with the given frame width. The width of the image loaded must be evenly divisible by the frame width.

func (State) Publish

func (s State) Publish()

Publish updates the screen. Changes to the screen are not guarunteed to actually appear until Publish() has been called.

func (*State) Run

func (s *State) Run(opts *StateOptions, init func() bool) (reterr error)

Run starts the game. It blocks until an unrecoverable error occurs or until the game otherwise exits.

Before the game enters the mainloop, init is called. If init returns false, the game exits. init may be nil.

type StateOptions

type StateOptions struct {
	// The width and height of the screen.
	Width  int
	Height int

	// The target FPS of the game.
	//
	// TODO: Make it possible to remove the FPS cap.
	FPS int
}

StateOptions are options for initializing a State.

Jump to

Keyboard shortcuts

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