diff --git a/.gitignore b/.gitignore index 4882201..a8c96c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ exe *.vim +*.exe diff --git a/gx/camera.go b/camera.go similarity index 97% rename from gx/camera.go rename to camera.go index 3614995..bf36e34 100644 --- a/gx/camera.go +++ b/camera.go @@ -1,4 +1,4 @@ -package gx +package gg // Implements the camera component // for the main window. diff --git a/cmd/math/main.go b/cmd/math/main.go index 645bfe5..ea0c113 100644 --- a/cmd/math/main.go +++ b/cmd/math/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/surdeus/gox/src/gx" + "github.com/reklesio/gg/src/gx" "fmt" ) @@ -13,10 +13,7 @@ func main() { gx.Vertex{30, 40}, gx.Vertex{40, 30}, } - + fmt.Println("barycenter:", p.Barycenter()) fmt.Println("edges:", p.Edges()) } - - - diff --git a/cmd/test/main.go b/cmd/test/main.go index 0b1a664..b64328e 100644 --- a/cmd/test/main.go +++ b/cmd/test/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/surdeus/gox/gx" + "github.com/reklesio/gg" "github.com/hajimehoshi/ebiten/v2/examples/resources/images" "github.com/hajimehoshi/ebiten/v2" "bytes" @@ -12,7 +12,7 @@ import ( ) const ( - HighestL gx.Layer = -iota + HighestL gg.Layer = -iota DebugL TriangleL PlayerL @@ -21,76 +21,76 @@ const ( ) type Player struct { - *gx.Sprite - MoveSpeed gx.Float - ScaleSpeed gx.Float - gx.Layer + *gg.Sprite + MoveSpeed gg.Float + ScaleSpeed gg.Float + gg.Layer } -type Debug struct{ - gx.Layer +type Debug struct { + gg.Layer } type Rect struct { - *gx.DrawableRectangle - gx.Layer + *gg.DrawableRectangle + gg.Layer } type Tri struct { - *gx.DrawablePolygon - gx.Layer + *gg.DrawablePolygon + gg.Layer } func NewTri() *Tri { ret := &Tri{} - ret.DrawablePolygon = &gx.DrawablePolygon{} - ret.Transform.S = gx.V(1, 1) - - ret.Triangles = gx.Triangles{ - gx.Triangle{ - gx.V(0, 0), - gx.V(100, 100), - gx.V(0, -50), + ret.DrawablePolygon = &gg.DrawablePolygon{} + ret.Transform.S = gg.V(1, 1) + + ret.Triangles = gg.Triangles{ + gg.Triangle{ + gg.V(0, 0), + gg.V(100, 100), + gg.V(0, -50), }, - gx.Triangle{ - gx.V(0, 0), - gx.V(-100, -100), - gx.V(0, 50), + gg.Triangle{ + gg.V(0, 0), + gg.V(-100, -100), + gg.V(0, 50), }, } - ret.Color = gx.Color{gx.MaxColorV, gx.MaxColorV, 0, gx.MaxColorV} + ret.Color = gg.Color{gg.MaxColorV, gg.MaxColorV, 0, gg.MaxColorV} ret.Visible = true ret.Layer = TriangleL - + return ret } func NewRect() *Rect { - ret := &Rect{&gx.DrawableRectangle{ - Rectangle: gx.Rectangle{ - Transform: gx.Transform{ - S: gx.Vector{ - X: 200, - Y: 400, - }, + ret := &Rect{&gg.DrawableRectangle{ + Rectangle: gg.Rectangle{ + Transform: gg.Transform{ + S: gg.Vector{ + X: 200, + Y: 400, }, }, - Color: gx.Color{ - gx.MaxColorV, - 0, - 0, - gx.MaxColorV, + }, + Color: gg.Color{ + gg.MaxColorV, + 0, + 0, + gg.MaxColorV, + }, + Visible: true, + /*Shader: gg.SolidWhiteColorShader, + Options: gg.ShaderOptions{ + Images: [4]*gg.Image{ + playerImg, + nil, + nil, + nil, }, - Visible: true, - /*Shader: gx.SolidWhiteColorShader, - Options: gx.ShaderOptions{ - Images: [4]*gx.Image{ - playerImg, - nil, - nil, - nil, - }, - },*/ + },*/ }, RectL, } @@ -98,190 +98,191 @@ func NewRect() *Rect { return ret } -func (r *Rect) Update(e *gx.Engine) error { +func (r *Rect) Update(e *gg.Engine) error { //r.R += 0.3 * e.DT() return nil } var ( - playerImg *gx.Image - player *Player - rectMove gx.Rectangle - rect *Rect - tri *Tri + playerImg *gg.Image + player *Player + rectMove gg.Rectangle + rect *Rect + tri *Tri ) func NewPlayer() *Player { ret := &Player{ - Sprite: &gx.Sprite{ - Transform: gx.Transform { - S: gx.Vector{5, 5}, - RA: gx.Vector{.5, .5}, + Sprite: &gg.Sprite{ + Transform: gg.Transform{ + S: gg.Vector{5, 5}, + RA: gg.Vector{.5, .5}, }, Visible: true, - ShaderOptions: gx.ShaderOptions { - Shader: gx.SolidWhiteColorShader, - Uniforms: make(map[string] any), + ShaderOptions: gg.ShaderOptions{ + Shader: gg.SolidWhiteColorShader, + Uniforms: make(map[string]any), }, }, - MoveSpeed: 90., + MoveSpeed: 90., ScaleSpeed: .2, } - + ret.Images[0] = playerImg ret.Layer = PlayerL - + return ret } -func (p *Player) Draw(e *gx.Engine, i *gx.Image) { +func (p *Player) Draw(e *gg.Engine, i *gg.Image) { p.Sprite.Draw(e, i) t := p.Transform t.S.X *= 4. t.S.Y *= 4. - rectMove = gx.Rectangle{ + rectMove = gg.Rectangle{ Transform: t, } - r := &gx.DrawableRectangle{ + r := &gg.DrawableRectangle{ Rectangle: rectMove, - Color: gx.Color{0, 0, gx.MaxColorV, gx.MaxColorV}, + Color: gg.Color{0, 0, gg.MaxColorV, gg.MaxColorV}, } r.Draw(e, i) } -func (p *Player) Start(e *gx.Engine, v ...any) { +func (p *Player) Start(e *gg.Engine, v ...any) { fmt.Println("starting") c := e.Camera() - c.RA = gx.V(360, 240) + c.RA = gg.V(360, 240) } -func (p *Player) Update(e *gx.Engine) error { +func (p *Player) Update(e *gg.Engine) error { dt := e.DT() c := e.Camera() keys := e.Keys() - + p.Uniforms["Random"] = any(rand.Float32()) - for _, v := range keys {switch v { - case ebiten.KeyArrowUp : - c.P.Y += p.MoveSpeed * dt - case ebiten.KeyArrowLeft : - c.P.X -= p.MoveSpeed * dt - case ebiten.KeyArrowDown : - c.P.Y -= p.MoveSpeed * dt - case ebiten.KeyArrowRight : - c.P.X += p.MoveSpeed * dt - case ebiten.KeyW : - p.P.Y += p.MoveSpeed * dt - case ebiten.KeyA : - p.P.X -= p.MoveSpeed * dt - case ebiten.KeyS : - p.P.Y -= p.MoveSpeed * dt - case ebiten.KeyD : - p.P.X += p.MoveSpeed * dt - case ebiten.KeyR : - c.R += gx.Pi * p.ScaleSpeed * dt - case ebiten.KeyT : - c.R -= gx.Pi * p.ScaleSpeed * dt - case ebiten.KeyRightBracket : - if e.KeyIsPressed(ebiten.KeyShift) { - p.R -= gx.Pi * 0.3 * dt - } else { - p.R += gx.Pi * 0.3 * dt + for _, v := range keys { + switch v { + case ebiten.KeyArrowUp: + c.P.Y += p.MoveSpeed * dt + case ebiten.KeyArrowLeft: + c.P.X -= p.MoveSpeed * dt + case ebiten.KeyArrowDown: + c.P.Y -= p.MoveSpeed * dt + case ebiten.KeyArrowRight: + c.P.X += p.MoveSpeed * dt + case ebiten.KeyW: + p.P.Y += p.MoveSpeed * dt + case ebiten.KeyA: + p.P.X -= p.MoveSpeed * dt + case ebiten.KeyS: + p.P.Y -= p.MoveSpeed * dt + case ebiten.KeyD: + p.P.X += p.MoveSpeed * dt + case ebiten.KeyR: + c.R += gg.Pi * p.ScaleSpeed * dt + case ebiten.KeyT: + c.R -= gg.Pi * p.ScaleSpeed * dt + case ebiten.KeyRightBracket: + if e.KeyIsPressed(ebiten.KeyShift) { + p.R -= gg.Pi * 0.3 * dt + } else { + p.R += gg.Pi * 0.3 * dt + } + case ebiten.KeyF: + if e.KeyIsPressed(ebiten.KeyShift) { + c.S.X -= gg.Pi * p.ScaleSpeed * dt + } else { + c.S.X += gg.Pi * p.ScaleSpeed * dt + } + case ebiten.KeyG: + if e.KeyIsPressed(ebiten.KeyShift) { + c.S.Y -= gg.Pi * p.ScaleSpeed * dt + } else { + c.S.Y += gg.Pi * p.ScaleSpeed * dt + } + case ebiten.KeyZ: + if e.KeyIsPressed(ebiten.KeyShift) { + c.RA.X -= gg.Pi * p.MoveSpeed * dt + } else { + c.RA.X += gg.Pi * p.MoveSpeed * dt + } + case ebiten.KeyX: + if e.KeyIsPressed(ebiten.KeyShift) { + c.RA.Y -= gg.Pi * p.MoveSpeed * dt + } else { + c.RA.Y += gg.Pi * p.MoveSpeed * dt + } + case ebiten.KeyV: + if e.KeyIsPressed(ebiten.KeyShift) { + tri.R -= gg.Pi * 0.3 * dt + } else { + tri.R += gg.Pi * 0.3 * dt + } + case ebiten.KeyLeftBracket: + if e.KeyIsPressed(ebiten.KeyShift) { + rect.R -= gg.Pi * 0.3 * dt + } else { + rect.R += gg.Pi * 0.3 * dt + } + case ebiten.Key0: + e.Del(p) + case ebiten.KeyB: + if p.Layer != PlayerL { + p.Layer = PlayerL + } else { + p.Layer = HighestL + } } - case ebiten.KeyF : - if e.KeyIsPressed(ebiten.KeyShift) { - c.S.X -= gx.Pi * p.ScaleSpeed * dt - } else { - c.S.X += gx.Pi * p.ScaleSpeed * dt - } - case ebiten.KeyG : - if e.KeyIsPressed(ebiten.KeyShift) { - c.S.Y -= gx.Pi * p.ScaleSpeed * dt - } else { - c.S.Y += gx.Pi * p.ScaleSpeed * dt - } - case ebiten.KeyZ : - if e.KeyIsPressed(ebiten.KeyShift) { - c.RA.X -= gx.Pi * p.MoveSpeed * dt - } else { - c.RA.X += gx.Pi * p.MoveSpeed * dt - } - case ebiten.KeyX : - if e.KeyIsPressed(ebiten.KeyShift) { - c.RA.Y -= gx.Pi * p.MoveSpeed * dt - } else { - c.RA.Y += gx.Pi * p.MoveSpeed * dt - } - case ebiten.KeyV : - if e.KeyIsPressed(ebiten.KeyShift) { - tri.R -= gx.Pi * 0.3 * dt - } else { - tri.R += gx.Pi * 0.3 * dt - } - case ebiten.KeyLeftBracket : - if e.KeyIsPressed(ebiten.KeyShift) { - rect.R -= gx.Pi * 0.3 * dt - } else { - rect.R += gx.Pi * 0.3 * dt - } - case ebiten.Key0 : - e.Del(p) - case ebiten.KeyB : - if p.Layer != PlayerL { - p.Layer = PlayerL - } else { - p.Layer = HighestL - } - }} + } return nil } func (d *Debug) Draw( - e *gx.Engine, - i *gx.Image, + e *gg.Engine, + i *gg.Image, ) { keyStrs := []string{} for _, k := range e.Keys() { keyStrs = append(keyStrs, k.String()) } - + if rectMove.Vertices().Contained(rect).Len() > 0 || - rect.Vertices().Contained(rectMove).Len() > 0 { + rect.Vertices().Contained(rectMove).Len() > 0 { keyStrs = append(keyStrs, "THIS IS SHIT") } - + e.DebugPrint(i, strings.Join(keyStrs, ", ")) - + } -func (d *Debug) IsVisible() bool {return true} +func (d *Debug) IsVisible() bool { return true } func main() { - e := gx.NewEngine(&gx.WindowConfig{ - Title: "Test title", - Width: 720, + e := gg.NewEngine(&gg.WindowConfig{ + Title: "Test title", + Width: 720, Height: 480, - VSync: true, + VSync: true, }) var err error - playerImg, err = gx.LoadImage(bytes.NewReader(images.Runner_png)) + playerImg, err = gg.LoadImage(bytes.NewReader(images.Runner_png)) if err != nil { log.Fatal(err) } - player = NewPlayer() rect = NewRect() tri = NewTri() - + e.Add(&Debug{}) e.Add(player) e.Add(rect) e.Add(tri) fmt.Println(rect.GetLayer(), player.GetLayer()) - + e.Run() } diff --git a/gx/collider.go b/collider.go similarity index 98% rename from gx/collider.go rename to collider.go index f3a7317..2e3704c 100644 --- a/gx/collider.go +++ b/collider.go @@ -1,4 +1,4 @@ -package gx +package gg // Implementing the interface lets // the engine to work faster about diff --git a/gx/debug.go b/debug.go similarity index 93% rename from gx/debug.go rename to debug.go index 6bd41d9..1710bfe 100644 --- a/gx/debug.go +++ b/debug.go @@ -1,4 +1,4 @@ -package gx +package gg import ( "github.com/hajimehoshi/ebiten/v2/ebitenutil" diff --git a/gx/elipse.go b/elipse.go similarity index 95% rename from gx/elipse.go rename to elipse.go index 44c2cf1..79c6e78 100644 --- a/gx/elipse.go +++ b/elipse.go @@ -1,4 +1,4 @@ -package gx +package gg // The structure represents elipses. type Elipse struct { diff --git a/gx/engine.go b/engine.go similarity index 99% rename from gx/engine.go rename to engine.go index 0e104b4..19312c5 100644 --- a/gx/engine.go +++ b/engine.go @@ -1,4 +1,4 @@ -package gx +package gg import ( "github.com/hajimehoshi/ebiten/v2" diff --git a/gx/errors.go b/errors.go similarity index 95% rename from gx/errors.go rename to errors.go index f8ba5e4..5183591 100644 --- a/gx/errors.go +++ b/errors.go @@ -1,4 +1,4 @@ -package gx +package gg import ( "errors" diff --git a/gix/main.go b/gix/main.go deleted file mode 100644 index fecf8b8..0000000 --- a/gix/main.go +++ /dev/null @@ -1,6 +0,0 @@ -package gix - -import ( -) - - diff --git a/go.mod b/go.mod index 98e6dfd..9b9c3b5 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/surdeus/gox +module github.com/reklesio/gg go 1.20 diff --git a/gx/misc.go b/gx/misc.go deleted file mode 100644 index ca27035..0000000 --- a/gx/misc.go +++ /dev/null @@ -1,3 +0,0 @@ -package gx - - diff --git a/gx/img.go b/img.go similarity index 98% rename from gx/img.go rename to img.go index f114f47..44d9772 100644 --- a/gx/img.go +++ b/img.go @@ -1,4 +1,4 @@ -package gx +package gg import ( "github.com/hajimehoshi/ebiten/v2" diff --git a/gx/keys.go b/keys.go similarity index 95% rename from gx/keys.go rename to keys.go index 3694b50..c22b95c 100644 --- a/gx/keys.go +++ b/keys.go @@ -1,4 +1,4 @@ -package gx +package gg import ( "github.com/hajimehoshi/ebiten/v2" diff --git a/gx/line.go b/line.go similarity index 99% rename from gx/line.go rename to line.go index 72f3b47..3b058ed 100644 --- a/gx/line.go +++ b/line.go @@ -1,4 +1,4 @@ -package gx +package gg import ( "math" diff --git a/gx/math.go b/math.go similarity index 98% rename from gx/math.go rename to math.go index c9ead6a..a1bed90 100644 --- a/gx/math.go +++ b/math.go @@ -1,4 +1,4 @@ -package gx +package gg import ( "math" diff --git a/gx/matrix.go b/matrix.go similarity index 88% rename from gx/matrix.go rename to matrix.go index 53f059d..913c143 100644 --- a/gx/matrix.go +++ b/matrix.go @@ -1,4 +1,4 @@ -package gx +package gg import ( "github.com/hajimehoshi/ebiten/v2" diff --git a/media/gopher.png b/media/gopher.png new file mode 100644 index 0000000..33fba74 Binary files /dev/null and b/media/gopher.png differ diff --git a/misc.go b/misc.go new file mode 100644 index 0000000..b2a357b --- /dev/null +++ b/misc.go @@ -0,0 +1,3 @@ +package gg + + diff --git a/gx/object.go b/object.go similarity index 98% rename from gx/object.go rename to object.go index 3b2cdf1..b7a1527 100644 --- a/gx/object.go +++ b/object.go @@ -1,4 +1,4 @@ -package gx +package gg // Implementing the interface type // will call the function OnStart diff --git a/gx/polygon.go b/polygon.go similarity index 98% rename from gx/polygon.go rename to polygon.go index 21d78e4..ce4cc9b 100644 --- a/gx/polygon.go +++ b/polygon.go @@ -1,4 +1,4 @@ -package gx +package gg import ( ) diff --git a/gx/ray.go b/ray.go similarity index 91% rename from gx/ray.go rename to ray.go index 6d63c87..1e7e4ed 100644 --- a/gx/ray.go +++ b/ray.go @@ -1,4 +1,4 @@ -package gx +package gg // The type represents math ray. type Ray struct { diff --git a/readme.md b/readme.md index dc3747a..40215f4 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,8 @@ -# gox +# gg -2D graphcs engine based on [ebiten](https://github.com/hajimehoshi/ebiten). +![Insert here a gopher, please](https://raw.githubusercontent.com/reklesio/gg/master/media/gopher.png) + +Golang Graphics, Gopher Games or Good Game engine for 2D applications. + +Basing on [ebiten](https://github.com/hajimehoshi/ebiten). diff --git a/gx/rect.go b/rect.go similarity index 99% rename from gx/rect.go rename to rect.go index c265803..cfcff88 100644 --- a/gx/rect.go +++ b/rect.go @@ -1,4 +1,4 @@ -package gx +package gg import ( "github.com/hajimehoshi/ebiten/v2" diff --git a/gx/shader.go b/shader.go similarity index 99% rename from gx/shader.go rename to shader.go index 7e736fe..6b64af1 100644 --- a/gx/shader.go +++ b/shader.go @@ -1,4 +1,4 @@ -package gx +package gg import ( "github.com/hajimehoshi/ebiten/v2" diff --git a/gx/sprite.go b/sprite.go similarity index 99% rename from gx/sprite.go rename to sprite.go index 5546f66..c383368 100644 --- a/gx/sprite.go +++ b/sprite.go @@ -1,4 +1,4 @@ -package gx +package gg import ( "github.com/hajimehoshi/ebiten/v2" diff --git a/gx/time.go b/time.go similarity index 87% rename from gx/time.go rename to time.go index 2b385f8..5c435db 100644 --- a/gx/time.go +++ b/time.go @@ -1,4 +1,4 @@ -package gx +package gg import ( "time" diff --git a/gx/transform.go b/transform.go similarity index 99% rename from gx/transform.go rename to transform.go index 0c9be30..6e0daf9 100644 --- a/gx/transform.go +++ b/transform.go @@ -1,4 +1,4 @@ -package gx +package gg import ( //"github.com/hajimehoshi/ebiten/v2" diff --git a/gx/triangle.go b/triangle.go similarity index 99% rename from gx/triangle.go rename to triangle.go index b56ad8a..282db5b 100644 --- a/gx/triangle.go +++ b/triangle.go @@ -1,4 +1,4 @@ -package gx +package gg import ( "math" diff --git a/gx/vector.go b/vector.go similarity index 99% rename from gx/vector.go rename to vector.go index 6fbeed8..e369896 100644 --- a/gx/vector.go +++ b/vector.go @@ -1,4 +1,4 @@ -package gx +package gg import ( //"github.com/hajimehoshi/ebiten/v2"