示例#1
0
            public ResolutionTestNode(State stateref, string name)
                : base(stateref, name)
            {
                Body        = new Body(this, "Body");
                Body.Bounds = new Vector2(70, 70);

                _physics = new Physics(this, "_physics");
                _physics.LinkDependency(Physics.DEPENDENCY_BODY, Body);
                _physics.Mass        = 10f;
                _physics.Restitution = 1f;
                _physics.Drag        = .95f;

                Shape = new AABB(this, "AABB");
                Shape.LinkDependency(AABB.DEPENDENCY_BODY, Body);

                Collision = new Collision(this, "Collision");
                Collision.LinkDependency(Collision.DEPENDENCY_SHAPE, Shape);
                Collision.LinkDependency(Collision.DEPENDENCY_PHYSICS, _physics);
                Collision.Initialize();

                _imageRender = new ImageRender(this, "Image", Assets.Pixel);
                _imageRender.LinkDependency(ImageRender.DEPENDENCY_BODY, Body);
                _imageRender.Scale = new Vector2(70, 70);
                _imageRender.Layer = .5f;

                _textBody = new Body(this, "_textBody");

                _textRender = new TextRender(this, "_textRender");
                _textRender.LinkDependency(TextRender.DEPENDENCY_BODY, _textBody);
                _textRender.Color = Color.White;
                _textRender.Font  = Assets.Font;
                _textRender.Text  = Name;
                _textRender.Layer = 1f;
            }
示例#2
0
        public Bullet(Node parent, string name)
            : base(parent, name)
        {
            Render = new ImageRender(this, "Render");
            Render.SetTexture(GetRoot <State>().GetService <AssetCollector>().GetAsset <Texture2D>("bullet"));
            Render.Layer = .1f;
            Render.Scale = new Vector2(.1f);
            Render.Color = Color.White;
            Render.LinkDependency(ImageRender.DEPENDENCY_BODY, Body);

            //Make our collision rectangles the size of the rendered sprite.
            Body.Bounds = Render.Bounds;
            Body.Origin = new Vector2(Render.Texture.Width / 2f, Render.Texture.Height / 2f);

            Shape        = new Circle(this, "Shape", Body.Width / 2);
            Shape.Offset = new Vector2(Body.Width / 2, Body.Height / 2);
            Shape.LinkDependency(Circle.DEPENDENCY_BODY, Body);

            Collision.Group.AddMask(1);
            Collision.Pair.AddMask(2);
            Collision.Immovable     = true;
            Collision.CollideEvent += collision => Recycle();
            Collision.LinkDependency(Collision.DEPENDENCY_SHAPE, Shape);
            Shape.LinkDependency(Circle.DEPENDENCY_COLLISION, Collision);

            DeathTimer = new Timer(this, "DeathTimer");
            DeathTimer.Milliseconds = 2000;
            DeathTimer.LastEvent   += Recycle;
            DeathTimer.LastEvent   += DeathTimer.Stop;
        }
示例#3
0
        public BaseNode(Node parent, string name) : base(parent, name)
        {
            Body = new Body(this, "Body");

            Physics = new Physics(this, "Physics");
            Physics.LinkDependency(Physics.DEPENDENCY_BODY, Body);

            Collision = new Collision(this, "Collision");
            Collision.LinkDependency(Collision.DEPENDENCY_PHYSICS, Physics);
        }
        public BaseNode(Node parent, string name)
            : base(parent, name)
        {
            Body = new Body(this, "Body");

            Physics = new Physics(this, "Physics");
            Physics.LinkDependency(Physics.DEPENDENCY_BODY, Body);

            Collision = new Collision(this, "Collision");
            Collision.LinkDependency(Collision.DEPENDENCY_PHYSICS, Physics);
        }
示例#5
0
            public TestEntity(Node parent, string name)
                : base(parent, name)
            {
                Body = new Body(this, "Body");

                Physics      = new Physics(this, "Physics");
                Physics.Mass = 10;
                Physics.LinkDependency(Physics.DEPENDENCY_BODY, Body);

                Collision = new Collision(this, "Collision");
                Collision.Group.AddMask(0);
                Collision.Pair.AddMask(0);
                Collision.ResolutionGroup.AddMask(0);
                Collision.LinkDependency(Collision.DEPENDENCY_PHYSICS, Physics);
            }
示例#6
0
            public override void Initialize()
            {
                base.Initialize();
                Body.Width  = Render.DrawRect.Width;
                Body.Height = Render.DrawRect.Height;
                Body.Origin = new Vector2(Render.Texture.Width / 2f, Render.Texture.Height / 2f);

                Shape        = new Circle(this, "Circle", Body.Width / 2);
                Shape.Offset = new Vector2(Body.Width / 2, Body.Height / 2);
                Shape.Debug  = true;
                Shape.LinkDependency(Circle.DEPENDENCY_BODY, Body);

                Collision.LinkDependency(Collision.DEPENDENCY_SHAPE, Shape);
                Shape.LinkDependency(Circle.DEPENDENCY_COLLISION, Collision);
            }
示例#7
0
            public AABBTester(Node parent, string name, float width = 20, float height = 20)
                : base(parent, name)
            {
                AABB = new AABB(this, "AABB");
                AABB.LinkDependency(AABB.DEPENDENCY_BODY, Body);
                AABB.LinkDependency(AABB.DEPENDENCY_COLLISION, Collision);

                Body.Width  = width;
                Body.Height = height;

                Render = new ShapeTypes.Rectangle(this, "Render", true);
                Render.LinkDependency(ImageRender.DEPENDENCY_BODY, Body);
                Body.Origin = new Vector2(.5f); //Half of a pixel since that is the size of the brush.

                Collision.LinkDependency(Collision.DEPENDENCY_SHAPE, AABB);
            }
示例#8
0
            public CircleTester(Node parent, string name, float radius)
                : base(parent, name)
            {
                Circle        = new Circle(this, "Circle", radius);
                Circle.Offset = new Vector2(radius);
                Circle.LinkDependency(Circle.DEPENDENCY_BODY, Body);
                Circle.LinkDependency(Circle.DEPENDENCY_COLLISION, Collision);

                Body.Bounds = new Vector2(Circle.Diameter);

                Render       = new ImageRender(this, "Render", Assets.Circle);
                Render.Scale = new Vector2(Circle.Diameter / Assets.Circle.Width);
                Render.LinkDependency(ImageRender.DEPENDENCY_BODY, Body);

                Body.Origin = new Vector2(Render.Texture.Width / 2f, Render.Texture.Height / 2f);
                Collision.LinkDependency(Collision.DEPENDENCY_SHAPE, Circle);
            }
示例#9
0
        public PlayerShip(Node parent, string name)
            : base(parent, name)
        {
            Body.X = EntityGame.Viewport.Width / 2f;
            Body.Y = EntityGame.Viewport.Height / 2f;

            Physics.Drag        = 0.97f;
            Physics.AngularDrag = 0.9f;

            Render = new ImageRender(this, "Render");
            Render.SetTexture(GetRoot <State>().GetService <AssetCollector>().GetAsset <Texture2D>("ship"));
            Render.Layer = .01f;
            Render.Scale = new Vector2(.128f);
            Render.LinkDependency(ImageRender.DEPENDENCY_BODY, Body);

            Body.Bounds = Render.Bounds;
            Body.Origin = new Vector2(Render.Texture.Width / 2f, Render.Texture.Height / 2f);


            Gun = new SimpleGun(this, "SimpleGun");
            Gun.LinkDependency(SimpleGun.DEPENDENCY_BODY, Body);
            Gun.LinkDependency(SimpleGun.DEPENDENCY_PHYSICS, Physics);
            Shape        = new Circle(this, "Circle", Body.Width * .8f);
            Shape.Offset = new Vector2(Body.Width / 2, Body.Height / 2);
            Shape.Debug  = true;
            Shape.LinkDependency(Circle.DEPENDENCY_BODY, Body);

            Collision.Group.AddMask(0);
            Collision.Pair.AddMask(2);
            Collision.CollideEvent += OnCollide;
            Collision.Immovable     = true;
            Collision.LinkDependency(Collision.DEPENDENCY_SHAPE, Shape);
            Shape.LinkDependency(Circle.DEPENDENCY_COLLISION, Collision);


            //Control
            UpButton      = new DoubleInput(this, "UpButton", Keys.W, Buttons.DPadUp, PlayerIndex.One);
            DownButton    = new DoubleInput(this, "DownButton", Keys.S, Buttons.DPadDown, PlayerIndex.One);
            LeftButton    = new DoubleInput(this, "LeftButton", Keys.A, Buttons.DPadLeft, PlayerIndex.One);
            RightButton   = new DoubleInput(this, "RightButton", Keys.D, Buttons.DPadRight, PlayerIndex.One);
            FireButton    = new DoubleInput(this, "FireButton", Keys.Space, Buttons.A, PlayerIndex.One);
            ThrustTrigger = new GamePadTrigger(this, "ThrustTrigger", Triggers.Right, PlayerIndex.One);
            //GravityTrigger = new GamePadTrigger(this, "GravityTrigger", Triggers.Left, PlayerIndex.One);

            LookAnalog = new GamePadAnalog(this, "LookAnalog", Sticks.Left, PlayerIndex.One);
        }
示例#10
0
        public Asteroid(Node parent, string name)
            : base(parent, name)
        {
            Body.X     = RandomHelper.GetFloat() * EntityGame.Viewport.Right;
            Body.Y     = RandomHelper.GetFloat() * EntityGame.Viewport.Bottom;
            Body.Angle = MathHelper.TwoPi * RandomHelper.GetFloat();

            Physics.Thrust(RandomHelper.GetFloat(30, 60));
            Physics.Restitution = 1.5f;

            Render = new ImageRender(this, "Render");
            Render.SetTexture(GetRoot <State>().GetService <AssetCollector>().GetAsset <Texture2D>("circle"));
            Render.Scale = new Vector2(RandomHelper.GetFloat(.25f, .5f));
            Render.LinkDependency(ImageRender.DEPENDENCY_BODY, Body);

            Body.Width  = Render.DrawRect.Width;
            Body.Height = Render.DrawRect.Height;
            Body.Origin = new Vector2(Render.Texture.Width / 2f, Render.Texture.Height / 2f);

            Physics.Mass = Render.Scale.X;

            Health            = new Health(this, "Health", 3);
            Health.DiedEvent += entity => Destroy(this);

            Shape        = new Circle(this, "Circle", Body.Width / 2);
            Shape.Offset = new Vector2(Body.Width / 2, Body.Height / 2);
            Shape.Debug  = true;
            Shape.LinkDependency(Circle.DEPENDENCY_BODY, Body);

            Collision.Pair.AddMask(0);
            Collision.Pair.AddMask(1);
            Collision.Group.AddMask(2);
            Collision.Pair.AddMask(2);
            Collision.ResolutionGroup.AddMask(2);
            Collision.CollideEvent += OnCollide;
            Collision.LinkDependency(Collision.DEPENDENCY_SHAPE, Shape);
            Shape.LinkDependency(Circle.DEPENDENCY_COLLISION, Collision);

            _ghoster = new AsteroidGhoster(this, "Ghoster");
            _ghoster.LinkDependency(AsteroidGhoster.DEPENDENCY_BODY, Body);
            _ghoster.LinkDependency(AsteroidGhoster.DEPENDENCY_RENDER, Render);
            _ghoster.LinkDependency(AsteroidGhoster.DEPENDENCY_COLLISION, Collision);
            _ghoster.Initialize();
            _ghoster.SetOnCollide(OnCollide);
        }
示例#11
0
            public AabbNode(State stateref, string name)
                : base(stateref, name)
            {
                Body.Bounds = new Vector2(50 + RandomHelper.GetFloat(0, 30), 50 + RandomHelper.GetFloat(0, 30));

                Shape = new AABB(this, "AABB");
                Shape.LinkDependency(AABB.DEPENDENCY_BODY, Body);
                Shape.LinkDependency(AABB.DEPENDENCY_COLLISION, Collision);

                Collision.LinkDependency(Collision.DEPENDENCY_SHAPE, Shape);

                ImageRender.Scale = new Vector2(Body.Width, Body.Height);
                ImageRender.Layer = .5f;

                TextRender.Color = Color.White;
                TextRender.Font  = Assets.Font;
                TextRender.Text  = Name;
                TextRender.Layer = 1f;
            }
示例#12
0
            /// <summary>
            /// /Creates a new AABBEntity
            /// </summary>
            /// <param name="stateref"></param>
            /// <param name="name"></param>
            public CollisionTestNode(State stateref, string name)
                : base(stateref, name)
            {
                Body = new Body(this, "Body");

                Physics = new Physics(this, "Physics");
                Physics.LinkDependency(Physics.DEPENDENCY_BODY, Body);

                Collision = new Collision(this, "Collision");
                Collision.LinkDependency(Collision.DEPENDENCY_PHYSICS, Physics);

                ImageRender = new ImageRender(this, "Image", Assets.Pixel);
                ImageRender.LinkDependency(ImageRender.DEPENDENCY_BODY, Body);

                TextBody = new Body(this, "TextBody");

                TextRender = new TextRender(this, "Render");
                TextRender.LinkDependency(TextRender.DEPENDENCY_BODY, TextBody);
            }
示例#13
0
            public CircleNode(State stateref, string name)
                : base(stateref, name)
            {
                Shape        = new Circle(this, "Circle", 30);
                Shape.Offset = new Vector2((Shape as Circle).Radius);
                Shape.LinkDependency(Circle.DEPENDENCY_BODY, Body);
                Shape.LinkDependency(Circle.DEPENDENCY_COLLISION, Collision);

                Collision.LinkDependency(Collision.DEPENDENCY_SHAPE, Shape);

                Body.Bounds = new Vector2((Shape as Circle).Diameter);

                ImageRender.Scale = new Vector2(Body.Width, Body.Height);
                ImageRender.Layer = .5f;

                TextRender.Color = Color.White;
                TextRender.Font  = Assets.Font;
                TextRender.Text  = Name;
                TextRender.Layer = 1f;
            }
            /// <summary>
            /// /Creates a new AABBEntity
            /// </summary>
            /// <param name="stateref"></param>
            /// <param name="name"></param>
            public CollisionTestNode(State stateref, string name)
                : base(stateref, name)
            {
                Body = new Body(this, "Body");

                Physics = new Physics(this, "Physics");
                Physics.LinkDependency(Physics.DEPENDENCY_BODY, Body);

                Collision = new Collision(this, "Collision");
                Collision.LinkDependency(Collision.DEPENDENCY_PHYSICS, Physics);

                ImageRender = new ImageRender(this, "Image", Assets.Pixel);
                ImageRender.LinkDependency(ImageRender.DEPENDENCY_BODY, Body);

                TextBody = new Body(this, "TextBody");

                TextRender = new TextRender(this, "Render");
                TextRender.LinkDependency(TextRender.DEPENDENCY_BODY, TextBody);
            }
            public ResolutionTestNode(State stateref, string name)
                : base(stateref, name)
            {
                Body = new Body(this, "Body");
                Body.Bounds = new Vector2(70, 70);

                _physics = new Physics(this, "_physics");
                _physics.LinkDependency(Physics.DEPENDENCY_BODY, Body);
                _physics.Mass = 10f;
                _physics.Restitution = 1f;
                _physics.Drag = .95f;

                Shape = new AABB(this, "AABB");
                Shape.LinkDependency(AABB.DEPENDENCY_BODY, Body);

                Collision = new Collision(this, "Collision");
                Collision.LinkDependency(Collision.DEPENDENCY_SHAPE, Shape);
                Collision.LinkDependency(Collision.DEPENDENCY_PHYSICS, _physics);
                Collision.Initialize();

                _imageRender = new ImageRender(this, "Image", Assets.Pixel);
                _imageRender.LinkDependency(ImageRender.DEPENDENCY_BODY, Body);
                _imageRender.Scale = new Vector2(70, 70);
                _imageRender.Layer = .5f;

                _textBody = new Body(this, "_textBody");

                _textRender = new TextRender(this, "_textRender");
                _textRender.LinkDependency(TextRender.DEPENDENCY_BODY, _textBody);
                _textRender.Color = Color.White;
                _textRender.Font = Assets.Font;
                _textRender.Text = Name;
                _textRender.Layer = 1f;
            }
            public TestEntity(Node parent, string name)
                : base(parent, name)
            {
                Body = new Body(this, "Body");

                Physics = new Physics(this, "Physics");
                Physics.Mass = 10;
                Physics.LinkDependency(Physics.DEPENDENCY_BODY, Body);

                Collision = new Collision(this, "Collision");
                Collision.Group.AddMask(0);
                Collision.Pair.AddMask(0);
                Collision.ResolutionGroup.AddMask(0);
                Collision.LinkDependency(Collision.DEPENDENCY_PHYSICS, Physics);
            }