Esempio n. 1
0
        // Processes whatever power-up/item the player has equipped.
        public void ProcessItem(GridLayer grid, AddShadowCopy[] addShadowCopies, ShadowCopy[] shadowCopies, Texture2D tx2ShadowCopy)
        {
            switch (strItem)
            {
            case "drk":     // If the node contained a dark area, spawn an additional shadow copy.
            {
                if (addShadowCopies.Contains(null))
                {
                    int intNewCopyIndex;
                    intNewCopyIndex = Array.IndexOf(addShadowCopies, null);
                    addShadowCopies[intNewCopyIndex]             = new AddShadowCopy();
                    addShadowCopies[intNewCopyIndex].EntityImage = tx2ShadowCopy;
                    addShadowCopies[intNewCopyIndex].Initialize(EntityNode);
                }
            }
                strItem = null;
                break;

            case "bld":
                EntityNode.Colour = Color.Red;     // Make the colour of the node the player is in red, to show a blade is equipped.
                for (int intCopyIndex = 0; intCopyIndex < shadowCopies.GetLength(0); intCopyIndex++)
                {
                    if (shadowCopies[intCopyIndex] != null && EntityNode.Tile.Intersects(shadowCopies[intCopyIndex].EntityNode.Tile))
                    {                   // If a shadow copy exists and it intersects the player, remove the copy.
                        shadowCopies[intCopyIndex] = null;
                        strItem = null; // Remove the player's item after use.
                    }
                }
                for (int intCopyIndex = 0; intCopyIndex < addShadowCopies.GetLength(0); intCopyIndex++)
                {
                    if (addShadowCopies[intCopyIndex] != null && EntityNode.Tile.Intersects(addShadowCopies[intCopyIndex].EntityNode.Tile))
                    {                   // If a shadow copy exists and it intersects the player, remove the copy.
                        addShadowCopies[intCopyIndex] = null;
                        strItem = null; // Remove the player's item after use.
                    }
                }
                // if a shadow copy is in the same node as a player with a blade. Remove the shadow copy.
                break;

            case "lbm":                                                       // Casts a light ray where the player is facing from the centre of the player.
                LightRay lightBeam = new LightRay(EntityPosition + new Vector2(RectEntityWidth / 2, RectEntityHeight / 2), EntityDirection, 200, grid);
                BeamKillCopy(grid, lightBeam, addShadowCopies, shadowCopies); // If the beam intersects a shadow copy, remove it.
                break;

            case "frt":
                intHealth = 1000;     // If the player has a fruit, reset the player's health to 100.
                strItem   = null;
                break;
            }
        }
Esempio n. 2
0
        // Casts light rays in the direction that the shadow copy is facing.
        public void CastLightRays(GridLayer grid)
        {
            // Stores the directions in which light rays should be casted.
            Vector2[] v2Directions = new Vector2[3];
            // Directions to cast lines in are calculated: direction vector = cos(angle) - sin(angle)
            v2Directions[0] = new Vector2((float)Math.Sin(EntityRotation), -(float)Math.Cos(EntityRotation));
            v2Directions[0].Normalize(); // Cast a light ray in the direction that the copy is facing.
            v2Directions[1] = new Vector2((float)Math.Sin(EntityRotation - 0.5), -(float)Math.Cos(EntityRotation - 0.5));
            v2Directions[1].Normalize(); // Cast a light ray to the left of the first one.
            v2Directions[2] = new Vector2((float)Math.Sin(EntityRotation + 0.5), -(float)Math.Cos(EntityRotation + 0.5));
            v2Directions[2].Normalize(); // Cast a light ray which is to the right of the first one.

            // Stores the centre of the shadow copy so that rays can be casted from there.
            Vector2 v2CentreOfCopy = EntityPosition + new Vector2(RectEntityWidth / 2, RectEntityHeight / 2);

            LRRays = new LightRay[3];
            // Create the light rays in the three directions using the constructor of the light ray class.
            for (int intRayIndex = 0; intRayIndex < 3; intRayIndex++)
            {
                LRRays[intRayIndex] = new LightRay(v2CentreOfCopy, v2Directions[intRayIndex], intSight, grid);
            }
        }
Esempio n. 3
0
 // Checks if a shadow copy is within the range of a light beam and removes it if it is.
 public void BeamKillCopy(GridLayer grid, LightRay lightBeam, AddShadowCopy[] addShadowCopies, ShadowCopy[] shadowCopies)
 { // Check each point in the beam, if the point is in the same node as a copy, remove the shadow copy.
     foreach (Point point in lightBeam.Points)
     {
         for (int intCopyIndex = 0; intCopyIndex < shadowCopies.GetLength(0); intCopyIndex++)
         {
             if (shadowCopies[intCopyIndex] != null && shadowCopies[intCopyIndex].RectEntity.Intersects(grid.GetNode(point).Tile))
             {                   // Only check and remove the copy if it actually exists.
                 shadowCopies[intCopyIndex] = null;
                 strItem = null; // Removes the player's item after use.
             }
         }
         for (int intCopyIndex = 0; intCopyIndex < addShadowCopies.GetLength(0); intCopyIndex++)
         {
             if (addShadowCopies[intCopyIndex] != null && addShadowCopies[intCopyIndex].RectEntity.Intersects(grid.GetNode(point).Tile))
             {                   // Only check and remove the copy if it actually exists.
                 addShadowCopies[intCopyIndex] = null;
                 strItem = null; // Removes the player's item after use.
             }
         }
         grid.GetNode(point).Colour = Color.White; // Makes any nodes in the beam brighter.
     }
 }