Esempio n. 1
0
        private ShipViewerWindow ShowShipViewer(Swimbot bot, Point clickPoint)
        {
            // Make the camera follow this bean
            //TODO: Place a 2D graphic behind the selected ship
            //TODO: Zoom in on it
            #region Create Viewer

            ShipViewerWindow retVal = new ShipViewerWindow(bot, this);
            retVal.SetColorTheme_Dark_Gradient();

            #endregion

            // Place Viewer
            Point screenClickPoint = UtilityWPF.TransformToScreen(clickPoint, grdViewPort);
            ShipViewerWindow.PlaceViewerInCorner(retVal, screenClickPoint);

            // This places the viewer to the right of where they clicked - which is fine if they can't drag the item
            // around, but it's in the way if they try to move the object
            //Point popupPoint = new Point(windowClickPoint.X + 50, windowClickPoint.Y - (viewer.Height / 3d));
            //popupPoint = UtilityWPF.EnsureWindowIsOnScreen(popupPoint, new Size(viewer.Width, viewer.Height));		// don't let the popup straddle monitors
            //viewer.Left = popupPoint.X;
            //viewer.Top = popupPoint.Y;

            retVal.Show();      // it needs to be shown first to get the size

            return(retVal);
        }
Esempio n. 2
0
        private void AddEgg_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_bots.Count == 0)
                {
                    MessageBox.Show("Add a bot first", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                Swimbot bot = _bots[StaticRandom.Next(_bots.Count)];

                Point3D position = bot.PositionWorld + Math3D.GetRandomVector_Spherical_Shell(bot.Radius * 1.5d);

                // The radius should be 20% the size of the adult ship
                ShipDNA dna    = bot.GetNewDNA();
                double  radius = dna.PartsByLayer.SelectMany(o => o.Value).
                                 Max(o => o.Position.ToVector().Length + Math1D.Max(o.Scale.X, o.Scale.Y, o.Scale.Z))
                                 * .2d;

                Egg <ShipDNA> egg = new Egg <ShipDNA>(position, radius, _world, _material_Egg, _itemOptions, dna);

                egg.PhysicsBody.AngularVelocity = bot.PhysicsBody.AngularVelocity;
                egg.PhysicsBody.Velocity        = bot.PhysicsBody.Velocity;

                egg.PhysicsBody.ApplyForceAndTorque += new EventHandler <BodyApplyForceAndTorqueArgs>(Egg_ApplyForceAndTorque);

                _map.AddItem(egg);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 3
0
        private void Collision_BotFood(object sender, MaterialCollisionArgs e)
        {
            try
            {
                Body shipBody    = e.GetBody(_material_Bot);
                Body mineralBody = e.GetBody(_material_Food);

                Swimbot bot = _bots.Where(o => o.PhysicsBody.Equals(shipBody)).FirstOrDefault();
                if (bot == null)
                {
                    return;
                }

                Mineral mineral = _map.GetItem <Mineral>(mineralBody);
                if (mineral == null)
                {
                    return;
                }

                bot.CollidedMineral(mineral);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private ShipViewerWindow ShowShipViewer(Swimbot bot, Point clickPoint)
        {
            // Make the camera follow this bean
            //TODO: Place a 2D graphic behind the selected ship
            //TODO: Zoom in on it
            #region Create Viewer

            ShipViewerWindow retVal = new ShipViewerWindow(bot);
            retVal.Owner = this;		// the other settings like topmost, showintaskbar, etc are already set in the window's xaml
            retVal.PopupBorder = new SolidColorBrush(UtilityWPF.ColorFromHex("60000000"));
            retVal.PopupBackground = new SolidColorBrush(UtilityWPF.ColorFromHex("30000000"));
            retVal.ViewportBorder = new SolidColorBrush(UtilityWPF.ColorFromHex("E0000000"));

            LinearGradientBrush brush = new LinearGradientBrush();
            brush.StartPoint = new Point(0, 0);
            brush.EndPoint = new Point(1, 1);

            GradientStopCollection gradients = new GradientStopCollection();
            gradients.Add(new GradientStop(UtilityWPF.ColorFromHex("E0EBEDE4"), 0d));
            gradients.Add(new GradientStop(UtilityWPF.ColorFromHex("E0DFE0DA"), .1d));
            gradients.Add(new GradientStop(UtilityWPF.ColorFromHex("E0E0E0E0"), .6d));
            gradients.Add(new GradientStop(UtilityWPF.ColorFromHex("E0DADBD5"), .9d));
            gradients.Add(new GradientStop(UtilityWPF.ColorFromHex("E0D7DBCC"), 1d));
            brush.GradientStops = gradients;

            retVal.ViewportBackground = brush;

            retVal.PanelBorder = new SolidColorBrush(UtilityWPF.ColorFromHex("8068736B"));
            retVal.PanelBackground = new SolidColorBrush(UtilityWPF.ColorFromHex("80424F45"));
            retVal.Foreground = new SolidColorBrush(UtilityWPF.ColorFromHex("F0F0F0"));

            #endregion

            // Place Viewer
            Point screenClickPoint = UtilityWPF.TransformToScreen(clickPoint, grdViewPort);
            ShipViewerWindow.PlaceViewerInCorner(retVal, screenClickPoint);

            // This places the viewer to the right of where they clicked - which is fine if they can't drag the item
            // around, but it's in the way if they try to move the object
            //Point popupPoint = new Point(windowClickPoint.X + 50, windowClickPoint.Y - (viewer.Height / 3d));
            //popupPoint = UtilityWPF.EnsureWindowIsOnScreen(popupPoint, new Size(viewer.Width, viewer.Height));		// don't let the popup straddle monitors
            //viewer.Left = popupPoint.X;
            //viewer.Top = popupPoint.Y;

            retVal.Show();      // it needs to be shown first to get the size

            return retVal;
        }
        private void btnAddBot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //TODO: Implement:
                //  ConverterMatterToFuel
                //  ConverterMatterToEnergy

                //_itemOptions.CameraColorRGBNeuronDensity = 160 * 3;

                #region DNA

                List<ShipPartDNA> parts = new List<ShipPartDNA>();

                parts.Add(new ShipPartDNA() { PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 1.43121944558768), Scale = new Vector3D(2.7969681248785, 2.7969681248785, 0.754175785992705) });

                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.617709955450103, 0, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366) });
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-2.16134944924876E-05, -0.60985890545398, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366) });
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.00387496389974934, 0.618396858731443, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366) });
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.624666220599071, 0.00100528924605325, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366) });

                parts.Add(new ShipPartDNA() { PartType = CargoBay.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 0), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.850947345148112, -0.0019217800299223, -0.1657062616585), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00589599969475301, 0.850929089078933, -0.1657062616585), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00522521361558187, -0.850933472485232, -0.165706261658499), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.850949515219971, 0, -0.165706261658499), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994) });

                parts.Add(new ShipPartDNA() { PartType = ConverterMatterToFuel.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.232899395582397, -0.238935114546265, 0.773100284172734), Scale = new Vector3D(0.903613735551713, 0.903613735551713, 0.903613735551713) });
                parts.Add(new ShipPartDNA() { PartType = ConverterMatterToEnergy.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.22797553388197, 0.226717979419686, 0.775967026847012), Scale = new Vector3D(0.903613735551713, 0.903613735551713, 0.903613735551713) });

                parts.Add(new ShipPartDNA() { PartType = SensorSpin.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.262933776282848, 0.240405245709603, 0.755961022082205), Scale = new Vector3D(1, 1, 1) });
                parts.Add(new ShipPartDNA() { PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.250217552102507, -0.280865739393283, 0.743561713316594), Scale = new Vector3D(0.399083346950047, 0.399083346950047, 0.236501125779081) });       // This is just a placeholder for a future sensor (need to put something here so mass is balanced)

                parts.Add(new ShipPartDNA() { PartType = CameraColorRGB.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00208559296997747, 0, 2.00222812584528), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00137913748707474, 0, -1.20661030017992), Scale = new Vector3D(1.29260597488229, 1.29260597488229, 1.29260597488229), ThrusterType = ThrusterType.One });

                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Orientation = new Quaternion(-0.623025498564933, -0.775855164007238, -0.0622612340741654, 0.0775340657568128), Position = new Point3D(0.189965645143804, -0.859019870524953, 0.883258802478369), Scale = new Vector3D(0.522840753255495, 0.522840753255495, 0.522840753255495), ThrusterType = ThrusterType.One });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Orientation = new Quaternion(0.948585651195026, -0.300495041099996, 0.0947956598959211, 0.0300295768554372), Position = new Point3D(-0.719304806310003, 0.506559650891123, 0.883258802478371), Scale = new Vector3D(0.522840753255495, 0.522840753255495, 0.522840753255495), ThrusterType = ThrusterType.One });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Orientation = new Quaternion(0.304146575685315, -0.947421167104513, 0.0303944881633535, 0.0946792887093452), Position = new Point3D(0.715381156965589, 0.512085817563994, 0.883258802478369), Scale = new Vector3D(0.522840753255495, 0.522840753255495, 0.522840753255495), ThrusterType = ThrusterType.One });

                ShipDNA dna = ShipDNA.Create(parts);
                dna.ShipLineage = Guid.NewGuid().ToString();

                #endregion

                ShipCoreArgs core = new GameItems.ShipCoreArgs()
                {
                    Map = _map,
                    Material_Ship = _material_Bot,
                    World = _world,
                };

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Projectile,
                    Radiation = _radiation,
                    CameraPool = _cameraPool,
                };

                //Swimbot bot = await Swimbot.GetNewSwimbotAsync(dna, _world, _material_Bot, _map, extra);
                Swimbot bot = new Swimbot(BotConstructor.ConstructBot(dna, core, extra));
                bot.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Bot_ApplyForceAndTorque);

                bot.PhysicsBody.Rotation = Math3D.GetRandomRotation();
                bot.PhysicsBody.Position = Math3D.GetRandomVector_Spherical(BOUNDRYSIZEHALF * .5d).ToPoint();

                //bot.PhysicsBody.Position = new Point3D(0, 0, BOUNDRYSIZEHALF * -.75d);

                if (bot.Energy != null)
                {
                    bot.Energy.QuantityCurrent = bot.Energy.QuantityMax * .5d;
                }
                if (bot.Fuel != null)
                {
                    bot.Fuel.QuantityCurrent = bot.Fuel.QuantityMax * .5d;
                }
                bot.RecalculateMass();

                _map.AddItem(bot);
                _bots.Add(bot);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 public ExplodingBot(Swimbot bot, double waveSpeed, double forceAtCenter, double maxRadius, Viewport3D viewport, double visualStartRadius)
     : base(bot.PhysicsBody, waveSpeed, forceAtCenter, maxRadius, viewport, visualStartRadius)
 {
     this.Bot = bot;
 }
Esempio n. 7
0
        private void AddBot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //TODO: Implement:
                //  ConverterMatterToFuel
                //  ConverterMatterToEnergy

                //_itemOptions.CameraColorRGBNeuronDensity = 160 * 3;

                #region DNA

                List <ShipPartDNA> parts = new List <ShipPartDNA>();

                parts.Add(new ShipPartDNA()
                {
                    PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 1.43121944558768), Scale = new Vector3D(2.7969681248785, 2.7969681248785, 0.754175785992705)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.617709955450103, 0, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-2.16134944924876E-05, -0.60985890545398, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.00387496389974934, 0.618396858731443, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.624666220599071, 0.00100528924605325, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = CargoBay.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 0), Scale = new Vector3D(1, 1, 1)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.850947345148112, -0.0019217800299223, -0.1657062616585), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00589599969475301, 0.850929089078933, -0.1657062616585), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00522521361558187, -0.850933472485232, -0.165706261658499), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.850949515219971, 0, -0.165706261658499), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = ConverterMatterToFuel.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.232899395582397, -0.238935114546265, 0.773100284172734), Scale = new Vector3D(0.903613735551713, 0.903613735551713, 0.903613735551713)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = ConverterMatterToEnergy.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.22797553388197, 0.226717979419686, 0.775967026847012), Scale = new Vector3D(0.903613735551713, 0.903613735551713, 0.903613735551713)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = SensorSpin.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.262933776282848, 0.240405245709603, 0.755961022082205), Scale = new Vector3D(1, 1, 1)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.250217552102507, -0.280865739393283, 0.743561713316594), Scale = new Vector3D(0.399083346950047, 0.399083346950047, 0.236501125779081)
                });                                                                                                                                                                                                                                                                         // This is just a placeholder for a future sensor (need to put something here so mass is balanced)

                parts.Add(new ShipPartDNA()
                {
                    PartType = CameraColorRGB.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00208559296997747, 0, 2.00222812584528), Scale = new Vector3D(1, 1, 1)
                });

                parts.Add(new ThrusterDNA()
                {
                    PartType = Thruster.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00137913748707474, 0, -1.20661030017992), Scale = new Vector3D(1.29260597488229, 1.29260597488229, 1.29260597488229), ThrusterType = ThrusterType.One
                });

                parts.Add(new ThrusterDNA()
                {
                    PartType = Thruster.PARTTYPE, Orientation = new Quaternion(-0.623025498564933, -0.775855164007238, -0.0622612340741654, 0.0775340657568128), Position = new Point3D(0.189965645143804, -0.859019870524953, 0.883258802478369), Scale = new Vector3D(0.522840753255495, 0.522840753255495, 0.522840753255495), ThrusterType = ThrusterType.One
                });
                parts.Add(new ThrusterDNA()
                {
                    PartType = Thruster.PARTTYPE, Orientation = new Quaternion(0.948585651195026, -0.300495041099996, 0.0947956598959211, 0.0300295768554372), Position = new Point3D(-0.719304806310003, 0.506559650891123, 0.883258802478371), Scale = new Vector3D(0.522840753255495, 0.522840753255495, 0.522840753255495), ThrusterType = ThrusterType.One
                });
                parts.Add(new ThrusterDNA()
                {
                    PartType = Thruster.PARTTYPE, Orientation = new Quaternion(0.304146575685315, -0.947421167104513, 0.0303944881633535, 0.0946792887093452), Position = new Point3D(0.715381156965589, 0.512085817563994, 0.883258802478369), Scale = new Vector3D(0.522840753255495, 0.522840753255495, 0.522840753255495), ThrusterType = ThrusterType.One
                });

                ShipDNA dna = ShipDNA.Create(parts);
                dna.ShipLineage = Guid.NewGuid().ToString();

                #endregion

                ShipCoreArgs core = new GameItems.ShipCoreArgs()
                {
                    Map           = _map,
                    Material_Ship = _material_Bot,
                    World         = _world,
                };

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options             = _editorOptions,
                    ItemOptions         = _itemOptions,
                    Material_Projectile = _material_Projectile,
                    Radiation           = _radiation,
                    CameraPool          = _cameraPool,
                };

                //Swimbot bot = await Swimbot.GetNewSwimbotAsync(dna, _world, _material_Bot, _map, extra);
                Swimbot bot = new Swimbot(BotConstructor.ConstructBot(dna, core, extra));
                bot.PhysicsBody.ApplyForceAndTorque += new EventHandler <BodyApplyForceAndTorqueArgs>(Bot_ApplyForceAndTorque);

                bot.PhysicsBody.Rotation = Math3D.GetRandomRotation();
                bot.PhysicsBody.Position = Math3D.GetRandomVector_Spherical(BOUNDRYSIZEHALF * .5d).ToPoint();

                //bot.PhysicsBody.Position = new Point3D(0, 0, BOUNDRYSIZEHALF * -.75d);

                if (bot.Energy != null)
                {
                    bot.Energy.QuantityCurrent = bot.Energy.QuantityMax * .5d;
                }
                if (bot.Fuel != null)
                {
                    bot.Fuel.QuantityCurrent = bot.Fuel.QuantityMax * .5d;
                }
                bot.RecalculateMass();

                _map.AddItem(bot);
                _bots.Add(bot);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 8
0
 public ExplodingBot(Swimbot bot, double waveSpeed, double forceAtCenter, double maxRadius, Viewport3D viewport, double visualStartRadius)
     : base(bot.PhysicsBody, waveSpeed, forceAtCenter, maxRadius, viewport, visualStartRadius)
 {
     this.Bot = bot;
 }