Example #1
0
    public void CreateBlockPush(GameGridBlock blockObj, Vector3 pushAwayFrom)
    {
        PushBlockAway push = blockObj.gameObject.AddComponent <PushBlockAway>();

        push.PushAwayFrom        = pushAwayFrom;
        push.PushTime            = BlockPushEffect.PushTime;
        push.HangTime            = BlockPushEffect.HangTime;
        push.PushSpeed           = BlockPushEffect.PushSpeed;
        push.PushFalloffExponent = BlockPushEffect.PushFalloffExponent;
    }
Example #2
0
 /// <summary>
 /// Outputs the coordinates of the given block in the grid.
 /// If the given block doesn't exist in the grid, returns {-1, -1}.
 /// </summary>
 public Vector2i GetLocation(GameGridBlock block)
 {
     if (poses.ContainsKey(block))
     {
         return(poses[block]);
     }
     else
     {
         return(new Vector2i(-1, -1));
     }
 }
Example #3
0
    /// <summary>
    /// Creates a basic block with the given properties and adds it to the world grid.
    /// </summary>
    public GameGridBlock CreateBlock(Vector2 position, Vector2i gridLoc, int colorID)
    {
        Transform     tr    = ((GameObject)Instantiate(BlockPrefab)).transform;
        GameGridBlock block = tr.GetComponent <GameGridBlock>();

        tr.position   = new Vector3(position.x, position.y, tr.position.z);
        block.ColorID = colorID;

        GameGrid.Instance.AddBlock(gridLoc, block);

        return(block);
    }
Example #4
0
    /// <summary>
    /// Adds the given block to this grid at the given location.
    /// If the given location is occupied, the new block is NOT placed.
    /// Returns whether the given block was successfully placed.
    /// </summary>
    public bool AddBlock(Vector2i loc, GameGridBlock block)
    {
        if (blocks[loc.X, loc.Y] != null)
        {
            return(false);
        }

        poses.Add(block, loc);
        blocks[loc.X, loc.Y] = block;

        return(true);
    }
Example #5
0
    void Update()
    {
        if (IsInputDisabled)
        {
            return;
        }


        //Get any mouse/touch input.
        Vector2?worldInputPos = null;

        if (Input.GetMouseButtonDown(0))
        {
            worldInputPos = (Vector2)BlockViewCam.ScreenToWorldPoint(Input.mousePosition);
        }
        else if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began)
        {
            worldInputPos = (Vector2)BlockViewCam.ScreenToWorldPoint((Vector3)Input.touches[0].position);
        }

        //If there was mouse/touch input, see if the point is overlapping anything in the scene.
        if (worldInputPos.HasValue)
        {
            Collider2D hit = Physics2D.OverlapPoint(worldInputPos.Value);
            if (hit != null)
            {
                //If a block was tapped/clicked, clear it.
                GameGridBlock tryBlock = hit.GetComponent <GameGridBlock>();
                if (tryBlock != null)
                {
                    List <Vector2i> cleared = GameGrid.Instance.ClearBlock(GameGrid.Instance.GetLocation(tryBlock));
                    GameplayController.Instance.ClearedBlocks(cleared, GameplayController.ClearBlockActions.PlayerInput);
                }
            }
        }
    }
 void Awake()
 {
     rend  = GetComponent <Renderer>();
     block = GetComponent <GameGridBlock>();
 }
Example #7
0
 void Awake()
 {
     block = GetComponent <GameGridBlock>();
 }
Example #8
0
 /// <summary>
 /// Moves the given block to the given new location.
 /// Assumes no block is there already.
 /// </summary>
 public void MoveBlock(GameGridBlock block, Vector2i newLoc)
 {
     blocks[newLoc.X, newLoc.Y]             = block;
     blocks[poses[block].X, poses[block].Y] = null;
     poses[block] = newLoc;
 }
    protected override void Update()
    {
        base.Update();

        //Update UI text.
        TurnsLeftUIText.text = TurnsLeft.ToString() + " left";
        if (!SkillzSDK.Api.IsTournamentInProgress)
        {
            CurrentPlayerUIText.text = (IsPlayer1Turn ? "Player 1" : "Player 2");
        }

        //If in online tournament, check for end of turn.
        if (SkillzSDK.Api.IsTournamentInProgress)
        {
            if (Skillz_tookTurn && !LocalPlayer.IsInputDisabled)
            {
                //Serialize the game data for output.
                string knownID = Skillz_GameData.KnownPlayerID;
                Skillz_GameData               = new TurnBasedGameData();
                Skillz_GameData.TurnsLeft     = TurnsLeft;
                Skillz_GameData.KnownPlayerID = knownID;
                Skillz_GameData.SetScore(PlayerUniqueID, PlayerOneScore);
                Skillz_GameData.SetOtherScore(PlayerUniqueID, PlayerTwoScore);
                Skillz_GameData.Blocks = new int[GameGrid.Instance.GetGridSize().X,
                                                 GameGrid.Instance.GetGridSize().Y];
                for (int x = 0; x < GameGrid.Instance.GetGridSize().X; ++x)
                {
                    for (int y = 0; y < GameGrid.Instance.GetGridSize().Y; ++y)
                    {
                        Vector2i      loc   = new Vector2i(x, y);
                        GameGridBlock block = GameGrid.Instance.GetBlock(loc);

                        if (block == null)
                        {
                            Skillz_GameData.Blocks[x, y] = -1;
                        }
                        else
                        {
                            Skillz_GameData.Blocks[x, y] = block.ColorID;
                        }
                    }
                }

                //Is the game over?
                if (TurnsLeft == 0)
                {
                    SkillzSDK.TurnBasedMatchOutcome whoWon = SkillzSDK.TurnBasedMatchOutcome.NoOutcome;
                    if (PlayerOneScore > PlayerTwoScore)
                    {
                        whoWon = SkillzSDK.TurnBasedMatchOutcome.Win;
                    }
                    else if (PlayerOneScore < PlayerTwoScore)
                    {
                        whoWon = SkillzSDK.TurnBasedMatchOutcome.Loss;
                    }
                    else
                    {
                        whoWon = SkillzSDK.TurnBasedMatchOutcome.Draw;
                    }

                    Skillz_tookTurn = false;
                    SkillzSDK.Api.FinishTurn(Skillz_GameData.ToString(),
                                             SkillzSDK.TurnBasedRoundOutcome.NoOutcome,
                                             whoWon,
                                             PlayerOneScore.ToString(),
                                             PlayerOneScore, PlayerTwoScore);
                }
                //Otherwise, continue as normal.
                else
                {
                    Skillz_tookTurn = false;
                    SkillzSDK.Api.FinishTurn(Skillz_GameData.ToString(),
                                             SkillzSDK.TurnBasedRoundOutcome.NoOutcome,
                                             SkillzSDK.TurnBasedMatchOutcome.NoOutcome,
                                             PlayerOneScore.ToString(),
                                             PlayerOneScore, PlayerTwoScore);
                }
            }
        }
        //Otherwise, check for end of game.
        else
        {
            if (!LocalPlayer.IsInputDisabled && TurnsLeft <= 0)
            {
                Application.LoadLevel("PresentTurnBasedScore");
            }
        }
    }