當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Activer.GetShiftedFrontSide方法代碼示例

本文整理匯總了Golang中MonsterQuest/gameObjectsBase.Activer.GetShiftedFrontSide方法的典型用法代碼示例。如果您正苦於以下問題:Golang Activer.GetShiftedFrontSide方法的具體用法?Golang Activer.GetShiftedFrontSide怎麽用?Golang Activer.GetShiftedFrontSide使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MonsterQuest/gameObjectsBase.Activer的用法示例。


在下文中一共展示了Activer.GetShiftedFrontSide方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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.GetShiftedFrontSide方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。