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


Golang Entity.SetPosition方法代碼示例

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


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

示例1: SwapPositionWith

func (e *Entity) SwapPositionWith(other interfaces.Entity) {
	if !e.IsTangible() || !other.IsTangible() {
		log.Fatalf("Swap only makes sense for tangible entities. Got %v & %v",
			e.GetName(), other.GetName())
	}

	/* It's crucial that two tagnible entities don't end up on same tile */
	boardId, x, y := e.GetPosition()
	boardId2, x2, y2 := other.GetPosition()
	e.BoardId, e.X, e.Y = boardId2, x2, y2
	/* Can work since both entities are technically in the same place */
	other.SetPosition(boardId, x, y)

	/* Manually trigger trodden functions since we didn't SetPosition */
	for _, entity := range e.Game.GetEntitiesAtSpace(e.GetPosition()) {
		entity.Trodden(e)
	}

	/* other's reposition function will be called by SetPosition */
	e.RepositionFunction(boardId, x, y, boardId2, x2, y2)
}
開發者ID:Garoth,項目名稱:StAbbey,代碼行數:21,代碼來源:entity.go

示例2: placeEntityRandomly

func (g *Game) placeEntityRandomly(entity interfaces.Entity, boardId int) {
	x, y := g.GetRandomEmptySpace()
	entity.SetPosition(boardId, x, y)
	g.AddEntity(entity)
}
開發者ID:Garoth,項目名稱:StAbbey,代碼行數:5,代碼來源:game.go

示例3: PlaceAtNearestTile

func (g *Game) PlaceAtNearestTile(ent interfaces.Entity, boardId, x, y int) {
	tryX, tryY := -1, -1

	/* assuming BOARD_WIDTH is the higher of the two */
	for radius := 0; radius < interfaces.BOARD_WIDTH+5; radius++ {

		/* Testing horizontally an vertically closest tiles */
		/* Right */
		tryX, tryY = x+radius, y
		if g.CanMoveToSpace(boardId, tryX, tryY) {
			ent.SetPosition(boardId, tryX, tryY)
			return
		}

		/* Bottom */
		tryX, tryY = x, y+radius
		if g.CanMoveToSpace(boardId, tryX, tryY) {
			ent.SetPosition(boardId, tryX, tryY)
			return
		}

		/* Left */
		tryX, tryY = x-radius, y
		if g.CanMoveToSpace(boardId, tryX, tryY) {
			ent.SetPosition(boardId, tryX, tryY)
			return
		}

		/* Top */
		tryX, tryY = x, y-radius
		if g.CanMoveToSpace(boardId, tryX, tryY) {
			ent.SetPosition(boardId, tryX, tryY)
			return
		}

		/* Testing all tiles at increasing distances away */
		for wallLen := 0; wallLen < (radius*2)+1; wallLen++ {
			/* Testing top wall of new circle */
			tryX, tryY = x-radius+wallLen, y-radius
			if g.CanMoveToSpace(boardId, tryX, tryY) {
				ent.SetPosition(boardId, tryX, tryY)
				return
			}

			/* Testing right wall of new circle */
			tryX, tryY = x+radius, y-radius+wallLen
			if g.CanMoveToSpace(boardId, tryX, tryY) {
				ent.SetPosition(boardId, tryX, tryY)
				return
			}

			/* Testing left wall of new circle */
			tryX, tryY = x-radius, y-radius+wallLen
			if g.CanMoveToSpace(boardId, tryX, tryY) {
				ent.SetPosition(boardId, tryX, tryY)
				return
			}

			/* Testing bottom wall of new circle */
			tryX, tryY = x-radius+wallLen, y+radius
			if g.CanMoveToSpace(boardId, tryX, tryY) {
				ent.SetPosition(boardId, tryX, tryY)
				return
			}
		}
	}
}
開發者ID:Garoth,項目名稱:StAbbey,代碼行數:67,代碼來源:game.go

示例4: setEntity

func setEntity(game interfaces.Game, entity interfaces.Entity,
	boardId, x, y int) {
	entity.SetPosition(boardId, x, y)
	game.AddEntity(entity)
}
開發者ID:Garoth,項目名稱:StAbbey,代碼行數:5,代碼來源:generator-util.go

示例5: setEntity

func (me *entranceGen) setEntity(game interfaces.Game,
	entity interfaces.Entity, x, y int) {

	entity.SetPosition(me.GetId(), x, y)
	game.AddEntity(entity)
}
開發者ID:Garoth,項目名稱:StAbbey,代碼行數:6,代碼來源:entrance.go


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