示例#1
0
func (f *GameField) FreeForObject(x, y float64) bool {
	tl := geometry.MakePoint(x-consts.OBJECT_HALF, y-consts.OBJECT_HALF)
	br := geometry.MakePoint(x+consts.OBJECT_HALF, y+consts.OBJECT_HALF)
	tr := geometry.MakePoint(x+consts.OBJECT_HALF, y-consts.OBJECT_HALF)
	bl := geometry.MakePoint(x-consts.OBJECT_HALF, y+consts.OBJECT_HALF)
	rect := geometry.MakeRectangle(tl, br)
	var pts = []*geometry.Point{tl, br, bl, tr}
	blockeds := make([]*geometry.Rectangle, 0, 100)
	for _, point := range pts {
		col, row := int(point.X), int(point.Y)
		if f.IsBlocked(col, row) {
			blockeds = append(blockeds, f.GetCellRectangle(col, row))
		}
	}
	for _, blocked := range blockeds {
		if rect.CrossedByRect(blocked) {
			return false
		}
	}
	for _, point := range pts {
		for _, actor := range f.GetActors(int(point.X), int(point.Y)) {
			r := actor.GetRectangle()
			if rect.CrossedByRect(&r) {
				return false
			}
		}
	}
	return true
}
示例#2
0
func (ml *mobList) initializeMobsGenerators(filename string) {
	areas, _ := os.Open(consts.PATH_TO_MAPS + filename)
	defer areas.Close()
	reader := bufio.NewReader(areas)
	for {
		bytes, _, err := reader.ReadLine()
		if err == nil {
			data := strings.Split(string(bytes), ":")
			l, r := utils.ParseFloat(data[0]), utils.ParseFloat(data[1])
			t, b := utils.ParseFloat(data[2]), utils.ParseFloat(data[3])
			depth := utils.ParseInt64(data[4])
			duration := utils.ParseFloat(data[5])
			area := geometry.MakeRectangle(geometry.MakePoint(l, t), geometry.MakePoint(r, b))
			if kinds, isExist := ml.mobsDepth[depth]; isExist {
				ml.addGen(NewMobGenerator(&kinds, area, depth, duration, ml.pipeline))
			}
		} else {
			break
		}
	}
}
示例#3
0
func (f *GameField) GetCellRectangle(col, row int) *geometry.Rectangle {
	return geometry.MakeRectangle(geometry.MakePoint(float64(col), float64(row)), geometry.MakePoint(float64(col+1), float64(row+1)))
}