engine

package
v0.0.0-...-8afbcd3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package engine provides the "engine" that builds on top of ebiten and is used to implemente the game.

Index

Constants

This section is empty.

Variables

View Source
var (
	Debug *log.Logger
)

Functions

func InitLogger

func InitLogger(debug bool)

Types

type Control

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

Control handles the control methods (keyboard and gamepad). Up, Down, ... methods will always report the keyboard state and, when available, the gamepad state.

func (*Control) A

func (c *Control) A() bool

func (*Control) B

func (c *Control) B() bool

func (*Control) CheckGamepad

func (c *Control) CheckGamepad()

CheckGamepad checks when a gamepad is connected/disconnected. This should be run ideally once per frame.

func (*Control) Down

func (c *Control) Down() bool

func (*Control) IsGamepadDisconnected

func (c *Control) IsGamepadDisconnected() bool

IsGamepadDisconnected will returh true if the gampad was disconnected. In order to return true, it had to be connected at some point.

func (*Control) Left

func (c *Control) Left() bool

func (*Control) Right

func (c *Control) Right() bool

func (*Control) Select

func (c *Control) Select() bool

func (*Control) Start

func (c *Control) Start() bool

func (*Control) Up

func (c *Control) Up() bool

type Loader

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

Loader is a simple resource loader supporting files and zip achives.

func NewLoader

func NewLoader(path string) (*Loader, error)

NewLoader creates a new loader using path as location for the assets. If the path ends in ".pak", it will be opened as a zip archive.

func (*Loader) Close

func (l *Loader) Close() error

Close closes the loader. Only required if an archive is used. Once the loader is closed, it shouldn't be used again.

func (*Loader) LoadFont

func (l *Loader) LoadFont(name string, scale int) (font.Face, error)

LoadFont loads a font into a font.Dace using the resource name. Scale is a factor applied to size 8.

func (*Loader) LoadImage

func (l *Loader) LoadImage(name string) (*ebiten.Image, error)

LoadImage loads an image into an ebiten.Image using the resource name. This can be loaded from disk (from assets/ directory) or a zip archive.

type Scene

type Scene interface {
	Update(control *Control) error
	Draw(screen *ebiten.Image)
}

Scene interface describes a scene managed by the scene manager. It is similar to a ebiten.Game, only that the Layout method is not required.

Update doesn't need to call CheckGamepad on control, that happens on the manager itelf.

type SceneManager

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

SceneManager implement a wrapper around scenes. Implements a stack of scenes.

var (
	SceneMan SceneManager
)

func (*SceneManager) Draw

func (s *SceneManager) Draw(screen *ebiten.Image)

Draw calls update on current scene.

func (*SceneManager) Layout

func (s *SceneManager) Layout(outsideWidth int, outsideHeight int) (int, int)

Layout will set the layout on ebiten.

func (*SceneManager) PopScene

func (s *SceneManager) PopScene() Scene

PopScene removes the current scene.

func (*SceneManager) PushScene

func (s *SceneManager) PushScene(scene Scene)

PushScene adds a scene to the stack. That scene is the new current (active) scene.

func (*SceneManager) SetLayout

func (s *SceneManager) SetLayout(screenWidth int, screenHeight int)

SetLayout sets the with and height of the internal screen. screenWidth defaults to 320 pixels. screenHeight defaults to 240 pixels.

func (*SceneManager) Update

func (s *SceneManager) Update() error

Update calls update on current scene. It calls control's CheckGamepad, so the Update method on the scene shouldn't need to call it.

Jump to

Keyboard shortcuts

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