Skip to content

Video game made in golang, based on sdl2 bindings

Notifications You must be signed in to change notification settings

topheman/gopher-ball

Repository files navigation

gopher-ball

DOWNLOAD DEMOS in the releases section
Choose your build by platform - supporting both MacOS (darwin) and Windows.

Goal

I have a JavaScript background (both frontend and NodeJS). I started go a few weeks ago (really enjoy it - just like a NodeJS with pointers and threads 😜).

For my first side project in Go, I decided to make a video game, since I think it's a very good way to get into a new programming language.

The Youtube Videos tutorial JustForFunc by Francesc Campoy were a great resource.

At the end, the development only took me a few days whereas the packaging / build part took me a lot of time (and is still in progress) ... For this part, I must thank veeableful for her help on this issue.

If you feel like to help, please take a look at the issues.

Install

You need to install first SDL2 and the SDL2 bindings for Go.

Install SDL2

You need to install first SDL2 and the SDL2 bindings for Go. To do so, follow the instructions here. It is quite easy to install on basically any platform.

You will also need to install pkg-config.

Example (on Mac OS X - with pkg-config already present):

$ which pkg-config
/usr/local/bin/pkg-config
$ brew install sdl2
$ brew install sdl2_image
$ brew install sdl2_ttf
$ brew install sdl2_mixer
$ go get -v github.com/veandco/go-sdl2/sdl
$ go get -v github.com/veandco/go-sdl2/mix
$ go get -v github.com/veandco/go-sdl2/img
$ go get -v github.com/veandco/go-sdl2/ttf

Development

You can build a dev version of the game via a simple go build.

You can also create the same build via make darwin-dev (same as go build, though it will name the binary gopher-ball.app, so that when you open it from the finder it doesn't open a terminal first).

Build

TLDR;

  • make darwin: will create a bundle for MacOS, in the ./dist folder (needs a Mac OS system)
  • make windows: will create a bundle for Windows, in the ./dist folder (needs a Windows system)
  • make clean: cleans up the ./dist folder
  • make (alias of make help): prints out the documentation of the Makefile

Explanation

There were a lot of apps made in golang with sdl2 (or other golang bridge with c) but none of them implement a release step (generate a standalone binary that you could share).

Since, there are C libraries involved, it implies that you link them in some way in the bundle you will generate. Here is my solution (please share yours):

On MacOS:

  • Create a bundle with the same folder structure as any MacOS .app
  • Identify the specific shared libraries (the ones under /user/local) using otool -L <binary_name> (same as Linux's ldd)
  • Repeat previous step on each libraries (to identify the links between nested libraries)
  • Copy those libraries to the bundle inside Contents/Frameworks
  • Link the root libraries (the one required by the binary) with install_name_tool -change <lib_name> @executable_path/../Frameworks/<lib_name> <binary_name>
  • Link the nested libraries with install_name_tool -change <lib_name> @executable_path/../Frameworks/<lib_name> <parent_lib_name>

Checkout the Makefile for the whole build steps.

Note: Some part of that could be automated via some recursive script - here is a start.

On Windows:

To list the dll used by the binary (using cygwin as bash):

ldd dist/gopher-ball-windows-amd64/gopher-ball-windows-amd64.exe | grep -v Windows

Or use dependencywalker.

Credits

Preview

Preview

Preview