- commit
- 745f4618044a51b537fa701665cac135fc7ff5d0
- parent
- eae6cec5c12cb4bac8fcc42f7c4192f9038b6c52
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-09-22 05:36
tweak map generation
Diffstat
| M | game.go | 10 | +++++----- |
| M | geo.go | 11 | +++++++++++ |
2 files changed, 16 insertions, 5 deletions
diff --git a/game.go b/game.go
@@ -80,14 +80,14 @@ func (game *Game) createId() int {
80 80 }
81 81
82 82 func (game *Game) generateMap() {
83 -1 prev := Rect{-5, -5, 5, 5}
-1 83 prev := Rect{-3, -3, 3, 3}
84 84
85 85 game.Rects = []Rect{prev}
86 86 lines := []Rect{}
87 87
88 -1 for i := 1; i <= 12; i++ {
89 -1 rect := randomRect(50)
90 -1 if rect.Area() < 250 {
-1 88 for i := 1; i <= 15; i++ {
-1 89 rect := randomRect(25)
-1 90 if rect.Area() < 150 && rect.Perimeter() < 80 {
91 91 game.Rects = append(game.Rects, rect)
92 92
93 93 p1 := prev.Center()
@@ -100,7 +100,7 @@ func (game *Game) generateMap() {
100 100 }
101 101 }
102 102
103 -1 game.Ladder = prev.Center()
-1 103 game.Ladder = prev.RandomPoint()
104 104
105 105 for _, line := range lines {
106 106 game.Rects = append(game.Rects, line)
diff --git a/geo.go b/geo.go
@@ -36,6 +36,10 @@ func (rect *Rect) Area() int {
36 36 return (rect.X2 - rect.X1) * (rect.Y2 - rect.Y1)
37 37 }
38 38
-1 39 func (rect *Rect) Perimeter() int {
-1 40 return ((rect.X2 - rect.X1) + (rect.Y2 - rect.Y1)) * 2
-1 41 }
-1 42
39 43 func (rect *Rect) Contains(x int, y int) bool {
40 44 return x >= rect.X1 && x <= rect.X2 && y >= rect.Y1 && y <= rect.Y2
41 45 }
@@ -46,3 +50,10 @@ func (rect *Rect) Center() Point {
46 50 (rect.Y2 + rect.Y1) / 2,
47 51 }
48 52 }
-1 53
-1 54 func (rect *Rect) RandomPoint() Point {
-1 55 return Point{
-1 56 rect.X1 + rand.Intn(rect.X2-rect.X1+1),
-1 57 rect.Y1 + rand.Intn(rect.Y2-rect.Y1+1),
-1 58 }
-1 59 }