Example #1
0
func (g *Game) GetPlayerByEntity(entity interfaces.Entity) interfaces.Player {
	for player, ent := range g.PlayersToEntities {
		if ent.GetEntityId() == entity.GetEntityId() {
			return player
		}
	}

	return nil
}
Example #2
0
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)
}
Example #3
0
func (g *Game) AddEntity(entity interfaces.Entity) {
	g.Entities[entity.GetEntityId()] = entity
}
Example #4
0
func (g *Game) placeEntityRandomly(entity interfaces.Entity, boardId int) {
	x, y := g.GetRandomEmptySpace()
	entity.SetPosition(boardId, x, y)
	g.AddEntity(entity)
}
Example #5
0
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
			}
		}
	}
}
Example #6
0
func setEntity(game interfaces.Game, entity interfaces.Entity,
	boardId, x, y int) {
	entity.SetPosition(boardId, x, y)
	game.AddEntity(entity)
}
Example #7
0
func NewEntity(e interfaces.Entity) *Entity {
	se := &Entity{}
	se.EntityId = e.GetEntityId()
	se.Name = e.GetName()
	se.Type = e.GetType()
	se.Subtype = e.GetSubtype()
	se.MaxArdour = e.GetMaxArdour()
	se.Ardour = e.GetArdour()
	se.BoardId, se.X, se.Y = e.GetPosition()
	se.ActionQueue = e.GetStringActionQueue()
	return se
}
Example #8
0
/* Generic action handler for any entity */
func act(entity interfaces.Entity, action interfaces.Action) {
	if err := action.Act(entity, GAME); err != nil {
		log.Printf("%v: %v", entity.GetName(), err)
	}
}
Example #9
0
func (me *entranceGen) setEntity(game interfaces.Game,
	entity interfaces.Entity, x, y int) {

	entity.SetPosition(me.GetId(), x, y)
	game.AddEntity(entity)
}