~johanvandegriff/ruegolike

308d1db01124b88fae93263c3e50511ea961139a — Johan Vandegriff 1 year, 4 months ago 21eb3a7
fixed edge cases for room rendering :)
4 files changed, 171 insertions(+), 37 deletions(-)

M display.go
M dungeon.go
M generate.go
M main.go
M display.go => display.go +161 -25
@@ 321,10 321,12 @@ func Display(s tcell.Screen, playerPos Position, visible *[height][width]bool, e
			if explored1[y][x] {
				char := level.GetChar(Point{x, y})
				if level.GetTile(Point{x, y}).IsRoom() && char != '*' {
					var isFloor [3][3]bool
					numFloors := 0
					for x2 := -1; x2 <= 1; x2++ {
						for y2 := -1; y2 <= 1; y2++ {
							if isXYInRange(x+x2, y+y2) && level.GetTile(Point{x + x2, y + y2}).IsRoomFloor() && explored1[y+y2][x+x2] {
							isFloor[x2+1][y2+1] = isXYInRange(x+x2, y+y2) && level.GetTile(Point{x + x2, y + y2}).IsRoomFloor() && explored1[y+y2][x+x2]
							if isFloor[x2+1][y2+1] {
								numFloors++
							}
						}


@@ 354,8 356,7 @@ func Display(s tcell.Screen, playerPos Position, visible *[height][width]bool, e
							} else if !isRoomBelow && !isRoomRight {
								char = '#'
							}
						}
						if char == '└' {
						} else if char == '└' {
							if isRoomAbove && isRoomRight {
								// char = '└'
							} else if !isRoomAbove && isRoomRight {


@@ 365,8 366,7 @@ func Display(s tcell.Screen, playerPos Position, visible *[height][width]bool, e
							} else if !isRoomAbove && !isRoomRight {
								char = '#'
							}
						}
						if char == '┐' {
						} else if char == '┐' {
							if isRoomBelow && isRoomLeft {
								// char = '┐'
							} else if !isRoomBelow && isRoomLeft {


@@ 376,8 376,7 @@ func Display(s tcell.Screen, playerPos Position, visible *[height][width]bool, e
							} else if !isRoomBelow && !isRoomLeft {
								char = '#'
							}
						}
						if char == '┘' {
						} else if char == '┘' {
							if isRoomAbove && isRoomLeft {
								// char = '┘'
							} else if !isRoomAbove && isRoomLeft {


@@ 387,9 386,7 @@ func Display(s tcell.Screen, playerPos Position, visible *[height][width]bool, e
							} else if !isRoomAbove && !isRoomLeft {
								char = '#'
							}
						}

						if char == '─' {
						} else if char == '─' {
							if isRoomLeft && isRoomRight {
								// char = '─'
							} else if !isRoomLeft && isRoomRight {


@@ 399,8 396,7 @@ func Display(s tcell.Screen, playerPos Position, visible *[height][width]bool, e
							} else if !isRoomLeft && !isRoomRight {
								char = '#'
							}
						}
						if char == '│' {
						} else if char == '│' {
							if isRoomAbove && isRoomBelow {
								// char = '│'
							} else if !isRoomAbove && isRoomBelow {


@@ 410,9 406,7 @@ func Display(s tcell.Screen, playerPos Position, visible *[height][width]bool, e
							} else if !isRoomAbove && !isRoomBelow {
								char = '#'
							}
						}

						if char == '├' {
						} else if char == '├' {
							if isRoomAbove && isRoomBelow && isRoomRight {
								// char = '├'
							} else if !isRoomAbove && isRoomBelow && isRoomRight {


@@ 430,8 424,7 @@ func Display(s tcell.Screen, playerPos Position, visible *[height][width]bool, e
							} else if !isRoomAbove && !isRoomBelow && !isRoomRight {
								char = '#'
							}
						}
						if char == '┤' {
						} else if char == '┤' {
							if isRoomAbove && isRoomBelow && isRoomLeft {
								// char = '┤'
							} else if !isRoomAbove && isRoomBelow && isRoomLeft {


@@ 449,8 442,7 @@ func Display(s tcell.Screen, playerPos Position, visible *[height][width]bool, e
							} else if !isRoomAbove && !isRoomBelow && !isRoomLeft {
								char = '#'
							}
						}
						if char == '┬' {
						} else if char == '┬' {
							if isRoomLeft && isRoomRight && isRoomBelow {
								// char = '┬'
							} else if !isRoomLeft && isRoomRight && isRoomBelow {


@@ 468,8 460,7 @@ func Display(s tcell.Screen, playerPos Position, visible *[height][width]bool, e
							} else if !isRoomLeft && !isRoomRight && !isRoomBelow {
								char = '#'
							}
						}
						if char == '┴' {
						} else if char == '┴' {
							if isRoomLeft && isRoomRight && isRoomAbove {
								// char = '┴'
							} else if !isRoomLeft && isRoomRight && isRoomAbove {


@@ 487,9 478,7 @@ func Display(s tcell.Screen, playerPos Position, visible *[height][width]bool, e
							} else if !isRoomLeft && !isRoomRight && !isRoomAbove {
								char = '#'
							}
						}

						if char == '┼' {
						} else if char == '┼' {
							if isRoomLeft && isRoomRight && isRoomAbove && isRoomBelow {
								// char = '┼'
							} else if !isRoomLeft && isRoomRight && isRoomAbove && isRoomBelow {


@@ 524,6 513,153 @@ func Display(s tcell.Screen, playerPos Position, visible *[height][width]bool, e
								char = '#'
							}
						}

						isFloorTop := isFloor[1][0]
						isFloorBottom := isFloor[1][2]
						isFloorLeft := isFloor[0][1]
						isFloorRight := isFloor[2][1]

						isFloorTopLeft := isFloor[0][0]
						isFloorTopRight := isFloor[2][0]
						isFloorBottomLeft := isFloor[0][2]
						isFloorBottomRight := isFloor[2][2]

						isFloorTopAny := isFloorTop || isFloorTopLeft || isFloorTopRight
						isFloorBottomAny := isFloorBottom || isFloorBottomLeft || isFloorBottomRight
						isFloorLeftAny := isFloorLeft || isFloorTopLeft || isFloorBottomLeft
						isFloorRightAny := isFloorRight || isFloorTopRight || isFloorBottomRight

						if char == '┌' {
							if !isFloorBottomRight {
								char = '#'
							}
						} else if char == '└' {
							if !isFloorTopRight {
								char = '#'
							}
						} else if char == '┐' {
							if !isFloorBottomLeft {
								char = '#'
							}
						} else if char == '┘' {
							if !isFloorTopLeft {
								char = '#'
							}
						} else if char == '─' {
							if !isFloorTopAny && !isFloorBottomAny {
								char = '#'
							}
						} else if char == '│' {
							if !isFloorLeftAny && !isFloorRightAny {
								char = '#'
							}
						} else if char == '├' {
							if !isFloorLeftAny && !isFloorTopRight && !isFloorBottomRight {
								char = '#'
							} else if !isFloorLeftAny && !isFloorTopRight && isFloorBottomRight {
								char = '┌'
							} else if !isFloorLeftAny && isFloorTopRight && !isFloorBottomRight {
								char = '└'
							} else if !isFloorLeftAny && isFloorTopRight && isFloorBottomRight {
								// char = '├'
							} else if isFloorLeftAny && !isFloorTopRight && !isFloorBottomRight {
								char = '│'
							} else if isFloorLeftAny && !isFloorTopRight && isFloorBottomRight {
								// char = '├'
							} else if isFloorLeftAny && isFloorTopRight && !isFloorBottomRight {
								// char = '├'
							} else if isFloorLeftAny && isFloorTopRight && isFloorBottomRight {
								// char = '├'
							}
						} else if char == '┤' {
							if !isFloorRightAny && !isFloorTopLeft && !isFloorBottomLeft {
								char = '#'
							} else if !isFloorRightAny && !isFloorTopLeft && isFloorBottomLeft {
								char = '┐'
							} else if !isFloorRightAny && isFloorTopLeft && !isFloorBottomLeft {
								char = '┘'
							} else if !isFloorRightAny && isFloorTopLeft && isFloorBottomLeft {
								// char = '┤'
							} else if isFloorRightAny && !isFloorTopLeft && !isFloorBottomLeft {
								char = '│'
							} else if isFloorRightAny && !isFloorTopLeft && isFloorBottomLeft {
								// char = '┤'
							} else if isFloorRightAny && isFloorTopLeft && !isFloorBottomLeft {
								// char = '┤'
							} else if isFloorRightAny && isFloorTopLeft && isFloorBottomLeft {
								// char = '┤'
							}
						} else if char == '┬' {
							if !isFloorTopAny && !isFloorBottomLeft && !isFloorBottomRight {
								char = '#'
							} else if !isFloorTopAny && !isFloorBottomLeft && isFloorBottomRight {
								char = '┌'
							} else if !isFloorTopAny && isFloorBottomLeft && !isFloorBottomRight {
								char = '┐'
							} else if !isFloorTopAny && isFloorBottomLeft && isFloorBottomRight {
								// char = '┬'
							} else if isFloorTopAny && !isFloorBottomLeft && !isFloorBottomRight {
								char = '─'
							} else if isFloorTopAny && !isFloorBottomLeft && isFloorBottomRight {
								// char = '┬'
							} else if isFloorTopAny && isFloorBottomLeft && !isFloorBottomRight {
								// char = '┬'
							} else if isFloorTopAny && isFloorBottomLeft && isFloorBottomRight {
								// char = '┬'
							}
						} else if char == '┴' {
							if !isFloorBottomAny && !isFloorTopLeft && !isFloorTopRight {
								char = '#'
							} else if !isFloorBottomAny && !isFloorTopLeft && isFloorTopRight {
								char = '└'
							} else if !isFloorBottomAny && isFloorTopLeft && !isFloorTopRight {
								char = '┘'
							} else if !isFloorBottomAny && isFloorTopLeft && isFloorTopRight {
								// char = '┴'
							} else if isFloorBottomAny && !isFloorTopLeft && !isFloorTopRight {
								char = '─'
							} else if isFloorBottomAny && !isFloorTopLeft && isFloorTopRight {
								// char = '┴'
							} else if isFloorBottomAny && isFloorTopLeft && !isFloorTopRight {
								// char = '┴'
							} else if isFloorBottomAny && isFloorTopLeft && isFloorTopRight {
								// char = '┴'
							}
						} else if char == '┼' {
							if !isFloorBottomLeft && !isFloorBottomRight && !isFloorTopLeft && !isFloorTopRight {
								char = '#'
							} else if !isFloorBottomLeft && !isFloorBottomRight && !isFloorTopLeft && isFloorTopRight {
								char = '└'
							} else if !isFloorBottomLeft && !isFloorBottomRight && isFloorTopLeft && !isFloorTopRight {
								char = '┘'
							} else if !isFloorBottomLeft && !isFloorBottomRight && isFloorTopLeft && isFloorTopRight {
								char = '┴'
							} else if !isFloorBottomLeft && isFloorBottomRight && !isFloorTopLeft && !isFloorTopRight {
								char = '┌'
							} else if !isFloorBottomLeft && isFloorBottomRight && !isFloorTopLeft && isFloorTopRight {
								char = '├'
							} else if !isFloorBottomLeft && isFloorBottomRight && isFloorTopLeft && !isFloorTopRight {
								// char = '┼'
							} else if !isFloorBottomLeft && isFloorBottomRight && isFloorTopLeft && isFloorTopRight {
								// char = '┼'
							} else if isFloorBottomLeft && !isFloorBottomRight && !isFloorTopLeft && !isFloorTopRight {
								char = '┐'
							} else if isFloorBottomLeft && !isFloorBottomRight && !isFloorTopLeft && isFloorTopRight {
								// char = '┼'
							} else if isFloorBottomLeft && !isFloorBottomRight && isFloorTopLeft && !isFloorTopRight {
								char = '┤'
							} else if isFloorBottomLeft && !isFloorBottomRight && isFloorTopLeft && isFloorTopRight {
								// char = '┼'
							} else if isFloorBottomLeft && isFloorBottomRight && !isFloorTopLeft && !isFloorTopRight {
								char = '┬'
							} else if isFloorBottomLeft && isFloorBottomRight && !isFloorTopLeft && isFloorTopRight {
								// char = '┼'
							} else if isFloorBottomLeft && isFloorBottomRight && isFloorTopLeft && !isFloorTopRight {
								// char = '┼'
							} else if isFloorBottomLeft && isFloorBottomRight && isFloorTopLeft && isFloorTopRight {
								// char = '┼'
							}
						}
					}
				}
				// if char == '#' {


@@ 536,7 672,7 @@ func Display(s tcell.Screen, playerPos Position, visible *[height][width]bool, e
				}
			} else {
				if debug {
					s.SetContent(x+offsetX, y+offsetY, level.GetChar(Point{x, y}), nil, style2)
					s.SetContent(x+offsetX, y+offsetY, level.GetChar(Point{x, y}), nil, tcell.StyleDefault.Foreground(tcell.ColorDarkRed).Background(tcell.ColorBlack))
				} else {
					s.SetContent(x+offsetX, y+offsetY, ' ', nil, style2)
				}

M dungeon.go => dungeon.go +1 -1
@@ 78,7 78,7 @@ func (t *Tile) IsRoom() bool {
//IsRoomFloor - is the tile one that is normally generated inside a room?
func (t *Tile) IsRoomFloor() bool {
	c := t.char
	return c == '.' || c == '>' || c == '<' //|| c == '*'
	return c == '·' || c == '>' || c == '<' //|| c == '*'
}

//BlocksLight - returns whether or not a creature can see through the tile

M generate.go => generate.go +8 -10
@@ 115,7 115,7 @@ func genRoomLevel(level *Level) {
		//floor
		for i := 1; i < w-1; i++ {
			for j := 1; j < h-1; j++ {
				addBoxArt(level, y+j, x+i, '.')
				addBoxArt(level, y+j, x+i, '·')
			}
		}
	}


@@ 236,8 236,7 @@ func tryDrawCorridor(i1, i2 int, rooms []room, level *Level) bool {
		}

		//stop when it hits another room other than intended. if not close enough, abort. if close enough, keep it
		// if level[y][x] == '.' {
		if !level.GetTile(Point{x, y}).IsSolid() && nextSame { //TODO will this change once corridors are ':'
		if !level.GetTile(Point{x, y}).IsSolid() && nextSame {
			if (x-endX)*(x-endX)+(y-endY)*(y-endY) <= 8*8 {
				break
			} else {


@@ 267,7 266,6 @@ func tryDrawCorridor(i1, i2 int, rooms []room, level *Level) bool {
		}

		points = append(points, Point{x, y})
		// level[y][x] = '.'
	}

	for _, pt := range points {


@@ 562,7 560,7 @@ func genCaveLevel(level *Level) {
			if rand.Intn(100) < fillprob {
				level.SetChar(Point{xi, yi}, '#') //wall, 40%
			} else {
				level.SetChar(Point{xi, yi}, '.') //empty, 60%
				level.SetChar(Point{xi, yi}, '·') //empty, 60%
			}
			level2.SetChar(Point{xi, yi}, '#')
		}


@@ 591,7 589,7 @@ func genCaveLevel(level *Level) {

					for ii := -1; ii <= 1; ii++ {
						for jj := -1; jj <= 1; jj++ {
							if level.GetChar(Point{xi + jj, yi + ii}) != '.' {
							if level.GetChar(Point{xi + jj, yi + ii}) != '·' {
								adjCountR1++
							}
						}


@@ 604,7 602,7 @@ func genCaveLevel(level *Level) {
							if ii < 0 || jj < 0 || ii >= height || jj >= width {
								continue
							}
							if level.GetChar(Point{jj, ii}) != '.' {
							if level.GetChar(Point{jj, ii}) != '·' {
								adjCountR2++
							}
						}


@@ 612,7 610,7 @@ func genCaveLevel(level *Level) {
					if adjCountR1 >= r1Cutoff || adjCountR2 <= r2Cutoff {
						level2.SetChar(Point{xi, yi}, '#')
					} else {
						level2.SetChar(Point{xi, yi}, '.')
						level2.SetChar(Point{xi, yi}, '·')
					}
				}
			}


@@ 661,7 659,7 @@ func tryToAddStairs(z int, stairX, stairY, playerX, playerY int, dungeon *Dungeo
				}
				stairX = rand.Intn(width)
				stairY = rand.Intn(height)
				if dungeon.GetChar(Position{stairX, stairY, z - 1}) == '.' {
				if dungeon.GetChar(Position{stairX, stairY, z - 1}) == '·' {
					break
				}
			}


@@ 675,7 673,7 @@ func tryToAddStairs(z int, stairX, stairY, playerX, playerY int, dungeon *Dungeo
			}
			stairX = rand.Intn(width)
			stairY = rand.Intn(height)
			if mask[stairY][stairX] && dungeon.GetChar(Position{stairX, stairY, z - 1}) == '.' && dungeon.GetChar(Position{stairX, stairY, z}) == '.' &&
			if mask[stairY][stairX] && dungeon.GetChar(Position{stairX, stairY, z - 1}) == '·' && dungeon.GetChar(Position{stairX, stairY, z}) == '·' &&
				(stairX-oldStairX)*(stairX-oldStairX)+(stairY-oldStairY)*(stairY-oldStairY) >= minStairDist*minStairDist {
				break
			}

M main.go => main.go +1 -1
@@ 11,7 11,7 @@ import (

const width, height, depth = 48, 16, 32
const offsetX, offsetY = 1, 2
const debug = false
const debug = true

func main() {
	rand.Seed(time.Now().UnixNano())