Esempio n. 1
0
        public override void update()
        {
            base.update();

            if (input.wasLeftButtonClicked())
            {
                if (input.rectangle.Intersects(exitRec))
                {
                    ModalUtil.removeModal(id);
                }
                else if (input.rectangle.Intersects(setDestinationRectangle))
                {
                    setDestinationAction();
                }
            }
            else if (input.wasLeftButtonClickedAndHeld() && input.rectangle.Intersects(buyFuelRectangle))
            {
                buyFuelAction();
            }

            if (input.wasLeftButtonClickedAndHeld() && input.rectangle.Intersects(rect) && input.didMouseMove)
            {
                exitRec.Location = rect.Location + exitRecOffset;
                setDestinationRectangle.Location = rect.Location + setDestRecOffset;
                buyFuelRectangle.Location        = rect.Location + buyFuelRecOffset;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin(SpriteSortMode.Deferred, null,
                              null, null, null, null, Globals.camera.TranslationMatrix);

            //TODO: I guess make some states
            if (isPaused)
            {
                for (int p = 0; p < planets.Count; p++)
                {
                    spriteBatch.DrawString(font, planets[p].name + " visited: " + planets[p].timesVisited, new Vector2(100 * (int)(p / 30), p * 12 % Globals.screenHeight), Color.Pink);
                }
                spriteBatch.DrawString(font, "Human money: " + human.money, new Vector2(400, 40), Color.Green);
                spriteBatch.DrawString(font, "AI money: " + ai.money, new Vector2(400, 80), Color.Green);
            }
            else
            {
                foreach (Planet planet in planets)
                {
                    planet.Draw(spriteBatch);
                    Rectangle planetRect = planet.getCollisionRectangle();
                    if (inputHandler.rectangle.Intersects(planet.getCollisionRectangle()))
                    {
                        spriteBatch.DrawString(font, planetRect.X + ", " + planetRect.Y, planetRect.Location.ToVector2(), Color.Green);
                    }
                }

                ai.draw(spriteBatch);
                human.draw(spriteBatch);

                human.ships.ForEach(ship => {
                    if (inputHandler.rectangle.Intersects(ship.getCollisionRectangle()))
                    {
                        spriteBatch.DrawString(font, "Fuel: " + ship.fuelRemaining, ship.getCollisionRectangle().Center.ToVector2(), Color.Black);
                    }
                });

                ModalUtil.drawModals(spriteBatch);
            }
            spriteBatch.End();

            spriteBatch.Begin();
            human.drawNoTransform(spriteBatch);
            headerBar.draw(spriteBatch);
            inputHandler.draw(spriteBatch);
            spriteBatch.End();

            base.Draw(gameTime);
        }
Esempio n. 3
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;
                }
            }
        }
Esempio n. 4
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();
        }
Esempio n. 5
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            inputHandler.update();
            Globals.camera.update();

            //TODO: This stupid thing still isn't working 100% right
            if (inputHandler.wasKeyPressedAndReleased(Keys.F))
            {
                //isFullScreen = !isFullScreen;
                graphics.ToggleFullScreen();
                if (!graphics.IsFullScreen)
                {
                    this.graphics.PreferredBackBufferWidth  = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
                    this.graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
                }
                else
                {
                    graphics.PreferredBackBufferWidth  = 640;
                    graphics.PreferredBackBufferHeight = 480;
                }

                graphics.ApplyChanges();

                Globals.screenHeight = GraphicsDevice.Viewport.Height;
                Globals.screenWidth  = GraphicsDevice.Viewport.Width;
            }

            //TODO: I guess make some states
            if (isPaused)
            {
                if (inputHandler.wasKeyPressedAndReleased(Keys.Space))
                {
                    isPaused = false;
                }
            }
            else
            {
                if (inputHandler.wasKeyPressedAndReleased(Keys.Space))
                {
                    isPaused = true;
                }

                //AI Ship
                //if (inputHandler.wasLeftButtonClicked()) {
                //    foreach (Planet planet in planets) {
                //        if (planet.rectangle.Intersects(inputHandler.rectangle)) {
                //            Point planetCenter = planet.rectangle.Center;
                //            Ship ship = new Ship("AI " + ai.ships.Count, whiteSquare, planetCenter.X, planetCenter.Y, 3, 5, 2, 1000, Color.White);

                //            //Well this is weird. Have to set init planet as the one we clicked so that our
                //            //new destination isn't set to the same planet.
                //            //TODO: Make this better
                //            ship.dest = planet;
                //            ship.dest = PlanetUtil.getDestination(ship);
                //            ship.updateAngle(); //TODO: I don't like how this is stuck out here instead of being a private method

                //            ai.ships.Add(ship);
                //        }
                //    }
                //}

                //Human ship
                if (inputHandler.wasRightButtonClicked())
                {
                    foreach (Planet planet in planets)
                    {
                        if (planet.getCollisionRectangle().Intersects(inputHandler.rectangle))
                        {
                            Ship ship = new Ship("Human " + human.ships.Count, whiteSquare, planet, 7, 15, 2, 1000, Color.Black);

                            human.ships.Add(ship);
                        }
                    }
                }

                if (inputHandler.wasKeyPressedAndReleased(Keys.Down))
                {
                    ai.ships.ForEach(ship => ship.speed--);
                    human.ships.ForEach(ship => ship.speed--);
                }
                else if (inputHandler.wasKeyPressedAndReleased(Keys.Up))
                {
                    ai.ships.ForEach(ship => ship.speed++);
                    human.ships.ForEach(ship => ship.speed++);
                }

                ai.update();
                human.update();
                ModalUtil.updateModals();
            }

            base.Update(gameTime);
        }