Ejemplo n.º 1
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);
    }
Ejemplo n.º 2
0
    void PlayNote(int note)
    {
        float targetFreq = PitchManager.NoteToPitch(note);

        source.clip   = DoClip;
        source.pitch  = targetFreq / refFreq;
        source.volume = 1;
        source.Play();
    }
Ejemplo n.º 3
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);
                }
            }
        }
    }