Пример #1
0
        protected override void Open()
        {
            dispose += DemoHelper.BasicDemoSetup(DemoInfo);


            Scene.Engine.AddLogic(new GravityPointField(new Vector2D(500, 500), 1000, new Lifespan()));


            Light light = new Light();

            light.Position.X = 000;
            light.Position.Y = 000;
            light.Position.Z = 0100;

            Body        lightBody    = new Body(new PhysicsState(), ShapeFactory.CreateCircle(15, 20), 40, new Coefficients(0, 1), new Lifespan());
            BodyGraphic lightGraphic = new BodyGraphic(lightBody);

            lightGraphic.DrawProperties.Add(new Color3Property(1, 1, 1));

            Scene.AddGraphic(lightGraphic);

            lightBody.PositionChanged += delegate(object sender, EventArgs e)
            {
                light.Position = lightBody.State.Position.Linear.ToVector3D(100);
            };

            IShape shape = ShapeFactory.CreateSprite(
                Cache <SurfacePolygons> .GetItem("Monkey.png"),
                Cache <Surface> .GetItem("MonkeyNormal.bmp"),
                false, true,
                3, 8, 16,
                light);

            DemoHelper.AddGrid(DemoInfo, shape, 40, new BoundingRectangle(40, 40, 900, 900), 100, 100);
        }
Пример #2
0
        protected override void Open()
        {
            dispose += DemoHelper.BasicDemoSetup(DemoInfo);


            Scene.Engine.AddLogic(new LineFluidLogic(new Line(0, -1, -400), 1.95f, .02f, new Vector2D(0, 0), new Lifespan()));
            Scene.Engine.AddLogic(new GravityField(new Vector2D(0, 1000), new Lifespan()));

            Rectangle rect1 = Viewport.Rectangle;


            BoundingRectangle rect = new BoundingRectangle(rect1.Left, rect1.Top, rect1.Right, rect1.Bottom);

            rect.Min.X -= 75;
            rect.Min.Y -= 75;
            rect.Max.X += 75;
            rect.Max.Y += 75;
            DemoHelper.AddShell(DemoInfo, rect, 100, Scalar.PositiveInfinity).ForEach(delegate(Body b) { b.IgnoresGravity = true; });

            DemoHelper.AddRagDoll(DemoInfo, new Vector2D(340, 300));
            DemoHelper.AddRagDoll(DemoInfo, new Vector2D(640, 300));
            IShape shape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("fighter.png"), 3, 16, 4);

            DemoHelper.AddShape(DemoInfo, shape, 200, new ALVector2D(0, new Vector2D(200, 300)));
            DemoHelper.AddShape(DemoInfo, shape, 100, new ALVector2D(0, new Vector2D(500, 300)));
            DemoHelper.AddRectangle(DemoInfo, 20, 200, 25 / 5, new ALVector2D(0, 600, 600));
            DemoHelper.AddRectangle(DemoInfo, 20, 200, 25 / 5, new ALVector2D(0, 600, 620));
            DemoHelper.AddRectangle(DemoInfo, 50, 100, 50, new ALVector2D(0, 200, 400));
            DemoHelper.AddRectangle(DemoInfo, 50, 100, 50, new ALVector2D(0, 400, 200));

            Vector2D[] waterVertexes = new Vector2D[4]
            {
                new Vector2D(-10, 400),
                new Vector2D(10000, 400),
                new Vector2D(10000, 1000),
                new Vector2D(-10, 1000)
            };
            ScalarColor3[] waterColor = new ScalarColor3[4]
            {
                new ScalarColor3(0, 0, 1),
                new ScalarColor3(0, 0, 1),
                new ScalarColor3(0, 0, 1),
                new ScalarColor3(0, 0, 1)
            };
            Colored3VertexesDrawable drawable = new Colored3VertexesDrawable(Gl.GL_QUADS, waterVertexes, waterColor);

            Graphic graphic = new Graphic(drawable, Matrix2x3.Identity, new Lifespan());

            graphic.ZOrder = -1;
            Scene.AddGraphic(graphic);
        }
Пример #3
0
        public override void Update()
        {
#if SHOW_HUNGER
            Scene.RemoveGraphic(hungerText);
            hungerText = new Text(Hunger.ToString(), 12);
            Scene.AddGraphic(hungerText);
            hungerText.X = X - 8;
            hungerText.Y = Y - 15 - Size;
#endif
            if (AITickCounter == 0)
            {
                AITick();
                AITickCounter = Global.AITickDelay;
            }
            Hunger--;



            var nearestHerbivore = Global.Herbivores
                                   .Where(cell => Global.SquaredDistances[this][cell] < Size * Size && cell.Size <= Size)
                                   .OrderBy(cell => Global.SquaredDistances[this][cell])
                                   .FirstOrDefault() as IHerbivore;
            if (nearestHerbivore != null && Target == nearestHerbivore)
            {
                Eat(nearestHerbivore);
                UnlockTarget();
            }

            dynamic currentTarget;
            if (Target is Point)
            {
                currentTarget = (Target as Point?).Value;
            }
            else
            {
                currentTarget = Target as Cell;
            }

            if (Target == null || ((int)currentTarget.X == (int)X && (int)currentTarget.Y == (int)Y))
            {
                UnlockTarget();
            }
            base.Update();
        }
Пример #4
0
        protected override void Open()
        {
            dispose += DemoHelper.BasicDemoSetup(DemoInfo);

            IShape fighterShape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("fighter.png"), 4, 50, 5);
            Body   fighter      = new Body(new PhysicsState(new ALVector2D(0, 300, 300)), fighterShape, 5000, new Coefficients(0, 1), new Lifespan());

            fighter.State.Velocity.Angular = 9;
            fighter.Mass.MomentOfInertia   = Scalar.PositiveInfinity;

            BodyGraphic fighterGraphic = new BodyGraphic(fighter);

            Scene.AddGraphic(fighterGraphic);

            BodyGraphic fighterGraphic2 = (BodyGraphic)fighterGraphic.Duplicate();

            fighterGraphic2.Body.State.Position.Linear.Y = 500;
            fighterGraphic2.Body.State.Velocity.Angular  = -8.5f;
            Scene.AddGraphic(fighterGraphic2);


            Body      template2 = new Body(new PhysicsState(new ALVector2D(0, 200, 200)), ParticleShape.Default, 4, new Coefficients(0, 1), new Lifespan());
            Matrix2x3 m         = Matrix2x3.FromRotationZ(2);
            int       count     = 0;

            for (int x = -0; x < 1000; x += 25)
            {
                for (int y = -0; y < 1000; y += 25)
                {
                    count++;
                    Body body = template2.Duplicate();
                    body.State.Position.Linear = new AdvanceMath.Vector2D(x, y);
                    body.ApplyPosition();
                    body.State.Velocity.Linear.X = (250 - x) / 10f;
                    body.State.Velocity.Linear.Y = (250 - y) / 10f;
                    body.State.Velocity.Linear   = m * body.State.Velocity.Linear;
                    body.LinearDamping           = .9999f;
                    BodyGraphic g1 = new BodyGraphic(body);
                    Scene.AddGraphic(g1);
                }
            }
            Scene.Engine.AddLogic(new GravityPointField(new Vector2D(400, 400), 500, new Lifespan()));
        }
Пример #5
0
        private void DoGuns(Body body, Body enemy, Key fire)
        {
            //this method requires a deep understanding of delegates and events. ENJOY :P
            Scalar projectileSpeed  = 500;
            Scalar projectileRadius = 3;
            Scalar projectileMass   = 3;

            BoundingRectangle rect;
            Matrix2x3         ident = Matrix2x3.Identity;

            body.Shape.CalcBoundingRectangle(ref ident, out rect);


            DateTime lastFire = DateTime.Now;
            Scalar   distance = rect.Max.X + projectileRadius * 2;
            EventHandler <KeyboardEventArgs> keyDown = delegate(object sender, KeyboardEventArgs e)
            {
                DateTime now = DateTime.Now;
                if (e.Key == fire &&
                    !body.Lifetime.IsExpired &&
                    now.Subtract(lastFire).TotalSeconds > .3)
                {
                    lastFire = now;
                    Vector2D normal      = body.Matrices.ToWorldNormal * Vector2D.XAxis;
                    Vector2D position    = new Vector2D(body.Matrices.ToWorld.m02, body.Matrices.ToWorld.m12) + (normal * distance);
                    Vector2D offset      = normal.LeftHandNormal * 3 * projectileRadius;
                    Body     projectile1 = DemoHelper.AddCircle(DemoInfo, projectileRadius, 8, projectileMass, new ALVector2D(0, position + offset));
                    Body     projectile2 = DemoHelper.AddCircle(DemoInfo, projectileRadius, 8, projectileMass, new ALVector2D(0, position - offset));
                    projectile1.Lifetime.MaxAge = 5;
                    projectile2.Lifetime.MaxAge = 5;
                    Vector2D velocity = normal * projectileSpeed;
                    body.State.Velocity.Linear       -= (projectileMass * 2 * velocity) * body.Mass.MassInv;
                    projectile1.State.Velocity.Linear = velocity + body.State.Velocity.Linear;
                    projectile2.State.Velocity.Linear = velocity + body.State.Velocity.Linear;
                    EventHandler <CollisionEventArgs> collided = delegate(object sender1, CollisionEventArgs e1)
                    {
                        Body projectile = (Body)sender1;
                        projectile.Lifetime.IsExpired = true;
                        bool isHit = e1.Other == enemy || e1.Other == body;

                        List <Body> particles = DemoHelper.AddParticles(
                            DemoInfo,
                            projectile.State.Position.Linear,
                            projectile.State.Velocity.Linear,
                            (isHit) ? (200) : (10));
                        if (isHit && !e1.Other.Lifetime.IsExpired)
                        {
                            ExplosionLogic explosionLogic = new ExplosionLogic(
                                e1.Other.State.Position.Linear,
                                e1.Other.State.Velocity.Linear,
                                9000, .1f, e1.Other.Mass.Mass,
                                new Lifespan(.5f));
                            Scene.Engine.AddLogic(explosionLogic);
                            e1.Other.Lifetime.IsExpired = true;
                            particles[0].Removed       += delegate(object sender2, RemovedEventArgs e2)
                            {
                                if (particles[0].Lifetime.IsExpired)
                                {
                                    e1.Other.State.Velocity = ALVector2D.Zero;
                                    e1.Other.State.Position = new ALVector2D(DemoHelper.NextScalar(-600, 900), DemoHelper.NextScalar(-600, 900), DemoHelper.NextScalar(-600, 900));
                                    e1.Other.ApplyPosition();
                                    e1.Other.Lifetime.IsExpired = false;
                                    Scene.AddGraphic((BodyGraphic)e1.Other.Tag);
                                }
                            };
                        }
                        else if (e1.Other.Shape is CircleShape &&
                                 !e1.Other.IgnoresCollisionResponse)
                        {
                            e1.Other.Lifetime.IsExpired = true;
                        }
                    };
                    projectile1.Collided += collided;
                    projectile2.Collided += collided;
                }
            };

            Events.KeyboardDown += keyDown;
            dispose             += delegate()
            {
                Events.KeyboardDown -= keyDown;
            };
        }