GitHub - gonutz/prototype: Simple 2D game prototyping framework targetting Windows, Mac, Linux, WASM. (original) (raw)

prototype

Simply prototype 2D games using an easy, minimal interface that lets you draw simple primitives and images on the screen, easily handle mouse and keyboard events, and play sounds.

Games

Installation

Install the Go programming language. After clicking the download link you will be referred to the installation instructions for your specific operating system.

Install Git and make it available in the PATH so the Go tool can use it.

For Linux and macOS, you need a C compiler installed. On Windows this is not necessary.

Supported Targets

The prototype framework supports multiple targets:

Windows (default)

Linux/macOS (GLFW backend)

WebAssembly (experimental)

To build and run a WASM version of your game, you can use the drawsm tool. Install it with

go install github.com/gonutz/prototype/cmd/drawsm@latest

It allows you to run your game locally from within your project directory with

or build it into the project directory with

Installation (Library & Samples)

Documentation

For a description of all library functions, see the package doc page. Most functionality is in the Window interface, and documented via code comments.

Example

package main

import ( "math"

"github.com/gonutz/prototype/draw"

)

func main() { draw.RunWindow("Title", 640, 480, update) }

func update(window draw.Window) { w, h := window.Size() centerX, centerY := w/2, h/2

mouseX, mouseY := window.MousePosition()
mouseInCircle := math.Hypot(float64(mouseX-centerX), float64(mouseY-centerY)) < 20
color := draw.DarkRed
if mouseInCircle {
    color = draw.Red
}
window.FillEllipse(centerX-20, centerY-20, 40, 40, color)
window.DrawEllipse(centerX-20, centerY-20, 40, 40, draw.White)
if mouseInCircle {
    window.DrawScaledText("Close!", centerX-40, centerY+25, 1.6, draw.Green)
}

for _, click := range window.Clicks() {
    dx, dy := click.X-centerX, click.Y-centerY
    if dx*dx+dy*dy <= 20*20 {
        window.Close()
    }
}

}

This example displays a window with a round button in the middle to close it. It demonstrates basic drawing and event handling.