Exemple #1
0
 public Terrain(Game game, string heightmap, string[] textures, Camera3D camera)
     : base(game)
 {
     if (textures.Length < 4)
         throw new ArgumentException("Need four terrain textures.");
     this.asset = heightmap;
     this.textureAssets = textures;
     this.Camera = camera;
 }
Exemple #2
0
        public GameWorld3D(Game game)
            : base(game)
        {
            _owner = game;
            _gameObjects = new List<GameObject3D>();
            Camera = new Camera3D(game.GraphicsDevice.Viewport.AspectRatio);
            Camera.Position = new Vector3(1, 1, 10);

            _debugEffect = new BasicEffect(game.GraphicsDevice);

            DrawWorld = true;

            DebugMode = false;

            ForceUnload = false;
        }
Exemple #3
0
 public float Rotate(float speed, KeyboardState keyboardState, Camera3D Camera)
 {
     //we cannot turn while not moving
     if (speed > 0)
     {
         if (keyboardState.IsKeyDown(Keys.Left))
         {
             rotation += 0.96f;
             //camera rotation 630.0f equals 360 degrees of rotation
             Camera.Rotate(-1.68f, 0.0f);
         }
         if (keyboardState.IsKeyDown(Keys.Right))
         {
             rotation -= 0.96f;
             //camera rotation 630.0f equals 360 degrees of rotation
             Camera.Rotate(1.68f, 0.0f);
         }
     }
     return rotation;
 }
Exemple #4
0
        public void update(GameTime gametime, KeyboardState keyboardState, Camera3D Camera)
        {
            //set distance to object, higher speed means a slightly further off camera
            float CameraDistance = 6.0f + speed * 15;

            //calculates x and z distance to the object and places the camera directly behind the model
            Vector3 CameraRelativePosition = new Vector3(CameraDistance * (float)Math.Sin(MathHelper.ToRadians(RotateY + adjustCamera)), 2.7f, CameraDistance * (float)Math.Cos(MathHelper.ToRadians(RotateY + adjustCamera)));
            Camera.Position = Position + CameraRelativePosition;

            //calculate speed
            speed = Physics.update(speed, keyboardState, gametime);

            //if on obstacle has been hit, decrease speed
            speed = onObstacleHit(speed, gametime);

            //check if powerup is available and use boost
            speed = useSpeedPower(speed, gametime);

            //calculate rotation of object and camera
            RotateY = Physics.Rotate(speed, keyboardState, Camera);

            //rotate front wheels horizontally
            steerFrontWheels(keyboardState);

            //rotationspeed of the four wheels
            rotatiesnelheid = speed * 0.5f;
            //set rotation of specific mesh
            SetMeshRotationZ("voorwiellinks", rotatie += rotatiesnelheid);
            SetMeshRotationZ("voorwielrechts", rotatie);
            SetMeshRotationZ("achterwiellinks", rotatie + 180.0f);
            SetMeshRotationZ("achterwielrechts", rotatie + 180.0f);

            benzineInTank = benzine + z;
            if(benzineInTank < 0)
            {
                if (speed > 0)
                {
                    speed -= 0.005f;
                }
                else
                {
                    speed = 0;
                }
            }

            //x,z position relative to rotation
            z -= speed * (float)Math.Cos(MathHelper.ToRadians(RotateY));
            x -= speed * (float)Math.Sin(MathHelper.ToRadians(RotateY));

            //roadbounds
            if (x > 5)
            {
                x = 5;
                speed *= 0.999f;
            }else if( x < -5)
            {
                x = -5;
                speed *= 0.999f;
            }

            if (speed > 0)
            {
                AudioFactory.PlayOnceChangePitch("speed2", speed * 0.5f);
            }

            //updates the position with the new x and z values
            Position = new Vector3(x, y, z);
        }