tmgang

package module
v0.0.0-...-17bdda6 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

TerMinal (based) GAme eNGine

A Terminal based Game Engine.

Well... not quite. It's just a bunch of drawable entities and an opinionated way of running the functions. Some would call it a package!

Dependencies

This package is based on github.com/gdamore/tcell and its underlying dependencies.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicMenu

type BasicMenu struct {
	RectArea
	Style tcell.Style

	MenuItems       []string
	CurrentSelected int
}

BasicMenu will, given some options, allow selection with a * pointer.

func (*BasicMenu) Draw

func (bm *BasicMenu) Draw(s tcell.Screen, camera Coordinates, _, _ float32)

func (*BasicMenu) ProcessKeyEvent

func (bm *BasicMenu) ProcessKeyEvent(e *tcell.EventKey, camera Coordinates)

type BasicText

type BasicText struct {
	RectArea
	TextStyle tcell.Style
	Content   string
}

BasicText writes bounded unscrollable text

func (*BasicText) Draw

func (t *BasicText) Draw(s tcell.Screen, camera Coordinates, _, _ float32)

type Coordinates

type Coordinates struct {
	X int
	Y int
}

Coordinates of a position

type Engine

type Engine interface {
	Configure(*EngineOpts)
	ScreenSize() (int, int)
	Run(context.Context) error
}

The engine will Run your game.

Yes.

func NewEngine

func NewEngine() (Engine, error)

type EngineOpts

type EngineOpts struct {
	Fps          uint32
	InitialState StateKey
	StateMachine map[StateKey]State
	Overlays     []Overlay
}

type Entity

type Entity interface {
	Draw(s tcell.Screen, camera Coordinates, ratioX, ratioY float32)
}

Entity is the base of any game.

You will draw entities on your TUI to display your game. Any resize from the starting screen size will change the ratioX and ratioY variables.

type FlexChatBox

type FlexChatBox struct {
	RectArea

	OriginalRect RectArea

	Style tcell.Style

	Content []string
	// contains filtered or unexported fields
}

FlexChatBox writes bounded "scrollable" text when the Space key is pressed.

func (*FlexChatBox) Draw

func (r *FlexChatBox) Draw(s tcell.Screen, camera Coordinates, ratioX, ratioY float32)

func (*FlexChatBox) ProcessKeyEvent

func (r *FlexChatBox) ProcessKeyEvent(e *tcell.EventKey, camera Coordinates)

type FlexRectangle

type FlexRectangle struct {
	RectArea

	OriginalRect                 RectArea
	BackgroundStyle, BorderStyle tcell.Style
	// contains filtered or unexported fields
}

FlexRectangle is a basic drawing entitiy that adjusts with the resize

func (*FlexRectangle) Draw

func (r *FlexRectangle) Draw(s tcell.Screen, camera Coordinates, ratioX, ratioY float32)

type InteractiveEntity

type InteractiveEntity interface {
	ProcessKeyEvent(e *tcell.EventKey, camera Coordinates)
}

InteractiveEntity is a special entitity that processes events.

These entities will attempt to process keyboard events if they are currently displayed on the screen. As a game developer you create entities that implement this interface and give them to a state.

type Overlay

type Overlay interface {
	Draw(s tcell.Screen)
}

Overlays are entities that are drawn at the end, regardless of camera position.

type RectArea

type RectArea struct {
	Coordinates
	Width  int
	Height int
}

RectArea defines top left and dimensions of any rectangle area based entitiy.

type State

type State interface {
	GetDrawables() []Entity
	GetInteractables() []InteractiveEntity
	GetTimers() []TimeEntity
	GetCamera() Coordinates
	NextState() StateKey
}

State definition of the game state machine.

Any computing can be summarized by a state machine. A game, similarly so. This is the core definition of the states in the state machine. A state will be drawn (and interacted with), based on camera position theoretically infinite area the state spans (i.e., position of its entities).

type StateKey

type StateKey string

type StrictRectangle

type StrictRectangle struct {
	RectArea
	Style tcell.Style
}

StrictRectangle is the basic drawing entitiy.

func (*StrictRectangle) Draw

func (r *StrictRectangle) Draw(s tcell.Screen, camera Coordinates, _, _ float32)

type TimeEntity

type TimeEntity interface {
	ProcessFrameDuration(d time.Duration, camera Coordinates)
}

TimeEntity is a special entitity that processes the passage of time.

These entities will attempt to process the passage of time for each frame, an example for such usage would be for entities that have a speed associated with them.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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