Documentation ¶
Index ¶
- Variables
- type Anim
- type Imager
- type InvalidFrameWidthError
- type Room
- type State
- func (s *State) AddRoom(name string, room Room)
- func (s State) Bounds() image.Rectangle
- func (s State) Draw(img Imager, dst image.Point)
- func (s *State) EnterRoom(name string)
- func (s State) Fill(r image.Rectangle, c color.Color)
- func (s State) Frame() int
- func (s *State) KeyDown(code key.Code) bool
- func (s *State) KeyPress(code key.Code) bool
- func (s State) LoadAnim(r io.Reader, frameW int) (*Anim, error)
- func (s State) Publish()
- func (s *State) Run(opts *StateOptions, init func() bool) (reterr error)
- type StateOptions
Constants ¶
This section is empty.
Variables ¶
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) Start ¶
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.
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 ¶
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 (*State) AddRoom ¶
AddRoom adds a room to the game, or overwrites an existing room if one named name already exists.
func (*State) KeyPress ¶
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 ¶
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.