コード例 #1
0
ファイル: generator.go プロジェクト: ZurgInq/protogame
func (gen RoomsGenerator) addDoorsForLocations(room *g.Room, mapLocations [][]*g.Location, mapDoors [][]string) {
	for rowN, row := range mapLocations {
		for colN, location := range row {
			doors := mapDoors[rowN][colN]

			middleX := location.SizeX / 2
			middleY := location.SizeY / 2

			var triggerX, triggerY int
			var targetPos g.PosObj

			if strings.Contains(doors, "L") {
				doorIdx := gen.doorLocationIdx(location, g.DoorLeft)
				location.CellsMap[doorIdx] = "<"
				triggerX, triggerY = g.CellIdxToXY(doorIdx, location.SizeX)
				targetPos = *g.NewPosObj(mapLocations[rowN][colN-1], location.SizeX-1, middleY)
				gen.addDoorTrigger(room, *g.NewPosObj(location, triggerX, triggerY), targetPos, g.DoorLeft)
				gen.addDoorGuard(room, location, g.DoorLeft)
			}
			if strings.Contains(doors, "R") {
				doorIdx := gen.doorLocationIdx(location, g.DoorRight)
				location.CellsMap[doorIdx] = ">"
				triggerX, triggerY = g.CellIdxToXY(doorIdx, location.SizeX)
				targetPos = *g.NewPosObj(mapLocations[rowN][colN+1], 0, middleY)
				gen.addDoorTrigger(room, *g.NewPosObj(location, triggerX, triggerY), targetPos, g.DoorRight)
				gen.addDoorGuard(room, location, g.DoorRight)
			}
			if strings.Contains(doors, "U") {
				doorIdx := gen.doorLocationIdx(location, g.DoorUp)
				location.CellsMap[doorIdx] = `/\`
				triggerX, triggerY = g.CellIdxToXY(doorIdx, location.SizeX)
				targetPos = *g.NewPosObj(mapLocations[rowN-1][colN], middleX, location.SizeY-1)
				gen.addDoorTrigger(room, *g.NewPosObj(location, triggerX, triggerY), targetPos, g.DoorUp)
				gen.addDoorGuard(room, location, g.DoorUp)
			}
			if strings.Contains(doors, "D") {
				doorIdx := gen.doorLocationIdx(location, g.DoorDown)
				location.CellsMap[doorIdx] = `\/`
				triggerX, triggerY = g.CellIdxToXY(doorIdx, location.SizeX)
				targetPos = *g.NewPosObj(mapLocations[rowN+1][colN], middleX, 0)
				gen.addDoorTrigger(room, *g.NewPosObj(location, triggerX, triggerY), targetPos, g.DoorDown)
				gen.addDoorGuard(room, location, g.DoorDown)
			}
		}
	}

}
コード例 #2
0
ファイル: generator.go プロジェクト: ZurgInq/protogame
func (gen RoomsGenerator) markLocationAsFinish(room *g.Room, location *g.Location) {
	cellsCount := len(location.CellsMap)
	idx := cellsCount / 2
	location.CellsMap[idx] = "&"
	triggerX, triggerY := g.CellIdxToXY(idx, location.SizeX)
	exitTrigger := g.CreateExitTrigger(*g.NewPosObj(location, triggerX, triggerY))
	room.AddTrigger(exitTrigger)
	room.ExitLocationID = location.RefID()
}