private bool OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact) { //Collision With bouncable objects if (GameObjectData.GetType(fixtureB.UserData) == GameObjectType.BOUNDARY_SOLID || GameObjectData.GetType(fixtureB.UserData) == GameObjectType.SOLIDOBJECT) { if (_ballBody.LinearVelocity.Y <= 0) { _jumpForce.Y = _jumpImpulse; _ballBody.LinearVelocity = Vector2.Zero; _ballBody.ApplyLinearImpulse(_jumpForce, _ballBody.Position); } } //Collision with Spikes if (GameObjectData.GetType(fixtureB.UserData) == GameObjectType.SPIKE) { if (World.BodyList.Contains(fixtureB.Body) && !_ballExploded) World.RemoveBody(fixtureA.Body); _ballExploded = true; } //Collision with the end of hollo floor if (GameObjectData.GetType(fixtureB.UserData) == GameObjectType.BOUNDARY_HOLLO) { if (World.BodyList.Contains(fixtureB.Body)) World.RemoveBody(fixtureA.Body); _ballExploded = true; _explotionAnimationFrame = 16.1f; } //Collision with Level Completed Wall if (GameObjectData.GetType(fixtureB.UserData) == GameObjectType.LEVELCOMPLEWALL) { if (!_LevelCompleted) { LevelOverScreen obj = new LevelOverScreen(_scoreBoard.Distance, _scoreBoard.Diamonds, false, CurrentLevel.LevelName); obj.ShowMenuScreen += (_, __) => { ScreenManager.RemoveScreen(this); }; obj.NextLevel += (_, __) => { this.ExitScreen(); if (OnNextLevel != null) OnNextLevel(this._currentLevelIndex); this._LevelCompleted = true; }; ScreenManager.AddScreen(obj, null); } } return true; }
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { //Explosion movement if (_ballExploded) { _explotionAnimationFrame += 0.25f; //If Explosion animation over then show GameOverScreen if (_explotionAnimationFrame >= 16) { _explotionAnimationFrame = 16.1f; _ballExploded = false; LevelOverScreen obj = new LevelOverScreen(_scoreBoard.Distance, _scoreBoard.Diamonds, true, CurrentLevel.LevelName); obj.ShowMenuScreen += (_, __) => { _ballExploded = false; _explotionAnimationFrame = 0; this.ExitScreen(); }; obj.RestartLevel += (_, __) => { _explotionAnimationFrame = 0; _ballExploded = false; ScreenManager.Camera.Position = Vector2.Zero; LoadContent(); }; ScreenManager.AddScreen(obj, null); } } else { //Evey update increment the score if (this.IsActive) { _scoreBoard.Update(gameTime); //Move camera to force player to move ScreenManager.Camera.MoveCamera(Vector2.UnitX / 6); //Move the background _background.Move(ConvertUnits.ToDisplayUnits(Vector2.UnitX / 6)); //Move background clouds _clouds.Move(ConvertUnits.ToDisplayUnits(Vector2.UnitX / 4)); } } //If game over screen or any other screen is on top of current screen. if (this.IsActive) { //Move Both the front wall and left Spike strip according to camera position _spikeStripBody.Position = Camera2D.ConvertScreenToWorld( new Vector2(Assets.CELLSIZE_FARSEER / 2, ScreenManager.GraphicsDevice.Viewport.Height / 2)); _fontWall.Position = Camera2D.ConvertScreenToWorld( new Vector2(ScreenManager.GraphicsDevice.Viewport.Width, ScreenManager.GraphicsDevice.Viewport.Height / 2)); //Rotate the ball to make it look more dynamic. _ballBody.AngularVelocity = -2; } //Base Update base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); }