part 2, 2/8
This commit is contained in:
parent
bd576b4e54
commit
ace6a7d811
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"go.formatTool": "goimports"
|
||||
}
|
25
entity/entity.go
Normal file
25
entity/entity.go
Normal file
|
@ -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,
|
||||
}
|
||||
}
|
5
go.mod
5
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
|
||||
)
|
||||
|
|
5
go.sum
5
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=
|
||||
|
|
14
main.go
14
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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user