gosge

module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: Apache-2.0

README

gosge

Go Simple Game Engine using an ECS

go version godoc Build Status conduct

Info

gosge is an opinionated 2D only game engine the uses GOECS for easily develop games with an ECS paradigm.

Internally uses the go port of raylib for most of the device functionalities, including rendering.

Simple Hello World

package main

import (
	"github.com/juan-medina/goecs/pkg/entity"
	"github.com/juan-medina/gosge/pkg/components/color"
	"github.com/juan-medina/gosge/pkg/components/geometry"
	"github.com/juan-medina/gosge/pkg/components/text"
	"github.com/juan-medina/gosge/pkg/engine"
	"github.com/juan-medina/gosge/pkg/game"
	"github.com/juan-medina/gosge/pkg/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}
)

func main() {
	if err := game.Run(opt, loadGame); err != nil {
		log.Fatalf("error running the game: %v", err)
	}
}

func loadGame(eng engine.Engine) error {
	// Preload font
	if err := eng.LoadFont(fontName); err != nil {
		return err
	}

	// get the ECS world
	wld := eng.World()

	// gameScale from the real screen size to our design resolution
	gameScale := eng.GetScreenSize().CalculateScale(designResolution)

	// add the centered text
	wld.Add(entity.New(
		text.Text{
			String:     "Hello World",
			HAlignment: text.CenterHAlignment,
			VAlignment: text.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
}

Run examples

The examples are available on this folder, or can be run using make:

$ make run example=hello
$ make run example=eyes
$ make run example=layers
$ make run example=stages
$ make run example=animation

Alternatively you could run them with :

$ go run examples/hello/hello.go
$ go run examples/eyes/eyes.go
$ go run examples/layers/layers.go
$ go run examples/stages/stages.go
$ go run examples/animation/animation.go

Requirements

Ubuntu
X11
apt-get install libgl1-mesa-dev libxi-dev libxcursor-dev libxrandr-dev libxinerama-dev
Wayland
apt-get install libgl1-mesa-dev libwayland-dev libxkbcommon-dev
Fedora
X11
dnf install mesa-libGL-devel libXi-devel libXcursor-devel libXrandr-devel libXinerama-devel
Wayland
dnf install mesa-libGL-devel wayland-devel libxkbcommon-devel
macOS

On macOS, you need Xcode or Command Line Tools for Xcode.

Windows

On Windows, you need C compiler, like Mingw-w64 or TDM-GCC. You can also build binary in MSYS2 shell.

Installation

go get -v -u github.com/juan-medina/gosge

Build Tags

  • opengl21 : uses OpenGL 2.1 backend (default is 3.3)
  • wayland : builds against Wayland libraries

Examples Resources

Directories

Path Synopsis
examples
Package internal are the internal packages
Package internal are the internal packages
engine
Package engine internal engine implementation
Package engine internal engine implementation
render
Package render device rendering implementation
Package render device rendering implementation
render/ray
Package ray the implementation of render.Render for raylib
Package ray the implementation of render.Render for raylib
storage
Package storage x
Package storage x
systems
Package systems are the world.System for the engine
Package systems are the world.System for the engine
pkg
Package pkg holds the public API for gosge
Package pkg holds the public API for gosge
components
Package components contains the components already defined
Package components contains the components already defined
components/animation
Package animation are the components for running and sprite.Sprite animations
Package animation are the components for running and sprite.Sprite animations
components/color
Package color handles Color components
Package color handles Color components
components/device
Package device include device related types
Package device include device related types
components/effects
Package effects include different components for adding effects
Package effects include different components for adding effects
components/geometry
Package geometry handle components with geometry concepts
Package geometry handle components with geometry concepts
components/shapes
Package shapes contains various drawable shapes
Package shapes contains various drawable shapes
components/sprite
Package sprite handle the Sprite component
Package sprite handle the Sprite component
components/ui
Package ui contains the components for displaying ui elements
Package ui contains the components for displaying ui elements
engine
Package engine contains the definition of the Engine
Package engine contains the definition of the Engine
events
Package events contain the events for our engine
Package events contain the events for our engine
game
Package game handling the creation of a game
Package game handling the creation of a game
options
Package options contains our game Options
Package options contains our game Options

Jump to

Keyboard shortcuts

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