aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-12-09 10:28:42 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:54 +0100
commit53f15bcda076043dbd6763fc85f6bd85cc7f3e71 (patch)
treef27aabb3af38d453736768b7926ff1eb9c0f99fe
parent35ce4679a4c48ae25ed8cbe108f0bc2430af8b8d (diff)
downloadmuhqs-game-53f15bcda076043dbd6763fc85f6bd85cc7f3e71.tar.gz
muhqs-game-53f15bcda076043dbd6763fc85f6bd85cc7f3e71.zip
support special wall, gate and tower tile selection
-rw-r--r--go/game/tile.go16
-rw-r--r--go/ui/mapView.go137
2 files changed, 138 insertions, 15 deletions
diff --git a/go/game/tile.go b/go/game/tile.go
index f8d160da..47f9a5d6 100644
--- a/go/game/tile.go
+++ b/go/game/tile.go
@@ -10,6 +10,8 @@ type TileType int
const (
neutral TileType = iota + 1
tower
+ gate
+ wall
house
farm
street
@@ -24,6 +26,10 @@ func (t TileType) String() string {
return "neutral"
case tower:
return "tower"
+ case wall:
+ return "wall"
+ case gate:
+ return "gate"
case house:
return "house"
case farm:
@@ -40,9 +46,15 @@ func (t TileType) String() string {
return ""
}
+func (t TileType) IsFortification() bool {
+ return t == TileTypes.Wall || t == TileTypes.Gate || t == TileTypes.Tower
+}
+
var TileTypes = struct {
Neutral TileType
Tower TileType
+ Wall TileType
+ Gate TileType
House TileType
Farm TileType
Street TileType
@@ -52,6 +64,8 @@ var TileTypes = struct {
}{
Neutral: neutral,
Tower: tower,
+ Wall: wall,
+ Gate: gate,
House: house,
Farm: farm,
Street: street,
@@ -63,6 +77,8 @@ var TileTypes = struct {
var TileNames = map[string]TileType{
"neutral": neutral,
"tower": tower,
+ "wall": wall,
+ "gate": gate,
"house": house,
"farm": farm,
"street": street,
diff --git a/go/ui/mapView.go b/go/ui/mapView.go
index 97dc19a2..1a91703c 100644
--- a/go/ui/mapView.go
+++ b/go/ui/mapView.go
@@ -70,7 +70,7 @@ func (mv *MapView) Width() int {
return maxWidth * TILE_WIDTH
}
-func rotateStreetImg(x, y int, radian float64, op *ebiten.DrawImageOptions) {
+func rotateTileImg(x, y int, radian float64, op *ebiten.DrawImageOptions) {
// Move the image's center to the screen's upper-left corner.
// This is a preparation for rotating. When geometry matrices are applied,
// the origin point is the upper-left corner.
@@ -84,7 +84,8 @@ func rotateStreetImg(x, y int, radian float64, op *ebiten.DrawImageOptions) {
op.GeoM.Translate(float64(TILE_WIDTH)/2, float64(TILE_HEIGHT)/2)
}
-func (vw *MapView) rotateStreet(x, y int, op *ebiten.DrawImageOptions) {
+func (vw *MapView) handleStreet(x, y int, op *ebiten.DrawImageOptions) *ebiten.Image {
+ var img *ebiten.Image
connections, left, right, above, below := vw.gameState.Map.FindStreetConnections(x, y)
if connections == 0 {
@@ -95,30 +96,128 @@ func (vw *MapView) rotateStreet(x, y int, op *ebiten.DrawImageOptions) {
// This street is not connected to anything. Seams odd!
if connections == 0 {
- log.Printf("Street at (%d, %d) is not connected", x, y)
+ log.Printf("Street at (%d, %d) is not connected", x, y)
+ img = assets.GetTile("street")
} else if (connections == 1 ||
(connections == 2 && ((left && right) || (above && below)))) &&
(above || below) {
- rotateStreetImg(x, y, math.Pi/2, op)
+
+ img = assets.GetTile("street")
+ if above || below {
+ rotateTileImg(x, y, math.Pi/2, op)
+ }
} else if connections == 2 {
+ img = assets.GetTile("street_2")
// normal orientation above and right
if right && below {
- rotateStreetImg(x, y, 3*math.Pi/2, op)
+ rotateTileImg(x, y, math.Pi/2, op)
} else if left && below {
- rotateStreetImg(x, y, math.Pi, op)
+ rotateTileImg(x, y, math.Pi, op)
} else if above && left {
- rotateStreetImg(x, y, math.Pi/2, op)
+ rotateTileImg(x, y, 3*math.Pi/2, op)
}
} else if connections == 3 {
+ img = assets.GetTile("street_3")
// normal orientation left above right
if above && right && below {
- rotateStreetImg(x, y, 3*math.Pi/2, op)
+ rotateTileImg(x, y, math.Pi/2, op)
} else if left && below && right {
- rotateStreetImg(x, y, math.Pi, op)
+ rotateTileImg(x, y, math.Pi, op)
} else if below && left && above {
- rotateStreetImg(x, y, math.Pi/2, op)
+ rotateTileImg(x, y, 3*math.Pi/2, op)
+ }
+ } else if connections == 4 {
+ img = assets.GetTile("street_4")
+ }
+
+ return img
+}
+
+func (vw *MapView) handleWall(x, y int, op *ebiten.DrawImageOptions) *ebiten.Image {
+ var img *ebiten.Image
+ connections, left, right, above, below := vw.gameState.Map.FindFortificationConnections(x, y)
+
+ if connections == 0 {
+ // This wall is not connected to another wall ->
+ // check any other non neutral tiles
+ connections, left, right, above, below = vw.gameState.Map.FindAnyConnections(x, y)
+ }
+
+ // This wall is not connected to anything. Seams odd!
+ if connections == 0 {
+ log.Printf("Wall at (%d, %d) is not connected", x, y)
+ img = assets.GetTile("wall")
+ } else if (connections == 1 ||
+ (connections == 2 && ((left && right) || (above && below)))) &&
+ (above || below) {
+
+ if above || below {
+ img = assets.GetTile("wall_ud")
+ } else {
+ img = assets.GetTile("wall")
+ }
+ } else if connections == 2 {
+ if above {
+ img = assets.GetTile("wall_elbow_up")
+ } else {
+ img = assets.GetTile("wall_elbow_down")
+ }
+
+ if left {
+ op.GeoM.Scale(-1, 1)
+ op.GeoM.Translate(float64(img.Bounds().Dx()), 0)
}
+ } else if connections == 3 || connections == 4 {
+ img = assets.GetTile("wall")
}
+
+ return img
+}
+
+func (vw *MapView) handleGate(x, y int, op *ebiten.DrawImageOptions) (img *ebiten.Image) {
+ _, left, right, above, below := vw.gameState.Map.FindFortificationConnections(x, y)
+
+ if left || right {
+ img = assets.GetTile("gate_lr")
+ } else if above || below {
+ img = assets.GetTile("gate_ud")
+ } else {
+ img = assets.GetTile("gate")
+ }
+
+ return
+}
+
+func (vw *MapView) handleTower(x, y int, op *ebiten.DrawImageOptions) *ebiten.Image {
+ connections, left, right, above, _ := vw.gameState.Map.FindFortificationConnections(x, y)
+ if connections == 0 {
+ return assets.GetTile("tower")
+ }
+
+ selector := ""
+ if left {
+ selector += "l"
+ }
+ if right {
+ selector += "r"
+ }
+ if above {
+ selector += "u"
+ }
+ // corner cases where tower is placed on the edge
+ if selector != "" && !strings.Contains(selector, "r") && len(vw.gameState.Map.Tiles[y])-1 == x {
+ selector += "r"
+ }
+
+ if selector != "" && !strings.Contains(selector, "l") && x == 0 {
+ selector += "l"
+ }
+
+ tileName := "tower"
+ if selector != "" {
+ tileName += "_" + selector
+ }
+ return assets.GetTile(tileName)
}
func (vw *MapView) newLayerImage() *ebiten.Image {
@@ -137,12 +236,20 @@ func (vw *MapView) drawMapLayer(screen *ebiten.Image) {
for x := 0; x < len(vw.gameState.Map.Tiles[y]); x++ {
pos := game.Position{X: x, Y: y}
tile := vw.gameState.Map.TileAt(pos)
- tileImg := assets.GetTile(tile.Raw)
-
+ var tileImg *ebiten.Image
op := &ebiten.DrawImageOptions{}
- // Rotate Street
- if tile.Type == game.TileTypes.Street {
- vw.rotateStreet(x, y, op)
+
+ switch tile.Type {
+ case game.TileTypes.Street:
+ tileImg = vw.handleStreet(x, y, op)
+ case game.TileTypes.Wall:
+ tileImg = vw.handleWall(x, y, op)
+ case game.TileTypes.Gate:
+ tileImg = vw.handleGate(x, y, op)
+ case game.TileTypes.Tower:
+ tileImg = vw.handleTower(x, y, op)
+ default:
+ tileImg = assets.GetTile(tile.Raw)
}
op.GeoM.Translate(x_px, y_px)