{"id":18938309,"url":"https://github.com/faiface/gogame","last_synced_at":"2025-04-15T19:30:23.740Z","repository":{"id":57502825,"uuid":"64868752","full_name":"faiface/gogame","owner":"faiface","description":"A simple and useful game library in Go.","archived":false,"fork":false,"pushed_at":"2017-01-23T21:25:40.000Z","size":46,"stargazers_count":12,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T01:12:13.304Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/faiface.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-03T18:16:02.000Z","updated_at":"2022-02-20T22:50:13.000Z","dependencies_parsed_at":"2022-08-31T08:01:44.243Z","dependency_job_id":null,"html_url":"https://github.com/faiface/gogame","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faiface%2Fgogame","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faiface%2Fgogame/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faiface%2Fgogame/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faiface%2Fgogame/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/faiface","download_url":"https://codeload.github.com/faiface/gogame/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249138504,"owners_count":21218898,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T12:14:03.096Z","updated_at":"2025-04-15T19:30:23.461Z","avatar_url":"https://github.com/faiface.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# I no longer work on this library. Check out [Pixel](https://github.com/faiface/pixel) instead.\n\n# Gogame\n\nA simple and useful game library in Go. Doc: https://godoc.org/github.com/faiface/gogame\n\n```\ngo get github.com/faiface/gogame\n```\n\n## Requirements\n\nThis library is using SDL2 under the hood. That means that you need to have original SDL2 libraries\ninstalled. So far, these are required:\n\n- SDL2\n- SDL2_image\n- SDL2_gfx\n\n## Short Guide\n\n### Basics\n\nFirst, let's import Gogame.\n\n```go\nimport \"github.com/faiface/gogame\"\n```\n\nBefore you use any of Gogame, you have to initialize it. If you're writing a game, that usually\nhappens at the beginning of a program. When you're done with Gogame, you have to quit it.\n\n```go\nfunc main() {\n\tgogame.Init()\n\tdefer gogame.Quit()\n}\n```\n\nIf you've ever written a game, you surely are familiar with the \"game loop\" concept. Gogame manages\nthis for you with `gogame.Loop` function. Let's take a look at it's signature:\n\n```go\nfunc Loop(cfg Config, lf LoopFunc) error\n```\n\nLoop takes `Config` as it's first argument, and a `LoopFunc` as it's second argument. `Config` is\nbasically a configuration of your game window and some additional settings. `LoopFunc` stands for:\n\n```go\ntype LoopFunc func(ctx Context)\n```\n\nOk, so `LoopFunc` is a function that takes a `gogame.Context`. We'll see what it means later. Gogame\nwill call this function at the every iteration of the game loop. `gogame.Loop` function basically\nworks like this (pseudocode):\n\n```go\nfunc Loop(cfg Config, lf LoopFunc) error {\n\t// make a game window\n\n\tfor {\n\t\t// update input and output\n\n\t\tctx := /* make context */\n\t\tlf(ctx)\n\t}\n}\n```\n\nLet's make a `Config` and call `gogame.Loop` to start a game! For `LoopFunc` we'll use an\nanonymous function, to make it easier.\n\n```go\npackage main\n\nimport \"github.com/faiface/gogame\"\n\nfunc main() {\n\tgogame.Init()\n\tdefer gogame.Quit()\n\n\tcfg := gogame.Config{\n\t\tTitle:       \"Hello, Gogame!\" // title of the game window\n\t\tWidth:       1024,            // width of the game window\n\t\tHeight:      768,             // height of the game window\n\t\tFPS:         60,              // our LoopFunc will be called 60 times per second\n\t\tQuitOnClose: true,            // whenever you close a window, game loop ends\n\t}\n\n\tgogame.Loop(cfg, func(ctx gogame.Context) {\n\t\t// nothing here yet\n\t})\n}\n```\n\nWhen you run this program, you should see an empty black window with title \"Hello, Gogame!\". Great!\n\n### Context\n\nAs you could see, `LoopFunc` has one argument: a `Context`. What is it? It is a way to interact with\nyou game window. All the input from the mouse and keyboard, and all the drawing goes through a\n`Context`.\n\n#### Input\n\nGogame doesn't provide a traditional event system for input, because I don't think it's the best\nway to deal with input. Instead, it provides a set of methods that allow you to check the state of\nyour input devices. For example, you can use `ctx.KeyDown(gogame.KeyLeft)` to check if the left\narrow is pressed on you keyboard. Here's an incomplete overview of the methods. You can find all of\nthem in the documentation of the `gogame.Input` interface.\n\n```go\ngogame.Loop(cfg, func(ctx gogame.Context) {\n\tif ctx.KeyDown(gogame.KeyLeft) {\n\t\tfmt.Println(\"Left arrow is being pressed down!\")\n\t}\n\tif ctx.KeyJustDown(gogame.KeySpace) {\n\t\tfmt.Println(\"You have just pressed space!\")\n\t}\n\tif ctx.KeyJustUp(gogame.KeySpace) {\n\t\tfmt.Println(\"You have just released space!\")\n\t}\n\tfmt.Println(ctx.MousePosition())\n\tif ctx.MouseJustDown(gogame.MouseLeft) {\n\t\tfmt.Println(\"Left mouse button just pressed!\")\n\t}\n\tfmt.Println(ctx.WindowSize())\n})\n```\n\n#### Output\n\nYou can also use `Context` to do all kinds of graphical output (audio output is coming). Here's\nagain an incomplete overview, you can find all of the methods in the documentation of\n`gogame.Output` interface.\n\n```go\ngogame.Loop(cfg, func(ctx gogame.Context) {\n\tctx.Clear(gogame.Colors[\"red\"])\n\tctx.DrawPicture(gogame.Rect{X: 100, Y: 100, W: 50, H: 50}, myDog)\n\tctx.DrawLine(gogame.Vec{X: 100, Y: 100}, gogame.Vec{X: 500, Y: 400}, 10, gogame.Colors[\"red\"])\n})\n```\n\n### Pictures\n\nSomewhere they are called 'images', elsewhere 'textures', even elsewhere 'surfaces', we call them\n*pictures*. You can load a picture from a file using `gogame.LoadPicture` function like this:\n\n```go\nmyDog := gogame.LoadPicture(\"data/mydog.png\")\n```\n\nThen you can draw a picture onto the window using the `ctx.DrawPicture` method:\n\n```go\nctx.DrawPicture(gogame.Rect{X: 100, Y: 100, W: 50, H: 50}, myDog)\n```\n\nThe picture will be stretched to fit the provided rectangle precisely.\n\n### What else is supported?\n\nAnimations, cameras, canvases, ... look up the documentation\n(https://godoc.org/github.com/faiface/gogame)!\n\n## Notes\n\nThis library is currently heavily in development alongside my game.\n\nIt is by no means complete yet and may be changing in major ways.\n\n## Contribution\n\nIs very welcome! You can improve the documentation, open issues, and contribute code.\nDon't hesitate and do a pull request!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaiface%2Fgogame","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffaiface%2Fgogame","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaiface%2Fgogame/lists"}