Code Monkey home page Code Monkey logo

golang-moving-square's Introduction

Golang Moving Square Test

A simple program that opens a window with a black background and a white square that you can move with the arrow keys. I wanted to test Go's interop with C and its Webassembly capabilities.

I used emoon's minifb for the desktop version. I've only built it for Mac but it should work on Windows, Linux and FreeBSD as these platforms are supported by minifb.

I used tinygo to build the web version

screen-gif screen-gif

Build Instructions

clone recursively with:

git clone --recursive https://github.com/phillvancejr/golang-moving-square.git

Desktop with Minifb

Mac

For mac you can use the makefile provided. Minifb uses CMake so you need that in your path.

make minifb
make desktop

The platform defaults to mac, so if you're on a different unix you should pass the platform and the cmake flags to make minifb, for example

make minifb platform=linux cmake_flags='-DUSE_WAYLAND_API=OFF'

For other desktop OS' look at minifb's build instructions

minifb.go

In minifb.go add #cgo <os> LDFLAGS: -Ldeps/<os> -lminifb

#cgo CFLAGS: -Ideps/minifb/include
#cgo darwin LDFLAGS: -Ldeps/mac -lminifb
#cgo darwin LDFLAGS: -framework MetalKit -framework Metal -framework Cocoa
#cgo <os> LDFLAGS: -Ldeps/<os> -lminifb
#include <MiniFB.h>
#include <stdlib.h>

Web with Wasm & TinyGo

You need tinygo in your path of course, then if using the makefile

make web
make server
./server

The server defaults to port 8000 but you can pass another port on the command line

Controls

Just use the arrow keys to move around and escape key to close the window on desktop

golang-moving-square's People

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.