Skip to content

Commit

Permalink
release to gomoku
Browse files Browse the repository at this point in the history
* see github.com/ymohl-cl/gomoku
  • Loading branch information
ymohl-cl committed Mar 31, 2021
1 parent 5e8a28e commit 1bf350d
Show file tree
Hide file tree
Showing 36 changed files with 600 additions and 819 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ install:

.PHONY: build
build: test
@go build -a -ldflags '-extldflags "-static"' ./...
@go build -buildmode=pie -a -ldflags '-extldflags "-static"' ./...

test:
@go test -count=1 ./...
Expand Down
43 changes: 27 additions & 16 deletions README.md
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.
Expand All @@ -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"
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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 removed Ressources/stocky.ttf
Binary file not shown.
2 changes: 1 addition & 1 deletion audio/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/veandco/go-sdl2/mix"
"github.com/veandco/go-sdl2/sdl"
"github.com/ymohl-cl/game-builder/objects"
"github.com/ymohl-cl/go-ui/objects"
)

// Audio structure
Expand Down
13 changes: 13 additions & 0 deletions config.go
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
}
77 changes: 0 additions & 77 deletions drivers/drivers.go

This file was deleted.

7 changes: 7 additions & 0 deletions error.go
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"
)
83 changes: 83 additions & 0 deletions event.go
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
}
Loading

0 comments on commit 1bf350d

Please sign in to comment.