コード例 #1
0
    public bool Move(Vector2Int direction)
    {
        var target = position + direction;

        if (ObstacleMap.ObstacleIn(target) == null)
        {
            position = target;
            transform.DOMove(new Vector3(target.x, target.y, 0) + new Vector3(0.5f, 0.5f, 0) * Globals.TILE_SIZE, Globals.TIME_BETWEEN_TURNS);
            return(true);
        }
        else
        {
            return(false);
        }
    }
コード例 #2
0
    public IEnumerator Shoot(Vector2Int init, Vector2Int target)
    {
        Vector3 i = new Vector3(init.x + 0.5f, init.y + 0.5f, 0);
        Vector3 f = new Vector3(target.x + 0.5f, target.y + 0.5f, 0);

        transform.DOMove(i, 0);
        transform.DOMove(f, Globals.TIME_BETWEEN_TURNS).SetEase(Ease.Linear);
        yield return(new WaitForSeconds(Globals.TIME_BETWEEN_TURNS));

        if (ObstacleMap.ObstacleIn(target) != null && ObstacleMap.ObstacleIn(target).GetComponent <IBulletTarget>() != null)
        {
            yield return(ObstacleMap.ObstacleIn(target).GetComponent <IBulletTarget>().OnBulletTouch());
        }
        Destroy(this.gameObject);
    }
コード例 #3
0
    private void SwapBarrelForRaft()
    {
        var mapBuilder = FindObjectOfType <MapBuilder>();

        foreach (var o in horizontalBarrelsOnWater)
        {
            GameObject obj = ObstacleMap.ObstacleIn(new Vector2Int((int)o.x, (int)o.y)).gameObject;
            ObstacleMap.obstacles.Remove(new Vector2Int((int)o.x, (int)o.y));
            Destroy(obj);
        }
        foreach (var o in verticalBarrelsOnWater)
        {
            GameObject obj = ObstacleMap.ObstacleIn(new Vector2Int((int)o.x, (int)o.y)).gameObject;
            ObstacleMap.obstacles.Remove(new Vector2Int((int)o.x, (int)o.y));
            Destroy(obj);
        }

        mapBuilder.CreateObstacle(mapBuilder.horizontalRaft, horizontalBarrelsOnWater);
        mapBuilder.CreateObstacle(mapBuilder.verticalRaft, verticalBarrelsOnWater);
    }
コード例 #4
0
    public IEnumerator ShootBullet()
    {
        GetComponent <AudioSource>().Play();
        Vector2Int bulletPosition = position;

        for (int i = 0; i < Globals.BULLET_RANGE; i++)
        {
            bulletPosition += direction;
            var obstacle = ObstacleMap.ObstacleIn(bulletPosition);
            if (obstacle != null && obstacle.GetComponent <ICannonBulletTarget>() != null)
            {
                print("Cannon Bullet Start at <" + position.x + "," + position.y +
                      "> until reaches <" + bulletPosition.x + "," + bulletPosition.y + ">");
                break;
            }
        }
        var bullet = Instantiate(cannonBulletPrefab, transform.position, Quaternion.identity);

        yield return(bullet.GetComponent <CannonBullet>().Shoot(position, bulletPosition));
    }
コード例 #5
0
 public IEnumerator Walk()
 {
     transform.GetChild(0).GetComponent <PlayerAnimation>().ChangeAnimation(lookDirection);
     isWaiting = false;
     if (FindObjectOfType <GroundMap>().IsBorderTile(position + lookDirection))
     {
         yield return(null);
     }
     if (ObstacleMap.ObstacleIn(position + lookDirection) == null)
     {
         if (FindObjectOfType <GroundMap>().IsSandTile(position + lookDirection))
         {
             position += lookDirection;
             var targetPosition = new Vector3(position.x, position.y, 0);
             transform.DOMove(targetPosition + new Vector3(0.5f, 0.5f, 0) * Globals.TILE_SIZE, Globals.TIME_BETWEEN_TURNS);
         }
         else
         {
             ErrorHandling.AddError(new Error(Compiler.steps, "WALKING ON WATER"));
             transform.GetChild(2).GetComponent <PlayerErrorMessage>().ShowError();
         }
     }
     else
     {
         if (ObstacleMap.ObstacleIn(position + lookDirection).OnPush(lookDirection))
         {
             position += lookDirection;
             var targetPosition = new Vector3(position.x, position.y, 0);
             transform.DOMove(targetPosition + new Vector3(0.5f, 0.5f, 0) * Globals.TILE_SIZE, Globals.TIME_BETWEEN_TURNS);
         }
         else
         {
             ErrorHandling.AddError(new Error(Compiler.steps, "PUSHING OBSTACLE"));
             transform.GetChild(2).GetComponent <PlayerErrorMessage>().ShowError();
         }
     }
     yield return(null);
 }