Documentation
¶
Overview ¶
Package gosge is a opinionated 2D only game engine that use an ECS
gosge uses https://github.com/juan-medina/goecs) and https://github.com/gen2brain/raylib-go, the go port of https://www.raylib.com/ for rendering and device manager
Example ¶
Simple Usage
/* * Copyright (c) 2020 Juan Medina. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package main import ( "github.com/juan-medina/gosge" "github.com/juan-medina/gosge/components/color" "github.com/juan-medina/gosge/components/geometry" "github.com/juan-medina/gosge/components/ui" "github.com/juan-medina/gosge/options" "log" ) // game options var opt = options.Options{ Title: "Hello Game", BackGround: color.Black, } const ( fontName = "resources/go_regular.fnt" fontSize = 100 ) var ( // designResolution is how our game is designed designResolution = geometry.Size{Width: 1920, Height: 1080} ) // Simple Usage func main() { if err := gosge.Run(opt, loadGame); err != nil { log.Fatalf("error running the game: %v", err) } } func loadGame(eng *gosge.Engine) error { // Preload font if err := eng.LoadFont(fontName); err != nil { return err } // get the ECS world world := eng.World() // gameScale from the real screen size to our design resolution gameScale := eng.GetScreenSize().CalculateScale(designResolution) // add the centered text world.AddEntity( ui.Text{ String: "Hello World", HAlignment: ui.CenterHAlignment, VAlignment: ui.MiddleVAlignment, Font: fontName, Size: fontSize * gameScale.Min, }, geometry.Point{ X: designResolution.Width / 2 * gameScale.Point.X, Y: designResolution.Height / 2 * gameScale.Point.Y, }, color.White, ) return nil }
Output:
Index ¶
- func Run(opt options.Options, init InitFunc) error
- type Engine
- func (e *Engine) AddGameStage(name string, init InitFunc)
- func (e Engine) GeTiledMapSize(name string) (size geometry.Size, err error)
- func (e *Engine) GetScreenSize() geometry.Size
- func (e *Engine) GetSpriteSize(sheet string, name string) (geometry.Size, error)
- func (e *Engine) Listener(_ *goecs.World, event interface{}, _ float32) error
- func (e Engine) LoadFont(fileName string) error
- func (e Engine) LoadMusic(filename string) error
- func (e Engine) LoadSound(filename string) error
- func (e Engine) LoadSprite(filename string, pivot geometry.Point) error
- func (e *Engine) LoadSpriteSheet(fileName string) error
- func (e Engine) LoadTiledMap(filename string) error
- func (e Engine) MeasureText(font string, str string, size float32) (result geometry.Size, err error)
- func (e *Engine) Run() error
- func (e *Engine) SetBackgroundColor(color color.Solid)
- func (e Engine) SpriteAtContains(spr sprite.Sprite, at geometry.Point, point geometry.Point) bool
- func (e Engine) SpritesCollides(spr1 sprite.Sprite, at1 geometry.Point, spr2 sprite.Sprite, at2 geometry.Point) bool
- func (e *Engine) World() *goecs.World
- type InitFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is our game engine
func (*Engine) AddGameStage ¶
AddGameStage adds a new game stage to our game with the given name, for changing to that stage send a events.ChangeStage
func (Engine) GeTiledMapSize ¶
GeTiledMapSize returns the geometry.Size of a given tile map
func (*Engine) GetScreenSize ¶
GetScreenSize returns the current screen size
func (*Engine) GetSpriteSize ¶
GetSpriteSize returns the geometry.Size of a given sprite
func (Engine) LoadSprite ¶
LoadSprite preloads a single sprite.Sprite
func (*Engine) LoadSpriteSheet ¶
LoadSpriteSheet preloads a sprite.
func (Engine) LoadTiledMap ¶
LoadTiledMap preload a tiled map
func (Engine) MeasureText ¶
func (e Engine) MeasureText(font string, str string, size float32) (result geometry.Size, err error)
MeasureText return the geometry.Size of a string with a defined size and spacing
func (*Engine) SetBackgroundColor ¶
SetBackgroundColor changes the current background color.Solid
func (Engine) SpriteAtContains ¶
SpriteAtContains indicates if a sprite.Sprite at a given geometry.Point contains a geometry.Point
Directories
¶
Path | Synopsis |
---|---|
Package components contains the components already defined
|
Package components contains the components already defined |
animation
Package animation are the components for running and sprite.Sprite animations
|
Package animation are the components for running and sprite.Sprite animations |
audio
Package audio are the components for audio and music
|
Package audio are the components for audio and music |
color
Package color handles Color components
|
Package color handles Color components |
device
Package device include device related types
|
Package device include device related types |
effects
Package effects include different components for adding effects
|
Package effects include different components for adding effects |
geometry
Package geometry handle components with geometry concepts
|
Package geometry handle components with geometry concepts |
shapes
Package shapes contains various drawable shapes
|
Package shapes contains various drawable shapes |
sprite
Package sprite handle the Sprite component
|
Package sprite handle the Sprite component |
tiled
Package tiled has the components for adding tiled maps to our game
|
Package tiled has the components for adding tiled maps to our game |
ui
Package ui contains the components for displaying ui elements
|
Package ui contains the components for displaying ui elements |
Package events contain the events for our engine
|
Package events contain the events for our engine |
examples
|
|
Package managers contains the managers for the engine
|
Package managers contains the managers for the engine |
ray
Package ray is the managers.Device implementation using raylib
|
Package ray is the managers.Device implementation using raylib |
Package options contains our game Options
|
Package options contains our game Options |