当前位置: 首页>>代码示例>>Golang>>正文


Golang Activer.GetCollisionableSide方法代码示例

本文整理汇总了Golang中MonsterQuest/gameObjectsBase.Activer.GetCollisionableSide方法的典型用法代码示例。如果您正苦于以下问题:Golang Activer.GetCollisionableSide方法的具体用法?Golang Activer.GetCollisionableSide怎么用?Golang Activer.GetCollisionableSide使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MonsterQuest/gameObjectsBase.Activer的用法示例。


在下文中一共展示了Activer.GetCollisionableSide方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: checkCollisionWithActors

func (m *MoveFlag) checkCollisionWithActors(obj gameObjectsBase.Activer, dir int, shift float64) (bool, geometry.Point) {
	segment, pos := obj.GetCollisionableSide(dir, shift)
	col1, row1 := int(segment.Point1.X), int(segment.Point1.Y)
	col2, row2 := int(segment.Point2.X), int(segment.Point2.Y)
	res := m.checkCollisionWithActorsInCell(col1, row1, &segment) || m.checkCollisionWithActorsInCell(col2, row2, &segment)
	if res {
		pos = obj.GetCenter()
	}
	return res, pos
}
开发者ID:apanasenko,项目名称:MonsterQuest,代码行数:10,代码来源:baseFlags.go

示例2: checkCollisionWithWalls

func (m *MoveFlag) checkCollisionWithWalls(obj gameObjectsBase.Activer, dir int, shift float64) (bool, geometry.Point) {
	pos := obj.GetShiftedFrontSide(dir, shift)
	if m.field.IsBlocked(int(math.Floor(pos.X)), int(math.Floor(pos.Y))) {
		switch dir {
		case consts.NORTH_DIR:
			pos.Y = math.Ceil(pos.Y) + consts.OBJECT_HALF
		case consts.SOUTH_DIR:
			pos.Y = math.Floor(pos.Y) - consts.OBJECT_HALF
		case consts.EAST_DIR:
			pos.X = math.Floor(pos.X) - consts.OBJECT_HALF
		case consts.WEST_DIR:
			pos.X = math.Ceil(pos.X) + consts.OBJECT_HALF
		}
		return false, pos
	}
	eps := consts.SLIDE_THRESHOLD
	side, pos := obj.GetCollisionableSide(dir, shift)
	res1 := m.field.IsBlocked(int(side.Point1.X), int(side.Point1.Y))
	res2 := m.field.IsBlocked(int(side.Point2.X), int(side.Point2.Y))
	var near float64
	if res1 || res2 {
		switch dir {
		case consts.NORTH_DIR, consts.SOUTH_DIR:
			if res1 {
				near = math.Ceil(side.Point1.X) - side.Point1.X
			} else {
				near = math.Floor(side.Point1.X) - side.Point1.X
			}
			if math.Abs(near) <= eps {
				side.Point1.X = side.Point1.X + near
				side.Point2.X = side.Point2.X + near
			} else {
				return false, obj.GetCenter()
			}
			pos.X = (side.Point1.X + side.Point2.X) / 2
		case consts.EAST_DIR, consts.WEST_DIR:
			if res1 {
				near = math.Ceil(side.Point1.Y) - side.Point1.Y
			} else {
				near = math.Floor(side.Point1.Y) - side.Point1.Y
			}
			if math.Abs(near) <= eps {
				side.Point1.Y = side.Point1.Y + near
				side.Point2.Y = side.Point2.Y + near
			} else {
				return false, obj.GetCenter()
			}
			pos.Y = (side.Point1.Y + side.Point2.Y) / 2
		}
	}
	return true, pos
}
开发者ID:apanasenko,项目名称:MonsterQuest,代码行数:52,代码来源:baseFlags.go


注:本文中的MonsterQuest/gameObjectsBase.Activer.GetCollisionableSide方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。