コード例 #1
0
 public void ExecuteNext(Player player, GameMaster.EDirection keyPressed)
 {
     m_currentAction = m_actions[m_nextIndex];
     m_currentAction.OnEndRelay.AddListener(OnEndAction);
     m_currentAction.Execute(player, keyPressed);
     UpdatePlayerSprite(player);
 }
コード例 #2
0
    private IEnumerator SpawnVisual(Vector2 spawnPos, GameMaster.EDirection direction)
    {
        if (m_visualSpawned != null)
        {
            ResourceManager.Instance.ReleaseInstance(m_visualSpawned);
        }
        m_visualSpawned = ResourceManager.Instance.AcquireInstance(Asset.VisualToPop, null);
        m_visualSpawned.transform.position = spawnPos;
        m_visualSpawned.transform.right    = Utils.ConvertDirectionToVector(direction);
        yield return(new WaitForSeconds(Asset.TimeVisualStay));

        ResourceManager.Instance.ReleaseInstance(m_visualSpawned);
        m_visualSpawned = null;
    }
コード例 #3
0
    public override void Execute(Player player, GameMaster.EDirection keyPressed)
    {
        Vector2 newPos = player.transform.position;

        newPos = newPos + Utils.ConvertDirectionToVector(keyPressed);
        if (GameMaster.Instance.CanPlayerMove(newPos))
        {
            player.Move(player.transform.position, newPos);
            OnFinishAction(true);
        }
        else
        {
            OnFinishAction(false);
        }
    }
コード例 #4
0
    private void LineSwap(Player player, GameMaster.EDirection direction)
    {
        Vector2 directionVec = Utils.ConvertDirectionToVector(direction);
        Vector2 nextPos      = (Vector2)player.transform.position + directionVec;
        Cell    targetCell   = GameMaster.Instance.Grid.GetCell(nextPos);

        if (targetCell != null)
        {
            bool foundCell = false;
            while (!foundCell)
            {
                if (targetCell.Entities.Count > 0)
                {
                    foundCell = true;
                }
                else
                {
                    nextPos = nextPos + directionVec;
                    Cell nextCell = GameMaster.Instance.Grid.GetCell(nextPos);
                    if (nextCell == null)
                    {
                        nextPos  -= directionVec;
                        foundCell = true;
                    }
                    else
                    {
                        targetCell = nextCell;
                    }
                }
            }

            List <GameEntity> toMove = new List <GameEntity>(targetCell.Entities);
            bool hasSwap             = false;
            foreach (GameEntity entity in toMove)
            {
                entity.Move(entity.transform.position, player.transform.position);
                hasSwap = true;
            }
            player.Move(player.transform.position, nextPos);
            OnFinishAction(true, hasSwap);
        }
        else
        {
            OnFinishAction(false);
        }
    }
コード例 #5
0
    public static Vector2 ConvertDirectionToVector(GameMaster.EDirection direction)
    {
        switch (direction)
        {
        case GameMaster.EDirection.UP:
            return(Vector2.up);

        case GameMaster.EDirection.DOWN:
            return(Vector2.down);

        case GameMaster.EDirection.LEFT:
            return(Vector2.left);

        case GameMaster.EDirection.RIGHT:
            return(Vector2.right);
        }
        return(Vector2.zero);
    }
コード例 #6
0
    public override void Execute(Player player, GameMaster.EDirection keyPressed)
    {
        Vector2 aimPos = (Vector2)player.transform.position + Utils.ConvertDirectionToVector(keyPressed);
        Cell    cell   = GameMaster.Instance.Grid.GetCell(aimPos);

        if (cell != null)
        {
            player.StartCoroutine(SpawnVisual(aimPos, keyPressed));
            bool hasHit = false;
            for (int i = cell.Entities.Count - 1; i >= 0; i--)
            {
                hasHit = true;
                cell.Entities[i].Hit();
            }
            OnFinishAction(true, hasHit);
        }
        else
        {
            OnFinishAction(false);
        }
    }
コード例 #7
0
    private void BasicSwap(Player player, GameMaster.EDirection direction)
    {
        Vector2 nextPos    = (Vector2)player.transform.position + (Utils.ConvertDirectionToVector(direction) * Asset.Range);
        Cell    targetCell = GameMaster.Instance.Grid.GetCell(nextPos);

        if (targetCell != null)
        {
            List <GameEntity> toMove = new List <GameEntity>(targetCell.Entities);
            bool hasSwap             = false;
            foreach (GameEntity entity in toMove)
            {
                entity.Move(entity.transform.position, player.transform.position);
                hasSwap = true;
            }
            player.Move(player.transform.position, nextPos);
            OnFinishAction(true, hasSwap);
        }
        else
        {
            OnFinishAction(false);
        }
    }
コード例 #8
0
    public override void Execute(Player player, GameMaster.EDirection keyPressed)
    {
        Vector3 position = player.transform.position + (Vector3)Utils.ConvertDirectionToVector(keyPressed);
        Cell    cell     = GameMaster.Instance.Grid.GetCell(position);

        if (cell != null)
        {
            foreach (GameEntity gameEntity in cell.Entities)
            {
                if (gameEntity.tag == "Shield")
                {
                    OnFinishAction(false);
                    return;
                }
            }
            Shield shield = ResourceManager.Instance.AcquireInstance(Asset.ShieldPrefab, null);
            shield.Move(shield.transform.position, position);
            OnFinishAction(true, false);
        }
        else
        {
            OnFinishAction(false);
        }
    }
コード例 #9
0
 public abstract void Execute(Player player, GameMaster.EDirection keyPressed);
コード例 #10
0
    public void OnTicUpdate(float ticNumber)
    {
        if (m_canSpawnNextHazard)
        {
            Hazard prefabToSpawn = null;
            m_hazardsToSpawn.Shuffle();
            foreach (Hazard hazardToSpawn in m_hazardsToSpawn)
            {
                if (ticNumber % hazardToSpawn.UpdateEveryTicTime == 0)
                {
                    prefabToSpawn = hazardToSpawn;
                    break;
                }
            }
            if (prefabToSpawn == null)
            {
                return;
            }
            m_hazardsToSpawn.Remove(prefabToSpawn);
            bool hasEntityOnCell = true;
            GameMaster.EDirection chooseDirection = default(GameMaster.EDirection);
            Vector3 spawnPoint = Vector3.zero;
            int     tryLimit   = 0;
            while (hasEntityOnCell)
            {
                chooseDirection = prefabToSpawn.AllowedDirections[UnityEngine.Random.Range(0, prefabToSpawn.AllowedDirections.Count)];
                spawnPoint      = GameMaster.Instance.GetSpawnPosition(chooseDirection);
                hasEntityOnCell = GameMaster.Instance.Grid.GetCell(spawnPoint).Entities.Count > 0;
                if (tryLimit > 1000)
                {
                    tryLimit = 0;
                    return;                    //Spawn on next frame
                }
                else
                {
                    tryLimit++;
                }
            }
            Hazard hazard = ResourceManager.Instance.AcquireInstance(prefabToSpawn, null);
            hazard.transform.position = spawnPoint;
            switch (chooseDirection)
            {
            case GameMaster.EDirection.UP:
                hazard.transform.right = Vector2.down;
                break;

            case GameMaster.EDirection.DOWN:
                hazard.transform.right = Vector2.up;
                break;

            case GameMaster.EDirection.RIGHT:
                hazard.transform.right = Vector2.left;
                break;

            case GameMaster.EDirection.LEFT:
                hazard.transform.right = Vector2.right;
                break;
            }
            hazard.Init(chooseDirection);
            m_canSpawnNextHazard = false;
        }
    }
コード例 #11
0
 public override void Execute(Player player, GameMaster.EDirection direction)
 {
     //BasicSwap(player, direction);
     LineSwap(player, direction);
 }
コード例 #12
0
 public virtual void Init(GameMaster.EDirection direction)
 {
     m_elapsedTime      = 0.0f;
     m_spawnedDirection = direction;
     CheckGridState();
 }