コード例 #1
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;
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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;
            }
コード例 #5
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);
            }
コード例 #6
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);
            }