Esempio n. 1
0
        /// <summary>
        /// Create PhysicBreakable
        /// </summary>
        /// <param name="position">set position</param>
        /// <param name="setHitPoints">set HitPoints, object breaks if this value is lesser equal zero</param>
        /// <param name="setDiffuseTexture">set diffuseTexture</param>
        /// <param name="setCollisionTexture">set collisionTexture</param>
        public PhysicBreakable(Vector2 position, int setHitPoints, string setDiffuseTexture, string setCollisionTexture, bool WithCannon)
        {
            this.WithCannon = WithCannon;
            // set Hitpoints
            hitpoints = setHitPoints;

            // load collision and diffuse Texture
            _textureBodyXna = ScreenManager.Content.Load <Texture2D>(setCollisionTexture);
            _diffuseTexture = ScreenManager.Content.Load <Texture2D>(setDiffuseTexture);

            // initialize Effect
            _effectXna                = new BasicEffect(ScreenManager.Device);
            _effectXna.Texture        = _diffuseTexture;
            _effectXna.TextureEnabled = true;

            // Create the body an set the position
            CreateBody();
            body.Position = position;
            body.UserData = "enemyTower";

            if (WithCannon == true)
            {
                cannon = new Cannon(true);
                body.IgnoreCollisionWith(cannon.Body);

                cannon.Body.IgnoreCollisionWith(GameDemo1.vehicle.Body);
                cannon.Body.IgnoreCollisionWith(GameDemo1.vehicle.WheelBackBody);
                cannon.Body.IgnoreCollisionWith(GameDemo1.vehicle.WheelFrontBody);
                cannon.Body.IgnoreCollisionWith(GameDemo1.vehicle.cannon.Body);

                // TODO Cannon fix
                //_fix = new RevoluteJoint(cannon.Body, body, body.GetLocalVector(cannon.Body.Position), cannon.Body.GetLocalVector(body.Position));
                _fix                = new RevoluteJoint(cannon.Body, body, body.GetLocalVector(cannon.Body.Position), new Vector2(0f, -1f));
                _fix.MotorSpeed     = 1.0f;
                _fix.MaxMotorTorque = 1000f;
                _fix.MotorEnabled   = true;
                PhysicsGameScreen.World.AddJoint(_fix);

                enemyShot = new Shot(true);
                enemyShot.shotBody.UserData = "enemyShot";
                enemyShot.shotBody.Position = body.Position;
                //enemyShot.shotBody.IgnoreGravity = true;
                enemyShot.shotBody.IgnoreCollisionWith(cannon.Body);
                body.IgnoreCollisionWith(enemyShot.shotBody);
            }
        } // PhysicBreakable(position, diffuseTexture, collisionTexture)