oak

A pure Go game engine

Github星跟蹤圖

Oak

A pure Go game engine

GoDoc
Go Report Card
Code Coverage
Mentioned in Awesome Go

Table of Contents

  1. Installation

  2. Motivation

  3. Features

  4. Support

  5. Quick Start

  6. Implementation and Examples

  7. Finished Games


Installation

go get -u github.com/oakmound/oak/v2...

Or in GOPATH mode (not using go modules):

go get -u github.com/oakmound/oak/...

Motivation

The initial version of oak was made to support Oakmound Studio's game,
Agent Blue, and was developed in parallel.
Oak supports Windows with no dependencies and Linux with limited audio dependencies. We don't own a machine to check with, but hypothetically it supports OSX as well.
We hope that users will be able to make great pure Go games with oak and welcome improvements.

Because Oak wants to have as few non-Go dependencies as possible, Oak does not use OpenGL or GLFW.
We're open to adding support for these in the future for performance gains, but we always want
an alternative that requires zero or near-zero dependencies.

Features

  1. Window Rendering
    • Windows and key events forked from shiny
    • Logical frame rate distinct from Draw rate
    • Fullscreen, Window Positioning support
    • Auto-scaling for screen size changes
  2. Image Management
    • render.Renderable interface
    • Sprite Sheet Batch Loading at startup
    • Manipulation
      • render.Modifiable interface
      • Built in Transformations and Filters
      • Some built-ins via gift
      • Extensible Modification syntax func(image.Image) *image.RGBA
    • Built in Renderable types covering common use cases
      • Sprite, Sequence, Switch, Composite
      • Primitive builders, ColorBox, Line, Bezier
      • History-tracking Reverting
    • Primarily 2D
  3. Particle System
    • particles!

  4. Mouse Handling
    • Click Collision
    • MouseEnter / MouseExit reaction events
    • Drag Handling
  5. Joystick Support
    • particles!

  6. Audio Support
    • Positional filters to pan and scale audio based on a listening position
  7. Collision
    • Collision R-Tree forked from rtreego
    • 2D Raycasting
    • Collision Spaces
      • Attachable to Objects
      • Auto React to collisions through events
      • OnHit bindings func(s1,s2 *collision.Space)
      • Start/Stop collision with targeted objects
  8. 2D Physics System
    • Vectors
      • Attachable to Objects / Renderables
      • Friction
  9. Event Handler, Bus
    • PubSub system: event.CID can Bind(fn,eventName) and Trigger(eventName) events
  10. Shaping
    • Convert shapes into:
      • Containment checks
      • Outlines
      • 2D arrays
  11. Custom Console Commands
  12. Logging
    • Swappable with custom implementations
    • Default Implementation: 4 log levels, writes to file and stdout

Support

For discussions not significant enough to be an Issue or PR, see the #oak channel on the gophers slack.

Quick Start

This is an example of the most basic oak program:


oak.Add("firstScene",
    // Initialization function
    func(prevScene string, inData interface{}) {}, 
    // Loop to continue or stop the current scene
    func() bool {return true}, 
    // Exit to transition to the next scene
    func() (nextScene string, result *scene.Result) {return "firstScene", nil}) 
oak.Init("firstScene")

See the examples folder for longer demos, godoc for reference documentation, and the wiki for more guided feature sets, tutorials and walkthroughs.

Implementation and Examples

Platformer

Platformer

Build up to having a simple platforming game by doing the following: Setup a character, get it to move, set basic gravity, get it to jump, make it only jump on solid ground, put it all together.


char := entities.NewMoving(100, 100, 16, 32,
	render.NewColorBox(16, 32, color.RGBA{255, 0, 0, 255}),
nil, 0, 0)

char.Bind(func(id int, nothing interface{}) int {
	char := event.GetEntity(id).(*entities.Moving)

	// Move left and right with A and D
	if oak.IsDown(key.A) {
		char.Delta.SetX(-char.Speed.X())
	} else if oak.IsDown(key.D) {
		char.Delta.SetX(char.Speed.X())
	} else {
		char.Delta.SetX(0)
	}
	oldX, oldY := char.GetPos()
    char.ShiftPos(char.Delta.X(), char.Delta.Y())
	return 0
}, event.Enter)

Top Down Shooter

Learn to use the collision library and make short term shots that collide with the entites marked with collision labels.

Shoota

Radar

Often times you might want to create a minimap or a radar for a game, check out this example for a barebones implementation

Radar

Slideshow

A different way to use the oak engine.

Slideshow

Examples of Finished Games

Agent Blue

AgentBlue

Fantastic Doctor

Fantastic Overview

Fantastic Overview 2

Jeremy The Clam

Clammy

主要指標

概覽
名稱與所有者oakmound/oak
主編程語言Go
編程語言Go (語言數: 5)
平台
許可證Apache License 2.0
所有者活动
創建於2017-07-15 16:24:27
推送於2025-02-16 18:03:09
最后一次提交2025-01-19 11:28:28
發布數43
最新版本名稱v4.1.1 (發布於 )
第一版名稱v1.0.0 (發布於 )
用户参与
星數1.6k
關注者數41
派生數83
提交數2k
已啟用問題?
問題數133
打開的問題數13
拉請求數83
打開的拉請求數1
關閉的拉請求數11
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?