コード例 #1
0
    protected override void Execute(List <PoolEntity> entities)
    {
        var movingEntity = entities.SingleEntity <PoolEntity>();
        var target       = pool.aIMoveTargetEntity;

        if (target == null || !target.hasPosition)
        {
            return;
        }

        var targetPos  = target.position;
        var currentPos = movingEntity.position;
        var moveX      = 0;
        var moveY      = 0;

        bool moveYish = Mathf.Abs(targetPos.x - currentPos.x) == 0;

        if (moveYish)
        {
            moveY = targetPos.y > currentPos.y ? 1 : -1;
        }
        else
        {
            moveX = targetPos.x > currentPos.x ? 1 : -1;
        }
        int newX = currentPos.x + moveX;
        int newY = currentPos.y + moveY;

        ICollection <PoolEntity> existing;
        bool canMove = pool.IsGameBoardPositionOpen(newX, newY, out existing);

        if (existing != null && !existing.Empty())
        {
            canMove = PrepareMove(movingEntity, existing);
        }

        if (canMove)
        {
            movingEntity.ReplacePosition(newX, newY);
        }

        // skip next turn
        movingEntity.isSkipTurn        = true;
        movingEntity.isActiveTurnBased = false;
    }
コード例 #2
0
    protected override void Execute(List <PoolEntity> entities)
    {
        var position = pool.controllableEntity.position;
        ICollection <PoolEntity> posEntities;

        pool.IsGameBoardPositionOpen(position, out posEntities);

        PoolEntity food;

        if (posEntities != null &&
            posEntities.ContainsComponent(PoolComponentsLookup.Food, out food))
        {
            int points = food.food.points;

            pool.AddToFoodBag(points);
            pool.DestroyEntity(food);
        }
    }
コード例 #3
0
    protected override void Execute(List <PoolEntity> entities)
    {
        if (pool.isGameOver ||
            pool.isLevelTransitionDelay ||
            !pool.hasMoveInput ||
            !pool.isControllable ||
            !pool.controllableEntity.isActiveTurnBased)
        {
            // ignore input
            return;
        }

        var controllable = pool.controllableEntity;

        pool.ReplaceFoodBag(pool.foodBag.points - 1);

        var movement    = pool.moveInput.movement;
        var movementPos = ToVector(movement);

        var currentPos = controllable.position;
        int newX       = currentPos.x + (int)movementPos.x;
        int newY       = currentPos.y + (int)movementPos.y;

        ICollection <PoolEntity> existing;
        bool canMove = pool.IsGameBoardPositionOpen(newX, newY, out existing);

        if (existing != null)
        {
            canMove = PrepareMove(controllable, existing);
        }

        if (canMove)
        {
//            pool.PlayAudio(controllable.audioWalkSource);
            controllable.ReplacePosition(newX, newY);
        }

        controllable.isActiveTurnBased = false;
    }
コード例 #4
0
 public static bool IsGameBoardPositionOpen(this PoolContext context,
                                            PositionComponent position,
                                            out ICollection <PoolEntity> entities)
 {
     return(context.IsGameBoardPositionOpen(position.x, position.y, out entities));
 }