예제 #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 AsteroidGhost(Node parent, string name)
                : base(parent, name)
            {
                Body = new Body(this, "Body");

                Render = new ImageRender(this, "Render");
                Render.SetTexture(GetRoot <State>().GetService <AssetCollector>().GetAsset <Texture2D>("circle"));
                Render.LinkDependency(ImageRender.DEPENDENCY_BODY, Body);

                Collision = new Collision(this, "Collision");
                Collision.Pair.AddMask(0);
                Collision.Pair.AddMask(1);
                Collision.Pair.AddMask(2);
                Collision.Group.AddMask(3);
            }
예제 #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 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);
        }