示例#1
0
        /// <summary>
        /// Executed when a mouse button is pressed.
        /// </summary>
        /// <param name="e"></param>
        public override void MousePressed(MouseEventArgs e)
        {
            // Do nothing if the game already has stopped.
            if (victory)
            {
                return;
            }

            base.MousePressed(e);
            List <Entity.Entity> toBeRemoved = new List <Entity.Entity>();

            shots++;

            // Convert display coordinates into coordinates on map.
            Point     loctationOnMap = map.ToMapCoordinates(e.Location);
            Rectangle collisionBox   = new Rectangle(loctationOnMap, new Size(1, 1));

            // Gathering entities that were hit by the cursor.
            foreach (Entity.Entity entity in entities)
            {
                if (entity.CollidesWith(collisionBox))
                {
                    toBeRemoved.Add(entity);
                }
            }
            if (toBeRemoved.Count > 1)
            {
                doubleHits = toBeRemoved.Count - 1;
            }

            // Removing the entities.
            lock (entities)
            {
                foreach (Entity.Entity entity in toBeRemoved)
                {
                    entities.Remove(entity);
                    EntityDies();
                }
            }
        }