Beispiel #1
0
        public Bullet(string name, MathsLibrary.Vector3 pos, float rotation, Game Gam)
        {
            //create the bullets sprite object
            SpriteObject sprite = new SpriteObject();

            sprite.Load("..\\Images\\PNG\\Bullets\\bulletBeige_outline.png");
            sprite.Name = name + "_Sprite";
            sprite.SetPosition(sprite.Height - sprite.Height / 2, -10);
            sprite.SetRotate(90 * (float)(Math.PI / 180.0f));

            //set the sprite object as a child of the bullet
            AddChild(sprite);

            //set the bullet position and rotation
            SetPosition(pos);
            SetRotate(rotation);

            Name = name;
            Game = Gam;

            ///add and set up the components
            //add the physics move component
            AddComponent(new PhysicsBody(this));

            //set the move type of the physics move to non uniform (uses acceleration)
            (GetComponent(typeof(PhysicsBody)) as PhysicsBody).MoveType = PhysicsBody.PhysicsMoveType.NonUniform;

            //set the x velocity to 500
            (GetComponent(typeof(PhysicsBody)) as PhysicsBody).Velocity = new Vector2(500, 0);

            //set the x acceleration to 10
            (GetComponent(typeof(PhysicsBody)) as PhysicsBody).Acceleration = new Vector2(10, 0);

            //add a destroy timer with a 2 second timer
            AddComponent(new DestroyTimer(2f, this));

            //add a collider set for AABB
            AddComponent(new Collider(Collider.CollisionType.AABB, this));

            //set the bullet to destroy itself when it collides with another collider
            (GetComponent(typeof(Collider)) as Collider).DestroySelfOnCollision = true;
            (GetComponent(typeof(Collider)) as Collider).isTrigger = true;


            MakeSureCollisionComponentsAreLast();
        }
        public GameObject(string name, MathsLibrary.Vector3 pos, float rotation, string ImageAddress, Game Gam)
        {
            //create objects sprite object
            SpriteObject sprite = new SpriteObject();

            sprite.Load(ImageAddress);
            sprite.Name = name + "_Sprite";
            sprite.SetPosition(-sprite.Width / 2.0f, sprite.Height / 2.0f);
            sprite.SetRotate(-90 * (float)(Math.PI / 180.0f));

            //add the sprite object as a child
            AddChild(sprite);

            //set object position and rotaion
            SetPosition(pos);
            SetRotate(rotation);

            Name = name;
            game = Gam;
        }
 //move the object by the vector
 public void Translate(MathsLibrary.Vector3 vector3)
 {
     localTransform.Translate(vector3);
     UpdateTransform();
 }
 //set position with a vector3
 public void SetPosition(MathsLibrary.Vector3 pos)
 {
     localTransform.SetTranslation(pos.x, pos.y);
     UpdateTransform();
 }