Exemple #1
0
        public void update()
        {
            LineSegment segmentToPlayer = new LineSegment (position,player.getPosition());

            bool couldSeePlayerBefore = canSeePlayer;
            canSeePlayer = true;

                foreach (LineSegment wall in walls) {
                    if (LineSegment.TestIntersection (segmentToPlayer, wall)) {
                        canSeePlayer = false;
                        break;
                    }
                }

            if (canSeePlayer) {
                target = player.getPosition ();
                setStalkSpeed ();
            }

            if (!canSeePlayer && couldSeePlayerBefore) {
                setRandomTarget ();
                setWanderSpeed ();
            }

                PointD vectorDistance = new PointD (target.X - position.X, target.Y - position.Y);
            double scalarDistance = Math.Sqrt (Math.Pow(vectorDistance.X,2) + Math.Pow(vectorDistance.Y,2));

            if (scalarDistance < tolerance) {
                ;
            } else {
                double total = Math.Abs (vectorDistance.X) + Math.Abs (vectorDistance.Y);
                position.X += (vectorDistance.X / total) * speed;
                position.Y += vectorDistance.Y / total * speed;
            }
        }
Exemple #2
0
        private void drawAll()
        {
            if (framesaver < framesaverLimit) {
                framesaver++;
                return;
            } else {
                framesaver = 0;
            }

            Cairo.Context cr = Gdk.CairoHelper.Create(drawArea.GdkWindow);

            clearDrawArea (cr);

            foreach (LineSegment segment in lineSegments) {
                cr.LineWidth = 2;
                cr.SetSourceRGB(0.0, 0.2, 0.0);

                cr.MoveTo(segment.P1);
                cr.LineTo (segment.P2);

                cr.Stroke ();
            }

            for (int x = 0; x < width; x += resolution) {
                for (int y = 0; y < height; y += resolution) {
                    PointD testPoint = new PointD (x, y);
                    LineSegment ls = new LineSegment (player.getPosition (), testPoint);
                    foreach (LineSegment wall in lineSegments) {
                        if (intersectionTester.TestIntersection (wall, ls)) {
                            cr.MoveTo (testPoint);
                            cr.SetSourceRGB (0.3, 0.3, 0.3);
                            cr.Arc (testPoint.X, testPoint.Y, resolution / 2, 0, 2 * Math.PI);
                            cr.Fill ();
                            break;
                        }
                    }
                }
            }

            framesaver = 0;

            player.draw (cr);

            foreach (Ghost g in ghosts) {
                g.draw (cr);
            }

            drawArea.QueueDraw ();

            ((IDisposable) cr.GetTarget()).Dispose();
            ((IDisposable) cr).Dispose();
        }
Exemple #3
0
 public bool TestIntersection(LineSegment s1, LineSegment s2)
 {
     return LineSegment.TestIntersection(s1,s2);
 }
Exemple #4
0
        // How should we treat points on the line?
        public static bool TestIntersection(LineSegment l1, LineSegment l2)
        {
            double l1p1 = l2.CalculatePointInStandardForm (l1.p1);
            double l1p2 = l2.CalculatePointInStandardForm (l1.p2);

            //if (Math.Abs (l1p1) < tolerance || Math.Abs (l1p2) < tolerance) {]
            // Ignore this ->
            // touching lines will be considered intersecting

            // If the signs differ the points are on different sides of the
            // other line. If the signs are the same tho they are on the same
            // side of the other segment and hence no intersection.
            if (Math.Sign (l1p1) == Math.Sign (l1p2)) {
                return false;
            }

            double l2p1 = l1.CalculatePointInStandardForm (l2.p1);
            double l2p2 = l1.CalculatePointInStandardForm (l2.p2);

            //if (Math.Abs (l2p1) < tolerance || Math.Abs (l2p2) < tolerance) {}
            // Ignore this -> touching lines will be considered intersection

            if (Math.Sign (l2p1) == Math.Sign (l2p2)) {
                return false;
            }

            // Different signs for all points and lines involved. Intersection!
            return true;
        }
Exemple #5
0
 public bool TestIntersection(LineSegment s1, LineSegment s2)
 {
     return ComputationalGeometry.IntersectProp(s1.P1,s1.P2,s2.P1,s2.P2);
 }