예제 #1
0
 void Respawn()
 {
     position = game.Check_Furthest_Spawn(position);
     radar.updateLocation();
     Health = 100;
     aiMode = AImode.WANDER;
     radar.EnemyPosition = null;
     alive = true;
     if (!AIControlled)
     {
         idleTimer = 0f;
     }
 }
예제 #2
0
        public Tank(Game1 game, Model m, Vector3 position, Keys[] Controls, int id, Model Shot, bool ai, PlayerIndex pad, float initialYaw)
        {
            this.game      = game;
            myModel        = m;
            this.shotModel = Shot;
            this.id        = id;
            world          = Matrix.Identity;

            this.Controls = Controls;
            this.pad      = pad;

            dirDefault       = new Vector3(0f, 0f, -1f); //default direction
            yaw              = initialYaw;
            rotation         = Matrix.CreateFromYawPitchRoll(yaw, 0f, 0f);
            defaultDirection = Vector3.Transform(dirDefault, rotation);
            direction        = Vector3.Transform(dirDefault, rotation);
            this.position    = position;

            terrainNormal = game.map.getNormal(position.X, position.Z); //current position's terrain normal
            right         = Vector3.Cross(direction, terrainNormal);    //tank's Right
            trueDirection = Vector3.Cross(right, terrainNormal);        //Direction which the tank faces when he is in the terrain
            trueDirection.Normalize();

            scale             = 0.005f; //Model's SCalling
            speed             = 5f;     //Tank's default Speed
            velocity          = Vector3.Zero;
            blockingDirection = Vector3.Zero;

            moving = false;

            #region Bones Creation
            //Bones Variables Creation
            turretBone     = myModel.Bones["turret_geo"];
            cannonBone     = myModel.Bones["canon_geo"];
            rightWheel     = myModel.Bones["r_front_wheel_geo"];
            leftWheel      = myModel.Bones["l_front_wheel_geo"];
            rightBackWheel = myModel.Bones["r_back_wheel_geo"];
            leftBackWheel  = myModel.Bones["l_back_wheel_geo"];
            hatch          = myModel.Bones["hatch_geo"];
            #endregion

            #region Bones Transforms
            //bones Transforms
            turretTransform         = turretBone.Transform;
            cannonTransform         = cannonBone.Transform;
            rightWheelTransform     = rightWheel.Transform;
            leftWheelTransform      = leftWheel.Transform;
            rightBackWheelTransform = rightBackWheel.Transform;
            leftBackWheelTransform  = leftBackWheel.Transform;
            hatchTransform          = hatch.Transform;
            #endregion

            boneTransform = new Matrix[myModel.Bones.Count];
            rotacao       = Matrix.Identity;

            #region bone Angles
            //Bone Angles
            turretAngle         = 0f;
            cannonAngle         = 0f;
            rightWheelAngle     = 0f;
            leftWheelAngle      = 0f;
            rightBackWheelAngle = 0f;
            leftBackWheelAngle  = 0f;
            hatchAngle          = 0f;
            #endregion

            turretRotation  = Matrix.CreateFromYawPitchRoll(turretAngle, 0f, 0f); //turret's rotation matrix
            turretDirection = Vector3.Transform(dirDefault, turretRotation);      //turret's direction for third person camera purposes

            //COLISION
            collider = new Sphere(position, 2f);   //Radius is fine tuned
            game.colliders.Add(this as ICollider); //add the tank to the collider list
            Tankcoliding = false;
            Hit          = false;
            hittime      = 0;

            reloading   = false;
            reloadTimer = 0;

            capabilities     = GamePad.GetCapabilities(pad); //controller capabilities check
            gamepad          = GamePad.GetState(pad);        //controller
            kbPreviousState  = Keyboard.GetState();          //THIS SAVES THE PREVIOUS KEYBOARD STATE SO THAT SINGLE BUTTON PRESSES ARE POSSIBLE
            padPreviousState = gamepad;                      //THIS SAVES THE PREVIOUS GAMEPAD STATE SO THAT SINGLE BUTTON PRESSES ARE POSSIBLE
            keyboard         = true;

            dustEmitters = new DustLineEmitter[4];
            Color dustColor = Color.SandyBrown;
            dustEmitters[0] = new DustLineEmitter(game, boneTransform[rightWheel.Index].Translation, rotation.Left, 0.8f, Vector3.Forward, 10, dustColor, Vector3.Cross(rotation.Backward, rotation.Up));
            dustEmitters[1] = new DustLineEmitter(game, boneTransform[leftWheel.Index].Translation, rotation.Right, 0.8f, Vector3.Forward, 10, dustColor, Vector3.Cross(rotation.Backward, rotation.Up));
            dustEmitters[2] = new DustLineEmitter(game, boneTransform[rightBackWheel.Index].Translation, rotation.Right, 1f, Vector3.Forward, 10, dustColor, Vector3.Cross(rotation.Backward, rotation.Up));
            dustEmitters[3] = new DustLineEmitter(game, boneTransform[leftBackWheel.Index].Translation, rotation.Left, 1f, Vector3.Forward, 10, dustColor, Vector3.Cross(rotation.Backward, rotation.Up));

            AIControlled   = ai;
            idleTimer      = 0;
            radar          = new BoidRadar(game, this);
            IdealDirection = direction;
            aiMode         = AImode.WANDER;

            Health = 100;
            alive  = true;

            //Lights
            #region Lighting
            foreach (ModelMesh mesh in myModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.LightingEnabled           = true;
                    effect.DirectionalLight0.Enabled = true;
                    effect.DiffuseColor      = game.LightManager.diffuseColor;                                //kd
                    effect.SpecularColor     = game.LightManager.specularColor;                               //Specular Light  //ks
                    effect.SpecularPower     = game.LightManager.specularPower;                               //Power of Specular Light //s
                    effect.AmbientLightColor = game.LightManager.ambientLightColor;                           //Ia
                    effect.DirectionalLight0.DiffuseColor  = game.LightManager.directionalLightDiffuseColor;  //Directional Light's Color //Id
                    effect.DirectionalLight0.Direction     = game.LightManager.directionalLightDirection;     //Directional light's Direction
                    effect.DirectionalLight0.SpecularColor = game.LightManager.directionalLightSpecularColor; //Is
                }
            }
            #endregion
        }