macaw

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

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

Go to latest
Published: Nov 26, 2018 License: Zlib Imports: 10 Imported by: 4

README

Macaw Build Status Coverage Status GoDoc Go Report Card

Macaw is a 2D Game Engine using SDL2. Macaw is written in Go with the ECS architecture pattern.

Demo

Installation and requirements

  • Go: https://golang.org/dl/
  • SDL2: You will need to install SDL2 in your machine and the binding for Go. You can find more information on how to install on your OS here: https://github.com/veandco/go-sdl2 Also, make sure if you are compiling from source code to enable CGO (export CGO_ENABLED=1)
  • Macaw framework: go get github.com/tubelz/macaw

Usage

You can find a working example in the repository https://github.com/tubelz/pong-macaw/ That example covers many functionalities such as:

  • Initialization
  • Game loop
  • Usage of entities, components and systems (ECS)
  • Scene
  • Camera
  • Observers
  • Creating a new system
  • Fonts
  • Input handler

A more complex (and fun) example can be found in https://github.com/tubelz/crazybird !

Building with Docker

You can check the crazybird example to see how games can be built with docker.

A simple example, though, involves three steps:

  1. Pulling the docker image (docker pull rennomarcus/macaw:latest)
  2. Running in interactive mode (docker run -it rennomarcus/macaw:latest)
  3. Build the application with a simple command go build .. Now you have a game built without installing any depency (other than docker)

Discussion (issues/suggestions)

If you have questions, suggestions, or just want to chat about our Game Engine you can go to use the Discord app and join our server: https://discord.gg/SXQYsdK

If there is a bug you can open an issue here. Your input is fundamental for the project's success. :)

Contributing

There's always something to be worked on! Don't be afraid to open an issue or submit a PR. Please check the contributing guide for more information!

License

The code here is under the zlib license. You can read more here

Documentation

Overview

Package macaw provides some of the core concepts required by the game engine Macaw. To create our games we are still require to use other internal packages: entity, system, and input.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Window is the window of our game
	Window *sdl.Window
	// WinWidth has the default screen width
	WinWidth = int32(800)
	// WinHeight has the default screen height
	WinHeight = int32(600)
	// WinTitle has the default screen title
	WinTitle = "Macaw"
)

We only have one input manager for now and one window, so they are going to be globals

Functions

func Initialize

func Initialize() error

Initialize initialize SDL libraries

func PlayMusic

func PlayMusic(file string)

PlayMusic plays the file and leave it as background music

func PlaySound

func PlaySound(file string) error

PlaySound plays the file once

func Quit

func Quit()

Quit cleans up all initialized subsystems

func QuitFont

func QuitFont()

QuitFont unloads libraries loaded with ttf.Init()

func QuitImg

func QuitImg()

QuitImg unloads libraries loaded with img.Init()

func QuitSound

func QuitSound()

QuitSound close open files and unloads libraries loaded with mix.Init()

func SetFullscreen

func SetFullscreen(flags uint32)

SetFullscreen changes the Window's fullscreen state Flags are: sdl.WINDOW_FULLSCREEN (0x00000001) - for "real" fullscreen with a videomode change sdl.WINDOW_FULLSCREEN_DESKTOP (sdl.WINDOW_FULLSCREEN | 0x00001000) - for "fake" fullscreen that takes the size of the desktop 0 - window mode

func StopMusic

func StopMusic()

StopMusic stops the music

Types

type GameLoop

type GameLoop struct {
	InputManager *input.Manager
	SceneManager
	// contains filtered or unexported fields
}

GameLoop is the data structure which will execute our systems in order. inspired by http://www.koonsolo.com/news/dewitters-gameloop/

func (*GameLoop) Run

func (g *GameLoop) Run()

Run executes the game loop

type Scene

type Scene struct {
	Name          string
	UpdateSystems []system.Systemer    // responsible to update the game
	RenderSystem  *system.RenderSystem // responsible to render the game
	InitFunc      func()
	ExitFunc      func()
	SceneOptions
}

Scene is responsible to hold the systems in a scene

func (*Scene) AddGameUpdateSystem

func (s *Scene) AddGameUpdateSystem(system system.Systemer)

AddGameUpdateSystem adds the systems which will run in the game loop

func (*Scene) AddRenderSystem

func (s *Scene) AddRenderSystem(system *system.RenderSystem)

AddRenderSystem adds the render system to our game loop

func (*Scene) Exit

func (s *Scene) Exit()

Exit executes a function, if setted, when scene is excited

func (*Scene) Init

func (s *Scene) Init()

Init initializes the scene according to the options

type SceneManager

type SceneManager struct {
	Scenes []*Scene

	// SceneMap has the position of the scene in the array
	SceneMap map[string]int
	// contains filtered or unexported fields
}

SceneManager manges the scenes in the game

func (*SceneManager) AddScene

func (s *SceneManager) AddScene(scene *Scene)

AddScene adds a new scene

func (*SceneManager) ChangeScene

func (s *SceneManager) ChangeScene(sceneName string) *Scene

ChangeScene changes to a specific scene by its name

func (*SceneManager) Current

func (s *SceneManager) Current() *Scene

Current returns the current Scene

func (*SceneManager) NextScene

func (s *SceneManager) NextScene() *Scene

NextScene goes to the next scene if it exists

func (*SceneManager) RemoveScene

func (s *SceneManager) RemoveScene()

RemoveScene removes a scene

type SceneOptions

type SceneOptions struct {
	HideCursor bool // true - hides, false - shows
	Music      string
	BgColor    sdl.Color
}

SceneOptions contains the options for the scene

Directories

Path Synopsis
Package cmd is used to parse the command line arguments.
Package cmd is used to parse the command line arguments.
Package entity provides the entity manager, spritesheet and font structure, and some built-in components.
Package entity provides the entity manager, spritesheet and font structure, and some built-in components.
Package input provides a wrapper to handle user input events (keyboard and mouse for now).
Package input provides a wrapper to handle user input events (keyboard and mouse for now).
internal
utils
Package utils contains some internal tools we use in macaw.
Package utils contains some internal tools we use in macaw.
Package math provides structures and functions to handle mathematical functions.
Package math provides structures and functions to handle mathematical functions.
Package system provides the interface used in the game engine, messaging between systems, and some built in systems.
Package system provides the interface used in the game engine, messaging between systems, and some built in systems.

Jump to

Keyboard shortcuts

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