Beispiel #1
0
    /// <summary>
    /// Freeze paddle method
    /// </summary>
    /// <param name="side"></param>
    /// <param name="freezeDuration"></param>
    void FreezePaddle(ScreenSide side, float freezeDuration)
    {
        print("Freeze");
        // Handles Left Side Freezing
        if (side == ScreenSide.Left && p1IsFrozen == false)
        {
            freezeTimer.Duration = freezeDuration;

            freezeTimer.Run();
            p1IsFrozen = true;
        }
        else
        {
            freezeTimer.Duration = freezeTimer.Duration + freezeDuration;

            freezeTimer.Run();
            p1IsFrozen = true;
        }

        // Handles Right Side Freezing
        if (side == ScreenSide.Right && p2IsFrozen == false)
        {
            freezeTimer.Duration = freezeDuration;
            freezeTimer.Run();
            p2IsFrozen = true;
        }
        else if (side == ScreenSide.Right && p2IsFrozen == true)
        {
            freezeTimer.Duration = freezeTimer.Duration + freezeDuration;
            freezeTimer.Run();
            p2IsFrozen = true;
        }
    }
Beispiel #2
0
    void SpawnStar()
    {
        //ScreenSide side = (ScreenSide)Random.Range(0, 4);
        Vector3 spawnPos;

        switch (side)
        {
        case ScreenSide.TOP:
            spawnPos = Camera.main.ScreenToWorldPoint(new Vector3(Random.Range(0, dx), dy + padding, 0f));
            break;

        case ScreenSide.RIGHT:
            spawnPos = Camera.main.ScreenToWorldPoint(new Vector3(dx + padding, Random.Range(0, dy), 0f));
            break;

        case ScreenSide.BOTTOM:
            spawnPos = Camera.main.ScreenToWorldPoint(new Vector3(Random.Range(0, dx), 0 - padding, 0f));
            break;

        default:
            spawnPos = Camera.main.ScreenToWorldPoint(new Vector3(0 - padding, Random.Range(0, dy), 0f));
            break;
        }
        side       = (ScreenSide)(((int)side + 1) % 4);
        spawnPos.z = 0f;
        Instantiate(star, spawnPos, Quaternion.identity);
        star.GetComponent <FallingStar>().duration = fallDuration;
    }
Beispiel #3
0
        public List<ChefsController> GetMirrorController(ScreenSide side)
        {
            if(!_Controllers.ContainsKey(side))
                return null;

            return _Controllers[side];
        }
Beispiel #4
0
        /// <summary>
        /// Returns the reflected coordinate (x or y) based on what side of the screen the entity has passed.
        /// </summary>
        /// <param name="side">The side of the screen the entity has passed</param>
        /// <param name="screenWidth">The width of the screen</param>
        /// <param name="screenHeight">The height of the screen</param>
        /// <returns>The reflected x or y coordinate</returns>
        private float GetReflectCoord(ScreenSide side, float screenWidth, float screenHeight)
        {
            // Get the side, and return the corresponding x-coordinate
            switch (side)
            {
            //----------------
            // X Reflection
            case ScreenSide.Right:
                return(-EffectiveWidth);

            case ScreenSide.Left:
                return(screenWidth + EffectiveWidth);

            //----------------

            //----------------
            // Y Reflection
            case ScreenSide.Top:
                return(screenHeight + EffectiveHeight);

            case ScreenSide.Bottom:
                return(-EffectiveHeight);

            //----------------

            // If we got this far, something went horribly wrong
            default:
                throw new ArgumentException("Invalid side", "side");
            }
        }
Beispiel #5
0
        public Vector2 GetNearestOutsidePosition()
        {
            // Get the nearest border
            var        newPosition = Position();
            ScreenSide side        = GetNearestBorder();

            switch (side)
            {
            case ScreenSide.Left:
                newPosition.X = -Width();
                break;

            case ScreenSide.Top:
                newPosition.Y = -Height();
                break;

            case ScreenSide.Right:
                newPosition.X = Game.ViewportAdapter.VirtualWidth + Width();
                break;

            case ScreenSide.Bottom:
                newPosition.Y = Game.ViewportAdapter.VirtualHeight + Height();
                break;

            default:
                break;
            }

            return(newPosition);
        }
        public Vector3 GetRandomizedOutOfBoundsPosition(
            ScreenSide side,
            Vector2 size,
            float offset = 0)
        {
            var halfSize        = GetHalfSizeFor(side, size) + offset;
            var randomComponent = GetRandomComponentFor(side, size);

            switch (side)
            {
            case ScreenSide.Top:
                return(new Vector3(randomComponent, _screenSizeModel.HeightExtendUnits + halfSize, 0));

            case ScreenSide.Bottom:
                return(new Vector3(randomComponent, -(_screenSizeModel.HeightExtendUnits + halfSize), 0));

            case ScreenSide.Left:
                return(new Vector3(-(_screenSizeModel.WidthExtendUnits + halfSize), randomComponent, 0));

            case ScreenSide.Right:
                return(new Vector3(_screenSizeModel.WidthExtendUnits + halfSize, randomComponent, 0));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #7
0
        /*** CONFIG METHODS ***/

        private void SetupAmbiLight()
        {
            dynamic config = JsonConvert.DeserializeObject(File.ReadAllText("config.json"));

            bool   formIsHidden = config.startsHidden;
            double gamma        = config.gamma;

            AmbiLight.multiThreading            = config.multiThreading;
            AmbiLight.scanDepth                 = config.scanDepth;
            AmbiLight.pixelsToSkipPerCoordinate = config.pixelsToSkipPerCoordinate;
            AmbiLight.delay        = config.delay;
            AmbiLight.frameTimeout = config.frameTimeout;
            AmbiLight.previewMode  = config.preview;

            HuePorts   huePorts = new HuePorts(config.devices.ToObject <Device[]>(), gamma);
            ScreenSide right    = new ScreenSide(config.ambiLight.right.screenRegions.ToObject <ScreenRegion[]>(), Direction.Right);
            ScreenSide left     = new ScreenSide(config.ambiLight.left.screenRegions.ToObject <ScreenRegion[]>(), Direction.Left);
            ScreenSide top      = new ScreenSide(config.ambiLight.top.screenRegions.ToObject <ScreenRegion[]>(), Direction.Top);
            ScreenSide bottom   = new ScreenSide(config.ambiLight.bottom.screenRegions.ToObject <ScreenRegion[]>(), Direction.Bottom);

            ScreenSide[] screenSides = new ScreenSide[] { top, right, bottom, left };

            ambiLight = new AmbiLight(screenSides, formIsHidden, huePorts, previewImage);
            Logger.Add("Loaded AmbiLight from config.json");
            Logger.Add("----------------------------");
        }
Beispiel #8
0
        public float GetRandomOutsideAngle(ScreenSide side, int maxAngle, int?topAngle = null)
        {
            var randomAngle = Game.GameManager.Random.Next(-maxAngle, maxAngle);

            if (topAngle.HasValue)
            {
                randomAngle -= topAngle.Value;
            }

            switch (side)
            {
            case ScreenSide.Left:
                randomAngle -= 90;
                break;

            case ScreenSide.Right:
                randomAngle += 90;
                break;

            case ScreenSide.Bottom:
                randomAngle += 180;
                break;

            default:
                break;
            }

            return(randomAngle);
        }
Beispiel #9
0
        /// <summary>
        /// Constructs a button.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="position"></param>
        /// <param name="transitionOnTime"></param>
        /// <param name="transitionOffTime"></param>
        /// <param name="transitionOnSide"></param>
        /// <param name="transitionOffSide"></param>
        public Button(
            string text, 
            Vector2 position, 
            Color color,
            Color selectedColor,
            float scale,
            float selectedScale,
            double selectionTransitionOnTime,
            double selectionTransitionOffTime,
            double transitionOnTime, 
            double transitionOffTime, 
            ScreenSide transitionOnSide, 
            ScreenSide transitionOffSide)
            : base(transitionOnTime, transitionOffTime, transitionOnSide, transitionOffSide, null, position)
        {
            this.text = new TextComponent(text, position);

            this.color = color;
            this.selectedColor = selectedColor;

            this.scale = scale;
            this.selectedScale = selectedScale;

            this.selectionTransition = new Transition(selectionTransitionOnTime, selectionTransitionOffTime);

            this.OnSelection += Button_Selection;
            this.OnDeselection += Button_Deselection;

            this.TabStop = true;
        }
Beispiel #10
0
        private void FillBufferFromScreenWith(ScreenSide screenSide)
        {
            ScreenRegion       currentScreenRegion;
            Collection <Point> currentLedCoordinates;
            int totalRed;
            int totalGreen;
            int totalBlue;
            int totalCoordinates;
            int colorIndex = 0;

            for (int regionIndex = 0; regionIndex < screenSide.screenRegions.Length; regionIndex++)
            {
                currentScreenRegion   = screenSide.screenRegions[regionIndex];
                currentLedCoordinates = currentScreenRegion.coordinates;

                totalRed         = totalGreen = totalBlue = 0;
                totalCoordinates = currentLedCoordinates.Count;

                foreach (Point currentLedCoordinate in currentLedCoordinates)
                {
                    colorIndex = Screen.PrimaryScreen.Bounds.Width * 4 * currentLedCoordinate.Y + currentLedCoordinate.X * 4;

                    totalBlue  += screenBuffer[colorIndex++];
                    totalGreen += screenBuffer[colorIndex++];
                    totalRed   += screenBuffer[colorIndex++];
                }

                Color color = Color.FromArgb(totalRed / totalCoordinates, totalGreen / totalCoordinates, totalBlue / totalCoordinates);

                foreach (Led currentLed in currentScreenRegion.leds)
                {
                    if (huePorts.huePorts[currentLed.device].isEnabled)
                    {
                        huePorts.huePorts[currentLed.device].SetOneLedToColor(currentLed.channel, currentLed.ledIndex, color);
                    }
                }

                if (previewMode)
                {
                    switch (screenSide.direction)
                    {
                    case Direction.Right:
                        colorPreview.SetPixel(19, regionIndex + 1, color);
                        break;

                    case Direction.Left:
                        colorPreview.SetPixel(0, regionIndex + 1, color);
                        break;

                    case Direction.Top:
                        colorPreview.SetPixel(regionIndex, 1, color);
                        break;

                    default:
                        colorPreview.SetPixel(regionIndex, 11, color);
                        break;
                    }
                }
            }
        }
        public float2 GetCurrentEdge(ScreenSide screenSide)
        {
            switch (screenSide)
            {
            case ScreenSide.Top:
                return(new float2(
                           0,
                           CameraPosition.y + HeightExtendUnits));

            case ScreenSide.Bottom:
                return(new float2(
                           0,
                           CameraPosition.y - HeightExtendUnits));

            case ScreenSide.Left:
                return(new float2(
                           CameraPosition.x - WidthExtendUnits,
                           0));

            case ScreenSide.Right:
                return(new float2(
                           CameraPosition.x + WidthExtendUnits,
                           0));

            default:
                throw new ArgumentOutOfRangeException(nameof(screenSide), screenSide, null);
            }
        }
Beispiel #12
0
 // Start is called before the first frame update
 void Start()
 {
     Debug.Log(dx);
     Debug.Log(dy);
     InvokeRepeating("SpawnStar", 0f, spawnRate);
     side = ScreenSide.TOP;
 }
Beispiel #13
0
    public void EndGame(ScreenSide winner)
    {
        gameOver.Play();
        var paddles = GameObject.FindGameObjectsWithTag("Player");
        var balls   = GameObject.FindGameObjectsWithTag("Ball");

        Timer.PauseAll();
        foreach (var pad in paddles)
        {
            pad.GetComponent <Paddle>().Pause();
        }
        foreach (var ball in balls)
        {
            ball.GetComponent <Ball>().Freeze();
        }

        switch (winner)
        {
        case ScreenSide.Left:
            Instantiate(player1Wins);
            break;

        case ScreenSide.Right:
            Instantiate(player2Wins);
            break;
        }
    }
Beispiel #14
0
    /// <summary>
    ///     Give more score to each side, called by outside world.
    /// </summary>
    /// <param name="scoringSide">Which side **scores the point**.</param>
    /// <param name="amountAdded">How many points said side gains.</param>
    void AddScore(ScreenSide scoringSide, int amountAdded)
    {
        switch (scoringSide)
        {
        case ScreenSide.Left:
            leftScore += amountAdded;
            break;

        case ScreenSide.Right:
            rightScore += amountAdded;
            break;
        }
        scoreText.text = leftScore.ToString() + " - " + rightScore;

        var cam = Camera.main;

        Assert.IsNotNull(cam);
        if (leftScore >= ConfigurationUtils.PointsToWin)
        {
            cam.GetComponent <GameOver>()
            .EndGame(ScreenSide.Left);
        }
        else if (rightScore >= ConfigurationUtils.PointsToWin)
        {
            cam.GetComponent <GameOver>()
            .EndGame(ScreenSide.Right);
        }
    }
Beispiel #15
0
        public void Init(ScreenSide side)
        {
            ScreenSide = side;

            bool isWide;
            bool isNegativeOffset;

            Vector2 size;
            Vector3 position;

            switch (side)
            {
            case ScreenSide.Top:
                isWide           = true;
                isNegativeOffset = false;
                break;

            case ScreenSide.Right:
                isWide           = false;
                isNegativeOffset = false;
                break;

            case ScreenSide.Bottom:
                isWide           = true;
                isNegativeOffset = true;
                break;

            case ScreenSide.Left:
                isWide           = false;
                isNegativeOffset = true;
                break;

            default:
                throw ExceptionUtil.ArgumentException(() => side);
            }

            float negativePositionMultiplier = isNegativeOffset ? -1f : 1f;
            float positionOffset             = ColliderWidth * -0.5f;

            if (isWide)
            {
                size = new Vector2(SpaceUtil.WorldMapSize.x, ColliderWidth);

                float y = (SpaceUtil.WorldMap.Top.y - positionOffset) * negativePositionMultiplier;
                position = new Vector3(0, y);
            }
            else
            {
                size = new Vector2(ColliderWidth, SpaceUtil.WorldMapSize.y);

                float x = (SpaceUtil.WorldMap.Right.x - positionOffset) * negativePositionMultiplier;
                position = new Vector3(x, 0);
            }

            var collider = GetComponent <BoxCollider2D>();

            collider.size = size;
            collider.transform.position = position;
        }
Beispiel #16
0
    void Gameover(ScreenSide side)
    {
        GameObject      instance = Instantiate(Resources.Load("gameovermenu")) as GameObject;
        GameOverMessage game     = instance.GetComponent <GameOverMessage>();

        game.SetWinner(side);
        AudioManager.Play(AudioClipName.GameOver);
    }
    /// <summary>
    /// Ends the game and displays the winner message
    /// </summary>
    /// <param name="winner">winning side</param>
    public void EndGame(ScreenSide winner)
    {
        // instantiate prefab and set score
        GameObject      gameOverMessage       = Instantiate(Resources.Load("GameOverMessage")) as GameObject;
        GameOverMessage gameOverMessageScript = gameOverMessage.GetComponent <GameOverMessage>();

        gameOverMessageScript.SetWinner(winner);
    }
Beispiel #18
0
    void QueueGameOver(ScreenSide side, int points)
    {
        //Object.Instantiate(Resources.Load("GameOverMessage"));
        GameOverMessage instance = Instantiate(Resources.Load("GameOverMessage", typeof(GameOverMessage))) as GameOverMessage;

        instance.SetWinner(side);
        AudioManager.Play(AudioClipName.GameOver);
    }
Beispiel #19
0
 public void InvokeFreezeEffect(ScreenSide side)
 {
     switch (base.GetBallType())
     {
     case BallType.Freezer:
         freezePaddleEvent.Invoke(side, duration);
         break;
     }
 }
Beispiel #20
0
 /// <summary>
 /// Sets the winning side in the message to the given side
 /// </summary>
 /// <param name="winner">winner</param>
 public void SetWinner(ScreenSide winner)
 {
     if (winner == ScreenSide.Left)
     {
         messageText.text = "Game Over!\n\nLeft player won!";
     }
     else
     {
         messageText.text = "Game Over!\n\nRight player won!";
     }
 }
Beispiel #21
0
 /// <summary>
 /// Constructs a label.
 /// </summary>
 /// <param name="text"></param>
 /// <param name="position"></param>
 /// <param name="transitionOnTime"></param>
 /// <param name="transitionOffTime"></param>
 /// <param name="transitionOnSide"></param>
 /// <param name="transitionOffSide"></param>
 public Label(
     string text,
     Vector2 position, 
     double transitionOnTime, 
     double transitionOffTime, 
     ScreenSide transitionOnSide,
     ScreenSide transitionOffSide)
     : base(transitionOnTime, transitionOffTime, transitionOnSide, transitionOffSide, null, position)
 {
     this.text = new TextComponent(text, position);
 }
Beispiel #22
0
 // Private constructor
 private GlobalState()
 {
     ostrichGameComplete = false;
     peacockGameComplete = false;
     seagullGameComplete = false;
     talkedToSeagull     = false;
     talkedToPenguin     = false;
     talkedToWhale       = false;
     staircaseUnlocked   = false;
     fishingRodGet       = false;
     exitSide            = ScreenSide.NONE;
 }
Beispiel #23
0
 /// <summary>
 /// Adds the given points to the given side
 /// </summary>
 /// <param name="side">screen side</param>
 /// <param name="points">points to add</param>
 void AddPoints(ScreenSide side, int points)
 {
     // add points and change text
     if (side == ScreenSide.Left)
     {
         leftScore += points;
     }
     else
     {
         rightScore += points;
     }
     scoreText.text = leftScore + ScoreSeparator + rightScore;
 }
Beispiel #24
0
    //functoin to add the times the ball gets out of the scene
    public void AddToScore(int realPoints, ScreenSide scoreSide)
    {
        if (scoreSide == ScreenSide.Left)
        {
            LScore += realPoints;
        }
        else
        {
            RScore += realPoints;
        }

        Stext.text = LScore.ToString() + ScoreDash + RScore.ToString();
    }
 /// <summary>
 /// Speedup the specified speedupSide and duration.
 /// </summary>
 /// <param name="speedupSide">Speedup side.</param>
 /// <param name="duration">Duration.</param>
 void Speedup(ScreenSide speedupSide, float duration)
 {
     speedup = true;
     if (!speedupTimer.Running)
     {
         speedupTimer.Duration = duration;
         speedupTimer.Run();
     }
     else
     {
         speedupTimer.AddTime(duration);
     }
 }
Beispiel #26
0
 /// <summary>
 ///     Used by others to add hits for each side.
 /// </summary>
 /// <param name="side">Which side gets the hit.</param>
 /// <param name="nHitsToAdd">How many hits they get, usually 1.</param>
 void AddHits(ScreenSide side, int nHitsToAdd)
 {
     if (side == ScreenSide.Left)
     {
         nLeftHits        += nHitsToAdd;
         leftHitsText.text = "Hits: " + nLeftHits;
     }
     else if (side == ScreenSide.Right)
     {
         nRightHits        += nHitsToAdd;
         rightHitsText.text = "Hits: " + nRightHits;
     }
 }
Beispiel #27
0
 //functon to add the time the ball hits
 public void AddPoints(int points, ScreenSide DefaultLeft)
 {
     if (DefaultLeft == ScreenSide.Left)
     {
         Lbounces            += points;
         LBouncerCounter.text = ScorePrefix + Lbounces.ToString();
     }
     else
     {
         Rbounces            += points;
         RBouncerCounter.text = ScorePrefix + Rbounces.ToString();
     }
 }
Beispiel #28
0
 /// <summary>
 ///     Add hits for each paddle
 /// </summary>
 public void AddHits(ScreenSide side, float nHitsToAdd)
 {
     if (side == ScreenSide.Left)
     {
         lefth        += nHitsToAdd;
         leftHits.text = LeftHitsPrefix + lefth.ToString();
     }
     else if (side == ScreenSide.Right)
     {
         righth        += nHitsToAdd;
         rightHits.text = RightHitsPrefix + righth.ToString();
     }
 }
Beispiel #29
0
 /// <summary>
 /// Does the freeze processing
 /// </summary>
 public void Freeze(ScreenSide fside, float ftime)
 {
     // Check which side got frozen
     if (side == fside)
     {
         if (freezerTimer.Running)
         {
             freezerTimer.FrozenTime = ftime;
         }
         freezerTimer.Run();
         frozen = true;
     }
 }
Beispiel #30
0
    static void SpeedUp(ScreenSide s, int t)
    {
        if (!speedy)
        {
            speedupTimer.Duration = ConfigurationUtils.SpeedupDuration;
        }
        else
        {
            speedupTimer.Duration += ConfigurationUtils.SpeedupDuration;
        }

        speedy = true;
        speedupTimer.Run();
    }
Beispiel #31
0
    /// <summary>
    ///     Control score of game
    /// </summary>
    public void AddScore(ScreenSide scoringSide, float amountAdded)
    {
        switch (scoringSide)
        {
        case ScreenSide.Left:
            lscore += amountAdded;
            break;

        case ScreenSide.Right:
            rscore += amountAdded;
            break;
        }
        scoreText.text = lscore.ToString() + ScorePrefix + rscore;
    }
Beispiel #32
0
 /// <summary>
 /// Adds the given hits to the given side
 /// </summary>
 /// <param name="side">screen side</param>
 /// <param name="hits">hits to add</param>
 void AddHits(ScreenSide side, int hits)
 {
     // add hits and change text
     if (side == ScreenSide.Left)
     {
         leftHit         += hits;
         leftHitText.text = HitsPrefix + leftHit;
     }
     else
     {
         rightHit         += hits;
         rightHitText.text = HitsPrefix + rightHit;
     }
 }
Beispiel #33
0
 public Control(
     double transitionOnTime, 
     double transitionOffTime,
     ScreenSide transitionOnSide, 
     ScreenSide transitionOffSide, 
     TextComponent text,
     Vector2 position)
 {
     transition = new Transition(transitionOnTime, transitionOffTime);
     this.transitionOnSide = transitionOnSide;
     this.transitionOffSide = transitionOffSide;
     this.text = text;
     Position = position;
 }
Beispiel #34
0
    /// <summary>
    /// To calculate the score
    /// </summary>
    /// <param name="scoringSide"></param>
    /// <param name="amountAdded"></param>
    public void AddScore(ScreenSide scoredSide, float amountAdded)
    {
        if (scoredSide == ScreenSide.Left)
        {
            scoreLeft += amountAdded;
        }

        else if (scoredSide == ScreenSide.Right)
        {
            scoreRight += amountAdded;
        }

        scoreText.text = scoreLeft.ToString() + ScorePrefix + scoreRight.ToString();
    }
    // Update is called once per frame.
    //    public void Update(){
    //        // Below Debug Log call is to check for random idle timings.
    //        //UnityEngine.Debug.Log("TIMER COUNT " + releaseWatch.ElapsedMilliseconds);
    //        //UnityEngine.Debug.Log("idleWatch: " + idleKeyWatch.ElapsedMilliseconds); // + '\n' + "idleTime: " + IDLE_TRIGGER_LIMIT);
    //
    //    }
    /// <summary>
    /// Update is called once per frame
    /// </summary>
    public void Update()
    {
        /*Below Debug Log call is to check for random idle timings*/
           // UnityEngine.Debug.Log("TIMER COUNT " + releaseWatch.ElapsedMilliseconds);
        //UnityEngine.Debug.Log("idleWatch: " + idleKeyWatch.ElapsedMilliseconds); // + '\n' + "idleTime: " + IDLE_TRIGGER_LIMIT);

        //UnityEngine.Debug.Log("SIZE " + Screen.width.ToString() + ", " + Screen.height.ToString());
        //if (!touchController.GetLastFingerPosition().Equals(TouchController.NULL_VECTOR))
          //  {
            //UnityEngine.Debug.Log("TYPE " + touchController.ReturnTouchType());
        //    UnityEngine.Debug.Log("DIST " + Vector2.Distance(touchController.GetLastFingerPosition(), Camera.mainCamera.WorldToScreenPoint(playerObject.transform.position)));
        //}

        //UnityEngine.Debug.Log("LAST " + justReleasedFingerPos);
        //UnityEngine.Debug.Log("ANGLE " + fingerSwipeAngle);
        /*if(playerObject){
            UnityEngine.Debug.Log("PLAYER " + Camera.mainCamera.WorldToScreenPoint(playerObject.transform.position));
        }*/
        //UnityEngine.Debug.Log("FINGER POS " + touchController.GetLastFingerPosition());

        if(gameStateManagerRef.inGame){
            // Initialize any left over managers, objects, refs, etc.
            InitRemainingRefs();

            // Could have used any of the managers but chose tearManagerRef, but this ensures no code gets executed until
            //	everything is initialized
            if(tearManagerRef){
                if(touchController.ReturnTouchType() == TouchType.NONE){
                    movingTornPiece = false;
                    currentDirection = ScreenSide.NONE;
                }
                if(tearManagerRef.HaveTornOnce && !tornPieceInitiated){
                    tornPiece = GameObject.Find("paper_CuttPieceOfPaper");
                    tornPieceInitiated = true;
                }
                // Determine if screen orientation or size has changed and re-assign touch positions/limits.
                HandleScreenChanges();

                // Sets touch globals such current/previous press state swipe detection and jump detectoin.
                SetTouchGlobals();

                // Detect first last and in between states/pos' for touch input positions.
                DetectFirstInput();
                DetectBetweenInput();
                DetectLastInput();

                // After horizontal and vertical movements are set determine player animation direction
                SetPlayerDirection();

                if(currPressState == PressState.UP && releaseSet){
                    ResetTouchFields();
                }

                // Update idle and keydown watches.
                UpdateInputWatches();

                // Limits time ellapsed on watches.
                LimitWatches();

                // Update and set new animations to be played in Animation Manager.
                UpdateAnimations();
            }
            /*else{
                UnityEngine.Debug.Log("MANAGERS ARE NULL");
            }*/
        }
    }
    /// <summary>
    /// Returns true if the player is attempting to move the player left or right on screen
    /// </summary>
    /// <param name="side"></param>
    /// <returns></returns>
    private bool PlayerMoveHorizontalTriggered(ScreenSide side)
    {
        if (gameStateManagerRef.inGame)
        {
            if (tearScript != null)
            {
                if (tearScript.GetMovingPiece() || tearScript.GetRotatingPiece())
                {
                    return false;
                }
            }
        }

        if((Input.GetKey(moveLeft) && side.Equals(ScreenSide.LEFT)) ||
           (Input.GetKey(moveRight) && side.Equals(ScreenSide.RIGHT)))
        {

            return true;
        }

        else
        {
            if(touchController.GetLastFingerPosition().Equals(TouchController.nullVector))
            {
                return false;
            }

            else
            {

                if
                    // did the player actually trigger a keyboard input
                ((touchController.ReturnTouchType() == TouchType.TAP ||
                    touchController.ReturnTouchType() == TouchType.DRAG) &&

                    // and did the player hit the viable horizontal section of the screen
                    ((side.Equals(ScreenSide.LEFT) &&
                    touchController.GetLastFingerPosition().x <= leftSideTouchLimitPos) ||
                    (side.Equals(ScreenSide.RIGHT) &&
                    touchController.GetLastFingerPosition().x >= rightSideTouchLimitPos)) &&

                    // and did the player hit the viable vertical section of the screen
                    touchController.GetLastFingerPosition().y <= bottomTouchLimitPos)
                {
                    //UnityEngine.Debug.Log("MOVING " + side.ToString());
                    return true;
                }

                return false;
            }
        }
    }
    // Returns true if the player is attempting to move the player left or right on screen.
    private bool PlayerMoveHorizontalTriggered(ScreenSide side)
    {
        if((!tearManagerRef.GetMovingPiece() && fingerGesture == FingerGesture.MOVE &&
                !foldRef.currentlyFolding &&
                (!tearManagerRef.PlayerCurrentlyTearing

            //This selection of code was commented out for controls by Douglas Weller
            /*||
                !worldCollisionRef.PointInsideObject(paperObject, touchController.GetLastFingerPosition())*/

            )) ||
                !gameStateManagerRef.OnMobileDevice()){
            if((Input.GetKey(wasdLeft) || Input.GetKey(arrowLeft)) ||
                    (Input.GetKey(wasdRight) || Input.GetKey(arrowRight))){
                if(Input.GetKey(wasdLeft) || Input.GetKey(arrowLeft)){
                    lastKeyboardSide = ScreenSide.RIGHT;
                }
                else if((Input.GetKey(wasdLeft) && Input.GetKey(wasdRight)) ||
                        (Input.GetKey(arrowLeft) && Input.GetKey(arrowRight))){
                    lastKeyboardSide = ScreenSide.RIGHT;
                }
                else{
                    lastKeyboardSide = ScreenSide.LEFT;
                }
                //UnityEngine.Debug.Log("WATCH " + justPressedWatch.ElapsedMilliseconds);
                //UnityEngine.Debug.Log("WALK");
                //UnityEngine.Debug.Log("TRUE");
                return true;
            }
            else{
                if(touchController.GetLastFingerPosition().Equals(TouchController.NULL_VECTOR)){
                    //UnityEngine.Debug.Log("FALSE");
                    return false;
                }
        else{
                    //if(
                            // did the player actually trigger a keyboard input
                            /*(touchController.ReturnTouchType() == TouchType.TAP ||
                            touchController.ReturnTouchType() == TouchType.DRAG) &&*/
                        /*
                            // and did the player hit the viable horizontal section of the screen
                            ((side.Equals(ScreenSide.LEFT) && ReturnSidePressed(touchController.GetLastFingerPosition()) == ScreenSide.LEFT) ||
                            ((side.Equals(ScreenSide.RIGHT) && ReturnSidePressed(touchController.GetLastFingerPosition()) == ScreenSide.RIGHT))) &&

                            // and did the player hit the viable vertical section of the screen
                            touchController.GetLastFingerPosition().x <= bottomTouchLimitPos.x &&
                            touchController.GetLastFingerPosition().y <= bottomTouchLimitPos.y)*/{
                        lastSidePressed = side;
                        //UnityEngine.Debug.Log("TRUE");
                        //UnityEngine.Debug.Log("MOVING " + side.ToString());
                        return true;
                    }

                    //UnityEngine.Debug.Log("FALSE");
                    return false;
            }
            }
        }

        /*else{
            UnityEngine.Debug.Log("FALSE");
        }*/
        return false;
    }
Beispiel #38
0
        /// <summary>
        /// Returns the reflected coordinate (x or y) based on what side of the screen the entity has passed.
        /// </summary>
        /// <param name="side">The side of the screen the entity has passed</param>
        /// <param name="screenWidth">The width of the screen</param>
        /// <param name="screenHeight">The height of the screen</param>
        /// <returns>The reflected x or y coordinate</returns>
        private float GetReflectCoord(ScreenSide side, float screenWidth, float screenHeight)
        {
            // Get the side, and return the corresponding x-coordinate
            switch (side)
            {
                //----------------
                // X Reflection
                case ScreenSide.Right:
                    return -EffectiveWidth;

                case ScreenSide.Left:
                    return (screenWidth + EffectiveWidth);
                //----------------

                //----------------
                // Y Reflection
                case ScreenSide.Top:
                    return (screenHeight + EffectiveHeight);

                case ScreenSide.Bottom:
                    return -EffectiveHeight;
                //----------------

                // If we got this far, something went horribly wrong
                default:
                    throw new ArgumentException("Invalid side", "side");
            }
        }
    // Resets fields used for detecting idle input and differentiating between moving and jumping.
    private void ResetTouchFields()
    {
        if (controllerRef.getGrounded())
        {
            fingerSwipeAngle = SWIPE_ANGLE_RESET_VALUE;
        }

        releaseSet = false;
        pressSet = false;
        lastSidePressed = ScreenSide.NONE;
        fingerIdlePos = TouchController.NULL_VECTOR;
        justPressedFingerPos = TouchController.NULL_VECTOR;
        justReleasedFingerPos = TouchController.NULL_VECTOR;
        justPressedSide = ScreenSide.NONE;
        justReleasedSide = justPressedSide;
    }
    // Use this for initialization.
    public void Start()
    {
        // Keeping GameObject component grabbing consistent among classes. - J.T.
        GameObject mainObject = GameObject.FindGameObjectsWithTag("MainObject")[0];

        if(GameObject.FindGameObjectsWithTag("MainObject").Length > 1){
            GameObject[] mainObjectList = GameObject.FindGameObjectsWithTag("MainObject");
            for(int i = 0; i < mainObjectList.Length; ++i){
                if(mainObjectList[i].GetComponent<GameStateManager>().objectSaved){
                    mainObject = mainObjectList[i];
                }
            }
        }

        gameStateManagerRef = mainObject.GetComponent <GameStateManager>();
        gameStateManagerRef.EnsureGameScriptsAdded();
        gameStateManagerRef.EnsureCoreScriptsAdded();
        screenManagerRef = mainObject.GetComponent<ScreenManager>();
        animManagerRef = mainObject.GetComponent<AnimationManager>();
        worldCollisionRef = mainObject.GetComponent<WorldCollision>();
        touchController = gameObject.GetComponent<TouchController>();
        soundManagerRef = gameStateManagerRef.GetSoundManager();
        paperObject = GameObject.FindGameObjectWithTag("background");
        tearBorder = GameObject.FindGameObjectWithTag("DeadSpace");
        foldBorder = GameObject.FindGameObjectWithTag("foldborder");
        unfoldBorder = GameObject.FindGameObjectWithTag("unfoldborder");
        unfoldBlocker = GameObject.FindGameObjectWithTag("RayTraceBlocker");
        moveBorder = GameObject.FindGameObjectWithTag("insideBorder");
        menuButton = GameObject.Find("MenuButton_Prefab");
        restartButton = GameObject.Find("RestartButton_Prefab");
        moveMode = true;
        tearMode = false;
        foldMode = false;
        //Keeping old code here in case something gets broken. - J.T.
        // Ensures all necessary scripts are added for the MainObject.
        /*
        gameStateManagerRef = gameObject.GetComponent<GameStateManager>();
        gameStateManagerRef.EnsureCoreScriptsAdded();
        gameStateManagerRef.EnsureGameScriptsAdded();
        screenManagerRef = gameObject.GetComponent<ScreenManager>();
        animManagerRef = gameObject.GetComponent<AnimationManager>();
        worldCollisionRef = gameObject.GetComponent<WorldCollision>();
        touchController = gameObject.GetComponent<TouchController>();
        */
        idleTriggerLimit = Random.Range (1000, 3000);
        keyDownWatch = new Stopwatch();
        idleKeyWatch = new Stopwatch();
        releaseWatch = new Stopwatch();
        justPressedWatch = new Stopwatch();
        playerBottomCollisionWatch = new Stopwatch();
        idlePlayerWatch = new Stopwatch();

        watchList.Add(keyDownWatch);
        watchList.Add(idleKeyWatch);
        watchList.Add(releaseWatch);
        watchList.Add(justPressedWatch);
        watchList.Add(playerBottomCollisionWatch);
        watchList.Add(idlePlayerWatch);

        wasdRight = KeyCode.D;
        wasdLeft = KeyCode.A;
        arrowRight = KeyCode.RightArrow;
        arrowLeft = KeyCode.LeftArrow;
        keyJump = KeyCode.Space;

        hasHorizontalCollision = false;
        currentDirection = ScreenSide.NONE;
        tornPieceInitiated = false;
        movingTornPiece = false;
    }