Exemple #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()
        {
            _frameCounter = new FramesPerSecondCounter();

            GSM    = new GameStateManager();
            socket = new Sockets();

            viewport = new ScalingViewportAdapter(graphics.GraphicsDevice, 800, 480);
            camera   = new Camera2D(viewport)
            {
                MinimumZoom = 0.1f,
                MaximumZoom = 2.0f,
                Zoom        = 1.0f,
                Origin      = new Vector2(400, 240),
                Position    = new Vector2(408, 270)
            };

            Window.AllowUserResizing = true;

            GSM.PushState(new GameState(GSM, camera));

            while (true)
            {
                if (socket.message == null)
                {
                    continue;
                }
                else
                {
                    PlayerPosition = new Vector2((int)socket.message["X"] * 32, (int)socket.message["Y"] * 32);
                    camera.LookAt(PlayerPosition);

                    Sockets.token = (string)socket.message["Token"];
                    break;
                }
            }

            base.Initialize();
        }
Exemple #2
0
        public override void Update(GameTime gameTime)
        {
            float deltaSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds;

            keyboardState = Keyboard.GetState();
            MouseState mouse = Mouse.GetState();

            movement = BaseBuilder.PlayerPosition;

            if (mouse.LeftButton == ButtonState.Pressed)
            {
                System.Console.WriteLine(string.Format("{0},{1}", mouse.X, mouse.Y));
            }

            // camera
            if (keyboardState.IsKeyDown(Keys.R))
            {
                camera.ZoomIn(deltaSeconds);
            }

            if (keyboardState.IsKeyDown(Keys.F))
            {
                camera.ZoomOut(deltaSeconds);
            }

            if (keyboardState.IsKeyDown(Keys.W) && oldKeyboardState.IsKeyUp(Keys.W))
            {
                movement.Y -= 32;
                if (CheckCollision(movement))
                {
                    moving = true;
                }
            }

            if (keyboardState.IsKeyDown(Keys.S) && oldKeyboardState.IsKeyUp(Keys.S))
            {
                movement.Y += 32;
                if (CheckCollision(movement))
                {
                    moving = true;
                }
            }

            if (keyboardState.IsKeyDown(Keys.A) && oldKeyboardState.IsKeyUp(Keys.A))
            {
                movement.X -= 32;
                if (CheckCollision(movement))
                {
                    moving = true;
                }
            }

            if (keyboardState.IsKeyDown(Keys.D) && oldKeyboardState.IsKeyUp(Keys.D))
            {
                movement.X += 32;
                if (CheckCollision(movement))
                {
                    moving = true;
                }
            }


            if (moving)
            {
                BaseBuilder.PlayerPosition = movement;
                camera.LookAt(BaseBuilder.PlayerPosition);

                Sockets.SendMovement((int)BaseBuilder.PlayerPosition.X / 32, (int)BaseBuilder.PlayerPosition.Y / 32);
                moving = false;
            }
            oldKeyboardState = keyboardState;
        }