예제 #1
0
 /**
  * Returns 1 if the center sprite is getting too close to the right edge,
  * Returns -1 if the center sprite is getting too close to the left edge
  * Returns 0 if the center sprite is not near any edge
  */
 private int isDisplacedX()
 {
     if (centerSprite.getX() + centerSprite.getImage().Width + displacementX + center_X_Displacement > output.Width)
     {
         return(-1);
     }
     else if (centerSprite.getX() + displacementX < center_X_Displacement && displacementX < 0)
     {
         return(1);
     }
     else
     {
         return(0);
     }
 }
예제 #2
0
        /**
         * Combines all images in the queue onto the output image
         * Starts with a clean background each time
         * Images appear stacked on top of each other, with the last added to the
         *    queue on top
         * Sprites are rendered first, text is always rendered last
         *
         * (Note by Nathan, this method could be optimized (?*) to distribute
         *   the load of drawing each sprite in the queue to instead be done
         *   whenever a sprite is added. *Wouldn't change the total time needed.)
         * @author Nathan Swartz, Benjamin Lippincott
         */
        public void Render()
        {
            if (this.hasChanged)
            {
                Graphics g = Graphics.FromImage(output);
                g.DrawImage(background, 0, 0);
                calculateDisplacement();

                // render each renderable's sprite that is displaying
                foreach (KeyValuePair <int, LinkedList <Renderable> > kvp in layers)
                {
                    foreach (Renderable renderable in kvp.Value)
                    {
                        if (renderable.isDisplaying())
                        {
                            ISprite s = renderable.getSprite();
                            g.DrawImage(s.getImage(),
                                        s.getX() + displacementX,
                                        s.getY() + displacementY);
                        }
                    }
                }

                // render each text overlay, on top of every other layer
                foreach (TextOverlay t in texts)
                {
                    using (Font f = t.getFont())
                    {
                        g.DrawString(t.getMessage(), f, Brushes.Black, new PointF(t.getX(), t.getY()));
                    }
                }

                g.Dispose();
                this.hasChanged = false;
            }
        }