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


Golang ICreature.SetTile方法代碼示例

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


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

示例1: internalCreatureTeleport

func (g *Game) internalCreatureTeleport(_creature pul.ICreature, _from pul.ITile, _to pul.ITile) (ret int) {
	ret = RET_NOERROR

	if _from == nil || _to == nil {
		ret = RET_NOTPOSSIBLE
	} else {
		// Move creature object to destination tile
		if ret = _from.RemoveCreature(_creature, true); ret == RET_NOTPOSSIBLE {
			return
		}

		if ret = _to.AddCreature(_creature, false); ret == RET_NOTPOSSIBLE {
			_from.AddCreature(_creature, false) // Something went wrong, put creature back on old tile
			return
		}

		_creature.SetTile(_to)

		// Tell creatures this creature has been teleported
		g.mutexCreatureList.RLock()
		defer g.mutexCreatureList.RUnlock()
		for _, value := range g.Creatures {
			if value != nil {
				value.OnCreatureMove(_creature, _from, _to, true)
			}
		}
	}

	// No error, played succesfully teleported
	if ret == RET_NOERROR {
		ret = RET_PLAYERISTELEPORTED
	}

	return
}
開發者ID:gasperko,項目名稱:pokemon-universe,代碼行數:35,代碼來源:game.go

示例2: OnCreatureMove

func (g *Game) OnCreatureMove(_creature pul.ICreature, _direction int) (ret int) {
	ret = RET_NOTPOSSIBLE

	if !CreatureCanMove(_creature) {
		return
	}

	currentTile := _creature.GetTile()
	destinationPosition := currentTile.GetPosition()

	switch _direction {
	case DIR_NORTH:
		destinationPosition.Y -= 1
	case DIR_SOUTH:
		destinationPosition.Y += 1
	case DIR_WEST:
		destinationPosition.X -= 1
	case DIR_EAST:
		destinationPosition.X += 1
	}

	// Check if destination tile exists
	destinationTile, ok := g_map.GetTileFromPosition(destinationPosition)
	if !ok {
		return
	}

	// Check if we can move to the destination tile
	if ret = destinationTile.CheckMovement(_creature, _direction); ret == RET_NOTPOSSIBLE {
		return
	}

	// Update position
	_creature.SetTile(destinationTile)

	// fmt.Printf("[%v] From (%v,%v) To (%v,%v)\n", _creature.GetName(), currentTile.Position.X, currentTile.Position.Y, destinationPosition.X, destinationPosition.Y)

	// Tell creatures this creature has moved
	g.mutexCreatureList.RLock()
	defer g.mutexCreatureList.RUnlock()
	for _, value := range g.Creatures {
		if value != nil {
			value.OnCreatureMove(_creature, currentTile, destinationTile, false)
		}
	}

	// Move creature object to destination tile
	if ret = currentTile.RemoveCreature(_creature, true); ret == RET_NOTPOSSIBLE {
		return
	}
	if ret = destinationTile.AddCreature(_creature, true); ret == RET_NOTPOSSIBLE {
		currentTile.AddCreature(_creature, false) // Something went wrong, put creature back on old tile
		_creature.SetTile(currentTile)
		return
	}

	// If ICreature is a player type we can check for wild encounter
	g.checkForWildEncounter(_creature)

	return
}
開發者ID:gasperko,項目名稱:pokemon-universe,代碼行數:61,代碼來源:game.go


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