Example #1
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            if (WKeyboard.KeyClick(Keys.Tab))
            {
                editorGUIEnabled = !editorGUIEnabled;
            }

            float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            client.AcceptPacketsWhileAvailable();

            if (currentTool != null)
            {
                currentTool.Update();
            }
            WMouse.Update();
            WKeyboard.Update();
            gizmoWorld.Update(deltaTime);
            world.Update(deltaTime);
            userGUI.Update(deltaTime);
            if (editorGUIEnabled)
            {
                editorGUI.Update(deltaTime);
            }

            base.Update(gameTime);
        }
Example #2
0
        public Game1()
        {
            instance = this;
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            world = new GameObject(Objects.Empty, false)
            {
                multiplayer = true
            };

            editorGUI = new GameObject(Objects.Empty, false)
            {
                multiplayer = false
            };

            gizmoWorld = new GameObject(Objects.Empty, false)
            {
                multiplayer = false
            };

            userGUI = new GameObject(Objects.Empty, false)
            {
                multiplayer = false
            };

            IsMouseVisible = true;
            camera         = new Camera();
            WMouse.camera  = camera;

            worldActionScript = new WUIShared.WUIWorldActionScript();
            worldActionScript.Bind("KeyDown", (args) => {
                Enum.TryParse((string)args[0], out Keys key);
                return(WKeyboard.currentKeyboardState.IsKeyDown(key) ? 1 : 0);
            });
            worldActionScript.Bind("KeyClick", (args) => {
                Enum.TryParse((string)args[0], out Keys key);
                return(WKeyboard.KeyClick(key) ? 1 : 0);
            });
            worldActionScript.Bind("ClientOwnedIs", (args) => {
                return(((GameObject)args[0]).ClientOwned ? 1 : 0);
            });
            worldActionScript.Bind("LocalPlayerIs", (args) => {
                return(localPlayer == ((GameObject)args[0]));
            });
            worldActionScript.Bind("LocalPlayerGet", (args) => {
                if (localPlayer == null)
                {
                    return(0);
                }
                return(worldActionScript.GetVariable(new string[] { localPlayer.name }));
            });
            worldActionScript.Bind("LocalPlayerSet", (args) => {
                localPlayer = ((GameObject)args[0]);
                return(null);
            });
            worldActionScript.Bind("LocalPlayerExists", (args) => localPlayer != null ? 1 : 0);
            worldActionScript.Bind("ParentSetToUI", (args) => {
                GameObject gameObject = ((GameObject)args[0]);
                if (gameObject.Parent != userGUI)
                {
                    return(1);                              // You are in UI!
                }
                gameObject.Remove(false, false);
                userGUI.AddChild(gameObject);
                return(0);
            });
            //MouseStuff
            worldActionScript.Bind("MouseGetWorldX", (args) => (int)WMouse.WorldPosition.X);
            worldActionScript.Bind("MouseGetWorldY", (args) => (int)WMouse.WorldPosition.Y);
            worldActionScript.Bind("MouseGetScreenX", (args) => (int)WMouse.Position.X);
            worldActionScript.Bind("MouseGetScreenY", (args) => (int)WMouse.Position.Y);
            worldActionScript.Bind("MouseLeftDown", (args) => (int)WMouse.mouseState.LeftButton);
            worldActionScript.Bind("MouseRightDown", (args) => (int)WMouse.mouseState.RightButton);
            worldActionScript.Bind("MouseLeftClick", (args) => WMouse.RightMouseClick() ? 1 : 0);
            worldActionScript.Bind("MouseRightClick", (args) => WMouse.LeftMouseClick() ? 1 : 0);
            worldActionScript.Bind("MouseOverObject", (args) => ((MouseClickableComponent)args[0]).mouseClickable.MouseOver ? 1: 0);
            worldActionScript.Bind("MouseLeftClickDownObject", (args) => ((MouseClickableComponent)args[0]).mouseClickable.MouseLeftClickDown ? 1 : 0);
            worldActionScript.Bind("MouseRightClickUpObject", (args) => ((MouseClickableComponent)args[0]).mouseClickable.MouseLeftClickUp ? 1 : 0);
            worldActionScript.Bind("MouseLeftDownObject", (args) => (((MouseClickableComponent)args[0]).mouseClickable.MouseOver && WMouse.mouseState.LeftButton == ButtonState.Pressed) ? 1 : 0);
            worldActionScript.Bind("MouseRightDownObject", (args) => (((MouseClickableComponent)args[0]).mouseClickable.MouseOver && WMouse.mouseState.RightButton == ButtonState.Pressed) ? 1 : 0);

            string[] config = File.ReadAllLines("Config.txt");
            client                    = new ClientBase(config[0], int.Parse(config[1]), 8388608); //8MB Of buffer so images can be sent.
            assetManager              = new ClientAssetManager(client);
            networkManager            = new NetworkManager(world);
            GameObject.networkManager = networkManager;
        }