Exemple #1
0
        public bool EnterLocation(Location location)
        {
            Location currentLocation = currentPlayer.GetLocationAtTime(currentTime);

            if (currentLocation == timeMachine && location != timeMachine)
            {
                Action actionEnter = new ActionEnter(currentTime, 1, timeMachine, timeMachine.connectedLocations[0]);
                AddAction(actionEnter);

                return(true);
            }
            else if (location != currentLocation)
            {
                for (int i = 0, length = currentLocation.connectedLocations.Length; i < length; i++)
                {
                    if (currentLocation.connectedLocations[i] == location)
                    {
                        Action actionEnter = new ActionEnter(currentTime, 1, currentPlayer.currentLocation, location);
                        AddAction(actionEnter);

                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #2
0
        bool TimeTravelCheck()
        {
            Action action = currentPlayer.GetLastAction();

            if (action != null)
            {
                ActionEnter actionEnter = action as ActionEnter;

                if (actionEnter != null && actionEnter.toLocation == timeMachine)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #3
0
        public Location GetLocationAtTime(int time)
        {
            Location result = initialLocation;

            if (history.Count > 0)
            {
                for (int i = 0, count = history.Count; i < count; i++)
                {
                    ActionEnter actionEnter = history[i] as ActionEnter;

                    if (actionEnter != null && time > actionEnter.time)
                    {
                        result = actionEnter.toLocation;
                    }
                }
            }

            return(result);
        }
Exemple #4
0
        public float GetTrackStart(float currentTimeInterpolated)
        {
            if (initialLocation.isTimeMachine)
            {
                for (int i = 0, count = history.Count; i < count; i++)
                {
                    ActionEnter actionEnter = history[i] as ActionEnter;

                    if (actionEnter != null)
                    {
                        return(actionEnter.time);
                    }
                }
            }
            else if (history.Count > 0)
            {
                return(history[0].time);
            }

            return(0);
        }
Exemple #5
0
        public void UpdateCharacter(float time)
        {
            float trackStart = GetTrackStart(time);
            float trackEnd   = GetTrackEnd(0, 0f, 0, false, false);

//            if (currentParadoxes.Count > 0)
//            {
//                Paradox paradox = currentParadoxes[0];
//
//                //GameObject paradoxVisuals = paradox.visuals;
//                //if (paradoxVisuals)
//                //   SetVisuals(paradoxVisuals);
//                //return;
//
//                if (time >= paradox.time)
//                {
//                    return;
//                }
//            }

            //Current action
            Action action = null;

            for (int i = 0, count = history.Count; i < count; i++)
            {
                Action a = history[i];
                //TODO, used to foreshadow move direction, maybe handle paradox visualsation differently
                if (time > a.time || (time == a.time && currentParadoxes.Count < 1))
                {
                    action = a;
                }
            }

            //Interpolate state
            Vector3 pos           = currentLocation.transform.position;
            Vector3 lookDirection = Vector3.back;

            GameObject nextVisuals = visualsDefault;

            if (action != null)
            {
                float timeFraction = time - action.time;
                //TODO, mf probably needs more generalised solution here

                if (action is ActionEnter)
                {
                    ActionEnter actionEnter = action as ActionEnter;

                    Vector3 fromPos = actionEnter.fromLocation.transform.position;
                    Vector3 toPos   = actionEnter.toLocation.transform.position;

                    lookDirection = (toPos - fromPos).normalized;

                    pos = Vector3.Lerp(fromPos, toPos, timeFraction);
                }
                else if (action is ActionWait)
                {
                    ActionWait actionWait = action as ActionWait;

                    if (actionWait != null && inventory.Count < 1)
                    {
                        nextVisuals = visualsWait;
                    }
                }
            }

            if (time > trackEnd)
            {
                nextVisuals   = visualsWait; //visualsWarning
                lookDirection = Vector3.back;
            }

            transform.position = pos;
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(lookDirection), 15f * Time.deltaTime);

            Vector3 carryPos = pickupPivot.position;

            for (int i = 0, count = inventory.Count; i < count; i++)
            {
                Item item = inventory[i];
                item.transform.position = carryPos;
                carryPos += Vector3.up * item.height;
            }

            if (action != null)
            {
                float timeFraction = time - action.time;

                if (action is ActionPickup)
                {
                    if (timeFraction > 0f)
                    {
                        ActionPickup actionPickup = action as ActionPickup;
//					Vector3 itemTargetPos = carryPos - Vector3.up * actionPickup.item.height;
                        if (inventory.Count > 0)
                        {
                            Item itemPickup = inventory[inventory.Count - 1];
                            //Debug.Log(item == actionPickup.currentItem);

                            //if (actionPickup.currentItem)
                            //{
                            Vector3 towardsPos = pickupPivot.position + Vector3.up * actionPickup.pickupOffset;
//                        Debug.Log(inventory.Count);
//                        Item item = inventory[inventory.Count - 1];
//                        item.transform.position = Vector3.Lerp(actionPickup.fromPos, towardsPos, timeFraction);
                            itemPickup.transform.position = Vector3.Lerp(actionPickup.fromPos, towardsPos, timeFraction);
//                        }
//                        else
//                        {
//                            Debug.LogWarning("this should probably be prevented", gameObject);
//                        }
                        }
                    }
                }
                else if (action is ActionDrop)
                {
                    if (timeFraction > 0f)
                    {
                        ActionDrop actionDrop = action as ActionDrop;

                        if (actionDrop.currentItem)
                        {
                            Vector3 fromPos = pickupPivot.transform.position + Vector3.up * actionDrop.pickupOffset;
                            actionDrop.currentItem.transform.position = Vector3.Lerp(fromPos, actionDrop.towardsPos, timeFraction);
                        }
                    }
                }
            }

            if (currentParadoxes.Count > 0)
            {
                GameObject paradoxVisuals = currentParadoxes[0].visuals;

                if (paradoxVisuals)
                {
                    nextVisuals = paradoxVisuals;
                }
            }

            //Time line
            Vector3 localScale = timeLine.bar.localScale;

            localScale.x            = trackEnd - trackStart;
            timeLine.bar.localScale = localScale;

            Vector3 localPos = timeLine.bar.localPosition;

            localPos.x = trackStart;
            timeLine.bar.localPosition = localPos;

            SetVisuals(nextVisuals);
        }
Exemple #6
0
        public float GetTrackEnd(int currentTime, float currentTimeInterpolated, int timeForNextDecision, bool currentPlayer, bool draggingPlayhead)
        {
            float result = 0f;

//			bool foundAction = false;

            if (history.Count > 0)
            {
                for (int i = history.Count - 1; i >= 0; i--)
                {
                    Action action = history[i];

                    Location    location    = GetLocationAtTime(action.time + action.duration);
                    ActionEnter actionEnter = action as ActionEnter;

                    if (location.isTimeMachine == false || (actionEnter != null && actionEnter.toLocation.isTimeMachine))
                    {
                        result = action.time + action.duration;
//						foundAction = true;
                        break;
                    }
                }
            }

            return(result);

//			if (currentPlayer)
//			{
//				if(draggingPlayhead)
//				{
//					if(currentTimeInterpolated > result)
//						result = currentTimeInterpolated;
//				}
//				else
//				{
//					if (timeForNextDecision > currentTimeInterpolated)
//					{
//						if (currentTime < timeForNextDecision)
//						{
////							if (currentTimeInterpolated < currentTime)
////							{
////								result = timeForNextDecision;
////							}
//							//if(currentTime - 1
//						}
//						else
//						{
//							result = currentTimeInterpolated;
//						}
//
////						if (foundAction)
////						{
////
////							Debug.Log (foundAction);
////						}
////						else
////						{
////							result = currentTimeInterpolated;
////						}
////						if (currentTime < timeForNextDecision)
////						{
////							result = currentTimeInterpolated;
////						}
////						else
////						{
////							result = timeForNextDecision;
////
////						}
////						else
////						{
////							result = currentTimeInterpolated;
////						}
//					}
//					else if (currentTimeInterpolated > currentTime)
//					{
//						result = currentTimeInterpolated;
//					}
//				}
//			}
//
//			return result;
        }