Example #1
0
        /// <summary>Initializes a new instance of the MatchViewModel class.</summary>
        /// <param name="endpoint">EndPoint to connect to.</param>
        public MatchViewModel(IPEndPoint endpoint)
        {
            var matchService = ServiceLocator.MatchService;

            // realm
            Entities = new ObservableCollection<object>();
            Realm = new Realm(new IRealmBehavior[] {
                new UpdatePlayerPositionRealmBehavior(),
                new UpdateBallPositionRealmBehavior(),
                new UpdateBulletPositionRealmBehavior()
            });

            // Commands
            KeyPressCommand = new KeyPressCommand(matchService);
            MouseMoveCommand = new MouseMoveCommand(matchService);
            MouseLeftButtonDownCommand = new MouseLeftButtonDownCommand(matchService);
            MouseRightButtonDownCommand = new MouseRightButtonDownCommand(matchService);
            ConnectCommand = new ConnectCommand(matchService, endpoint);

            // Behaviors
            ConnectionStateChangedBehavior = new ConnectionStateChangedBehavior(this);
            EntityModelStateChangedBehavior = new EntityModelStateChangedBehavior(this);
            EntityViewModelStateChangedBehavior = new EntityViewModelStateChangedBehavior(this);
            CameraFollowBehavior = new CameraFollowBehavior(this);
            UpdateRealmBehavior = new UpdateRealmBehavior(this);

            // MatchService events
            matchService.ConnectionStateChanged += (s, e) => ConnectionStateChangedBehavior.Handle(e.ConnectionState);
            matchService.EntityStateChanged += (s, e) => EntityModelStateChangedBehavior.Handle(e.Entity, e.EntityState);
            Entities.CollectionChanged += (s, e) => { lock (Realm) { EntityViewModelStateChangedBehavior.Handle(e); } };
            CompositionTarget.Rendering += (s, e) => { lock (Realm) { UpdateRealmBehavior.Handle(); } };
            CompositionTarget.Rendering += (s, e) => CameraFollowBehavior.Handle(matchService.GetMyPlayer());
        }
Example #2
0
        internal GameViewModel()
        {
            KeyPressCommand = new KeyPressCommand();

            GameControllerCommand = new GameControllerCommand();

            StartGameCommand = new StartGameCommand();
        }
Example #3
0
        private void KeyboardHook_KeyPress(object sender, KeyEventArgs e)
        {
            if (!isRecording || !settings.pressInsteadOfUpDown)
            {
                return;
            }
            Command newCommand = new KeyPressCommand(DateTime.Now.TimeOfDay - elapsedTime, e.KeyCode);

            elapsedTime = DateTime.Now.TimeOfDay;
            onNewCommand?.Invoke(newCommand);
        }
        private void btnAddKeyBinding_Click(object sender, EventArgs e)
        {
            string selectedCommandWord = cmbxCommandWords.GetItemText(cmbxCommandWords.SelectedItem);

            if (string.IsNullOrEmpty(selectedCommandWord))
            {
                MessageBox.Show("You must select a command that is triggered when the key is pressed", "Incorrect Input",
                                MessageBoxButtons.OK);
            }
            else if (txtBindKey.Text == null)
            {
                MessageBox.Show("You must set a key that triggers the command", "Incorrect Input", MessageBoxButtons.OK);
            }
            else
            {
                KeyPressCommand newCommand = new KeyPressCommand(selectedCommandWord, (Keys)bindingKey);
                settings.Commands.Add(newCommand);
                FillKeyBindingTable();
            }
        }
Example #5
0
		protected void IfKeyPressed( KeyCodes key, float delay, KeyPressCommand command )
		{
			if ( input.IsKeyPressed( key ) && keypressDelay < 0.0f )
			{
				keypressDelay = delay;
				command();
			}
		}
Example #6
0
		protected void IfKeyPressed( KeyCodes key, KeyPressCommand command )
		{
			IfKeyPressed( key, 0.5f, command );
		}
Example #7
0
 internal GameViewModel()
 {
     KeyPressCommand = new KeyPressCommand();
 }