示例#1
0
    public void CopyTimeTrackerState(ITimeTracker other)
    {
        TimeMachineController otherTM = other as TimeMachineController;

        if (otherTM != null)
        {
            Activated.Copy(otherTM.Activated);
            Occupied.Copy(otherTM.Occupied);
            ActivatedTimeStep.Copy(otherTM.ActivatedTimeStep);
            Countdown.Copy(otherTM.Countdown);

            Position.Copy(otherTM.Position);
            ItemForm = otherTM.ItemForm;

            playerID.Copy(otherTM.playerID);
            doneTimeTravelPlayerID = otherTM.doneTimeTravelPlayerID;
            IsAnimatingOpenClose   = otherTM.IsAnimatingOpenClose;
            IsAnimatingFold        = otherTM.IsAnimatingFold;
            IsAnimatingUnfold      = otherTM.IsAnimatingUnfold;

            isFoldable = otherTM.isFoldable;
        }
        else
        {
            gameController.LogError($"Cannot copy state from {other.GetType()} to {nameof(TimeMachineController)}");
        }
    }
        public void Setup()
        {
            _gamepad  = InputSystem.AddDevice <Gamepad>();
            _keyboard = InputSystem.AddDevice <Keyboard>();

            _game = Object.Instantiate(Resources.Load <GameObject>("Prefabs/GameController")).GetComponent <GameController>();

            PlayerController playerPrefab = Resources.Load <PlayerController>("Prefabs/Player");

            //_game.Player = Object.Instantiate(playerPrefab).GetComponent<PlayerController>();
            _game.Player.PlayerInput.enabled = true;

            TimeMachineController timeMachine = Object.Instantiate(Resources.Load <GameObject>("Prefabs/TimeMachine")).GetComponent <TimeMachineController>();
            BasicTimeTracker      moveableBox = Object.Instantiate(Resources.Load <GameObject>("Prefabs/MoveableBox")).GetComponent <BasicTimeTracker>();

            var levelEndObject = Object.Instantiate(Resources.Load <GameObject>("Prefabs/LevelEnd"));

            levelEndObject.transform.position = new Vector3(30, 0, 0);
        }
        public IEnumerator IntegrationTestsWithEnumeratorPasses()
        {
            TimeMachineController timeMachine = _game.timeMachines[0];

            Assert.IsFalse(timeMachine.IsActivatedOrOccupied);
            Assert.AreEqual(-1, timeMachine.Countdown.Current);
            Assert.IsFalse(_game.Player.IsActivating);
            yield return(null);

            PressAndRelease(_keyboard.spaceKey);
            yield return(null);

            //TODO: create some proper integration tests
            //Assert.IsTrue(_game.player.IsActivating);

            //Assert.AreEqual(0, timeMachine.Countdown.Current);

            // Use the Assert class to test conditions.
            // yield to skip a frame
            for (int i = 0; i < 100; i++)
            {
                yield return(null);
            }
        }
示例#4
0
    public void ExecutePastEvent(TimeEvent timeEvent)
    {
        if (gameController.CurrentPlayerID == ID)
        {
            gameController.LogError($"ExecutePastEvent on current player!");
        }

        if (timeEvent.Type == TimeEvent.EventType.PLAYER_GRAB)
        {
            if (gameController.CurrentPlayerID != ID)
            {
                bool         isFound      = false;
                ITimeTracker bestMatch    = null;
                ITimeTracker originalItem = gameController.GetObjectByID(timeEvent.TargetID) as ITimeTracker;
                // NOTE: There might be a bug if the original item was destroyed before this event occurs...
                //

                if (ItemID != -1)
                {
                    gameController.LogError($"Trying to grab {timeEvent.TargetID} when already holding {ItemID}!");
                }

                List <Collider2D> contacts = new List <Collider2D>();
                GrabCollider.GetContacts(contacts);
                foreach (var contact in contacts)
                {
                    if (contact.gameObject == gameObject)
                    {
                        continue;
                    }

                    ITimeTracker timeTracker = GameController.GetTimeTrackerComponent(contact.gameObject, true);
                    if (timeTracker == null)
                    {
                        continue;
                    }

                    if (timeTracker.ID == timeEvent.TargetID)
                    {
                        isFound = true;
                    }

                    if (isFound)
                    {
                        isFound = timeTracker.SetItemState(true);
                    }

                    // break the loop if we found the object bc we can only pick up one object
                    if (isFound)
                    {
                        ItemID = timeEvent.TargetID;
                        break;
                    }

                    // if object is equivalent enough, save it in case we don't find the actual object we previously picked up
                    if (originalItem != null && originalItem.IsEquivalentItem(timeTracker))
                    {
                        bestMatch = timeTracker;
                    }
                }

                if (bestMatch != null)
                {
                    isFound = bestMatch.SetItemState(true);
                    if (isFound)
                    {
                        ItemID = bestMatch.ID;
                    }
                }

                if (!isFound)
                {
                    gameController.LogError($"Player {ID} could not grab {timeEvent.TargetID}");
                    throw new TimeAnomalyException("Time Anomaly!",
                                                   $"Doppelganger could not grab the {gameController.GetUserFriendlyName(timeEvent.TargetID)}",
                                                   this);
                }
            }
        } // end PLAYER_GRAB
        else if (timeEvent.Type == TimeEvent.EventType.PLAYER_DROP)
        {
            if (ItemID != timeEvent.TargetID)
            {
                gameController.Log($"Note: dropping {ItemID} instead of {timeEvent.TargetID}");
            }
            if (gameController.DropItem(this, ItemID)) // check to see if we successfully drop the item
            {
                ItemID = -1;
            }
        } // end PLAYER_DROP
        else if (timeEvent.Type == TimeEvent.EventType.TIME_TRAVEL)
        {
            TimeMachineController timeMachine = gameController.GetTimeTrackerByID(timeEvent.TargetID) as TimeMachineController;

            if (timeMachine == null || !timeMachine.IsTouching(gameObject))
            {
                throw new TimeAnomalyException("Time Anomaly!", "Doppelganger could not use the Time Machine!", this);
            }
        } // end TIME_TRAVEL
        else if (timeEvent.Type == TimeEvent.EventType.ACTIVATE_TIME_MACHINE)
        {
            TimeMachineController timeMachine = gameController.GetTimeTrackerByID(timeEvent.TargetID) as TimeMachineController;

            if (timeMachine == null || !timeMachine.IsTouching(gameObject))
            {
                throw new TimeAnomalyException("Time Anomaly!", "Doppelganger could not activate the Time Machine!", this);
            }
        } // end ACTIVATE_TIME_MACHINE
    }