edit steel lord
This commit is contained in:
parent
fbb441de07
commit
9b8f7f04b1
2
go.mod
2
go.mod
|
@ -3,6 +3,6 @@ module steel
|
|||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/kettek/goro v0.0.0-20190628090227-a35769c6cfe8
|
||||
github.com/kettek/goro v0.0.0-20190712064943-f2e60f211651
|
||||
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb // indirect
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -5,6 +5,7 @@ github.com/gdamore/tcell v1.1.2 h1:Afe8cU6SECC06UmvaJ55Jr3Eh0tz/ywLjqWYqjGZp3s=
|
|||
github.com/gdamore/tcell v1.1.2/go.mod h1:h3kq4HO9l2On+V9ed8w8ewqQEmGCSSHOgQ+2h8uzurE=
|
||||
github.com/go-gl/glfw v0.0.0-20181213070059-819e8ce5125f/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||
github.com/gofrs/flock v0.7.0/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20180628210949-0892b62f0d9f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
|
@ -23,6 +24,8 @@ github.com/kettek/goro v0.0.0-20190627030747-34501f248e64 h1:pgAPlM6qutPnrkIDqlR
|
|||
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/kettek/goro v0.0.0-20190712064943-f2e60f211651 h1:VhL5yVz0lSMXbO7eK+lJ7jUe0IJRSV+4sUabMrUyDtQ=
|
||||
github.com/kettek/goro v0.0.0-20190712064943-f2e60f211651/go.mod h1:fO57DVF4MXRm+AOQWrFN0CFCbihOO36HUn42vjr00fU=
|
||||
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=
|
||||
|
@ -33,6 +36,7 @@ github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp
|
|||
golang.org/x/exp v0.0.0-20180710024300-14dda7b62fcd/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
|
||||
golang.org/x/image v0.0.0-20180926015637-991ec62608f3/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
|
||||
golang.org/x/image v0.0.0-20190118043309-183bebdce1b2 h1:FNSSV4jv1PrPsiM2iKGpqLPPgYACqh9Muav7Pollk1k=
|
||||
golang.org/x/image v0.0.0-20190118043309-183bebdce1b2/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
|
||||
golang.org/x/mobile v0.0.0-20180806140643-507816974b79/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
||||
golang.org/x/mobile v0.0.0-20190127143845-a42111704963/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
||||
|
|
6
main.go
6
main.go
|
@ -23,8 +23,8 @@ func main() {
|
|||
mapWidth, mapHeight := 80, 24
|
||||
|
||||
colors := map[string]goro.Color{
|
||||
"darkWall": goro.Color{R: 0, G: 0, B: 100, A:255},
|
||||
"darkGround": goro.Color{R: 50, G: 50, B: 150, A: 255},
|
||||
"darkWall": goro.ColorRed,
|
||||
"darkGround": goro.ColorBlue,
|
||||
}
|
||||
|
||||
gameMap := mapping.GameMap{
|
||||
|
@ -34,6 +34,8 @@ func main() {
|
|||
|
||||
gameMap.Initialize()
|
||||
|
||||
gameMap.MakeMap()
|
||||
|
||||
player := entity.NewEntity(screen.Columns/2, screen.Rows/2, '@', goro.Style{Foreground: goro.ColorWhite})
|
||||
npc := entity.NewEntity(screen.Columns/2-5, screen. Rows/2, '@', goro.Style{Foreground: goro.ColorYellow})
|
||||
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
package mapping
|
||||
|
||||
import (
|
||||
"github.com/kettek/goro"
|
||||
)
|
||||
|
||||
// GameMap is our map data type.
|
||||
type GameMap struct {
|
||||
Width, Height int
|
||||
|
@ -10,16 +15,53 @@ func (g *GameMap) Initialize() {
|
|||
g.Tiles = make([][]Tile, g.Width)
|
||||
|
||||
for x := range g.Tiles {
|
||||
g.Tiles[x] = make([]Tile, g. Height)
|
||||
g.Tiles[x] = make([]Tile, g.Height)
|
||||
for y := range g.Tiles[x] {
|
||||
g.Tiles[x][y] = Tile{
|
||||
BlockSight: true,
|
||||
BlockMovement: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MakeMap populates our GameMap with rooms.
|
||||
func (g *GameMap) MakeMap() {
|
||||
room1 := NewRect(20, 15, 10, 15)
|
||||
room2 := NewRect(35, 15, 10, 15)
|
||||
|
||||
g.CreateRoom(room1)
|
||||
g.CreateRoom(room2)
|
||||
g.CreateHTunnel(25, 40, 23)
|
||||
}
|
||||
|
||||
// CreateRoom creates a room from a provided rect.
|
||||
func (g *GameMap) CreateRoom(r *Rect) {
|
||||
for x := r.X1 + 1; x < r.X2; x++ {
|
||||
for y := r.Y1 + 1; y < r.Y2; y++ {
|
||||
if g.InBounds(x, y) {
|
||||
g.Tiles[x][y] = Tile{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Create HTunnel creates a horizontal tunnel from x1 to/from x1 starting at y.
|
||||
func (g *GameMap) CreateHTunnel(x1, x2, y int) {
|
||||
for x := goro.MinInt(x1, x2); x <= goro.MaxInt(x1, x2); x++ {
|
||||
if g.InBounds(x, y) {
|
||||
g.Tiles[x][y] = Tile{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CreateVTunnel creates a vertical tunnel from y1 to/from y2 starting at x.
|
||||
func (g *GameMap) CreateVTunnel(y1, y2, x int) {
|
||||
for y := goro.MinInt(y1, y2); y <= goro.MaxInt(y1, y2); y++ {
|
||||
if g.InBounds(x, y) {
|
||||
g.Tiles[x][y] = Tile{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IsBlocked returns if the given coordinates are blocking movement.
|
||||
|
@ -31,3 +73,10 @@ func (g *GameMap) IsBlocked(x, y int) bool {
|
|||
return g.Tiles[x][y].BlockMovement
|
||||
}
|
||||
|
||||
// InBounds returns if the given coordinates are within the map's bounds.
|
||||
func (g *GameMap) InBounds (x, y int) bool {
|
||||
if x < 0 || x >= g.Width || y < 0 || y >= g.Height {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
27
mapping/rect.go
Normal file
27
mapping/rect.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package mapping
|
||||
|
||||
// Rect is a helper type to represent a rectangular area.
|
||||
type Rect struct {
|
||||
X1, Y1, X2, Y2 int
|
||||
}
|
||||
|
||||
// NewRect returns a new Rect type with its properties calculated.
|
||||
func NewRect(x int, y int, w int, h int) *Rect {
|
||||
return &Rect{
|
||||
X1: x,
|
||||
Y1: y,
|
||||
X2: x + w,
|
||||
Y2: y + h,
|
||||
}
|
||||
}
|
||||
// Center returns the center of the Rect.
|
||||
func (r *Rect) Center() (x, y int) {
|
||||
return (r.X1 + r.X2) / 2, (r.Y1 + r.Y2) / 2
|
||||
}
|
||||
// Intersect returns a bool representing if the Rect intersects with another.
|
||||
func (r *Rect) Intersect(other *Rect) bool {
|
||||
if r.X1 <= other.X2 && r.X2 >= other.X1 && r.Y1 <= other.Y2 && r.Y2 >= other.Y1 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
|
@ -4,4 +4,3 @@ type Tile struct {
|
|||
BlockMovement bool
|
||||
BlockSight bool
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user