diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..8c45cda --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "go.formatTool": "goimports" +} \ No newline at end of file diff --git a/entity/entity.go b/entity/entity.go new file mode 100644 index 0000000..0a11974 --- /dev/null +++ b/entity/entity.go @@ -0,0 +1,25 @@ +package entity + +import ( + "github.com/kettek/goro" +) +// Entity is a type that represents an active entity in the world. +type Entity struct { + X, Y int + Rune rune + Style goro.Style +} +// Move moves the entity by a given amount. +func (e *Entity) Move(x, y int) { + e.X += x + e.Y += y +} +// NewEntity returns a pointer to a newly created Entity. +func NewEntity(x int, y int, r rune, s goro.Style) *Entity { + return &Entity{ + X: x, + Y: y, + Rune: r, + Style: s, + } +} \ No newline at end of file diff --git a/go.mod b/go.mod index edc433f..f54e16f 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module steel go 1.12 -require github.com/kettek/goro v0.0.0-20190627030747-34501f248e64 +require ( + github.com/kettek/goro v0.0.0-20190628090227-a35769c6cfe8 + golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb // indirect +) diff --git a/go.sum b/go.sum index 2ae97bc..859ccae 100644 --- a/go.sum +++ b/go.sum @@ -21,6 +21,8 @@ github.com/jfreymuth/oggvorbis v1.0.0/go.mod h1:abe6F9QRjuU9l+2jek3gj46lu40N4qlY github.com/jfreymuth/vorbis v1.0.0/go.mod h1:8zy3lUAm9K/rJJk223RKy6vjCZTWC61NA2QD06bfOE0= github.com/kettek/goro v0.0.0-20190627030747-34501f248e64 h1:pgAPlM6qutPnrkIDqlR1Rne1O60HsVQDE8tkKCZ1dJI= github.com/kettek/goro v0.0.0-20190627030747-34501f248e64/go.mod h1:wwgugDvR3Lhzz0hvCpjEFbu12RmCvkLDDYSzM3ILeww= +github.com/kettek/goro v0.0.0-20190628090227-a35769c6cfe8 h1:cRIFgXj8H9M6ZggN/jFaAGpJchSylj/ruF+ZqKb9JTY= +github.com/kettek/goro v0.0.0-20190628090227-a35769c6cfe8/go.mod h1:wwgugDvR3Lhzz0hvCpjEFbu12RmCvkLDDYSzM3ILeww= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -36,7 +38,10 @@ golang.org/x/mobile v0.0.0-20180806140643-507816974b79/go.mod h1:z+o9i4GpDbdi3rU golang.org/x/mobile v0.0.0-20190127143845-a42111704963/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190203050204-7ae0202eb74c h1:YeMXU0KQqExdpG959DFhAhfpY8myIsnfqj8lhNFRzzE= golang.org/x/sys v0.0.0-20190203050204-7ae0202eb74c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20190202235157-7414d4c1f71c/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/main.go b/main.go index 9b1dec7..095b7b7 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,8 @@ import ( "log" "github.com/kettek/goro" + + "steel/entity" ) func main() { @@ -17,24 +19,20 @@ func main() { screen.SetSize(60, 14) // Our initial variables. - playerX, playerY := screen.Columns/2, screen.Rows/2 + player := entity.NewEntity(screen.Columns/2, screen.Rows/2, '@', goro.Style{Foreground: goro.ColorWhite}) // The game loop. for { // Draw screen. - screen.DrawRune(playerX, playerY, '@', goro.Style{ - Foreground: goro.ColorRed, - }) + screen.DrawRune(player.X, player.Y, player.Rune, player.Style) screen.Flush() - screen.DrawRune(playerX, playerY, ' ', goro.Style{}) - + screen.DrawRune(player.X, player.Y, ' ', goro.Style{}) // Handle events. switch event := screen.WaitEvent().(type) { case goro.EventKey: switch action := handleKeyEvent(event).(type) { case ActionMove: - playerX += action.X - playerY += action.Y + player.Move(action.X, action.Y) case ActionQuit: goro.Quit() } diff --git a/steel.exe b/steel.exe new file mode 100644 index 0000000..7840b30 Binary files /dev/null and b/steel.exe differ