コード例 #1
0
ファイル: RunnerEvolution.cs プロジェクト: JasonCrease/GP1
        public static void DisplayWorld(World cWorld, Runner cRunner, Graphics g)
        {
            // Draw the player and his sensors.
            Bitmap   cTempBitmap       = new Bitmap(cWorld.GetWorldWidth(), cWorld.GetWorldHeight());
            Graphics gGraphicsOnBitmap = Graphics.FromImage(cTempBitmap);

            gGraphicsOnBitmap.Clear(Color.Black);
            gGraphicsOnBitmap.DrawImageUnscaled(cWorld.GetBackground(), 0, 0);
            PointF cPlayerPosition = cRunner.GetPosition();
            Vector cPlayerRotation = cRunner.GetRotation();

            gGraphicsOnBitmap.FillEllipse(Brushes.Red, cPlayerPosition.X - 5, cPlayerPosition.Y - 5, 10, 10);
            float dDistanceToIntersection = IntersectorFinder.FindIntersectionOnBitmap(cWorld.m_cBackgroundImageFast, cPlayerPosition, cPlayerRotation);

            gGraphicsOnBitmap.DrawLine(Pens.Red, cPlayerPosition, Vector.GetEndPointFromStartPoint(cPlayerPosition, cPlayerRotation.Multiply(dDistanceToIntersection)));
            gGraphicsOnBitmap.DrawLine(Pens.Red, cPlayerPosition, Vector.GetEndPointFromStartPoint(cPlayerPosition, cPlayerRotation.Rotate30Degrees().Multiply(30)));
            gGraphicsOnBitmap.DrawLine(Pens.Red, cPlayerPosition, Vector.GetEndPointFromStartPoint(cPlayerPosition, cPlayerRotation.RotateMinus30Degrees().Multiply(30)));

            g.DrawImageUnscaled(cTempBitmap, 0, 0);
            cTempBitmap.Dispose();
            gGraphicsOnBitmap.Dispose();
        }
コード例 #2
0
ファイル: Runner.cs プロジェクト: JasonCrease/GP1
 private void CalculateDistances(World cWorld)
 {
     m_dDistanceAhead          = IntersectorFinder.FindIntersectionOnBitmap(cWorld.m_cBackgroundImageFast, m_cPlayerPosition, m_cPlayerRotation);
     m_dDistance30DegreesRight = IntersectorFinder.FindIntersectionOnBitmap(cWorld.m_cBackgroundImageFast, m_cPlayerPosition, m_cPlayerRotation.Rotate30Degrees());
     m_dDistance30DegreesLeft  = IntersectorFinder.FindIntersectionOnBitmap(cWorld.m_cBackgroundImageFast, m_cPlayerPosition, m_cPlayerRotation.RotateMinus30Degrees());
 }
コード例 #3
0
ファイル: PlayTest.cs プロジェクト: JasonCrease/GP1
        void cTimer_Tick(object sender, EventArgs e)
        {
            // Move the player in it's direction.
            m_cPlayerPosition = Vector.GetEndPointFromStartPoint(m_cPlayerPosition, m_cDirectionVector);

            // Make sure that the player doesn't exit walls.
            if (m_cPlayerPosition.X < 0)
            {
                m_cPlayerPosition.X = 0;
            }
            if (m_cPlayerPosition.X >= this.Width)
            {
                m_cPlayerPosition.X = this.Width - 1;
            }
            if (m_cPlayerPosition.Y < 0)
            {
                m_cPlayerPosition.Y = 0;
            }
            if (m_cPlayerPosition.Y >= this.Height)
            {
                m_cPlayerPosition.Y = this.Height - 1;
            }

            if (m_fPressingRight == true)
            {
                m_cPlayerRotation = m_cPlayerRotation.Rotate5Degrees().Normalize();
            }
            if (m_fPressingLeft == true)
            {
                m_cPlayerRotation = m_cPlayerRotation.RotateMinus5Degrees().Normalize();
            }
            if (m_fPressingUp == true)
            {
                m_cDirectionVector.Add(m_cPlayerRotation.Multiply(SPEED_ADDITION));
            }
            if (m_fPressingDown == true)
            {
                m_cDirectionVector.Substract(m_cPlayerRotation.Multiply(SPEED_ADDITION));
            }

            // Draw the player and his sensors.
            Graphics g                 = this.CreateGraphics();
            Bitmap   cTempBitmap       = new Bitmap(this.Width, this.Height);
            Graphics gGraphicsOnBitmap = Graphics.FromImage(cTempBitmap);

            gGraphicsOnBitmap.Clear(Color.Black);
            gGraphicsOnBitmap.DrawImageUnscaled(m_cBackgroundImage, 0, 0);
            gGraphicsOnBitmap.FillEllipse(Brushes.Red, m_cPlayerPosition.X - 5, m_cPlayerPosition.Y - 5, 10, 10);
            float dDistanceToIntersectionAhead          = IntersectorFinder.FindIntersectionOnBitmap(m_cBackgroundImageFast, m_cPlayerPosition, m_cPlayerRotation);
            float dDistanceToIntersection30DegreesRight = IntersectorFinder.FindIntersectionOnBitmap(m_cBackgroundImageFast, m_cPlayerPosition, m_cPlayerRotation.Rotate30Degrees());
            float dDistanceToIntersection30DegreesLeft  = IntersectorFinder.FindIntersectionOnBitmap(m_cBackgroundImageFast, m_cPlayerPosition, m_cPlayerRotation.RotateMinus30Degrees());

            gGraphicsOnBitmap.DrawLine(Pens.Red, m_cPlayerPosition, Vector.GetEndPointFromStartPoint(m_cPlayerPosition, m_cPlayerRotation.Multiply(dDistanceToIntersectionAhead)));
            gGraphicsOnBitmap.DrawLine(Pens.Red, m_cPlayerPosition, Vector.GetEndPointFromStartPoint(m_cPlayerPosition, m_cPlayerRotation.Rotate30Degrees().Multiply(dDistanceToIntersection30DegreesRight)));
            gGraphicsOnBitmap.DrawLine(Pens.Red, m_cPlayerPosition, Vector.GetEndPointFromStartPoint(m_cPlayerPosition, m_cPlayerRotation.RotateMinus30Degrees().Multiply(dDistanceToIntersection30DegreesLeft)));
            gGraphicsOnBitmap.DrawString("Distance ahead " + dDistanceToIntersectionAhead, new Font("Times New Roman", 12.0f), Brushes.Red, 0, 0);

            g.DrawImageUnscaled(cTempBitmap, 0, 0);
            cTempBitmap.Dispose();
            gGraphicsOnBitmap.Dispose();
        }