~johanvandegriff/ruegolike

3d2b630b6fac3cbfb82cc19667ff3076e9b0d386 — Johan Vandegriff 1 year, 4 months ago 1017b2c
moved tile properties to functions
4 files changed, 36 insertions(+), 28 deletions(-)

M display.go
M dungeon.go
M generate.go
M main.go
M display.go => display.go +1 -1
@@ 54,7 54,7 @@ func blocksLight(x, y, octant, originX, originY int, level *Level) bool {
		nx += x
		ny += y
	}
	return !isXYInRange(nx, ny) || level.GetTile(Point{nx, ny}).blocksLight
	return !isXYInRange(nx, ny) || level.GetTile(Point{nx, ny}).BlocksLight()
}

//TODO move visible and explored to player/creature

M dungeon.go => dungeon.go +29 -23
@@ 25,11 25,11 @@ type Level struct {

//Tile - one square on a level
type Tile struct {
	char        int32 //the character that is displayed
	isSolid     bool  //are you prevented from walking through it?
	blocksLight bool  //are you prevented from seeing through it?
	isRoom      bool  //does it define the walls of a room?
	isCorner    bool  //is it the corner of a room?
	char int32 //the character that is displayed
	// isSolid     bool  //are you prevented from walking through it?
	// blocksLight bool  //are you prevented from seeing through it?
	// isRoom      bool  //does it define the walls of a room?
	// isCorner    bool  //is it the corner of a room?
}

//GetTile - retrieve a tile from the dungeon using an x, y, z position


@@ 57,28 57,34 @@ func (l *Level) GetChar(p Point) int32 {
	return l.tiles[p.y][p.x].char
}

//NewTile - create a new tile from a char
func NewTile(c int32) *Tile {
	isSolid, blocksLight, isRoom, isCorner := false, false, false, false
	if c == '#' {
		isSolid, blocksLight = true, true
	}
	if c == '├' || c == '┤' || c == '┬' || c == '┴' || c == '┼' || c == '┌' || c == '└' || c == '┐' || c == '┘' || c == '─' || c == '│' {
		isSolid, blocksLight, isRoom = true, true, true
	}
	if c == '├' || c == '┤' || c == '┬' || c == '┴' || c == '┼' || c == '┌' || c == '└' || c == '┐' || c == '┘' {
		isCorner = true
	}
	return &Tile{c, isSolid, blocksLight, isRoom, isCorner}
//IsSolid - returns whether or not a creature can move through the tile
func (t *Tile) IsSolid() bool {
	c := t.char
	return c == '#' || t.IsRoom()
}

//IsCorner - is the tile the corner of a room border?
func (t *Tile) IsCorner() bool {
	c := t.char
	return c == '├' || c == '┤' || c == '┬' || c == '┴' || c == '┼' || c == '┌' || c == '└' || c == '┐' || c == '┘'
}

//IsRoom - is the tile part of a room border?
func (t *Tile) IsRoom() bool {
	c := t.char
	return c == '─' || c == '│' || t.IsCorner()
}

//BlocksLight - returns whether or not a creature can see through the tile
func (t *Tile) BlocksLight() bool {
	return t.IsSolid()
}

//SetChar - set a char in a level using an x, y, z position
func (l *Level) SetChar(p Point, c int32) {
	l.tiles[p.y][p.x] = NewTile(c)
	l.tiles[p.y][p.x] = &Tile{c}
}

//

//GetChar - retrieve a char from the dungeon using an x, y, z position
func (d *Dungeon) GetChar(p Position) int32 {
	return d.GetTile(p).char


@@ 86,7 92,7 @@ func (d *Dungeon) GetChar(p Position) int32 {

//SetChar - set a char in a level using an x, y, z position
func (d *Dungeon) SetChar(p Position, c int32) {
	d.SetTile(p, NewTile(c))
	d.SetTile(p, &Tile{c})
}

//GetLevel - get one level from the dungeon


@@ 99,7 105,7 @@ func NewLevel() *Level {
	var tiles [height][width]*Tile
	for y := 0; y < height; y++ {
		for x := 0; x < width; x++ {
			tiles[y][x] = NewTile('#')
			tiles[y][x] = &Tile{'#'}
		}
	}
	return &Level{tiles}

M generate.go => generate.go +5 -3
@@ 252,7 252,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 { //TODO will this change once corridors are ':'
			if (x-endX)*(x-endX)+(y-endY)*(y-endY) <= 8*8 {
				break
			} else {


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

		//stop when it hits a corner of a room
		if level.GetTile(Point{x, y}).isCorner {
		if level.GetTile(Point{x, y}).IsCorner() {
			return false
		}



@@ 290,6 290,8 @@ func tryDrawCorridor(i1, i2 int, rooms []room, level *Level) bool {
func addBoxArt(level *Level, y, x int, new int32) {
	old := level.GetChar(Point{x, y})
	combined := new

	//TODO replace this madness with contextual rendering
	switch old {
	case '┌':
		switch new {


@@ 639,7 641,7 @@ func floodFill(x, y int, level *Level) [height][width]bool {
}

func floodFillAux(x, y int, level *Level, mask *[height][width]bool) {
	if isXYInRange(x, y) && !level.GetTile(Point{x, y}).isSolid && mask[y][x] == false {
	if isXYInRange(x, y) && !level.GetTile(Point{x, y}).IsSolid() && mask[y][x] == false {
		mask[y][x] = true
		// level[y][x] = '~'
		for dy := -1; dy <= 1; dy++ {

M main.go => main.go +1 -1
@@ 92,7 92,7 @@ func main() {

				if newPlayerX >= 0 && newPlayerX < width &&
					newPlayerY >= 0 && newPlayerY < height &&
					!dungeon.GetTile(Position{newPlayerX, newPlayerY, playerPos.z}).isSolid {
					!dungeon.GetTile(Position{newPlayerX, newPlayerY, playerPos.z}).IsSolid() {
					playerPos.x = newPlayerX
					playerPos.y = newPlayerY
					EmitStr(s, 15, 0, style1, "    ")