public override void Start()
 {
     base.Start();
     IsoRenderer.LastDirection      = 4;
     IsoRenderer.PreferredDirection = 4;
     IsoRenderer.SetDirection(Vector2.zero);
 }
Ejemplo n.º 2
0
        private void ApplyNewGeneratedMap()
        {
            Debug.Assert(mapGenTask.IsCompleted);
            map = mapGenTask.Result;
            if (cities == null)
            {
                cities = new List <City>(map.cityRooms.Count);
            }
            else
            {
                cities.Clear();
            }

            foreach (World.Generation.Room r in map.cityRooms)
            {
                cities.Add(new City(map.tiles, r));
            }

            if (renderer == null)
            {
                renderer = new IsoRenderer(map, tileset, cityFont);
            }
            else
            {
                renderer.ResetMap(map);
            }

            SetCameraBounds();
            CancelMapGeneration();
        }
 public override void Start()
 {
     base.Start();
     IsoRenderer.LastDirection = 4;
     IsoRenderer.SetDirection(Vector2.zero);
     IsoRenderer.PreferredDirection = 4;
     ballControlerScript            = BallUtils.FetchBallControllerScript(FieldBall);
 }
 public override void Start()
 {
     base.Start();
     IsSwingHasFinished             = true;
     IsoRenderer.LastDirection      = 6;
     IsoRenderer.PreferredDirection = 6;
     IsoRenderer.SetDirection(Vector2.zero);
 }
    protected IEnumerator Move(Vector3 startPosition, Vector3 endPosition)
    {
        IsMoving = true;
        t        = 0;

        if (allowDiagonals && correctDiagonalSpeed)
        {
            factor = 0.7071f;
        }
        else
        {
            factor = 1f;
        }

        while (t < 1f)
        {
            yield return(new WaitUntil(() => !PlayersTurnManager.IsCommandPhase && !GameData.isPaused));

            t += Time.deltaTime * (moveSpeed / gridSize) * factor;
            transform.position = Vector3.Lerp(startPosition, endPosition, t);

            if (IsoRenderer != null)
            {
                Vector2 direction = new Vector2();

                if (startPosition.x < endPosition.x)
                {
                    direction.x = 1;
                }
                else
                {
                    direction.x = -1;
                }

                if (startPosition.y < endPosition.y)
                {
                    direction.y = 1;
                }
                else
                {
                    direction.y = -1;
                }

                IsoRenderer.SetDirection(direction);
            }

            yield return(null);
        }

        IsMoving = false;
        yield return(0);
    }
    private void InitiateFielderAction()
    {
        BallController ballControlerScript = BallUtils.FetchBallControllerScript(FieldBall);

        if (FieldBall.activeInHierarchy && !HasSpottedBall)
        {
            IsoRenderer.LookAtFieldElementAnimation(FieldBall.transform.position);
            this.GetAngleToLookAt();
        }
        else if (HasSpottedBall && FieldBall.activeInHierarchy && !IsHoldingBall && ballControlerScript.IsTargetedByFielder)
        {
            Target = FieldBall.transform.position;
        }
    }
Ejemplo n.º 7
0
    protected IEnumerator MoveObject(Vector3 startPosition, Vector3 endPosition)
    {
        IsMoving = true;
        float interpolationPercentage = 0;

        while (interpolationPercentage < 1f)
        {
            if (IsMoveCanceled)
            {
                break;
            }

            interpolationPercentage += Time.deltaTime * (MoveSpeed / FieldUtils.GRID_SIZE);
            transform.position       = Vector3.Lerp(startPosition, endPosition, interpolationPercentage);

            if (IsoRenderer != null)
            {
                Vector2 direction = new Vector2();

                if (startPosition.x < endPosition.x)
                {
                    direction.x = 1;
                }
                else
                {
                    direction.x = -1;
                }

                if (startPosition.y < endPosition.y)
                {
                    direction.y = 1;
                }
                else
                {
                    direction.y = -1;
                }

                IsoRenderer.SetDirection(direction);
            }

            yield return(null);
        }

        IsMoveCanceled = false;
        IsMoving       = false;
        yield return(0);
    }
        public override void Initialize()
        {
            Debug.WriteLine("Init");

            XmlDocument tilesetXml = new XmlDocument();

            tilesetXml.Load("Content/tilesDef.xml");
            tileset = new Tileset(tilesetXml.SelectSingleNode("tiles"), Content);

            Sprite bikeNorth = new Sprite(Content.Load <Texture2D>("tiles"), new Rectangle(64, 384, 64, 48));
            Sprite bikeWest  = new Sprite(Content.Load <Texture2D>("tiles"), new Rectangle(0, 384, 64, 48));
            Sprite bikeEast  = new Sprite(Content.Load <Texture2D>("tiles"), new Rectangle(128, 384, 64, 48));
            Sprite bikeSouth = new Sprite(Content.Load <Texture2D>("tiles"), new Rectangle(128 + 64, 384, 64, 48));

            bikeSprites = new Sprite[] { bikeNorth, bikeEast, bikeSouth, bikeWest };

            var mapParameter = new GeneratorParameter()
            {
                size                 = new Point(128, 128),
                baseHeight           = 1,
                minHeight            = 8,
                maxHeight            = 16,
                waterMinDiff         = 4,
                forestSize           = 0.3f,
                resourceSize         = 0.5f,
                citiesNumber         = 0.4f,
                citySize             = 7.5f,
                citySizeRandomOffset = 2.5f,
                hasCities            = true,
                hasWater             = true,
                hasCityConnections   = true,
                hasRivers            = false,
                tileset              = tileset,
                randomSeed           = 869719833//615228352//1571703035 //123456789 //189370585 //1621216522 //123456789 //1571703035
            };

            map = new Map(mapParameter, camera, Content, GraphicsDevice, Config.Resolution);

            renderer = new IsoRenderer(map, tileset, Content.Load <SpriteFont>("Fonts/Xolonium_18"));

            simulator = new Simulator(0, map, CreateAgent, RemoveAgentFromScene);

            CreateUI();

            CameraInput.Initialize();
        }
Ejemplo n.º 9
0
        public override void Initialize()
        {
            XmlDocument tilesetXml = new XmlDocument();

            tilesetXml.Load("Content/tilesDef.xml");
            tileset = new Tileset(tilesetXml.SelectSingleNode("tiles"), Content);

            mapParameter = new GeneratorParameter()
            {
                size                 = new Point(128, 128),
                baseHeight           = 1,
                minHeight            = 8,
                maxHeight            = 16,
                waterMinDiff         = 4,
                forestSize           = 0.3f,
                resourceSize         = 0.5f,
                citiesNumber         = 0.4f,
                citySize             = 7.5f,
                citySizeRandomOffset = 2.5f,
                hasCities            = true,
                hasWater             = true,
                hasCityConnections   = true,
                hasRivers            = false,
                tileset              = tileset,
                randomSeed           = 869719833//615228352//1571703035 //123456789 //189370585 //1621216522 //123456789 //1571703035
            };

            cities = new List <City>(64);
            map    = new Map(mapParameter, camera, Content, GraphicsDevice, Config.Resolution);

            foreach (World.Generation.Room r in map.cityRooms)
            {
                cities.Add(new City(map.tiles, r));
            }

            renderer = new IsoRenderer(map, tileset, cityFont);

            CreateUI();

            SetCameraBounds();
            CameraInput.Initialize();
        }
Ejemplo n.º 10
0
    public void StayOnCurrentBase()
    {
        Debug.Log(this.name + " wait on current base");
        this.IsStaying = true;
        PlayersTurnManager playersTurnManager = GameUtils.FetchPlayersTurnManager();

        playersTurnManager.UpdatePlayerTurnAvailability(this.gameObject.name, TurnAvailabilityEnum.WAITING);
        IsoRenderer.ReinitializeAnimator();

        GameManager gameManager = GameUtils.FetchGameManager();

        bool isRunnersAllSafeAndStaying = gameManager.AttackTeamRunnerList.TrueForAll(runner => {
            RunnerBehaviour runnerBehaviour = PlayerUtils.FetchRunnerBehaviourScript(runner);
            return(runnerBehaviour.IsSafe && runnerBehaviour.IsStaying);
        });

        //test if all remaining runner are out and there no more batters
        int runnersCount = gameManager.AttackTeamRunnerList.Count;
        int batterCount  = gameManager.AttackTeamBatterListClone.Count;

        if (runnersCount == 0 && batterCount == 0 || batterCount == 0 && runnersCount > 0 && isRunnersAllSafeAndStaying)
        {
            gameManager.IsStateCheckAllowed = false;
            gameManager.ProcessNextInningHalf();
            return;
        }
        else if (isRunnersAllSafeAndStaying)
        {
            playersTurnManager.IsRunnersTurnsDone = true;
        }

        Vector3 nextBasePosition = this.GetNextBasePosition(this.CurrentBase);

        IsoRenderer.LookAtFieldElementAnimation(nextBasePosition);

        this.CalculateNextAction();
    }
Ejemplo n.º 11
0
    protected void MovePlayer()
    {
        if (!PlayersTurnManager.IsCommandPhase && !GameData.isPaused && Target.HasValue)
        {
            IsoRenderer.Animator.enabled = true;
            transform.position           = Vector3.MoveTowards(transform.position, Target.Value, this.MoveSpeed * Time.deltaTime);

            if (IsoRenderer != null)
            {
                Vector2 direction = new Vector2();

                if (transform.position.x < Target.Value.x)
                {
                    direction.x = 1;
                }
                else
                {
                    direction.x = -1;
                }

                if (transform.position.y < Target.Value.y)
                {
                    direction.y = 1;
                }
                else
                {
                    direction.y = -1;
                }

                IsoRenderer.SetDirection(direction);
            }
        }
        else
        {
            IsoRenderer.Animator.enabled = false;
        }
    }
Ejemplo n.º 12
0
    public void CalculateRunnerColliderInterraction(BaseEnum baseReached, bool isNextRunnerTurnPossible = false)
    {
        Debug.Log(this.name + " interracted with " + baseReached.ToString());
        this.CurrentBase = baseReached;

        PlayerStatus playerStatusScript = PlayerUtils.FetchPlayerStatusScript(this.gameObject);

        this.EnableMovement = false;

        PlayersTurnManager   playersTurnManager   = GameUtils.FetchPlayersTurnManager();
        TurnAvailabilityEnum turnAvailabilityEnum = TurnAvailabilityEnum.READY;

        switch (baseReached)
        {
        case BaseEnum.HOME_BASE:

            if (baseReached == BaseEnum.HOME_BASE && !this.HasPassedThroughThreeFirstBases())
            {
                Debug.Log("Get on HOME BASE FIRST TIME !!");
                this.NextBase = BaseEnum.FIRST_BASE;
                playersTurnManager.TurnState = TurnStateEnum.STANDBY;
                playersTurnManager.UpdatePlayerTurnAvailability(this.gameObject.name, turnAvailabilityEnum);
            }
            else
            {
                Debug.Log("Get on HOME BASE to mark a point");
                Debug.Log("WIN ONE POINT !!!");
                this.Target   = null;
                this.NextBase = this.CurrentBase;
                playerStatusScript.IsAllowedToMove = false;
                this.HasReachedHomeBase            = true;

                PlayerEnum        playerEnum = playerStatusScript.PlayerOwner;
                TeamsScoreManager teamsScoreManagerScript = GameUtils.FetchTeamsScoreManager();
                teamsScoreManagerScript.IncrementTeamScore(GameData.teamIdEnumMap[playerEnum]);
                this.IsStaying = true;
                IsoRenderer.ReinitializeAnimator();
                GameManager gameManager = GameUtils.FetchGameManager();

                this.gameObject.SetActive(false);
                gameManager.AttackTeamRunnerList.Remove(this.gameObject);
                playersTurnManager.UpdatePlayerTurnQueue(this.gameObject);
                gameManager.AttackTeamRunnerHomeList.Add(this.gameObject);

                int batterCount = gameManager.AttackTeamBatterListClone.Count;
                if (this.EquipedBat != null && batterCount > 0)
                {
                    GameObject      newBatter = gameManager.AttackTeamBatterListClone.First();
                    BatterBehaviour newbatterBehaviourScript = PlayerUtils.FetchBatterBehaviourScript(newBatter);
                    newbatterBehaviourScript.EquipedBat = this.EquipedBat;
                    this.EquipedBat = null;
                    gameManager.EquipBatToPlayer(newBatter);
                }

                int runnersCount = gameManager.AttackTeamRunnerList.Count;

                bool isRunnersAllSafeAndStaying = gameManager.AttackTeamRunnerList.TrueForAll(runner => {
                    RunnerBehaviour runnerBehaviour = PlayerUtils.FetchRunnerBehaviourScript(runner);
                    return(runnerBehaviour.IsSafe && runnerBehaviour.IsStaying);
                });

                if (runnersCount == 0 && batterCount == 0 || batterCount == 0 && runnersCount > 0 && isRunnersAllSafeAndStaying)
                {
                    gameManager.IsStateCheckAllowed = false;
                    gameManager.ProcessNextInningHalf();
                }
                else
                {
                    gameManager.IsStateCheckAllowed = true;
                }
            }

            break;

        case BaseEnum.FIRST_BASE:
            Debug.Log("Get on FIRST BASE");

            this.NextBase            = BaseEnum.SECOND_BASE;
            this.HasReachedFirstBase = true;
            if (this.IsInWalkState)
            {
                this.IsInWalkState   = false;
                turnAvailabilityEnum = TurnAvailabilityEnum.WAITING;
                IsoRenderer.ReinitializeAnimator();
            }

            playersTurnManager.UpdatePlayerTurnAvailability(this.gameObject.name, turnAvailabilityEnum);
            break;

        case BaseEnum.SECOND_BASE:
            Debug.Log("Get on SECOND BASE");
            this.NextBase             = BaseEnum.THIRD_BASE;
            this.HasReachedSecondBase = true;
            playersTurnManager.UpdatePlayerTurnAvailability(this.gameObject.name, turnAvailabilityEnum);
            break;

        case BaseEnum.THIRD_BASE:
            Debug.Log("Get on THIRD BASE");
            this.NextBase            = BaseEnum.HOME_BASE;
            this.HasReachedThirdBase = true;
            playersTurnManager.UpdatePlayerTurnAvailability(this.gameObject.name, turnAvailabilityEnum);
            break;

        default:
            Debug.Log("DO NOT KNOW WHAT HAPPEN");
            break;
        }

        if (isNextRunnerTurnPossible)
        {
            playersTurnManager.TurnState      = TurnStateEnum.RUNNER_TURN;
            PlayersTurnManager.IsCommandPhase = true;
        }
    }