sh2d

package module
v0.0.0-...-d637fd6 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: MIT Imports: 6 Imported by: 3

README

sh2d

Basic Entity-Component-System to make simple 2D games in GO.
Serves as base for a game that is currently in development.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetWindowHeight

func GetWindowHeight() int

GetWindowHeight GetWindowHeight

func GetWindowName

func GetWindowName() string

GetWindowName GetWindowName

func GetWindowWidth

func GetWindowWidth() int

GetWindowWidth GetWindowWidth

func SetActiveScene

func SetActiveScene(newScene *Scene)

SetActiveScene SetActiveScene

Types

type Component

type Component interface {
	Update(delta int64) error
	Draw(screen *ebiten.Image) error
}

Component asd

type GameObject

type GameObject struct {
	Position   geometry2d.Vector2D
	Rotation   float64
	Active     bool
	Components []Component
}

GameObject is a generic type all elements in the game should inherit

func (*GameObject) AddComponent

func (g *GameObject) AddComponent(newComponent Component)

AddComponent adds a new component to the game object

func (*GameObject) Draw

func (g *GameObject) Draw(screen *ebiten.Image) error

Draw draws all components to screen

func (*GameObject) GetComponent

func (g *GameObject) GetComponent(withType Component) Component

GetComponent gets a component of the speciied type

func (*GameObject) Update

func (g *GameObject) Update(delta int64) error

Update updates all conmponents

type Gameloop

type Gameloop struct {
}

Gameloop implements ebiten.Gameloop interface.

func NewGame

func NewGame(screenWidth, screenHeight int, name string) *Gameloop

NewGame creates a new game

func (*Gameloop) Draw

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

Draw draws the game screen. Draw is called every frame (typically 1/60[s] for 60Hz display).

func (*Gameloop) Layout

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

Layout takes the outside size (e.g., the window size) and returns the (logical) screen size. If you don't have to adjust the screen size with the outside size, just return a fixed size.

func (*Gameloop) Update

func (g *Gameloop) Update(screen *ebiten.Image) error

Update proceeds the game state. Update is called every tick (1/60 [s] by default).

type Scene

type Scene struct {
	SceneElements []*GameObject
}

Scene contains all elements on screen

func GetActiveScene

func GetActiveScene() *Scene

GetActiveScene GetActiveScene

func (*Scene) AddChild

func (s *Scene) AddChild(child *GameObject)

AddChild adds new child to scene

func (*Scene) RemoveChild

func (s *Scene) RemoveChild(child *GameObject)

RemoveChild removes a given child from the scene

Directories

Path Synopsis
assets
Package assets generated by go-bindata.// sources: resources/player/Minigun_Large_png_processed.png resources/player/PlayerRed_Frame_01_png_processed.png resources/anim/explosion/Explosion02_Frame_01_png_processed.png resources/anim/explosion/Explosion02_Frame_02_png_processed.png resources/anim/explosion/Explosion02_Frame_03_png_processed.png resources/anim/explosion/Explosion02_Frame_04_png_processed.png resources/anim/explosion/Explosion02_Frame_05_png_processed.png resources/anim/explosion/Explosion02_Frame_06_png_processed.png resources/anim/explosion/Explosion02_Frame_07_png_processed.png resources/anim/explosion/Explosion02_Frame_08_png_processed.png resources/anim/explosion/Explosion02_Frame_09_png_processed.png resources/background/PixelBackgroundSeamless.png resources/enemy/Asteroid 01_png_processed.png resources/enemy/Asteroid 02_png_processed.png resources/enemy/Asteroid 03_png_processed.png resources/enemy/Asteroid 04_png_processed.png
Package assets generated by go-bindata.// sources: resources/player/Minigun_Large_png_processed.png resources/player/PlayerRed_Frame_01_png_processed.png resources/anim/explosion/Explosion02_Frame_01_png_processed.png resources/anim/explosion/Explosion02_Frame_02_png_processed.png resources/anim/explosion/Explosion02_Frame_03_png_processed.png resources/anim/explosion/Explosion02_Frame_04_png_processed.png resources/anim/explosion/Explosion02_Frame_05_png_processed.png resources/anim/explosion/Explosion02_Frame_06_png_processed.png resources/anim/explosion/Explosion02_Frame_07_png_processed.png resources/anim/explosion/Explosion02_Frame_08_png_processed.png resources/anim/explosion/Explosion02_Frame_09_png_processed.png resources/background/PixelBackgroundSeamless.png resources/enemy/Asteroid 01_png_processed.png resources/enemy/Asteroid 02_png_processed.png resources/enemy/Asteroid 03_png_processed.png resources/enemy/Asteroid 04_png_processed.png

Jump to

Keyboard shortcuts

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