Skip to content

Instantly share code, notes, and snippets.

@jakelacey2012
Created November 13, 2017 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakelacey2012/f2457b940f518f60a4c113ece950ae3f to your computer and use it in GitHub Desktop.
Save jakelacey2012/f2457b940f518f60a4c113ece950ae3f to your computer and use it in GitHub Desktop.
Functional game loop
package main
import "fmt"
type coords struct {
x int
y int
}
type apple struct {
position coords
}
type gameState struct {
apple apple
}
func logic(state *gameState) {
state.apple.position.x = state.apple.position.x + 1
}
func gameLoop(running bool, state *gameState) bool {
if running == false {
return false
}
logic(state)
return gameLoop(running, state)
}
func main() {
// set the initial game state
state := gameState{
apple: apple{
position: coords{
x: 2,
y: 2,
},
},
}
gameLoop(true, &state)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment