private void World_Updating(object sender, WorldUpdatingArgs e) { try { _updateManager.Update_MainThread(e.ElapsedTime); _brushStrokes.Tick(); _backImageManager.Update(); _cameraHelper.Update(); _miniMap.Update(); _progressBars.Update(); Point3D position = _player.Ship.PositionWorld; if (_stations != null) { #region Space Stations SpaceStation2D currentlyOverStation = null; foreach (SpaceStation2D station in _stations) { // See if the ship is over the station Point3D stationPosition = station.PositionWorld; stationPosition.Z = 0; if ((stationPosition - position).LengthSquared < station.Radius * station.Radius) { currentlyOverStation = station; } } // Store the station that the ship is over if (currentlyOverStation == null) { statusMessage.Content = ""; } else { statusMessage.Content = "Press space to enter station"; //TODO: Play a sound if this is the first time they entered the station's range } _currentlyOverStation = currentlyOverStation; #endregion } #region Autosave if (DateTime.UtcNow > _nextAutoSave) { SaveSession(true, true); _nextAutoSave = GetNextAutoSaveTime(); } #endregion } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
private void CreateSpaceStations(SpaceStation2DDNA[] dna) { #region clear the old if (_stations != null) { foreach (var station in _stations) { _map.RemoveItem(station); } } _currentlyOverStation = null; _stations = null; #endregion if (dna == null || dna.Length == 0) { return; } #region get normalized positions var positionStats = dna. Select((o, i) => { Vector vect = o.Position.ToVector2D(); return new { Index = i, Pos = o.Position, Pos2D = vect, LenSqr = vect.LengthSquared, }; }). OrderByDescending(o => o.LenSqr). ToArray(); // Take the largest distance, scale to this double xyCoord = _boundryMax.X * STATION_BOUNDRY_PERCENT; xyCoord *= StaticRandom.NextDouble(.75, 1d); // don't always want to run the farthest to the edge double multiplier = 1d; if (!positionStats[0].LenSqr.IsNearZero()) { multiplier = xyCoord / Math.Sqrt(positionStats[0].LenSqr); } // Overwrite the positions foreach (var stat in positionStats) { dna[stat.Index].Position = (stat.Pos2D * multiplier).ToPoint3D(stat.Pos.Z); } #endregion List<SpaceStation2D> stations = new List<SpaceStation2D>(); foreach (SpaceStation2DDNA stationDNA in dna) { Inventory[] inventory = null; if (stationDNA.PlayerInventory != null) { inventory = stationDNA.PlayerInventory. Select(o => o.ToInventory()). ToArray(); } stations.Add(CreateSpaceStations_Build(stationDNA.Position, stationDNA.Flag, stationDNA.PurchasedVolume, inventory)); } _stations = stations.ToArray(); }
private SpaceStation2D CreateSpaceStations_Build(Point3D position, FlagProps flag = null, int? purchasedVolume = null, Inventory[] playerInventory = null) { Vector3D axis = new Vector3D(0, 0, 1); Quaternion rotation = Math3D.GetRotation(axis, Math3D.GetRandomVector_Cone(axis, 30)); SpaceStation2D retVal = new SpaceStation2D(position, _world, _material_SpaceStation, rotation, flag); retVal.SpinDegreesPerSecond = Math1D.GetNearZeroValue(.33, 1.1); retVal.RandomizeInventory(true); if (purchasedVolume != null && purchasedVolume.Value > retVal.PurchasedVolume) { retVal.PurchasedVolume = purchasedVolume.Value; } if (playerInventory != null) { retVal.PlayerInventory.AddRange(playerInventory); } _map.AddItem(retVal); return retVal; }
private void CreateSpaceStations() { const double ZMIN = -20; const double ZMAX = -12; double xyCoord = _boundryMax.X * STATION_BOUNDRY_PERCENT; double zCoord = StaticRandom.NextDouble(ZMIN, ZMAX); double minDistanceBetweenStationsSquared = 200d * 200d; #region clear the old if (_stations != null) { foreach (var station in _stations) { _map.RemoveItem(station); } } _currentlyOverStation = null; _stations = null; #endregion List<SpaceStation2D> stations = new List<SpaceStation2D>(); #region Home Station // Make one right next to the player at startup Point3D homeLocation = Math3D.GetRandomVector_Circular_Shell(12).ToPoint(); stations.Add(CreateSpaceStations_Build(new Point3D(homeLocation.X, homeLocation.Y, zCoord))); #endregion // Make a few more for (int cntr = 0; cntr < 4; cntr++) { // Come up with a position that isn't too close to any other station Vector3D position = new Vector3D(); while (true) { #region Figure out position position = Math3D.GetRandomVector_Circular(xyCoord); position.Z = StaticRandom.NextDouble(ZMIN, ZMAX); // See if this is too close to an existing station bool isTooClose = false; foreach (SpaceStation station in stations) { Vector3D offset = position - station.PositionWorld.ToVector(); if (offset.LengthSquared < minDistanceBetweenStationsSquared) { isTooClose = true; break; } } if (!isTooClose) { break; } #endregion } stations.Add(CreateSpaceStations_Build(position.ToPoint())); } _stations = stations.ToArray(); }
private void ShowSpaceDock(SpaceStation2D station) { PauseWorld(); if (_spaceDockPanel == null) { _spaceDockPanel = new SpaceDockPanel(_editorOptions, _itemOptions, _map, _material_Ship, _shipExtra); _spaceDockPanel.LaunchShip += SpaceDockPanel_LaunchShip; _spaceDockPanel.EditShip += SpaceDockPanel_EditShip; } _spaceDockPanel.ShipDocking(_player, station, _world); statusMessage.Content = ""; panelContainer.Child = _spaceDockPanel; panelContainer.Visibility = Visibility.Visible; }
private void btnLaunch_Click(object sender, RoutedEventArgs e) { try { if (this.LaunchShip == null) { MessageBox.Show("There is no event listener for the launch button", "Launch Button", MessageBoxButton.OK, MessageBoxImage.Error); return; } //TODO: Eject nearby items into space instead of taking them while (pnlNearbyItems.Children.Count > 0) { InventoryEntry item = (InventoryEntry)pnlNearbyItems.Children[0]; RemoveFrom_Cargo_Hangar_Neaby(item); StoreIn_Mineral_Part_Ship(item.Inventory); } // This panel is about to close, so drop references _player.CreditsChanged -= new EventHandler(Player_CreditsChanged); _player.ShipChanged -= new EventHandler<ShipChangedArgs>(Player_ShipChanged); _player = null; _station = null; this.LaunchShip(this, new EventArgs()); } catch (Exception ex) { MessageBox.Show(ex.ToString(), TITLE, MessageBoxButton.OK, MessageBoxImage.Error); } }
//TODO: Take any other objects that are near the player at the time of docking public void ShipDocking(Player player, SpaceStation2D station, World world) { _player = player; _station = station; _world = world; //NOTE: Can't use pnlFlag.ActualWidth, because it could be zero when this panel is newly instantiated pnlFlag.Content = new FlagVisual(pnlFlag.Width, pnlFlag.Height, _station.Flag.FlagProps); // can't just store it directly, it's the wrong size // Stop the ship //TODO: Stop any other objects that were passed in if (_player.Ship != null) { _player.Ship.PhysicsBody.Velocity = new Vector3D(0, 0, 0); _player.Ship.PhysicsBody.AngularVelocity = new Vector3D(0, 0, 0); } _player.CreditsChanged += new EventHandler(Player_CreditsChanged); Player_CreditsChanged(this, new EventArgs()); _player.ShipChanged += new EventHandler<ShipChangedArgs>(Player_ShipChanged); Player_ShipChanged(this, new ShipChangedArgs(null, _player.Ship)); OnHangarChanged(); ShowStationMinerals(); ShowStationParts(); ShowStationShips(world); ShowShipCargo(); //ShowNearbyItems(); ShowHangar(); GenerateRefillButtons(); }
private static Visual3D GetStationBlip(SpaceStation2D station) { const double SIZE = 35; FrameworkElement flag = station.Flag; BitmapSource flagImage = UtilityWPF.RenderControl(flag, Convert.ToInt32(SpaceStation2D.FLAGWIDTH), Convert.ToInt32(SpaceStation2D.FLAGHEIGHT), false); // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(new DiffuseMaterial(Brushes.White)); materials.Children.Add(new DiffuseMaterial(new ImageBrush(flagImage))); //materials.Children.Add(new SpecularMaterial(Brushes.White, 20d)); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; double avg = (SpaceStation2D.FLAGWIDTH + SpaceStation2D.FLAGHEIGHT) / 2; double width = SpaceStation2D.FLAGWIDTH * (SIZE / avg); double height = SpaceStation2D.FLAGHEIGHT * (SIZE / avg); Point max = new Point(width / 2, height / 2); Point min = new Point(-max.X, -max.Y); geometry.Geometry = UtilityWPF.GetSquare2D(min, max); // The flag was upside down geometry.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 180)); // Model Visual ModelVisual3D retVal = new ModelVisual3D(); retVal.Content = geometry; // Exit Function return retVal; }