//Constructor public PlayerGameObject(Vector2 position, GameObjectIndex container, PlayerRegistry players, InputManager inputManager, KeyboardFormat format) : base(position, new BoxCollider(position, HITBOX_SIZE), container) { //Initialize keyboard input source keyboardInput = new PlayerKeyboardInputSource(this, format); //Register in subsystems players.AddPlayer(this); inputManager.registerInputSource(keyboardInput); //Set subsystem references this.players = players; this.input = inputManager; //Get player images images = new List <CanvasBitmap>(); images.Add(ImageManager.getImageByName("red_ghost_up")); images.Add(ImageManager.getImageByName("red_ghost_right")); images.Add(ImageManager.getImageByName("red_ghost_down")); images.Add(ImageManager.getImageByName("red_ghost_left")); //Initialize image Image = images[1]; //Initialize movement array movement = new bool[4] { false, false, false, false }; //Initialize direction Direction = CardinalDirection.EAST; }
private void Update() { if (_session == null) { return; } var result = _session.Process(); switch (result.Type) { case ProcessingResult.ResultType.None: break; case ProcessingResult.ResultType.Error: Debug.LogError($"{result.SessionError} {result.ServerErrorId}"); break; case ProcessingResult.ResultType.Joined: Debug.Log("Waiting for players..."); break; case ProcessingResult.ResultType.Started: Debug.Log("Session started"); var inputSource = new KeyboardInputSource(Keyboard.current, Key.W, Key.S); var viewFactory = new LevelViewFactory(_assetLoader, new UiSystem(_assetLoader, _canvas)); _level = new NetworkLevel(inputSource, viewFactory, this, result.StartMessage); break; case ProcessingResult.ResultType.Active: if (!_level.HandleReceivedInputs(_session.ReceivedInputs)) { Debug.LogError(SessionError.ProtocolError); break; } var(inputs, optMsgFinish) = _level.Tick(); var optError = _session.SendMessages(inputs, optMsgFinish); if (optError.HasValue) { Debug.LogError(optError.Value); } break; case ProcessingResult.ResultType.Finished: var msgFinish = result.FinishMessage; var frames = string.Join(", ", msgFinish.Frames); var hashes = string.Join(", ", msgFinish.Hashes); var(frame, simulations) = _level.SimulationStats; Debug.Log($"Session finished at [{frames}] with state [{hashes}]\nSimulations: {frame} / {simulations}"); break; default: throw new ArgumentOutOfRangeException(); } }
public PlayerStateManager(GameState state) : base(state) { Keyboard = new KeyboardInputSource(); Mouse = new MouseInputSource(); GamePad = new GamePadInputSource(); PlayerAction = EntityAction.NONE; PlayerInventory = EntityInventory.NONE; }
private void Awake() { _assetLoader = AssetLoader.Create(); var viewFactory = new LevelViewFactory(_assetLoader, new UiSystem(_assetLoader, _canvas)); var levelInfo = CreateLevelInfo(); var lInputSrc = new KeyboardInputSource(Keyboard.current, Key.W, Key.S); var rInputSrc = new KeyboardInputSource(Keyboard.current, Key.UpArrow, Key.DownArrow); var inputs = new IInputSource[] { lInputSrc, rInputSrc }; _level = new LocalLevel(levelInfo, inputs, viewFactory); }