private IInteraction BuildInteraction(StaticItem thisGameItem, StaticItem thatGameItem) { IInteraction result; var items = new[] { thisGameItem, thatGameItem }; var staticItem = items.FirstOrDefault(item => !(item is MovingItem)); if (staticItem != null) { var otherItem = items.Single(item => item != staticItem); var movingItem = otherItem as MovingItem; if (otherItem is MovingItem) result = new InteractionWithStaticItems(this, staticItem, movingItem); else result = new StaticItemAndStaticItemInteraction(this, staticItem, otherItem); } else { result = new InteractionWithMovingItems(this, (MovingItem) thisGameItem, (MovingItem) thatGameItem); } //var shot = items.OfType<Shot>().FirstOrDefault(); //if (shot != null) // { // var otherItem = items.Single(item => item != shot); // var movingItem = otherItem as MovingItem; // result = movingItem != null // ? (IInteraction) new ShotAndMovingItemInteraction(this, shot, movingItem) // : new ShotAndStaticItemInteraction(this, shot, otherItem); // } //else // { // var movingItem = items.OfType<MovingItem>().FirstOrDefault(); // if (movingItem != null) // { // var otherItem = items.Single(item => item != movingItem); // var otherMovingItem = otherItem as MovingItem; // result = otherMovingItem != null // ? (IInteraction) new MovingItemAndMovingItemInteraction(this, movingItem, otherMovingItem) // : new MovingItemAndStaticItemInteraction(this, movingItem, otherItem); // } // else // result = new StaticItemAndStaticItemInteraction(this, thisGameItem, thatGameItem); // } return result; }
public void MoveUpALevel() { if (!this.Player.IsAlive()) return; int currentWorldAreaId = this._wl.GetWorldAreaIdForTilePos(this.Player.TilePosition); int maxId = this._wl.GetMaximumWorldAreaId(); var newState = Enumerable.Range(currentWorldAreaId + 1, maxId - currentWorldAreaId).Select(i => this._wl.GetStartStateForWorldAreaId(i)).FirstOrDefault(startState => startState != null); if (newState == null) return; var crystals = this.GameObjects.DistinctItemsOfType<Crystal>().Where(c => this._wl.GetWorldAreaIdForTilePos(c.TilePosition) == currentWorldAreaId); foreach (var c in crystals) { var i = new InteractionWithStaticItems(this, c, this.Player); i.Collide(); } this.Player.Reset(newState.PlayerPosition.ToPosition(), newState.PlayerEnergy); this.GameObjects.UpdatePosition(this.Player); var boulder = this.GameObjects.DistinctItemsOfType<Boulder>().FirstOrDefault(); if (boulder != null) { TilePos? tp = null; for (int i = 0; i < 16; i++) { int x = (i % 2 == 0) ? 7 - (i / 2) : 8 + ((i - 1) / 2); var potentialPosition = new TilePos(x, newState.PlayerPosition.Y); if (!IsStaticItemOnTile(potentialPosition)) { tp = potentialPosition; break; } } if (tp.HasValue) { boulder.Reset(tp.Value.ToPosition()); this.GameObjects.UpdatePosition(boulder); } } Point roomStart = GetContainingRoom(this.Player.Position).Location; this.Game.SpriteBatch.WindowOffset = new Vector2(roomStart.X, roomStart.Y); }