public override void Draw(Camera camera)
 {
     if (IsAlive)
     {
         base.Draw(camera);
     }
 }
        public override void Draw(Camera camera)
        {
            if (alive)
            {

                Matrix[] transforms = new Matrix[Model.Bones.Count];
                Model.CopyAbsoluteBoneTransformsTo(transforms);

                // Draw each mesh in the model
                foreach (ModelMesh mesh in Model.Meshes)
                {
                    foreach (BasicEffect basicEffect in mesh.Effects)
                    {
                        basicEffect.EnableDefaultLighting();
                        basicEffect.EmissiveColor = col;
                        basicEffect.Projection = camera.Projection;
                        basicEffect.View = camera.View;

                        Matrix world = GetWorld(transforms[mesh.ParentBone.Index], camera);
                        basicEffect.World = world;
                    }
                    mesh.Draw();
                }
            }
        }
 // Returns a matrix for the asteroids current position
 protected override Matrix GetWorld(Matrix meshTransform, Camera camera)
 {
     Matrix translation = Matrix.CreateTranslation(position);
     Matrix rotation = Matrix.CreateFromYawPitchRoll(rotationAngle, rotationAngle, rotationAngle);
     Matrix scale = Matrix.CreateScale(2f);
     return meshTransform * scale * rotation * translation;
 }
        // Returns a matrix so the gun stays with the camera
        protected override Matrix GetWorld(Matrix meshTransform, Camera camera)
        {
            Matrix scale = Matrix.CreateScale(0.2f);
            Matrix rotation = Matrix.CreateRotationY(MathHelper.Pi);
            Matrix translation = Matrix.CreateTranslation(new Vector3(0f, -0.7f, -1.8f));

            return meshTransform * scale * rotation * translation * Matrix.Invert(camera.View);
        }
 public Spaceship(Model model,Camera camera)
     : base(model)
 {
     this.cam = camera;
     col = new Vector3(0, 0, 0);
     direction = cam.Direction;
     position = new Vector3(0,40,6);
     bs = new BoundingSphere(position, 1f);
 }
示例#6
0
        public Bullet(Model model, Vector3 currentPoint, Camera camera)
            : base(model)
        {
            Matrix directionRotation = Matrix.CreateFromYawPitchRoll(camera.Yaw, camera.Pitch, camera.Roll);
            this.Direction = Vector3.Transform(-Vector3.UnitZ, directionRotation);

            this.initialPosition = currentPoint;
            this.Position = this.initialPosition + new Vector3(0f, -0.25f, -1.0f);
            this.IsAlive = true;
        }
示例#7
0
 public Bombard(Model model, Terrain terrain, 
     Texture2D tex, Camera camera, HUD hud, float milliseconds, Effect effect, Texture2D smokeTexture, Audio audio)
 {
     this.texture = tex;
     this.model = model;
     this.camera = camera;
     this.hud = hud;
     this.terrain = terrain;
     this.milliseconds = milliseconds;
     this.effect = effect;
     this.smokeTexture = smokeTexture;
     this.audio = audio;
     Vector3 rand = RandomPosition();
 }
        public LaserBeam(Model model, Camera camera, float maxDistance = DEFAULT_MAX_DISTANCE,
            float movementSpeed = DEFAULT_MOVEMENT_SPEED)
            : base(model)
        {
            Matrix directionRotation = Matrix.CreateFromYawPitchRoll(camera.Yaw, camera.Pitch, camera.Roll);
            this.Direction = Vector3.Transform(-Vector3.UnitZ, directionRotation);

            this.initialPosition = camera.Position + new Vector3(0, -.05f, 0) + 0.45f * Direction;
            this.Position = this.initialPosition;

            this.maxDistance = maxDistance;
            this.movementSpeed = movementSpeed;

            this.IsAlive = true;
        }
        public Asteroid(Model model, Vector3 randomPoint, Camera camera)
            : base(model)
        {
            this.IsAlive = true;

            this.initialPosition = randomPoint;
            this.position = this.initialPosition;

            Random r = new Random();
            float randomZ = position.Y * asteroidSpeed * (float)r.NextDouble();
            this.direction = new Vector3(0, 0, randomZ);

            this.rotationRate = (float)(position.Y * .001);
            this.rotationAngle = 0.0f;
        }
示例#10
0
        public Fragment(Model model, Vector3 starting, Camera camera)
            : base(model)
        {
            this.IsAlive = true;

            this.initialPosition = starting;
            this.position = this.initialPosition;

            Random r = new Random();
            this.direction = new Vector3(asteroidSpeed * (float)r.NextDouble(),
                asteroidSpeed * (float)r.NextDouble(),
                asteroidSpeed*(float)r.NextDouble());

            this.rotationRate = (float)(position.Y*.001);
            this.rotationAngle = 0.0f;
        }
        // Returns a matrix to drop the asteroid.
        public Matrix GetWorld(Matrix meshTransform, Camera camera)
        {
            Console.WriteLine("Previous Milli: " + previousMilliseconds);
            Console.WriteLine("Direction: " + camera.direction);
            Console.WriteLine("Previous Direction: " + tempDirection);
            Console.WriteLine("Milli: " + milliseconds);
            NewAsteroid(camera);
            ShakeCamera(camera);

            string line = " X: " + location.X + " Z: " + location.Z + " Size: " + size;
            Console.WriteLine(line);
            Matrix scale = Matrix.CreateScale(size);
            Matrix rotation = Matrix.CreateRotationY(MathHelper.Pi);
            Matrix translation = Matrix.CreateTranslation(location.X+ iii--, i-= ((ii += .01f)*speed), location.Z - iii);

            return meshTransform * scale * rotation * translation;
        }
        protected void NewAsteroid(Camera camera)
        {
            if (i < -5)
            {
                location = RandomPosition();
                i = 300;
                ii = .01f;
                iii = 300;
                shake[0] = true;
                shake[1] = true;
                if (!test)
                {
                    tempPosition = camera.position;
                    tempDirection = camera.direction;
                    tempUp = camera.Up;
                    test = true;
                }
            }

            //camera.ApplyYawRotation(-.30f);
            //if ((milliseconds > (previousMilliseconds + 150)))
            //    camera.ApplyPitchRotation(.30f);
        }
示例#13
0
        //Create new asteroid when hits the ground
        protected void NewAsteroid(Camera camera)
        {
            //Console.WriteLine(intensity);
            if (i < -5)
            {

                location = RandomPosition();
                i = 195;

                isShaking = true;
                shake[0] = true;
                if (!test)
                {
                    tempPosition = camera.Position;
                    tempDirection = camera.Direction;
                    tempUp = camera.Up;

                    tempPitch = camera.Pitch;
                    tempRoll = camera.Roll;
                    tempYaw = camera.Yaw;

                    test = true;
                }
                if (intensity > .6f)
                {
                    hud.RedHealth();
                    ShakeCamera(camera);
                }

            }
        }
        private void ShakeCamera(Camera camera)
        {
            if (shake[0])
            {
                if ((milliseconds > (previousMilliseconds + 50)) && shake[shakeIndex])
                {
                    camera.ApplyYawRotation(.05f);
                    shake[shakeIndex] = false;
                    shakeIndex = 2;
                    shake[shakeIndex] = true;

                }
                if ((milliseconds > (previousMilliseconds + 75)) && shake[shakeIndex])
                {

                    camera.ApplyYawRotation(-.15f);
                    shake[shakeIndex] = false;
                    shakeIndex = 3;
                    shake[shakeIndex] = true;

                }
                if ((milliseconds > (previousMilliseconds + 100)) && shake[shakeIndex])
                {

                    camera.ApplyRollRotation(.05f);
                    shake[shakeIndex] = false;
                    shakeIndex = 4;
                    shake[shakeIndex] = true;

                }
                if ((milliseconds > (previousMilliseconds + 125)) && shake[shakeIndex])
                {
                    camera.ApplyRollRotation(-.05f);
                    shake[shakeIndex] = false;
                    shakeIndex = 5;
                    shake[shakeIndex] = true;

                }
                if ((milliseconds > (previousMilliseconds + 150)) && shake[shakeIndex])
                {
                    camera.ApplyYawRotation(.05f);
                    shake[shakeIndex] = false;
                    shakeIndex = 6;
                    shake[shakeIndex] = true;

                }
                if ((milliseconds > (previousMilliseconds + 175)) && shake[shakeIndex])
                {
                    camera.ApplyYawRotation(-.05f);
                    shake[shakeIndex] = false;
                    shakeIndex = 0;
                    test = true;

                }

                if ((milliseconds > (previousMilliseconds + 200) && test))
                {
                    camera.direction = tempDirection;
                    camera.position = tempPosition;
                    camera.up = tempUp;
                    test = false;
                    shake[0] = false;
                    shake[1] = false;

                }

            }
        }
 // Provide a way for subclasses to alter the world transformation of the model
 protected virtual Matrix GetWorld(Matrix meshTransform, Camera camera)
 {
     return Matrix.Identity * meshTransform;
 }
示例#16
0
 public void Update(Camera camera, Terrain terrain)
 {
     UpdateRollAngle();
     UpdateYawAngle();
     UpdatePosition(camera, terrain);
 }
示例#17
0
        private void UpdatePosition(Camera camera, Terrain terrain)
        {
            // Move in a straight line along the direction the alien is facing
            Position += Direction * movementSpeed;

            // Keep the alien moving on the terrain
            RestrictPositionToTerrainBoundaries(terrain);

            // Ensure the alien still appears on the terrain
            Position.Y = terrain.GetHeight(Position.X, Position.Z) + POSITION_ABOVE_GROUND;
        }
示例#18
0
 // Returns a matrix for the asteroids current position
 protected override Matrix GetWorld(Matrix meshTransform, Camera camera)
 {
     Matrix scale = Matrix.CreateScale(.05f);
     Matrix translation = Matrix.CreateTranslation(Position);
     return meshTransform * scale * translation;
 }
示例#19
0
 // Returns a matrix so the gun stays with the camera
 protected override Matrix GetWorld(Matrix meshTransform, Camera camera)
 {
     Matrix scale = Matrix.CreateScale(0.02f);
     Matrix rotation = Matrix.CreateRotationY(MathHelper.Pi);
     Matrix roll = Matrix.CreateRotationZ(cam.Roll);
     Matrix translation = Matrix.CreateTranslation(new Vector3(0f, -0.25f, -1.0f));
     worldHolder = meshTransform * scale * rotation * roll * translation * Matrix.Invert(camera.View);
     return worldHolder;
 }
        private void InitializeCamera()
        {
            Terrain terrain = InitializeTerrain();
            float midX = (float)(terrain.MinX + terrain.MaxX) / 2.0f;
            float midZ = (float)(terrain.MinZ + terrain.MaxZ) / 2.0f;
            Vector3 position = new Vector3(midX, 0, midZ);
            camera = new PlanetCamera(Game, Vector3.Forward, Vector3.Up, position, terrain);
            camera.DrawOrder = 2;

            Game.Components.Add(camera);
            Game.Services.AddService(typeof(Camera), camera);
        }
示例#21
0
        //Shake Camera
        private void ShakeCamera(Camera camera)
        {
            int[] millsecondOffsets = { 50, 75, 100, 125, 150, 175 };

            for (int i = 0; i < SHAKE_COUNT; i++)
            {
                int millisecondOffset = millsecondOffsets[i];
                UpdateShake(millisecondOffset);
            }

            if ((milliseconds > (previousMilliseconds + 200) && test))
            {
                audio.PlayCue("explosion");

                camera.Direction = tempDirection;
                camera.Position = tempPosition;
                camera.Up = tempUp;

                camera.Yaw = tempYaw;
                camera.Pitch = tempPitch;
                camera.Roll = tempRoll;

                test = false;
                isShaking = false;
                shake[0] = false;
            }
        }
        private void InitializeCamera()
        {
            Vector3 position = new Vector3(0, 40, 5);
            Vector3 direction = new Vector3(0, 0, -1);
            camera = new SpaceCamera(Game, direction, Vector3.Up, position);
            camera.DrawOrder = 2;

            Game.Components.Add(camera);
            Game.Services.AddService(typeof(Camera), camera);
            AsteroidField field = InitializeField();
        }