Exemplo n.º 1
0
        public PlanetType(IStarRepository starRepository)
        {
            Field(s => s.PlanetId, nullable: false, type: typeof(IdGraphType)).Name("id");
            Field(s => s.PlanetName, nullable: false);
            Field(s => s.Mass, type: typeof(FloatGraphType));
            Field <FloatGraphType, double?>()
            .Name("radius")
            .Resolve(context =>
            {
                if (context.GetArgument("predictPlanetRadii", defaultValue: true))
                {
                    return(context.Source.Radius ?? PlanetUtil.PredictPlanetRadiusFromMass(context.Source.Mass.GetValueOrDefault()));
                }
                return(context.Source.Mass);
            });
            Field(s => s.Density, type: typeof(FloatGraphType));
            Field(s => s.Gravity, type: typeof(FloatGraphType));
            Field <IntGraphType>()
            .Name("temperature")
            .Resolve(context =>
            {
                if (context.Source.Temperature != null)
                {
                    return(context.Source.Temperature);
                }

                var star = context.Source.Star;
                if (star !.Luminosity != null)
                {
                    return((int)(252 * Math.Pow(star.Luminosity.GetValueOrDefault() / Math.Pow(context.Source.Orbit.SemiMajorAxis, 2), 0.25)));
                }
                return(null);
            });
            Field(s => s.AtmosphericPressure, type: typeof(FloatGraphType));
            Field(s => s.DiscoveryMethod, nullable: true);
            Field(s => s.DiscoveryYear, nullable: true, type: typeof(IntGraphType));
            Field <BooleanGraphType>()
            .Name("isRadiusPredicted")
            .Resolve(context => context.GetArgument("predictPlanetRadii", defaultValue: true) && context.Source.Radius == null);

            Field <OrbitType, Orbit>()
            .Name("orbit")
            .Resolve(context => context.Source.Orbit);

            Field <StarType, Star>()
            .Name("star")
            .ResolveAsync(context => starRepository.GetStarAsync(context.Source.StarId));
        }
Exemplo n.º 2
0
        public override void update()
        {
            ships.ForEach(ship => {
                if (!ship.isDocked)
                {
                    ship.move();
                }
            });

            if (input.wasKeyPressedAndReleased(Keys.C))
            {
                shipLookingForDestination = null;
            }

            if (input.wasLeftButtonClicked())
            {
                //TODO: How do we handle displays for multiple ships?
                //Additional popup asking them to choose which ship?
                List <Ship> selectedShips = ships.FindAll(ship => input.rectangle.Intersects(ship.getCollisionRectangle()));
                selectedShips.ForEach(ship => {
                    ShipInfo info = new ShipInfo(ship,
                                                 () => { shipLookingForDestination = ship; },
                                                 () => { buyFuel(ship); });

                    ModalUtil.addModal(info);
                });

                //Player clicked the 'Select Destination' button on ShipInfo
                if (shipLookingForDestination != null)
                {
                    //Make sure the Player clicked a planet to set the destination
                    Planet selectedPlanet = PlanetUtil.getPlanets().Find(planet => planet.getCollisionRectangle().Intersects(input.rectangle));
                    if (selectedPlanet != null)
                    {
                        if (PlanetUtil.isPlanetInRange(selectedPlanet, shipLookingForDestination))
                        {
                            shipLookingForDestination.setNewDestination(selectedPlanet);
                        }
                        else
                        {
                            //TODO: Alert that planet is out of range
                        }
                    }
                    //Cancel looking for a destination whether a planet is clicked or not
                    shipLookingForDestination = null;
                }
            }
        }
Exemplo n.º 3
0
        public void update()
        {
            if (needNewDest)
            {
                Planet newDest = PlanetUtil.getRandomValidDestination(this);

                //We'll get the same destination back only if we don't have enough fuel to travel
                if (dest != newDest)
                {
                    isDocked = false;
                    dest     = newDest;
                    updateAngle();
                }
            }

            if (!isDocked && fuelRemaining > 0)
            {
                move();
            }
        }
Exemplo n.º 4
0
        public void drawNoTransform(SpriteBatch sb)
        {
            //Draw line from ship to mouse
            if (shipLookingForDestination != null)
            {
                Color  lineColor   = Color.Red;
                Planet hoverPlanet = PlanetUtil.getPlanetMouseHoveringOver();

                if (hoverPlanet != null)
                {
                    if (PlanetUtil.isPlanetInRange(hoverPlanet, shipLookingForDestination))
                    {
                        lineColor = Color.Green;
                        InputHandler.Instance.tempMouseTexture = this.hoverPlanetSuccessText;
                    }
                    else
                    {
                        InputHandler.Instance.tempMouseTexture = this.hoverPlanetErrorText;
                    }
                }
                DrawUtil.drawLine(sb, shipLookingForDestination.getCollisionRectangle().Center.ToVector2(), input.pos, lineColor);
            }
        }
Exemplo n.º 5
0
        protected override void Initialize()
        {
            //this.IsMouseVisible = true;

            this.graphics.PreferredBackBufferWidth  = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
            this.graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;

            //graphics.ToggleFullScreen();

            whiteSquare = Content.Load <Texture2D>("WhiteSquare");
            font        = Content.Load <SpriteFont>("text");

            inputHandler = InputHandler.Instance;
            mouseTexture = whiteSquare;
            inputHandler.mouseTexture = mouseTexture;

            hoverPlanetErrorText   = whiteSquare;
            hoverPlanetSuccessText = whiteSquare;
            human = new Player(hoverPlanetErrorText, hoverPlanetSuccessText);

            Globals.screenHeight = GraphicsDevice.Viewport.Height;
            Globals.screenWidth  = GraphicsDevice.Viewport.Width;
            Globals.camera       = new Camera(GraphicsDevice.Viewport);
            Globals.camera.CenterOn(new Vector2(Globals.screenWidth / 2, Globals.screenHeight / 2));

            for (int i = 0; i < planetNum; i++)
            {
                Color  randColor = new Color(random.Next(256), random.Next(256), random.Next(256));
                Planet planet    = new Planet(whiteSquare,
                                              random.Next(-Globals.screenWidth / 2, Globals.screenWidth * 3 / 2 - planetSize),
                                              //+30 for height of HeaderBar
                                              random.Next(-Globals.screenHeight / 2 + 30, Globals.screenHeight * 3 / 2 - planetSize),
                                              planetSize, planetSize, randColor, i.ToString());
                planets.Add(planet);
            }

            if (shouldShowFourCornerPlanets)
            {
                Planet topLeft = new Planet(whiteSquare,
                                            -Globals.screenWidth / 2,
                                            //+30 for height of HeaderBar
                                            -Globals.screenHeight / 2 + 30,
                                            planetSize, planetSize, Color.Black, "Top Left");
                Planet topRight = new Planet(whiteSquare,
                                             Globals.screenWidth * 3 / 2 - planetSize,
                                             //+30 for height of HeaderBar
                                             -Globals.screenHeight / 2 + 30,
                                             planetSize, planetSize, Color.Black, "Top Right");
                Planet bottomLeft = new Planet(whiteSquare,
                                               -Globals.screenWidth / 2,
                                               Globals.screenHeight * 3 / 2 - planetSize,
                                               planetSize, planetSize, Color.Black, "Bottom Left");
                Planet bottomRight = new Planet(whiteSquare,
                                                Globals.screenWidth * 3 / 2 - planetSize,
                                                Globals.screenHeight * 3 / 2 - planetSize,
                                                planetSize, planetSize, Color.Black, "Bottom Right");

                planets.Add(topLeft);
                planets.Add(topRight);
                planets.Add(bottomLeft);
                planets.Add(bottomRight);
            }

            ModalUtil.init();
            PlanetUtil.init(ref planets);
            DrawUtil.init(whiteSquare);

            HeaderBar.init(human, whiteSquare, font);
            headerBar = HeaderBar.Instance;

            BaseInfo.init(whiteSquare, font);

            base.Initialize();
        }