Write Your Game in Go

Here is my cross-platform Go game prototyping library in action.

video.gif

This little space ship was created in only 47 lines of code:

package main

import "github.com/gonutz/prototype/draw"

func main() {
    x, y := 60, 240
    var bullets []bullet
    draw.RunWindow("Game", 640, 480, func(window draw.Window) {
        // handle input
        if window.IsKeyDown(draw.KeyRight) {
            x += 3
        } else if window.IsKeyDown(draw.KeyLeft) {
            x -= 3
        }
        if window.IsKeyDown(draw.KeyUp) {
            y -= 2
        } else if window.IsKeyDown(draw.KeyDown) {
            y += 2
        }
        if window.WasKeyPressed(draw.KeySpace) {
            bullets = append(bullets, bullet{x: x + 15, y: y, life: 1})
        }

        // update world
        n := 0
        for i := range bullets {
            bullets[i].x += 6
            bullets[i].life -= 0.01
            if bullets[i].life >= 0 {
                bullets[n] = bullets[i]
                n++
            }
        }
        bullets = bullets[:n]

        // render
        for _, b := range bullets {
            window.FillEllipse(b.x-5, b.y-5, 10, 10, draw.RGBA(0, 1, 0, b.life))
        }
        window.FillRect(x-20, y-20, 40, 40, draw.Red)
    })
}

type bullet struct {
    x, y int
    life float32
}

If you love the Go programming language as much as I do, why not create your game in Go? Give it a try. If you have any questions or suggestions for improvement, hit me up!