From cb1bdec005d19cedd18b9004afb828c84317dcc1 Mon Sep 17 00:00:00 2001 From: Manley Date: Sun, 5 Jun 2022 12:54:30 -0400 Subject: [PATCH] Initial commit --- .gitignore | 21 ++++++ LICENSE | 7 ++ ReadMe.md | 9 +++ core/rect2d.go | 14 ++++ core/vector2.go | 19 +++++ game/game.go | 36 +++++++++ go.mod | 5 ++ go.sum | 2 + gopher.bmp | Bin 0 -> 12342 bytes main.go | 42 +++++++++++ node/camera2d.go | 48 ++++++++++++ node/inode.go | 7 ++ node/node.go | 120 +++++++++++++++++++++++++++++ node/node2d.go | 38 ++++++++++ node/sprite2d.go | 46 ++++++++++++ rendering/camera2d.go | 18 +++++ rendering/render2d.go | 21 ++++++ rendering/standard_camera2d.go | 37 +++++++++ rendering/texture2d.go | 9 +++ sdl/sdl_render2d.go | 133 +++++++++++++++++++++++++++++++++ sdl/sdl_texture2d.go | 70 +++++++++++++++++ 21 files changed, 702 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 ReadMe.md create mode 100644 core/rect2d.go create mode 100644 core/vector2.go create mode 100644 game/game.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 gopher.bmp create mode 100644 main.go create mode 100644 node/camera2d.go create mode 100644 node/inode.go create mode 100644 node/node.go create mode 100644 node/node2d.go create mode 100644 node/sprite2d.go create mode 100644 rendering/camera2d.go create mode 100644 rendering/render2d.go create mode 100644 rendering/standard_camera2d.go create mode 100644 rendering/texture2d.go create mode 100644 sdl/sdl_render2d.go create mode 100644 sdl/sdl_texture2d.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3b735ec --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c67edd6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2022 Manley + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/ReadMe.md b/ReadMe.md new file mode 100644 index 0000000..9241b8b --- /dev/null +++ b/ReadMe.md @@ -0,0 +1,9 @@ +# Golang Game Framework + +Framework in Golang to simplify game development with SDL in Go. + +Currently, only basic rendering has been implemented. + +For an example on how to use it, see `game/game.go` and make your own changes! + +I have a strong desire to make this into a more flexible and feature complete system, but I cannot give any guarantees. Hopefully at minimum, this project can be seen as a reference for others! diff --git a/core/rect2d.go b/core/rect2d.go new file mode 100644 index 0000000..146edda --- /dev/null +++ b/core/rect2d.go @@ -0,0 +1,14 @@ +package core + +import "fmt" + +type Rect2D struct { + X float64 + Y float64 + W float64 + H float64 +} + +func (rect Rect2D) String() string { + return fmt.Sprintf("X: %v, Y: %v, W: %v, H: %v", rect.X, rect.Y, rect.W, rect.H) +} diff --git a/core/vector2.go b/core/vector2.go new file mode 100644 index 0000000..39c8b5d --- /dev/null +++ b/core/vector2.go @@ -0,0 +1,19 @@ +package core + +import "fmt" + +type Vector2 struct { + X float64 + Y float64 +} + +func (p Vector2) String() string { + return fmt.Sprintf("X: %v, Y: %v", p.X, p.Y) +} + +func (vector Vector2) Add(other Vector2) Vector2 { + return Vector2{ + X: vector.X + other.X, + Y: vector.Y + other.Y, + } +} diff --git a/game/game.go b/game/game.go new file mode 100644 index 0000000..5e49075 --- /dev/null +++ b/game/game.go @@ -0,0 +1,36 @@ +package game + +import ( + "log" + + "github.com/manleydev/golang-game-framework/node" + "github.com/manleydev/golang-game-framework/rendering" + "github.com/manleydev/golang-game-framework/sdl" +) + +func Run(root *node.Node, renderer rendering.Renderer2D) { + texture := sdl.NewSdlTexture2D(renderer, "gopher.bmp") + + g := node.NewSprite2D(texture) + defer root.AddChild(g) + + g.OnReady(func() error { + log.Println("Hello world!") + return nil + }) + + g.OnUpdate(func() error { + g.Rotation += 0.01 + return nil + }) + + g.Name = "Gopher" + + camera := node.NewCamera2D(&renderer, rendering.NewStandardCamera()) + defer root.AddChild(camera) + + camera.OnReady(func() error { + return camera.Enable() + }) + +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..59c6597 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/manleydev/golang-game-framework + +go 1.16 + +require github.com/veandco/go-sdl2 v0.4.21 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c551f58 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/veandco/go-sdl2 v0.4.21 h1:85AtFYv3vSPZvyOOxkJ03sHoJe8ESjPSZLr0KueQtVY= +github.com/veandco/go-sdl2 v0.4.21/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= diff --git a/gopher.bmp b/gopher.bmp new file mode 100644 index 0000000000000000000000000000000000000000..2078ea05dcf2aeb24a0da10708429e1fd0d52219 GIT binary patch literal 12342 zcmeI0F;2rk6huQ!N5v5+sZt|)PQk69;w&k17p@Riu_M2gX06$b1U|Fl`A=gP z5$_-S*WLNGFF#+(=WYHx?4HY1UgiAhar#Vx_w)4qdGohNs$DmSF94d%QwM+EfY-Ek z<=gWFP3Ecj_B_EO)vkPdo}kG*HQ$~mc%<5uZ_g7nnWyI4^8}AnyYlUMf+q9Se0!eY zk!n}IJx|bNo|2*CwQdV)xG_+ypDJ+YMDC!r=-a|wRaae zfq$glo9U5iSMM%z4*sb<-K?i3{qtT_^FMk1D`x&N_`QdxxbETk`8xbw{dW4X%N9l_ z|7!Shp_4DLY{|(V{Oc{*Weeka@;0Xe%a*nwT;F2D3gde6Hm3s1mbM{W-(tfGV>6lG z2U;_~C$v1&>BlUvY-#Y%4Y23djLzAcUA8bXreaP4u>9lsIoDKmh)z&vdrbVemiMc79{h6y?Yp#`pmX-t+d2Krspe&C wdm>NUwVcq8nLNF7#f;3;;b(bM@12dDUS|3Sf3tz