|
@@ -11,8 +11,11 @@ import (
|
|
|
)
|
|
|
|
|
|
type StarPos struct {
|
|
|
- Y int
|
|
|
- X int
|
|
|
+ Y int
|
|
|
+ X int
|
|
|
+}
|
|
|
+
|
|
|
+type StarInfo struct {
|
|
|
Symbol int
|
|
|
Color bool
|
|
|
}
|
|
@@ -21,7 +24,7 @@ type StarField struct {
|
|
|
RNG *rand.Rand
|
|
|
MX int
|
|
|
MY int
|
|
|
- Sky map[StarPos]struct{}
|
|
|
+ Sky map[StarPos]StarInfo
|
|
|
}
|
|
|
|
|
|
func (s *StarField) make_pos() StarPos {
|
|
@@ -37,17 +40,17 @@ func (s *StarField) make_pos() StarPos {
|
|
|
func (s *StarField) Regenerate() {
|
|
|
s.MX = door.Width
|
|
|
s.MY = door.Height
|
|
|
- s.Sky = make(map[StarPos]struct{})
|
|
|
|
|
|
s.RNG = rand.New(mt19937.New())
|
|
|
s.RNG.Seed(time.Now().UnixNano())
|
|
|
|
|
|
max_stars := ((s.MX * s.MY) / 40)
|
|
|
+ s.Sky = make(map[StarPos]StarInfo, max_stars)
|
|
|
+
|
|
|
for i := 0; i < max_stars; i++ {
|
|
|
pos := s.make_pos()
|
|
|
- pos.Symbol = i % 2
|
|
|
- pos.Color = i%5 < 2
|
|
|
- s.Sky[pos] = struct{}{}
|
|
|
+ info := StarInfo{Symbol: i % 2, Color: i%5 < 2}
|
|
|
+ s.Sky[pos] = info
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -68,7 +71,7 @@ func (s *StarField) Display(d *door.Door) {
|
|
|
var last_pos StarPos
|
|
|
|
|
|
// maps in go are not sorted
|
|
|
- for pos, _ := range s.Sky {
|
|
|
+ for pos, info := range s.Sky {
|
|
|
use_goto := true
|
|
|
|
|
|
if i != 0 {
|
|
@@ -104,12 +107,12 @@ func (s *StarField) Display(d *door.Door) {
|
|
|
d.Write(door.Goto(pos.X, pos.Y))
|
|
|
}
|
|
|
|
|
|
- if pos.Color {
|
|
|
+ if info.Color {
|
|
|
d.Write(dark)
|
|
|
} else {
|
|
|
d.Write(white)
|
|
|
}
|
|
|
- d.Write(stars[pos.Symbol])
|
|
|
+ d.Write(stars[info.Symbol])
|
|
|
last_pos = pos
|
|
|
last_pos.X++
|
|
|
i++
|