Example #1
0
        public void intersects(Player[] players)
        {
            //     Vector3 worldPos = device.Viewport.Unproject(new Vector3((float)players[0].center.X, (float)players[0].center.Y, 0),
               //                                                         camera.projection, camera.view, Matrix.Identity);

            Vector3 worldPos = device.Viewport.Unproject(new Vector3(0, 0, 0), camera.projection, camera.view, Matrix.Identity);
            Ray ray = new Ray(worldPos, -camera.view.Forward);
            Vector3 norm = ray.Direction;

            int j = 0;
            for (int i = 0; i < normals.Length; i++)
            {
                //if the dot product between them is > 0, then the angle must be < 90 degrees, so
                //this face is valid.
                if ((normals[i].X * norm.X) + (normals[i].Y * norm.Y) + (normals[i].Z * norm.Z) > 0)
                {
                    //test each square on this row
                    for (; j < (i + 1) * numSquaresAcross; j++)
                    {
                        foreach (Player p in players)
                        {
                            if (p != null)
                                squares[j].intersects(p);
                        }
                    }
                }
                else
                {
                    //(i+1) * numSquaresAcross: since the squares are set up in order, if i = 0, and there's 6
                    //squares across, we'll be skipping to index 6, the first square on the next side, which has a different normal
                    if (i < normals.Length - 1)
                        j = (i + 1) * numSquaresAcross;
                }

            }

            //foreach (MatchPiece piece in squares)
            //{
            //    //  foreach (Player p in players)
            //    piece.intersects(players);
            //}
        }
Example #2
0
        internal void FlipTo(Player player, int i)
        {
            GameObject.Score(player.index, GameObject.MATCHPOINTS);
            if (owner[i] != player.index)
            {
                if (owner[i] == -1) GameObject.PlaySound(ROW_FLIP_SOUND);
                else GameObject.PlaySound(ROW_STEAL_SOUND);
                // Row has been stolen
                // Allocate points
                GameObject.Score(player.index, GameObject.STEALPOINTS);
                owner[i] = player.index;
                isUnlocked[i] = false;
                colorOverlay[i] = player.fadedColor;
            }
            else
            {
                GameObject.Score(player.index, GameObject.LOCKPOINTS);
            }

            int numMatched = 1;
            for (int j = i*numSquaresAcross; j < (i+1)*numSquaresAcross; ++j)
            {
                if (!squares[j].isVirgin)
                {
                    squares[j].FlipVirgin(player);
                    ++numMatched;
                }
            }
            Debug.WriteLine(numMatched + "/" + numSquaresAcross);
            if (numMatched == numSquaresAcross)
            {
                // Player has filled in an entire row, reset side
                // Allocate points
                GameObject.Score(player.index, GameObject.COMPLETEPOINTS);
                ResetSide(i);
            }
        }
Example #3
0
 public void intersects(Player[] players)
 {
     //foreach (CubeSegment segment in cubeSegments)
     for(int i=0; i < cubeSegments.Length; i++)
         cubeSegments[i].intersects(players);
 }
Example #4
0
 public bool CanFlip(Player player, int i, bool affectedPieceIsVirgin)
 {
     return isUnlocked[i] || (owner[i] == player.index ^ !affectedPieceIsVirgin);
 }
Example #5
0
 public bool CanFlip(Player player)
 {
     return segment.CanFlip(player, segmentIndex, isVirgin);
 }
Example #6
0
 /// <summary>
 /// Here we're indicating the colour of the player and the input(gamepad/keyboard) index
 /// 0 <= index < MAXPLAYERS
 /// </summary>
 public static void AddPlayer(byte index, Color colour)
 {
     Debug.Assert(!playerList.Contains(index), "Cannot add two players with the same index (index=" + index + ")");
     Debug.Assert(index < MAXPLAYERS, "Cannot add a player with an index greater or equal to the maximum allowed players (index=" + index + ">=" + MAXPLAYERS + ")");
     playerList.Add(index);
     players[index] = new Player(index, screenSize / 2 + new TwoInt(-100 + index % 2 * 200, 100 * (byte)(index / 2)), colour);
 }
Example #7
0
        internal void FlipTo(Player player)
        {
            if (CanFlip(player))
            {
                // Player has fit a piece
                segment.FlipTo(player, segmentIndex);
                FlipVirgin(player);

            }
        }
Example #8
0
 internal void FlipVirgin(Player player)
 {
     GameObject.PlaySound(PIECE_DROP_SOUND);
         noninteractedColor = player.color;
         isVirgin = false;
 }
Example #9
0
        public bool intersects(Player player)
        {
            Vector2[] polygon = new Vector2[cubeFront.Length];
            for (int i = 0; i < cubeFront.Length; i++)
               polygon[i] = GameObject.GetScreenSpace(cubeFront[i].Position, worldTranslation);

            if (GlobalFuncs.PointInPolygonCollision2D(player.center, polygon))
            {
                if (playersSelecting[player.index] = player.Match(this.pieceID))
                {
                    interactedColor = player.fadedColor;
                    player.Attach(this);
                }
            }
            else
                playersSelecting[player.index] = false;

            return playersSelecting[player.index];
        }
Example #10
0
 internal void FlipVirgin(Player player)
 {
     noninteractedColor = player.color;
         isVirgin = false;
 }
Example #11
0
 public bool Drop(Player grabbingPlayer)
 {
     //if (grabbed && intersects(grabbingPlayer.center))
     //{
         grabbed = false;
         interactingPlayer = -1;
     //}
     return false;
 }
Example #12
0
 public bool intersects(Player[] players)
 {
     if (isIntersected && interactingPlayer >= 0 && intersects(players[interactingPlayer].center)) ; // yeah this is blank... for now
     else
     {
         isIntersected = false;
         interactingPlayer = -1;
         for (byte i = 0; i < players.Length; ++i)
             if (players[i] != null)
                 if (intersects(players[i].center))
                 {
                     isIntersected = true;
                     interactingPlayer = i;
                     players[i].Attach(this);
                     interactedColor = players[i].fadedColor;
                     break;
                 }
     }
     return isIntersected;
 }
Example #13
0
 public bool Grab(Player grabbingPlayer)
 {
     return grabbed = !grabbed && intersects(grabbingPlayer.center);
 }