Ejemplo n.º 1
0
        /// <summary>
        /// Fires the projectile in a line from the ship, straight.
        /// </summary>
        /// <param name="proj"></param>
        private void updateProjectileLocation(projectile proj, star starry)
        {
            if (bulletGravity == false)
            {
                Vector2D direction = proj.GetDirections(); // We have the direction
                direction *= projectileSpeed;

                proj.loc = proj.loc + direction;// Apply new velocity to position.

                checkIfOffScreen(proj, touhouMode);
            }
            else
            {
                Vector2D gravity = starry.loc - proj.loc; // Find the vector from the ship to the star.
                gravity.Normalize();                      // Turn the vector into a unit-length direction by normalizing.
                gravity *= starry.mass;                   // Adjust strentth of vector by multiplying star's mass.

                Vector2D thrust = new Vector2D(0, 0);     // no thrust for you.

                Vector2D acceleration = gravity + thrust; // combine all forces.

                proj.velocity += acceleration;            // Add acceleration to velocity.

                proj.loc = proj.loc + proj.velocity;      // Apply new velocity to position.

                checkIfOffScreen(proj, touhouMode);       // Wraparound if offscreen.
            }
        }
Ejemplo n.º 2
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);
        }