示例#1
0
    void Start()
    {
        GameManager.instance.onFreeKickBegin   += SetFreeKickButtonToPressed;
        GameManager.instance.onTurnStart       += SetCurrentlyAvailable;
        GameManager.instance.onCornerEnd       += SetCurrentlyAvailable;
        GameManager.instance.onCornerBegin     += OnRestartMoveBegin;
        GameManager.instance.onOutBegin        += OnRestartMoveBegin;
        GameManager.instance.onPlayerTurnEnd   += SetCurrentlyAvailable;
        GameManager.instance.onPlayerTurnStart += SetCurrentlyAvailable;
        GameManager.instance.onMatchEnd        += SetCurrentlyAvailable;
        GameManager.instance.onMatchEnd        += TurnOffTheStartButton;
        GameManager.instance.onPause           += OnGamePause;
        GameManager.instance.onUnpause         += OnGamePause;
        GameManager.instance.onHardPause       += OnGamePause;
        GameManager.instance.onHardUnpause     += OnGamePause;
        GameManager.instance.onHalfTime        += OnHalfTime;
        pitch   = GameObject.Find("Pitch").GetComponent <PitchManager>();
        buttons = new Dictionary <string, Button>();
        foreach (Button g in buttonParent.transform.GetComponentsInChildren <Button>())
        {
            buttons.Add(g.name, g);
        }
        buttons.Add("startButton", startButton);

        InitButtons();
    }
    /* #endregion */
    /* ---------------------------------------------------------------------------------------- */

    /* #region ---- Toggle OverlayGrid -------------------------------------------------------- */
    public void ToggleOverlayGrid()
    {
        PitchManager PitchManager = MatchManager.PitchManager;
        PitchGrid    PitchGrid    = MatchManager.PitchGrid;

        if (!_gridOn)
        {
            _gridOn = true;
        }
        else
        {
            _gridOn = false;
        }

        for (int x = 1; x <= MatchManager.PitchGrid.PitchSettings.PitchWidth; x++)
        {
            for (int z = 1; z <= MatchManager.PitchGrid.PitchSettings.PitchLength; z++)
            {
                if (_gridOn)
                {
                    GameObject overlayTile = (GameObject)Instantiate(gridOverlayPrefab);
                    overlayTile.transform.position = new Vector3(
                        overlayTile.transform.position.x - PitchGrid.XOffset + x,
                        overlayTile.transform.position.y,
                        overlayTile.transform.position.z - PitchGrid.ZOffset + z);
                    overlayTile.transform.SetParent(this.transform);
                    _gridOverlay[x, z] = overlayTile;
                }
                else
                {
                    Destroy(_gridOverlay[x, z]);
                }
            }
        }
    }
示例#3
0
    void Spawn()
    {
        if (Constants.Endless)
        {
            spawnTimer = spawnTime;
            spawnTime *= Constants.EndlessSpawnDecay;

            int from = Random.Range(Constants.MinNote, Constants.MaxNote + 1);
            int to   = Random.Range(Constants.MinNote, Constants.MaxNote + 1);
            while (to == from)
            {
                to = Random.Range(Constants.MinNote, Constants.MaxNote + 1);
            }

            floorManager.LightOn(from, true);
            PersonScript person = factory.CreatePerson();
            person.Appear(from, to);
            clients.Add(person);
        }
        else
        {
            int from = Constants.Level[curIdx];
            int to   = Constants.Level[curIdx + 1];

            string noteName = PitchManager.NoteToName(from);
            UpText.text   = noteName;
            DownText.text = noteName;
            floorManager.LightOn(from, true);
            PlayNote(from);
            PersonScript person = factory.CreatePerson();
            person.Appear(from, to);
            clients.Add(person);
        }
    }
示例#4
0
    IEnumerator ResumeGame(ArrayList toLightOn, int toLightOff)
    {
        yield return(new WaitForSeconds(1));

        floorManager.LightOff(toLightOff);
        foreach (int note in toLightOn)
        {
            floorManager.LightOn(note, false);
            if (!Constants.Endless)
            {
                PlayNote(note);
                string noteName = PitchManager.NoteToName(note);
                UpText.text   = noteName;
                DownText.text = noteName;
            }
        }

        if (Constants.Endless)
        {
            Constants.GameOn = true;
        }
        else
        {
            if (toLightOn.Count > 0 || clients.Count == 0)
            {
                curIdx++;
                UpdateTarget();
            }
            else
            {
                Constants.GameOn = true;
            }
        }
    }
示例#5
0
    void Start()
    {
        factory      = GetComponent <PersonFactory>();
        floorManager = GetComponent <FloorManager>();
        source       = GetComponent <AudioSource>();
        refFreq      = PitchManager.NoteToPitch(60); // C4

        InputController.OnDoubleTap += OnDoubleTap;
        InputController.OnSingleTap += OnSingleTap;

        Constants.GameOn = false;
        score            = 0;
        timer            = 0;
        gameEnded        = false;
        timerBarPos      = TimerBar.transform.position;
        clients          = new ArrayList();

        if (Constants.Endless)
        {
            spawnTime = Constants.EndlessInitSpawnTime;
            timer     = Constants.EndlessPatience;
        }
        else
        {
            curIdx   = 0;
            levelLen = Constants.Level.Length;
            timer    = Constants.NormalPatience;
        }

        Invoke("StartGame", 1);
    }
示例#6
0
        void Start()
        {
            joints = Model.All <KinectJoint>();

            logger.AddLogAppender <ConsoleAppender>();

            pitchManager = gameManager.GetComponentInChildren <PitchManager>();
        }
示例#7
0
    void Start()
    {
        float worldScreenWidth = (Camera.main.orthographicSize * 2 / Screen.height) * Screen.width;

        floorsOn = new ArrayList();
        floors   = new GameObject[Constants.MaxNote - Constants.MinNote + 1];
        for (int note = Constants.MinNote; note <= Constants.MaxNote; note++)
        {
            Vector3    pos   = new Vector3(0, NoteToPos(note));
            GameObject floor = Instantiate(FloorPrefab, pos, Quaternion.identity);
            floors[note - Constants.MinNote] = floor;

            var left     = floor.transform.Find("left_floor").GetComponent <SpriteRenderer>();
            var right    = floor.transform.Find("right_floor").GetComponent <SpriteRenderer>();
            var left_bg  = floor.transform.Find("left_bg").GetComponent <SpriteRenderer>();
            var right_bg = floor.transform.Find("right_bg").GetComponent <SpriteRenderer>();
            var text     = floor.transform.Find("name").GetComponent <TextMesh>();

            Vector3 bgScale = left_bg.transform.localScale;
            bgScale.x = worldScreenWidth / (2 * left_bg.sprite.bounds.size.x);

            left_bg.transform.localScale  = bgScale;
            right_bg.transform.localScale = bgScale;
            left_bg.color  = GetColor(note);
            right_bg.color = GetColor(note);

            Vector3 left_bg_pos = left_bg.transform.position;
            left_bg_pos.x = -worldScreenWidth / 4;
            left_bg.transform.position = left_bg_pos;

            Vector3 right_bg_pos = right_bg.transform.position;
            right_bg_pos.x = worldScreenWidth / 4;
            right_bg.transform.position = right_bg_pos;

            Vector3 leftPos = left.transform.position;
            leftPos.x = -worldScreenWidth / 4 - 1;
            left.transform.position = leftPos;

            Vector2 leftSize = left.size;
            leftSize.x = worldScreenWidth / 2 - 2;
            left.size  = leftSize;

            Vector3 rightPos = right.transform.position;
            rightPos.x = worldScreenWidth / 4 + 1;
            right.transform.position = rightPos;

            Vector2 rightSize = right.size;
            rightSize.x = worldScreenWidth / 2 - 2;
            right.size  = rightSize;

            text.text = PitchManager.NoteToName(note);

            Vector3 textPos = text.transform.position;
            textPos.x = worldScreenWidth / 2 - 1;
            text.transform.position = textPos;
        }
    }
示例#8
0
    void PlayNote(int note)
    {
        float targetFreq = PitchManager.NoteToPitch(note);

        source.clip   = DoClip;
        source.pitch  = targetFreq / refFreq;
        source.volume = 1;
        source.Play();
    }
示例#9
0
    /* #endregion */

    /* #region ---- Reset all tiles to none viable movement targets --------------------------- */
    private void setAllTilesNoneViableTarget(PitchManager PitchManager)
    {
        for (int x = 1; x <= MatchManager.PitchGrid.PitchSettings.PitchWidth; x++)
        {
            for (int z = 1; z <= MatchManager.PitchGrid.PitchSettings.PitchLength; z++)
            {
                PitchManager.GetPitchTile(x, z).IsViableTarget = false;
            }
        }
    }
 /* #region ---- Load PitchManager -------------------------------------------------------- */
 private void loadPitchManager()
 {
     if (PitchManager != null)
     {
         PitchManager.ResetInstance();
     }
     else
     {
         PitchManager = ScriptableObject.CreateInstance <PitchManager>();
     }
 }
示例#11
0
    // Use this for initialization
    void Awake()
    {
        PitchManager.instance = this;
        this.cMajorScale      = new List <float>();

        this.audioSourceMasterList = new List <AudioSource>();

        this.CreateCMajorScale();

        bassNote.SetupNote(false);
    }
    /* #endregion */

    /* #region ---- 2. SETUP & START MOVEMENT ------------------------------------------------- */
    private void movePlayerSetup(PitchTile targetTile)
    {
        MoveTargetTile = targetTile;
        MoveSourceTile = MatchManager.PitchManager.GetPitchTile(Player.CoordX, Player.CoordZ);

        PitchManager PitchManager = MatchManager.PitchManager;
        PathFinding  PathFinding  = MatchManager.PitchGrid.PathFinding;

        waypoints = PathFinding.GetPathToTarget(MoveTargetTile, Player);

        MatchManager.MatchPlayerManager.setPlayerInActionState(true);
        waypoints.RemoveAt(0);
        CurrentAction = PlayerAction.Move;
    }
示例#13
0
    void Update()
    {
        if (!Constants.GameOn)
        {
            return;
        }

        float note = PitchManager.PitchToNote(PitchManager.PitchValue);

        note = Mathf.Min(note, Constants.MaxNote);
        note = Mathf.Max(note, Constants.MinNote);
        Vector3 target = new Vector3(0, FloorManager.ApproxNoteToPos(note));

        Vector3 prevVelocity = velocity;
        Vector3 prevPos      = transform.position;

        transform.position = Vector3.SmoothDamp(transform.position, target, ref velocity, SmoothTime);

        bool was0 = Vector3.SqrMagnitude(prevVelocity - Vector3.zero) < Constants.VecPrecision;
        bool is0  = Vector3.SqrMagnitude(velocity - Vector3.zero) < Constants.VecPrecision;

        if (!was0 && is0)
        {
            if (FloorManager.AtFloor(note))
            {
                int floor = Mathf.RoundToInt(note);
                stopTimer = Constants.StopDelay;
                stopFloor = floor;
            }
        }
        else if (was0 && is0)
        {
            int curFloor = FloorManager.PosToNote(transform.position.y);
            if (curFloor == stopFloor && stopTimer > 0)
            {
                stopTimer -= Time.deltaTime;
                if (stopTimer <= 0)
                {
                    stopTimer = 0;
                    PitchManager.PitchValue = PitchManager.NoteToPitch(stopFloor);
                    Vector3 floorPos = new Vector3(0, FloorManager.NoteToPos(stopFloor));
                    transform.position = floorPos;
                    animator.SetTrigger(stopTrigger);
                    gameLogic.StoppedAt(stopFloor);
                }
            }
        }
    }
    // Use this for initialization
    void Awake()
    {
        //if not, set instance to this
        if (instance == null)
        {
            instance = this;
        }
        //If instance already exists and it's not this:
        else if (instance != this)
        {
            //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
            Destroy(gameObject);
        }


        //Sets this to not be destroyed when reloading scene
        DontDestroyOnLoad(gameObject);

        pitchManager = GetComponent <PitchManager>();
        InitGame();
    }
示例#15
0
    /* #endregion */
    /* ======================================================================================== */

    /* #region ==== D R A W  P A T H  L I N E ================================================= */

    /* #region ---- Draw movement path line from active player to target tile ----------------- */
    public void Draw(PitchTile targetIn)
    {
        if (MatchManager.MatchPlayerManager.CurrentActivePlayer.PlayerMode == PlayerMode.Move)
        {
            if (!MatchManager.MatchPlayerManager.PlayInAction)
            {
                PitchManager PitchManager = MatchManager.PitchManager;
                PitchGrid    PitchGrid    = MatchManager.PitchGrid;
                MatchPlayer  Player       = MatchManager.MatchPlayerManager.GetActivePlayer();


                /* #region ---- Reset Path ----------------------------------------- */
                ClearPlayerMovePathLines();
                setAllTilesNoneViableTarget(PitchManager);
                ResetAccMoveCost();
                MatchManager.PitchGrid.DeactivateMoveTargetOverlay();

                /* #endregion ------------------------------------------------------ */

                /* #region ---- Set new Path to target ----------------------------- */
                List <PitchTile> pathToTarget = PitchGrid.PathFinding.GetPathToTarget(targetIn, Player);
                listLinePoints = new List <Vector3>();

                /* #endregion ------------------------------------------------------ */

                /* #region ---- Draw Path Line & Rotate Player --------------------- */
                if (pathToTarget != null)
                {
                    /* #region ---- Player Calculate AP cost for rotation - */
                    int rotation = Player.GetRotationIndicator(pathToTarget[1].transform);
                    AccumulatedMoveCost = Player.CalcRotationApCost(rotation);

                    /* #endregion --------------------------------------------------- */

                    /* #region ---- Add to waypoints to List & update HUD ---------- */
                    GameObject PathLineObject = MatchManager.InstantiateGameObject(PitchGrid.PathLinePrefab);
                    PathLineObject.name = "PlayerMove PathLine";
                    LineRenderer lineRenderer = PathLineObject.GetComponent <LineRenderer>();
                    int          counter      = 0;
                    foreach (PitchTile pathTile in pathToTarget)
                    {
                        counter++;
                        //TODO: QuickFix: Find out why CurrentActionPoints has to be reduced by one for the player to not exceed CurrentActionPoints
                        if (Player.CurrentActionPoints - 1 >= AccumulatedMoveCost)
                        {
                            Vector3 linePoint = new Vector3(
                                pathTile.transform.position.x,
                                PathLineObject.transform.position.y,
                                pathTile.transform.position.z);

                            listLinePoints.Add(linePoint);

                            if (counter != 1)
                            {
                                AccumulatedMoveCost += pathTile.CostToEnter;
                            }
                            pathTile.IsViableTarget = true;
                        }

                        updateAPCostInHUD(AccumulatedMoveCost);
                    }
                    /* #endregion --------------------------------------------------- */

                    /* #region ---- Draw line and target tile overlay --------------- */
                    lineRenderer.positionCount = listLinePoints.Count;
                    activateTargetOverlay(listLinePoints);
                    lineRenderer.SetPositions(listLinePoints.ToArray());
                    /* #endregion --------------------------------------------------- */
                }

                /* #endregion ------------------------------------------------------ */
            }
        }
    }
    /* #endregion */
    /* ======================================================================================== */

    /* #region ==== C R E A T E  G R A P H ==================================================== */
    public void AddNeighbourTiles()
    {
        PitchManager PitchManager = MatchManager.PitchManager;
        int          pitchWidth   = MatchManager.PitchGrid.PitchSettings.PitchWidth;
        int          pitchLength  = MatchManager.PitchGrid.PitchSettings.PitchLength;

        for (int x = 1; x <= pitchWidth; x++)
        {
            for (int z = 1; z <= pitchLength; z++)
            {
                PitchTile PitchTile = PitchManager.GetPitchTile(x, z);
                PitchTile.NeighbourTiles = new List <PitchTile>();
                addNeighbourTiles(x, z, PitchTile);
            }
        }

        void addNeighbourTiles(int x, int z, PitchTile PitchTile)
        {
            /* North */
            if (z < pitchLength)
            {
                PitchTile neighbourPitchTile = PitchManager.GetPitchTile(x, z + 1);
                PitchTile.NeighbourTiles.Add(neighbourPitchTile);
            }

            /* South */
            if (z > 1)
            {
                PitchTile neighbourPitchTile = PitchManager.GetPitchTile(x, z - 1);
                PitchTile.NeighbourTiles.Add(neighbourPitchTile);
            }


            /* West */
            if (x < pitchWidth)
            {
                PitchTile neighbourPitchTile = PitchManager.GetPitchTile(x + 1, z);
                PitchTile.NeighbourTiles.Add(neighbourPitchTile);
            }

            /* East */
            if (x > 1)
            {
                PitchTile neighbourPitchTile = PitchManager.GetPitchTile(x - 1, z);
                PitchTile.NeighbourTiles.Add(neighbourPitchTile);
            }

            /* NorthWest */
            if (x < pitchWidth && z < pitchLength)
            {
                PitchTile neighbourPitchTile = PitchManager.GetPitchTile(x + 1, z + 1);
                PitchTile.NeighbourTiles.Add(neighbourPitchTile);
            }

            /* NorthEast */
            if (x > 1 && z < pitchLength)
            {
                PitchTile neighbourPitchTile = PitchManager.GetPitchTile(x - 1, z + 1);
                PitchTile.NeighbourTiles.Add(neighbourPitchTile);
            }

            /* SouthWest*/
            if (x < pitchWidth && z > 1)
            {
                PitchTile neighbourPitchTile = PitchManager.GetPitchTile(x + 1, z - 1);
                PitchTile.NeighbourTiles.Add(neighbourPitchTile);
            }

            /* SouthEast*/
            if (x > 1 && z > 1)
            {
                PitchTile neighbourPitchTile = PitchManager.GetPitchTile(x - 1, z - 1);
                PitchTile.NeighbourTiles.Add(neighbourPitchTile);
            }
        }
    }
示例#17
0
    /* #endregion */
    /* ======================================================================================== */

    /* #region ==== C A L C U L A T E  &  G E T  P A T H  T O  T A R G E T ==================== */

    public List <PitchTile> GetPathToTarget(PitchTile targetIn, MatchPlayer sourceIn)
    {
        PitchManager PitchManager = MatchManager.PitchManager;

        Dictionary <PitchTile, float>     distanceToSource  = new Dictionary <PitchTile, float>();
        Dictionary <PitchTile, PitchTile> previousPitchTile = new Dictionary <PitchTile, PitchTile>();
        List <PitchTile> unvisitedPitchTiles    = new List <PitchTile>();
        List <PitchTile> CalculatedPathToTarget = null;

        //Set target tile
        PitchTile target = PitchManager.GetPitchTile(targetIn.CoordX, targetIn.CoordZ);

        //Set source tile
        PitchTile source = PitchManager.GetPitchTile(sourceIn.CoordX, sourceIn.CoordZ);

        distanceToSource[source]  = 0;
        previousPitchTile[source] = null;

        //Set all other tiles and add all (incl. source) to list of unvisited tiles
        for (int x = 1; x <= MatchManager.PitchGrid.PitchSettings.PitchWidth; x++)
        {
            for (int z = 1; z <= MatchManager.PitchGrid.PitchSettings.PitchLength; z++)
            {
                PitchTile pitchTile = PitchManager.GetPitchTile(x, z);

                if (pitchTile != source)
                {
                    distanceToSource[pitchTile]  = Mathf.Infinity;
                    previousPitchTile[pitchTile] = null;
                }

                unvisitedPitchTiles.Add(pitchTile);
            }
        }

        while (unvisitedPitchTiles.Count > 0)
        {
            //"u" is going to be the unvisited node with the smallest distance.
            PitchTile u = null;

            //Find the tile with the shortest Distance to Source
            foreach (PitchTile possibleU in unvisitedPitchTiles)
            {
                if (u == null || distanceToSource[possibleU] < distanceToSource[u])
                {
                    u = possibleU;
                }
            }

            if (u == target)
            {
                break;
            }

            unvisitedPitchTiles.Remove(u);

            foreach (PitchTile v in u.NeighbourTiles)
            {
                //float alt = distanceToSource[u] + u.DistanceToTile(v);
                float alt = distanceToSource[u] + v.CostToEnter + costForDiagonalMove(u, v);
                if (alt < distanceToSource[v])
                {
                    distanceToSource[v]  = alt;
                    previousPitchTile[v] = u;
                }
            }
        }

        //If the while loop has ended or breaked, either we found the shortest path or there is no path to the target.
        if (previousPitchTile[target] == null)
        {
            return(CalculatedPathToTarget);
        }
        else
        {
            //Step trough the previousPitchTiles chain and add it to the pathToTarget.
            CalculatedPathToTarget = new List <PitchTile>();
            PitchTile current = target;  //start tile

            while (current != null)
            {
                CalculatedPathToTarget.Add(current);
                current = previousPitchTile[current]; //Reset current to the previous tile in the chain
            }

            CalculatedPathToTarget.Reverse();
            return(CalculatedPathToTarget);
        }
    }