예제 #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            m_camera      = new Camera2D(GraphicsDevice.Viewport);
            m_camera.Zoom = 1;
            //update = new ThreadStart(update_);
            asteroids    = new List <Asteroid>();
            drawing      = new Thread(update_);
            mainMenuText = new String[4] {
                "Play", "Controls", "Credits", "Exit"
            };
            mainMenuColors = new Color[4] {
                Color.White, Color.White, Color.White, Color.White
            };
            enemies = new List <enemy>();


            make_map();

            base.Initialize();
        }
 protected override void Initialize()
 {
     gameState   = GameState.World;
     worldCamera = new Camera2D(GraphicsDevice)
     {
         Zoom = 2, Position = -screenSize / 2f
     };
     inGameMenuCamera = new Camera2D(GraphicsDevice)
     {
         Zoom = 2, Position = -screenSize / 2f
     };
     inventoryCamera = new Camera2D(GraphicsDevice)
     {
         Zoom = 2, Position = -screenSize / 2f
     };
     currentCamera   = worldCamera;
     IsMouseVisible  = false;
     IsFixedTimeStep = true;
     graphics.SynchronizeWithVerticalRetrace = true;
     r = new Random();
     base.Initialize();
     spriteBatch = new SpriteBatch(GraphicsDevice);
 }
예제 #3
0
        protected override void LoadContent()
        {
            _viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
            _camera          = new Camera2D(_viewportAdapter);

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            var workingFolder = Directory.GetCurrentDirectory();

            _backgroundTexture = Content.Load <Texture2D>("black");

            var bulletTexture = Content.Load <Texture2D>("laserBlue03");
            var bulletRegion  = new TextureRegion2D(bulletTexture);
            var bulletFactory = new BulletFactory(_entityManager, bulletRegion);

            var spaceshipTexture = Content.Load <Texture2D>("playerShip1_blue");
            var spaceshipRegion  = new TextureRegion2D(spaceshipTexture);

            _player = _entityManager.AddEntity(new Spaceship(spaceshipRegion, bulletFactory));

            var meteorTexture = Content.Load <Texture2D>("meteorBrown_big1");
            var meteorRegion  = new TextureRegion2D(meteorTexture);

            for (var i = 0; i < 5; i++)
            {
                var x        = _random.Next(2) == 0 ? 1 : -1;
                var y        = _random.Next(2) == 0 ? 1 : -1;
                var velocity = new Vector2(x, y) * 10f;
                var meteor   = new Meteor(meteorRegion, velocity)
                {
                    Position = new Vector2(100, 100)
                };

                _entityManager.AddEntity(meteor);
            }
        }
예제 #4
0
        public void Update(GameTime gameTime, GamePadState pad, Player player, Camera2D camera, ContentManager manager, Player p1)
        {
            if (isWithinRadius(player.getRectangle()) && pad.Buttons.X == ButtonState.Pressed && !menuOpened)
            {
                menuOpened = true;
                Rectangle bounds = camera.getBounds();
                Vector2   center = new Vector2(camera.Location.X, camera.Location.Y);
                buttons.Add(new HubButton(new Vector2(center.X, (int)(center.Y - camera.getBounds().Height / 3.5)), "UPGRADE SPEED", manager, p1));
                buttons.Add(new HubButton(new Vector2(center.X, (int)(center.Y - camera.getBounds().Height / 7)), "UPGRADE ARMOR", manager, p1));
                buttons.Add(new HubButton(new Vector2(center.X, center.Y), "UPGRADE DAMAGE", manager, p1));
                buttons.Add(new HubButton(new Vector2(center.X, (int)(center.Y + camera.getBounds().Height / 7)), "UPGRADE RATE OF FIRE", manager, p1));
                buttons.Add(new HubButton(new Vector2(center.X, (int)(center.Y + camera.getBounds().Height / 3.5)), "UPGRADE STORAGE", manager, p1));
            }
            else if (pad.Buttons.Y == ButtonState.Pressed && menuOpened && menuColor.A == 255)
            {
                menuOpened = false;
            }

            if (menuOpened && menuColor.A != 255)
            {
                menuColor.R += 5;
                menuColor.G += 5;
                menuColor.B += 5;
                menuColor.A += 5;
            }
            else if (!menuOpened && menuColor.A != 0)
            {
                menuColor.R -= 5;
                menuColor.G -= 5;
                menuColor.B -= 5;
                menuColor.A -= 5;
            }

            if (menuColor.A != 0)
            {
                MouseState mouse         = Mouse.GetState();
                Vector2    mousePosition = new Vector2(mouse.X, mouse.Y);
                mousePosition = Vector2.Transform(mousePosition, Matrix.Invert(camera.TransformMatrix()));

                if (pad.Buttons.B == ButtonState.Pressed && p1.getRawResources() > 0)
                {
                    p1.setResources(p1.getRawResources() + p1.getResources());
                    p1.setRawResources(0);
                }

                foreach (HubButton button in buttons)
                {
                    button.Update(gameTime, camera, menuColor);

                    if (menuOpened)
                    {
                        if (button.isTouchingButton(mousePosition) && mouse.LeftButton == ButtonState.Pressed && !(oldMouse.LeftButton == ButtonState.Pressed))
                        {
                            if (button.getRequiredResources() <= p1.getResources())
                            {
                                string type = button.getType();
                                if (type.Equals("SPEED") && p1.getTopSpeed() < button.getStatMax())
                                {
                                    p1.setTopSpeed(p1.getTopSpeed() + 0.2);
                                    p1.setResources(p1.getResources() - button.getRequiredResources());
                                }
                                else if (type.Equals("ARMOR") && p1.getArmor() < button.getStatMax())
                                {
                                    p1.setArmor(p1.getArmor() + 1.0);
                                    p1.setResources(p1.getResources() - button.getRequiredResources());
                                }
                                else if (type.Equals("DAMAGE") && p1.getDamage() < button.getStatMax())
                                {
                                    p1.setDamage(p1.getDamage() + 1.0);
                                    p1.setResources(p1.getResources() - button.getRequiredResources());
                                }
                                else if (type.Equals("RATE OF FIRE") && p1.getRateOfFire() > button.getStatMax())
                                {
                                    p1.setRateOfFire(p1.getRateOfFire() - 50);
                                    p1.setResources(p1.getResources() - button.getRequiredResources());
                                }
                                else if (type.Equals("STORAGE") && p1.getStorage() < button.getStatMax())
                                {
                                    p1.setStorage(p1.getStorage() + 50);
                                    p1.setResources(p1.getResources() - button.getRequiredResources());
                                }
                                else
                                {
                                    Console.Beep(1500, 200);
                                    continue;
                                }
                                button.updateBar(p1);
                                Console.Beep(3000, 100);
                                Console.Beep(3000, 100);
                            }
                            else
                            {
                                Console.Beep(1500, 200);
                            }
                        }
                    }
                }

                oldMouse = mouse;
            }
        }