-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* see github.com/ymohl-cl/gomoku
- Loading branch information
Showing
36 changed files
with
600 additions
and
819 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# game-builder | ||
Game-builder is a game builder lite using [SDL2 veandco](https://github.com/veandco/go-sdl2). | ||
# Go-ui | ||
|
||
go-ui is a game builder lite using [SDL2 veandco](https://github.com/veandco/go-sdl2). | ||
It's not convention to compose a game, just proof of concept today. | ||
|
||
The wrapper is implemented with goroutines. | ||
|
@@ -12,35 +13,39 @@ I would be pleased to talk about that with you on mail: | |
`[email protected]` | ||
|
||
# Requirements | ||
|
||
See official github to SDL2 binding for Go by [veandco](https://github.com/veandco/go-sdl2). | ||
|
||
# Installation | ||
|
||
To install Golang see [getting started](https://golang.org/doc/install) | ||
|
||
To get SDL2 wrapper see [veandco](https://github.com/veandco/go-sdl2) | ||
|
||
`go get -v github.com/veandco/go-sdl2/{sdl,mix,img,ttf}` | ||
|
||
To get Game-Builder: | ||
To get go-ui: | ||
|
||
`go get -v github.com/ymohl-cl/game-builder` | ||
`go get -v github.com/ymohl-cl/go-ui` | ||
|
||
#### OSX | ||
|
||
Install SDL2: | ||
|
||
`brew install sdl2 sdl2_gfx sdl2_image sdl2_mixer sdl2_net sdl2_ttf` | ||
|
||
# Example | ||
|
||
You can view implementation example on this project [gomoku game](https://github.com/ymohl-cl/gomoku) | ||
|
||
Please, read godoc to know the specifications | ||
|
||
``` | ||
``` GOLANG | ||
package main | ||
|
||
import ( | ||
"github.com/ymohl-cl/game-builder/drivers" | ||
"github.com/ymohl-cl/game-builder/scripter" | ||
"github.com/ymohl-cl/go-ui/drivers" | ||
"github.com/ymohl-cl/go-ui/scripter" | ||
"github.com/ymohl-cl/gomoku/database" | ||
"github.com/ymohl-cl/gomoku/scenes/gomoku" | ||
"github.com/ymohl-cl/gomoku/scenes/loader" | ||
|
@@ -60,7 +65,7 @@ func main() { | |
var d drivers.VSDL | ||
var data *database.Data | ||
|
||
// init drivers sdl from game-builder | ||
// init drivers sdl from go-ui | ||
if d, err = drivers.Init(windowWidth, windowHeight, "Title of my windows"); err != nil { | ||
panic(err) | ||
} | ||
|
@@ -71,15 +76,15 @@ func main() { | |
panic(err) | ||
} | ||
|
||
// get new scripter application from game-builder | ||
// get new scripter application from go-ui | ||
s := scripter.New() | ||
|
||
// get loader scene from my app | ||
var loaderScene *loader.Load | ||
if loaderScene, err = loader.New(nil, d.GetRenderer()); err != nil { | ||
panic(err) | ||
} | ||
// add scene on the scripter (game-builder) | ||
// add scene on the scripter (go-ui) | ||
if err = s.AddLoader(loaderScene); err != nil { | ||
panic(err) | ||
} | ||
|
@@ -89,7 +94,7 @@ func main() { | |
if menuScene, err = menu.New(data, d.GetRenderer()); err != nil { | ||
panic(err) | ||
} | ||
// add scene on the scripter (game-builder) | ||
// add scene on the scripter (go-ui) | ||
if err = s.AddScene(menuScene, indexMenu, true); err != nil { | ||
panic(err) | ||
} | ||
|
@@ -99,29 +104,35 @@ func main() { | |
if gameScene, err = gomoku.New(data, d.GetRenderer()); err != nil { | ||
panic(err) | ||
} | ||
// add scene on the scripter (game-builder) | ||
// add scene on the scripter (go-ui) | ||
if err = s.AddScene(gameScene, indexGomoku, false); err != nil { | ||
panic(err) | ||
} | ||
|
||
// run application from game-builder | ||
// run application from go-ui | ||
s.Run(d) | ||
} | ||
``` | ||
|
||
# FAQ | ||
|
||
#### Why shaders aren't implemented ? | ||
Game-builder is a proof of concept for the moment. This lib provide that which are needest to make a simple project. | ||
|
||
go-ui is a proof of concept for the moment. This lib provide that which are needest to make a simple project. | ||
If you need shaders, please contact us. | ||
|
||
#### How do I contribute ? | ||
|
||
Contact me by mail: `[email protected]` | ||
|
||
# Acknowledgment | ||
|
||
Thanks at [veandco](https://github.com/veandco/go-sdl2) for their work. | ||
|
||
# License | ||
game-builder is BSD 3-clause licensed. | ||
|
||
go-ui is BSD 3-clause licensed. | ||
|
||
# Version | ||
V-0.1.1: implement library game-builder | ||
|
||
V-0.1.1: implement library go-ui |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package gamebuilder | ||
|
||
// Window configuration | ||
type Window struct { | ||
Title string | ||
Width int32 | ||
Height int32 | ||
} | ||
|
||
// ConfigUI about ui | ||
type ConfigUI struct { | ||
Window Window | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package gamebuilder | ||
|
||
const ( | ||
errorScriptModifier = "the script configuration can't be updated after to have start the app/game" | ||
errorSceneNotFound = "scene not found" | ||
errorSceneUsed = "scene is currently used" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package gamebuilder | ||
|
||
import ( | ||
"github.com/veandco/go-sdl2/sdl" | ||
"github.com/ymohl-cl/go-ui/objects" | ||
) | ||
|
||
// event : catch mouse and keyboard events | ||
func event(e sdl.Event, s Scene) error { | ||
var err error | ||
|
||
switch e.(type) { | ||
case *sdl.MouseMotionEvent: | ||
err = mouseMotionEvent(e.(*sdl.MouseMotionEvent), s) | ||
case *sdl.MouseButtonEvent: | ||
err = mouseButtonEvent(e.(*sdl.MouseButtonEvent), s) | ||
case *sdl.KeyboardEvent: | ||
err = keyboardEvent(e.(*sdl.KeyboardEvent), s) | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// mouseMotionEvent define a new mouse's position | ||
func mouseMotionEvent(mm *sdl.MouseMotionEvent, s Scene) error { | ||
layers, m := s.GetLayers() | ||
m.Lock() | ||
defer m.Unlock() | ||
|
||
size := len(layers) | ||
for i := size - 1; i >= 0; i-- { | ||
layer := layers[uint8(i)] | ||
for _, object := range layer { | ||
if object.IsOver(mm.X, mm.Y) { | ||
if object.GetStatus() != objects.SClick { | ||
go object.SetStatus(objects.SOver) | ||
} | ||
} else { | ||
go object.SetStatus(objects.SBasic) | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// mouseButtonEvent define a new mouse's action (click) | ||
func mouseButtonEvent(b *sdl.MouseButtonEvent, s Scene) error { | ||
if b.Button != sdl.BUTTON_LEFT { | ||
return nil | ||
} | ||
layers, m := s.GetLayers() | ||
m.Lock() | ||
defer m.Unlock() | ||
|
||
size := len(layers) | ||
for i := size - 1; i >= 0; i-- { | ||
layer := layers[uint8(i)] | ||
for _, object := range layer { | ||
if b.State == sdl.PRESSED { | ||
if object.GetStatus() == objects.SOver { | ||
go object.SetStatus(objects.SClick) | ||
break | ||
} | ||
} else if b.State == sdl.RELEASED { | ||
if object.GetStatus() == objects.SClick { | ||
go object.SetStatus(objects.SOver) | ||
go object.Click() | ||
break | ||
} | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// keyboardEvent : _ | ||
func keyboardEvent(k *sdl.KeyboardEvent, s Scene) error { | ||
go s.KeyboardEvent(k) | ||
return nil | ||
} |
Oops, something went wrong.