Example #1
0
        // This method is invoked when the DrawingPanel needs to be re-drawn
        /// <summary>
        /// Draws all the players, stars and projectiles each time the form is invalidated.
        /// The lock is used so cross-threads can't screw it up!
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            // Draw the players
            // Draw the stars
            // Draw the projectiles.

            lock (world)
            {
                foreach (var shipper in world.playersInWorld.ToList())
                {
                    ship p = shipper.Value as ship;
                    if (p.hp > 0) // If the HP is above zero, the ship deserves to be drawn.
                    {
                        DrawObjectWithTransform(e, p, world.worldPanel.Size.Width, p.GetLocation().GetX(), p.GetLocation().GetY(), p.GetDirections().ToAngle(), shipDrawer);
                    }
                }

                foreach (var starry in world.starsInWorld.ToList())
                {
                    star p = starry.Value as star;
                    DrawObjectWithTransform(e, p, world.worldPanel.Size.Width, p.GetLocation().GetX(), p.GetLocation().GetY(), 0, starDrawer);
                }

                foreach (var proj in world.projectilesInWorld.ToList())
                {
                    projectile p = proj.Value as projectile;

                    if (p.alive == true)
                    {
                        DrawObjectWithTransform(e, p, world.worldPanel.Size.Width, p.GetLocation().GetX(), p.GetLocation().GetY(), p.GetDirections().ToAngle(), projectileDrawer);
                    }
                    else // If it's dead, can be removed from the projectile list.
                    {
                        world.projectilesInWorld.Remove(p.ID);
                    }
                }
            }
            // Do anything that Panel (from which we inherit) needs to do
            base.OnPaint(e);
        }
Example #2
0
 public void checkIfOffScreen(projectile pro, bool extra)
 {
     if (extra == false) // If Touhou is off, make the projectiles kill when they get offscreen.
     {
         if (pro.GetLocation().GetX() > universeSize / 2 + 50 || pro.GetLocation().GetX() < -universeSize / 2 - 50)
         {
             pro.kill();
         }
         if (pro.GetLocation().GetY() > universeSize / 2 + 50 || pro.GetLocation().GetY() < -universeSize / 2 - 50)
         {
             pro.kill();
         }
     }
     else
     {
         if (pro.GetLocation().GetX() > universeSize / 2 || pro.GetLocation().GetX() < -universeSize / 2)
         {
             //we will want it to keep the y position and just rotate to the other side of the screen.
             double   yLocation    = pro.GetLocation().GetY();
             double   oldxLocation = pro.GetLocation().GetX();
             Vector2D newLocation  = new Vector2D(-(oldxLocation), yLocation);
             //Set the projectile location to the new location
             pro.setLocation(newLocation);
         }
         if (pro.GetLocation().GetY() > universeSize / 2 || pro.GetLocation().GetY() < -universeSize / 2)
         {
             //we will want it to keep the y position and just rotate to the other side of the screen.
             double   yLocation   = pro.GetLocation().GetY();
             double   xLocation   = pro.GetLocation().GetX();
             Vector2D newLocation = new Vector2D(xLocation, -yLocation);
             pro.setLocation(newLocation); // Set projectile to modified location.
         }
     }
 }