Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## A Pure Go game engine

[![Go Reference](https://pkg.go.dev/badge/github.com/oakmound/oak/v4.svg)](https://pkg.go.dev/github.com/oakmound/oak/v4)
[![Code Coverage](https://codecov.io/gh/oakmound/oak/branch/develop/graph/badge.svg)](https://codecov.io/gh/oakmound/oak)
[![Code Coverage](https://codecov.io/gh/oakmound/oak/branch/master/graph/badge.svg)](https://codecov.io/gh/oakmound/oak)
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go)

## Table of Contents
Expand Down Expand Up @@ -55,7 +55,7 @@

## Support <a name="support"></a>

For discussions not significant enough to be an Issue or PR, feel free to ping us in the #oak channel on the [gophers slack](https://invite.slack.golangbridge.org/).
For discussions not significant enough to be an Issue or PR, feel free to ping us in the #oak channel on the [gophers slack](https://invite.slack.golangbridge.org/). For insight into what is happening in oak see the [blog](https://200sc.dev/).

## Quick Start <a name="quick-start"></a>

Expand All @@ -79,27 +79,28 @@ func main() {
}
```

See below or the [examples](examples) folder for longer demos, [godoc](https://pkg.go.dev/github.com/oakmound/oak/v4) for reference documentation, and the [wiki](https://github.com/oakmound/oak/wiki) for more guided tutorials and walkthroughs.
See below or navigate to the [examples](examples) folder for demos. For more examples and documentation checkout [godoc](https://pkg.go.dev/github.com/oakmound/oak/v4) for reference documentation, the [wiki](https://github.com/oakmound/oak/wiki), or our extended features in [grove](https://github.com/oakmound/grove).

## Examples <a name="examples"></a>

| | | |
|:-------------------------:|:-------------------------:|:-------------------------:|
|<img width="1400" src="examples/platformer-tutorial/6-complete/example.gif" a=examples/platformer-tutorial> [Platformer](examples/platformer-tutorial) | <img width="1400" src="examples/top-down-shooter-tutorial/6-performance/example.gif"> [Top down shooter](examples/top-down-shooter-tutorial)|<img width="1400" src="examples/radar-demo/example.gif"> [Radar](examples/radar-demo) |
|<img width="1400" src="examples/slide/example.gif"> [Slideshow](examples/slide) | <img width="1400" src="examples/bezier/example.PNG"> [Bezier Curves](examples/bezier) |<img width="1400" src="examples/joystick-viz/example.gif"> [Joysticks](examples/joystick-viz)|
|<img width="1400" src="examples/collision-demo/example.PNG"> [Collision Demo](examples/collision-demo) | <img width="1400" src="examples/custom-cursor/example.PNG"> [Custom Mouse Cursor](examples/custom-cursor) |<img width="1400" src="examples/fallback-font/example.PNG"> [Fallback Fonts](examples/fallback-font)|
|<img width="1400" src="examples/screenopts/example.PNG"> [Screen Options](examples/screenopts) | <img width="1400" src="examples/multi-window/example.PNG"> [Multi Window](examples/multi-window) |<img width="1400" src="examples/particle-demo/overviewExample.gif"> [Particle Demo](examples/particle-demo)|
|<img width="1400" src="examples/platformer/example.gif" a=examples/platformer> [Platformer](examples/platformer) | <img width="1400" src="examples/top-down-shooter//example.gif"> [Top down shooter](examples/top-down-shooter)|<img width="1400" src="examples/flappy-bird//example.gif"> [Flappy Bird](examples/flappy-bird/)
| <img width="1400" src="examples/bezier/example.PNG"> [Bezier Curves](examples/bezier) |<img width="1400" src="examples/joystick-viz/example.gif"> [Joysticks](examples/joystick-viz)|<img width="1400" src="examples/piano/example.gif"> [Piano](examples/piano)|
|<img width="1400" src="examples/screenopts/example.PNG"> [Screen Options](examples/screenopts) | <img width="1400" src="examples/multi-window/example.PNG"> [Multi Window](examples/multi-window) |<img width="1400" src="examples/particle-demo/overviewExample.gif"> [Particles](examples/particle-demo)|

## Games using Oak <a name="finished-games"/>
## Games using Oak <a name="finished-games"></a>

To kick off a larger game project you can get started with [game-template](https://github.com/oakmound/game-template).

| | |
|:-------------------------:|:-------------------------:|
|<img width="1400" src="https://img.itch.zone/aW1hZ2UvMTk4MjIxLzkyNzUyOC5wbmc=/original/aRusLc.png" a=examples/platformer-tutorial> [Agent Blue](https://oakmound.itch.io/agent-blue) | <img width="1400" src="https://img.itch.zone/aW1hZ2UvMTY4NDk1Lzc4MDk1Mi5wbmc=/original/hIjzFm.png"> [Fantastic Doctor](https://github.com/oakmound/lowrez17)
|<img width="1400" src="https://img.itch.zone/aW1hZ2UvMzkwNjM5LzI2NzU0ODMucG5n/original/eaoFrd.png"> [Hiring Now: Looters](https://oakmound.itch.io/cheststacker) | <img width="1400" src="https://img.itch.zone/aW1hZ2UvMTYzNjgyLzc1NDkxOS5wbmc=/original/%2BwvZ7j.png"> [Jeremy The Clam](https://github.com/200sc/jeremy)
|<img width="1400" src="https://img.itch.zone/aW1hZ2UvOTE0MjYzLzUxNjg3NDEucG5n/original/5btfEr.png"> [Diamond Deck Championship](https://oakmound.itch.io/diamond-deck-championship) |
|<img width="1400" src="https://img.itch.zone/aW1hZ2UvOTE0MjYzLzUxNjg3NDEucG5n/original/5btfEr.png"> [Diamond Deck Championship](https://oakmound.itch.io/diamond-deck-championship) | <img width="1400" src="https://img.itch.zone/aW1nLzgzMDM5MjcucG5n/105x83%23/oA19CL.png"> [SokoPic](https://oakmound.itch.io/sokopic)

## On Pure Go <a name="pure-go"/>

Oak has recently brought in dependencies that include C code, but we still describe the engine as a Pure Go engine, which at face value seems contradictory. Oak's goal is that, by default, a user can pull down the engine and create a fully functional game or GUI application on a machine with no C compiler installed, so when we say Pure Go we mean that, by default, the library is configured so no C compilation is required, and that no major features are locked behind C compliation.

We anticipate in the immediate future needing to introduce alternate drivers that include C dependencies for performance improvements in some scenarios, and currently we have no OSX solution that lacks objective C code.
We anticipate in the immediate future needing to introduce alternate drivers that include C dependencies for performance improvements in some scasenarios, and currently we have no OSX solution that lacks objective C code.
4 changes: 2 additions & 2 deletions audio/fade.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/oakmound/oak/v4/audio/pcm"
)

// FadeIn wraps a reader such that it will linearly fades in over the given duration.
// FadeIn wraps a reader such that it will linearly fade in over the given duration.
func FadeIn(dur time.Duration, in pcm.Reader) pcm.Reader {
perSec := in.PCMFormat().BytesPerSecond()
bytesToFadeIn := int((time.Duration(perSec) / 1000) * (dur / time.Millisecond))
Expand Down Expand Up @@ -75,7 +75,7 @@ func (fir *fadeInReader) ReadPCM(b []byte) (n int, err error) {
return read, nil
}

// FadeOut wraps a reader such that it will linearly fades out over the given duration.
// FadeOut wraps a reader such that it will linearly fade out over the given duration.
func FadeOut(dur time.Duration, in pcm.Reader) pcm.Reader {
perSec := in.PCMFormat().BytesPerSecond()
bytestoFadeOut := int((time.Duration(perSec) / 1000) * (dur / time.Millisecond))
Expand Down
9 changes: 8 additions & 1 deletion audio/play_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ func TestLoopingSin(t *testing.T) {
Format: format,
})
ctx, cancel := context.WithCancel(context.Background())
done := make(chan struct{})
go func() {
err := audio.Play(ctx, r)
if err != nil {
t.Errorf("failed to play: %v", err)
}
close(done)
}()
if testing.Short() {
time.Sleep(100 * time.Millisecond)
Expand All @@ -83,7 +85,12 @@ func TestLoopingSin(t *testing.T) {
}
fmt.Println("stopping")
cancel()
time.Sleep(1 * time.Second)
select {
case <-done:
case <-time.After(1 * time.Second):
t.Errorf("play did not exit on cancel")
}

}

func bytesFromInts(is []int16, channels int) []byte {
Expand Down
142 changes: 0 additions & 142 deletions audio/writer_js.go

This file was deleted.

72 changes: 25 additions & 47 deletions examples/click-propagation/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package main

import (
"fmt"
"image"
"image/color"
"image/draw"

"github.com/oakmound/oak/v4"
"github.com/oakmound/oak/v4/collision"
Expand All @@ -14,22 +12,30 @@ import (
"github.com/oakmound/oak/v4/scene"
)

// This example demonstrates the use of the Propagated boolean on
// This example demonstrates the use of the StopPropagation boolean on
// mouse event payloads to prevent mouse interactions from falling
// through to lower UI elements after interacting with a higher layer

// TODO: make the boxes here more real, more like a real UI

func main() {
oak.AddScene("click-propagation", scene.Scene{
Start: func(ctx *scene.Context) {
z := 0
y := 400.0
for x := 20.0; x < 400; x += 20 {
z++
y -= 20
newHoverButton(ctx, x, y, 35, 35, color.RGBA{200, 200, 200, 200}, z)
newHoverButton(ctx, 10, 10, 620, 460, color.RGBA{255, 255, 100, 255}, 1)

newHoverButton(ctx, 30, 30, 190, 430, color.RGBA{255, 100, 100, 255}, 2)
newHoverButton(ctx, 240, 30, 370, 430, color.RGBA{255, 100, 255, 255}, 2)

const gridW = 10
for x := 50; x < 210-gridW; x += (gridW * 2) {
for y := 50; y < 450-gridW; y += (gridW * 2) {
newHoverButton(ctx, float64(x), float64(y), gridW, gridW, color.RGBA{100, 255, 255, 255}, 3)
}
}

newHoverButton(ctx, 260, 50, 100, 390, color.RGBA{100, 100, 255, 255}, 3)
for y := 70; y < 440-gridW; y += (gridW * 2) {
newHoverButton(ctx, 270, float64(y), 80, gridW, color.RGBA{255, 255, 255, 255}, 4)
}
newHoverButton(ctx, 380, 50, 200, 80, color.RGBA{100, 100, 100, 255}, 3)
},
})
oak.Init("click-propagation")
Expand All @@ -39,7 +45,7 @@ type hoverButton struct {
id event.CallerID

mouse.CollisionPhase
*changingColorBox
*render.ColorBoxR
}

func (hb *hoverButton) CID() event.CallerID {
Expand All @@ -49,58 +55,30 @@ func (hb *hoverButton) CID() event.CallerID {
func newHoverButton(ctx *scene.Context, x, y, w, h float64, clr color.RGBA, layer int) {
hb := &hoverButton{}
hb.id = ctx.Register(hb)
hb.changingColorBox = newChangingColorBox(x, y, int(w), int(h), clr)
hb.ColorBoxR = render.NewColorBoxR(int(w), int(h), clr)
hb.ColorBoxR.SetPos(x, y)

sp := collision.NewSpace(x, y, w, h, hb.id)
sp.SetZLayer(float64(layer))

mouse.Add(sp)
mouse.PhaseCollision(sp, ctx.Handler)

render.Draw(hb.changingColorBox, 0, layer)
render.Draw(hb.ColorBoxR, layer)

event.Bind(ctx, mouse.Click, hb, func(box *hoverButton, me *mouse.Event) event.Response {
fmt.Println(box, me.Point2)
box.changingColorBox.c = color.RGBA{128, 128, 128, 128}
event.Bind(ctx, mouse.ClickOn, hb, func(box *hoverButton, me *mouse.Event) event.Response {
box.ColorBoxR.Color = image.NewUniform(color.RGBA{128, 128, 128, 128})
me.StopPropagation = true
return 0
})
event.Bind(ctx, mouse.Start, hb, func(box *hoverButton, me *mouse.Event) event.Response {
fmt.Println("start")
box.changingColorBox.c = color.RGBA{50, 50, 50, 50}
box.ColorBoxR.Color = image.NewUniform(color.RGBA{50, 50, 50, 50})
me.StopPropagation = true
return 0
})
event.Bind(ctx, mouse.Stop, hb, func(box *hoverButton, me *mouse.Event) event.Response {
fmt.Println("stop")
box.changingColorBox.c = clr
box.ColorBoxR.Color = image.NewUniform(clr)
me.StopPropagation = true
return 0
})
}

type changingColorBox struct {
render.LayeredPoint
c color.RGBA
w, h int
}

func newChangingColorBox(x, y float64, w, h int, c color.RGBA) *changingColorBox {
return &changingColorBox{
LayeredPoint: render.NewLayeredPoint(x, y, 0),
c: c,
w: w,
h: h,
}
}

func (ccb *changingColorBox) Draw(buff draw.Image, xOff, yOff float64) {
x := int(ccb.X() + xOff)
y := int(ccb.Y() + yOff)
rect := image.Rect(x, y, ccb.w+x, ccb.h+y)
draw.Draw(buff, rect, image.NewUniform(ccb.c), image.Point{int(ccb.X() + xOff), int(ccb.Y() + yOff)}, draw.Over)
}

func (ccb *changingColorBox) GetDims() (int, int) {
return ccb.w, ccb.h
}
29 changes: 0 additions & 29 deletions examples/clipboard/go.mod

This file was deleted.

Loading