commit 8c884d4cab31a371a17e9e89792d371a2e89c2de Author: Noah Petherbridge Date: Thu Oct 26 18:03:11 2017 -0700 Initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..da32794 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,23 @@ +# Top-most EditorConfig file +root = true + +# Common settings for all files. I don't specify indent type here, because +# some EditorConfig implementations (notably Atom) will cause default settings +# and behaviors (like tab type auto-detection) to be overridden. +[*] +charset = utf-8 +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true + +[*.go] +indent_style = tab +indent_size = 4 + +[*.md] +indent_style = space +indent_size = 2 + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6fb1d5c --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +SHELL := /bin/bash + +VERSION=$(shell grep -e 'Version' doodle.go | head -n 1 | cut -d '"' -f 2) +BUILD=$(shell git describe --always) +CURDIR=$(shell curdir) + +# Inject the build version (commit hash) into the executable. +LDFLAGS := -ldflags "-X main.Build=$(BUILD)" + +# `make setup` to set up a new environment, pull dependencies, etc. +.PHONY: setup +setup: clean + go get -u ./... + +# `make build` to build the binary. +.PHONY: build +build: + gofmt -w . + go build $(LDFLAGS) -i -o bin/doodle cmd/doodle/main.go + +# `make run` to run it in debug mode. +.PHONY: run +run: + go run cmd/doodle/main.go -debug + +# `make test` to run unit tests. +.PHONY: test +test: + go test ./... + +# `make clean` cleans everything up. +.PHONY: clean +clean: +rm -rf bin dist diff --git a/README.md b/README.md new file mode 100644 index 0000000..23a165d --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Doodle diff --git a/cmd/doodle/main.go b/cmd/doodle/main.go new file mode 100644 index 0000000..1170f61 --- /dev/null +++ b/cmd/doodle/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "flag" + + "github.com/kirsle/doodle" +) + +// Build number is the git commit hash. +var Build string + +// Command line args +var ( + debug bool +) + +func init() { + flag.BoolVar(&debug, "debug", false, "Debug mode") +} + +func main() { + flag.Parse() + + app := doodle.New(debug) + _ = app +} diff --git a/doodle.go b/doodle.go new file mode 100644 index 0000000..03e0d98 --- /dev/null +++ b/doodle.go @@ -0,0 +1,59 @@ +package doodle + +import "github.com/veandco/go-sdl2/sdl" + +// Version number. +const Version = "0.0.0-alpha" + +// Doodle is the game object. +type Doodle struct { + Debug bool + + window *sdl.Window + renderer *sdl.Renderer +} + +// New initializes the game object. +func New(debug bool) *Doodle { + d := &Doodle{ + Debug: debug, + } + + // Initialize SDL. + if err := sdl.Init(sdl.INIT_EVERYTHING); err != nil { + panic(err) + } + defer sdl.Quit() + + // Create our window. + window, err := sdl.CreateWindow( + "Doodle v"+Version, + sdl.WINDOWPOS_CENTERED, + sdl.WINDOWPOS_CENTERED, + 800, + 600, + sdl.WINDOW_SHOWN, + ) + if err != nil { + panic(err) + } + defer window.Destroy() + + surface, err := window.GetSurface() + if err != nil { + panic(err) + } + + rect := sdl.Rect{ + X: 0, + Y: 0, + W: 200, + H: 200, + } + surface.FillRect(&rect, 0xffff0000) + window.UpdateSurface() + + sdl.Delay(2500) + + return d +}