public void NewGame() { _points = 0; _currentObjective.Model = _landingPad; _currentObjective = _pads[1]; _currentObjective.Model = _landingPadGreen; _menu.MainMenuIndex = _menu.Screens.IndexOf(_pause); _menu.SelectedMenuScreen = _menu.MainMenuIndex; _lem.Dispose(); _lem = new Lem(); _lem.Init(new Vector3(0, 3.05f * Metre.Y + Lem.MinY, 0), _lemModel, _flame, _currentGravity, 100, _soundEffect, _audioListener); _running = true; }
private void Collision() { foreach (IBound bound in _lem.GetBounds()) { foreach (IBound b in _currentGravity.Ground.GetBounds()) { if (bound.Intersects(b)) { GameOver("Lander touched the ground"); break; } } } foreach (LandingPad pad in _pads) { foreach (IBound bound in pad.GetBounds()) { while (true) { int collisions = 0; foreach (IBound lemBound in _lem.GetBounds()) { if (bound.Intersects(lemBound)) { collisions++; } } if (collisions == 4) { if (_score == 0 && _lem.Fuel == 0) { GameOver("Out of fuel"); } if (_score > 0) { _storeAvailable = true; } if (pad == _currentObjective) { pad.Model = _landingPad; _currentObjective = _pads[(_pads.IndexOf(pad) + 1) % _pads.Count]; _currentObjective.Model = _landingPadGreen; var diff = pad.Position - _lem.Position; diff.Y = 0; _score += 100 - (int)(((diff.Length()) / (7.5 * Metre.Y)) * 100f); _points += 1; } if (_lem.Velocity.Y < 0) { _lem.Position = new Vector3(_lem.Position.X, bound.Max().Y + Lem.MinY + 2.15f, _lem.Position.Z); } if (_lem.Velocity.Length() > 10) { GameOver("Landed too fast"); } _lem.Velocity = Vector3.Zero; break; } if (collisions == 0) { break; } if (Math.Abs(_lem.RotationX) == 0.00 && Math.Abs(_lem.RotationZ) == 0.0) { GameOver(string.Format(@"Only {0} feet on landing pad", collisions)); break; } if (Math.Abs(_lem.RotationX) > MathHelper.ToRadians(5) || Math.Abs(_lem.RotationZ) > MathHelper.ToRadians(5) && _lem.Velocity.Y < 0) { GameOver("Landing angle too steep"); break; } _lem.RotationX *= .98f; _lem.RotationZ *= .98f; if (Math.Abs(_lem.RotationX) < 0.01 && Math.Abs(_lem.RotationZ) < 0.01) { _lem.RotationX = 0; _lem.RotationZ = 0; } } } } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { _mainView = GraphicsDevice.Viewport; _bottomView = _mainView; _bottomView.Height = _mainView.Height / 3; _bottomView.Width = _bottomView.Height; _bottomView.X = 2; _bottomView.Y = 2; _spriteBatch = new SpriteBatch(GraphicsDevice); _grassTexture = Content.Load <Texture2D>("Images\\grass"); _fuelBlack = Content.Load <Texture2D>("Images\\fuelBlack"); _fuelGreen = Content.Load <Texture2D>("Images\\fuelGreen"); _fuelRed = Content.Load <Texture2D>("Images\\fuelRed"); _lemModel = Content.Load <Model>("models\\LEM\\LEM"); _menuMove = Content.Load <SoundEffect>("Sounds\\menuMove"); _menuSelect = Content.Load <SoundEffect>("Sounds\\menuSelect"); _scoreFont = Content.Load <SpriteFont>("Fonts\\Mono"); _menuBack = Content.Load <SoundEffect>("Sounds\\menuBack"); _flame = Content.Load <Model>("models\\jet\\jet"); _landingPad = Content.Load <Model>("models\\landingPad\\landingPad"); _landingPadGreen = Content.Load <Model>("models\\landingPad\\landingPadGreen"); var hudTexture = Content.Load <Texture2D>("Images\\hud"); _hud = new HeadsUpDisplay(_scoreFont, hudTexture, _fuelBlack, _fuelRed, _fuelGreen); _menu.Initialize(GraphicsDevice.Viewport, _scoreFont, _menuMove, _menuSelect, _menuBack); _soundEffect = Content.Load <SoundEffect>("Sounds\\engine"); var ground = new Ground(); ground.Init(_textureEffect, _textureEffectWvp, _textureEffectImage, _grassTexture, _groundVertices); //Equitorial Surface Body as listed on Wikipedia _gravity.Add("sun", new Body(new Vector3(0, -274.0f, 0), new Vector3(0.0f, 0.0f, 0.0f), ground)); _gravity.Add("mercury", new Body(new Vector3(0, -3.7f, 0), new Vector3(-.1f, 0.0f, .001f), ground)); _gravity.Add("venus", new Body(new Vector3(0, -8.87f, 0), new Vector3(0.1f, 0.0f, 0.15f), ground)); _gravity.Add("earth", new Body(new Vector3(0, -9.780327f, 0), new Vector3(.25f, 0.0f, 0.0f), ground)); _gravity.Add("moon", new Body(new Vector3(0, -1.622f, 0), new Vector3(0.0f, 0.0f, 0.0f), ground)); _gravity.Add("mars", new Body(new Vector3(0, -3.711f, 0), new Vector3(0.0f, 0.0f, 0.0f), ground)); _gravity.Add("jupiter", new Body(new Vector3(0, -24.79f, 0), new Vector3(0.0f, 0.0f, 0.0f), ground)); _gravity.Add("saturn", new Body(new Vector3(0, -10.44f, 0), new Vector3(0.0f, 0.0f, 0.0f), ground)); _gravity.Add("uranus", new Body(new Vector3(0, -8.69f, 0), new Vector3(0.0f, 0.0f, 0.0f), ground)); _gravity.Add("neptune", new Body(new Vector3(0, -11.15f, 0), new Vector3(0.0f, 0.0f, 0.0f), ground)); _gravity.Add("pluto", new Body(new Vector3(0, -0.658f, 0), new Vector3(0.0f, 0.0f, 0.0f), ground)); _currentGravity = _gravity["moon"]; InitMenu(); _lem.Init(new Vector3(0, 3.05f * Metre.Y + Lem.MinY, 0), _lemModel, _flame, _currentGravity, 100, _soundEffect, _audioListener); var pad = new LandingPad(); pad.Init(new Vector3(0, 3, 0) * Metre, _landingPad); _pads.Add(pad); pad = new LandingPad(); pad.Init(new Vector3(15, 3, -30) * Metre, _landingPadGreen); _pads.Add(pad); _currentObjective = pad; pad = new LandingPad(); pad.Init(new Vector3(45, 3, -60) * Metre, _landingPad); _pads.Add(pad); pad = new LandingPad(); pad.Init(new Vector3(90, 3, -40) * Metre, _landingPad); _pads.Add(pad); pad = new LandingPad(); pad.Init(new Vector3(60, 3, 50) * Metre, _landingPad); _pads.Add(pad); pad = new LandingPad(); pad.Init(new Vector3(30, 3, 40) * Metre, _landingPad); _pads.Add(pad); pad = new LandingPad(); pad.Init(new Vector3(0, 3, 30) * Metre, _landingPad); _pads.Add(pad); }