public CameraHelper(Player player, PerspectiveCamera camera, PerspectiveCamera cameraMap, MinimapHelper blips) { _player = player; _camera = camera; _cameraMap = cameraMap; _blips = blips; }
public EditShipTransfer(Player player, SpaceDockPanel spaceDock, Editor editor, EditorOptions editorOptions, World world, int material_Ship, Map map, ShipExtraArgs shipExtra) { _player = player; _spaceDock = spaceDock; _editor = editor; _editorOptions = editorOptions; _world = world; _material_Ship = material_Ship; _map = map; _shipExtra = shipExtra; }
public BackImageManager(Canvas canvas, Player player) { _canvas = canvas; _player = player; _canvas.SizeChanged += Canvas_SizeChanged; }
private static void SwapShip(Player player, ShipPlayer newShip) { Point3D position = player.Ship.PositionWorld; player.Ship = null; newShip.PhysicsBody.Position = position; newShip.PhysicsBody.Velocity = new Vector3D(0, 0, 0); newShip.PhysicsBody.AngularVelocity = new Vector3D(0, 0, 0); player.Ship = newShip; }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { _itemOptions = new ItemOptions(); _itemOptions.Thruster_StrengthRatio *= 4.5; _itemOptions.FuelToThrustRatio *= .03; _itemOptions.Projectile_Color = UtilityWPF.ColorFromHex("FFE330"); // using bee/wasp colors, because white looks too much like the stars _progressBars = new ShipProgressBarManager(pnlProgressBars); _progressBars.Foreground = new SolidColorBrush(UtilityWPF.ColorFromHex("BBB")); #region Init World // Set the size of the world to something a bit random (gets boring when it's always the same size) double halfSize = 325 + StaticRandom.Next(500); //halfSize *= 2; _boundryMin = new Point3D(-halfSize, -halfSize, -35); _boundryMax = new Point3D(halfSize, halfSize, 35); _world = new World(); _world.Updating += new EventHandler<WorldUpdatingArgs>(World_Updating); List<Point3D[]> innerLines, outerLines; _world.SetCollisionBoundry(out innerLines, out outerLines, _boundryMin, _boundryMax); // Draw the lines _boundryLines = new ScreenSpaceLines3D(true); _boundryLines.Thickness = 1d; _boundryLines.Color = WorldColors.BoundryLines; _viewport.Children.Add(_boundryLines); foreach (Point3D[] line in innerLines) { _boundryLines.AddLine(line[0], line[1]); } #endregion #region Materials _materialManager = new MaterialManager(_world); // Ship Game.Newt.v2.NewtonDynamics.Material material = new Game.Newt.v2.NewtonDynamics.Material(); _material_Ship = _materialManager.AddMaterial(material); // Exploding Ship material = new Game.Newt.v2.NewtonDynamics.Material(); material.IsCollidable = false; _material_ExplodingShip = _materialManager.AddMaterial(material); // Space Station (force field) material = new Game.Newt.v2.NewtonDynamics.Material(); material.IsCollidable = false; //material.Elasticity = .99d; // uncomment these if it should be collidable (it's an ellipse, and briefly shows a force field) //material.StaticFriction = .02d; //material.KineticFriction = .01d; _material_SpaceStation = _materialManager.AddMaterial(material); //_materialManager.RegisterCollisionEvent(_material_SpaceStation, _material_Asteroid, Collision_SpaceStation); //_materialManager.RegisterCollisionEvent(_material_SpaceStation, _material_Mineral, Collision_SpaceStation); // Mineral material = new Game.Newt.v2.NewtonDynamics.Material(); material.Elasticity = .5d; material.StaticFriction = .9d; material.KineticFriction = .4d; _material_Mineral = _materialManager.AddMaterial(material); // Asteroid material = new Game.Newt.v2.NewtonDynamics.Material(); material.Elasticity = .25d; material.StaticFriction = .9d; material.KineticFriction = .75d; _material_Asteroid = _materialManager.AddMaterial(material); // Projectile material = new Game.Newt.v2.NewtonDynamics.Material(); material.Elasticity = .95d; _material_Projectile = _materialManager.AddMaterial(material); // Swarmbot material = new Game.Newt.v2.NewtonDynamics.Material(); material.Elasticity = .95d; _material_SwarmBot = _materialManager.AddMaterial(material); // Collisions _materialManager.RegisterCollisionEvent(_material_Ship, _material_Mineral, Collision_ShipMineral); _materialManager.RegisterCollisionEvent(_material_Ship, _material_Asteroid, Collision_ShipAsteroid); _materialManager.RegisterCollisionEvent(_material_Ship, _material_Projectile, Collision_ShipProjectile); _materialManager.RegisterCollisionEvent(_material_Asteroid, _material_Projectile, Collision_AsteroidProjectile); _materialManager.RegisterCollisionEvent(_material_Asteroid, _material_SwarmBot, Collision_AsteroidSwarmBot); _materialManager.RegisterCollisionEvent(_material_Asteroid, _material_Asteroid, Collision_AsteroidAsteroid); #endregion #region Trackball //TODO: Only use this when debugging the scene //// Trackball //_trackball = new TrackBallRoam(_camera); //_trackball.KeyPanScale = 15d; //_trackball.EventSource = grdViewPort; //NOTE: If this control doesn't have a background color set, the trackball won't see events (I think transparent is ok, just not null) //_trackball.AllowZoomOnMouseWheel = true; //_trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete_NoLeft)); ////_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius); //_trackball.ShouldHitTestOnOrbit = true; #endregion #region Map _map = new Map(_viewport, null, _world); //_map.SnapshotFequency_Milliseconds = 250; // just use the map's default values //_map.SnapshotMaxItemsPerNode = 13; _map.ShouldBuildSnapshots = true; _map.ShouldShowSnapshotLines = false; _map.ShouldSnapshotCentersDrift = true; _map.ItemRemoved += new EventHandler<MapItemArgs>(Map_ItemRemoved); #endregion #region Radiation //TODO: Make radiation sources instead of a constant ambient -- sort of mini stars, or something manmade looking _radiation = new RadiationField() { AmbientRadiation = 1, }; #endregion #region UpdateManager //TODO: UpdateManager needs to inspect types as they are added to the map (map's ItemAdded event) _updateManager = new UpdateManager( new Type[] { typeof(ShipPlayer), typeof(SpaceStation2D), typeof(Projectile), typeof(Asteroid), typeof(SwarmBot1b) }, new Type[] { typeof(ShipPlayer), typeof(SwarmBot1b) }, _map); #endregion #region Brush Strokes _brushStrokes = new SwarmObjectiveStrokes(_world.WorldClock, _itemOptions.SwarmBay_BirthSize * 4, 6); // This would be for drawing the strokes //_brushStrokes.PointsChanged += BrushStrokes_PointsChanged; #endregion #region Player _player = new Player(); _player.Credits = 10; _player.ShipChanged += new EventHandler<ShipChangedArgs>(Player_ShipChanged); #endregion #region Minimap _miniMap = new MinimapHelper(_map, _viewportMap); #endregion #region Camera Helper _cameraHelper = new CameraHelper(_player, _camera, _cameraMap, _miniMap); #endregion #region MapPopulationManager _mapPopulationManager = new MapPopulationManager(_map, _world, new Point3D(_boundryMin.X, _boundryMin.Y, 0), new Point3D(_boundryMax.X, _boundryMax.Y, 0), _material_Asteroid, _material_Mineral, GetAsteroidMassByRadius, GetMineralsFromDestroyedAsteroid, ItemOptionsAstMin2D.MINASTEROIDRADIUS); _updateManager.AddNonMapItem(_mapPopulationManager, TokenGenerator.NextToken()); #endregion #region MapForcesManager _mapForcesManager = new MapForcesManager(_map, _boundryMin, _boundryMax); _updateManager.AddNonMapItem(_mapForcesManager, TokenGenerator.NextToken()); #endregion #region BackImageManager _backImageManager = new BackImageManager(backgroundCanvas, _player); #endregion #region Ship Extra _shipExtra = new ShipExtraArgs() { Options = _editorOptions, ItemOptions = _itemOptions, Material_Projectile = _material_Projectile, Material_SwarmBot = _material_SwarmBot, SwarmObjectiveStrokes = _brushStrokes, RunNeural = false, Radiation = _radiation, }; #endregion CreateStars3D(); //TODO: Move this to BackImageManager //CreateStars3DGrid(); //CreateShip(UtilityCore.GetRandomEnum<DefaultShipType>()); if (!LoadLatestSession()) { CreateNewSession(); } CreateAsteroids(); CreateMinerals(); //CreateProjectile(); _world.UnPause(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
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(); }