Esempio n. 1
0
 public BeatMap(bga_settings bga_settings, song_info_struct song_info, song_meta_struct song_meta, string songFilePath)
 {
     this.song_meta    = song_meta;
     this.bga_settings = bga_settings;
     this.song_info    = song_info;
     this.state        = STATE.SAMPLES_LOADED;
     //this.name = name;
     this.fileName     = song_meta.title + "~" + song_meta.artist + "~" + song_meta.album + ";" + bga_settings.rng_seed.ToString() + ".dat";
     this.songFilePath = songFilePath;
     this.timesPlayed  = 0;
     laneObjectStore   = new List <LaneObject>();
     scoreboard        = new List <WinDataClass>();
 }
Esempio n. 2
0
    public void StartBGA(ref AudioClip audioClip, ref WebInfo webInfo, bga_settings settings, song_meta_struct song, string songFilePath)
    {
        this.songFilePath = songFilePath;
        this.song_meta    = song;
        if (this.state != STATE.READY)
        {
            throw new Exception("Cannot start the beat generating algorithim if it is already being run! State: " + this.state);
        }
        this.state = STATE.ACTIVE;
        Debug.Log("Threshold, multiplier:");
        Debug.Log(settings.threshold_time);
        Debug.Log(settings.threshold_multiplier);
        this.settings = settings;
        if (settings.rng_seed == 0)
        {
            this.settings.rng_seed = generateNewRandomSeed();
            Debug.Log(this.settings.rng_seed);
        }

        bga_random = new System.Random(settings.rng_seed);

        song_info              = new song_info_struct(audioClip);
        song_info.samples      = new float[song_info.sampleCount * song_info.channels];
        song_info.sampleLength = song_info.length / (float)song_info.sampleCount;
        //GetData returns samples for both the L(eft) and R(ight) channels
        //audioClip.GetData(song_info.samples, 0);
        song_info.samples = webInfo.samples;

        output = new output_struct();

        persistentDataPath = Application.persistentDataPath; //We can't use unity specific calls in the bga thread, and we need this variable for later

        //Create the background thread and run the BGA algorithim
        //The algorthim will have access to all the public structs
        Debug.Log("make thread");
        //Thread BGAThread = new Thread(new ThreadStart(algorithimWrapper));
        //BGAThread.Start();
        // crash the ui thread #yolo
        algorithimWrapper();
    }
Esempio n. 3
0
    // Update is called once per frame
    void Update()
    {
        //Debug.Log(currentState);
        // beatmap select pov
        if (!updated)
        {
            if (currentState == 1)
            {
                generatingCanvas.SetActive(false);
                userProfileCanvas.SetActive(false);
                BGAMenu.SetActive(false);
                MapSelect.SetActive(true);

                playButton.SetActive(false);
                exitGameButton.SetActive(false);
                garageButton.SetActive(false);

                coinImage.SetActive(false);

                purchaseButton.SetActive(false);
                carPrice.SetActive(false);

                title.SetActive(false);


                //Debug.Log(MainMenuController.cameraLocations + " " + MainMenuController.cameraRotations);
                mainCamera.transform.position = Vector3.Lerp(mainCamera.transform.position, MainMenuController.cameraLocations[1], Time.deltaTime);
                mainCamera.transform.rotation = Quaternion.RotateTowards(mainCamera.transform.rotation, MainMenuController.cameraRotations[1], 70 * Time.deltaTime);

                if (mainCamera.transform.position == MainMenuController.cameraLocations[1] && mainCamera.transform.rotation == MainMenuController.cameraRotations[1])
                {
                    // only stops updating once the camera completes its transition
                    updated = true;
                }


                // main menu pov
            }
            else if (currentState == 2)
            {
                // disabling other canvases
                userProfileCanvas.SetActive(true);
                generatingCanvas.SetActive(false);
                MapSelect.SetActive(false);
                Garage.SetActive(false);
                BGAMenu.SetActive(false);

                playButton.SetActive(true);
                exitGameButton.SetActive(true);
                garageButton.SetActive(true);

                coinImage.SetActive(false);

                title.SetActive(true);

                mainCamera.transform.position = Vector3.Lerp(mainCamera.transform.position, MainMenuController.cameraLocations[0], Time.deltaTime);
                mainCamera.transform.rotation = Quaternion.RotateTowards(mainCamera.transform.rotation, MainMenuController.cameraRotations[0], 60 * Time.deltaTime);

                if (mainCamera.transform.position == MainMenuController.cameraLocations[0] && mainCamera.transform.rotation == MainMenuController.cameraRotations[0])
                {
                    // only stops updating once the camera completes its transition
                    updated = true;
                }

                handleCarVisibility(); // sets the visible car to the player's currently selected one

                // garage pov
            }
            else if (currentState == 3)
            {
                // enabling the car selection canvas
                Garage.SetActive(true);

                userProfileCanvas.SetActive(true);

                //disabling buttons
                playButton.SetActive(false);
                exitGameButton.SetActive(false);
                garageButton.SetActive(false);
                BGAMenu.SetActive(false);

                coinImage.SetActive(true);
                currentMoney.GetComponent <Text>().text = MainMenuController.player.money + "";

                purchaseButton.SetActive(true);
                carPrice.SetActive(true);

                // the player owns the current car
                if (MainMenuController.player.ownedCars.Contains(currentCarIndex))
                {
                    purchaseButton.GetComponent <Button>().interactable = true; // greys out the button
                    purchaseButton.GetComponentInChildren <Text>().text = "Select";
                    carPrice.SetActive(false);
                }
                else
                {
                    // player cannot afford car
                    if (cars[currentCarIndex].price > MainMenuController.player.money)
                    {
                        purchaseButton.GetComponent <Button>().interactable = false;
                        purchaseButton.GetComponentInChildren <Text>().text = "Insufficient Funds";
                        // player can afford car
                    }
                    else
                    {
                        purchaseButton.GetComponent <Button>().interactable = true;
                        purchaseButton.GetComponentInChildren <Text>().text = "Purchase";
                    }
                    carPrice.transform.GetChild(0).GetComponent <Text>().text = cars[currentCarIndex].price + "";
                    carPrice.SetActive(true);
                }

                title.SetActive(false);

                mainCamera.transform.position = Vector3.Lerp(mainCamera.transform.position, MainMenuController.cameraLocations[2], Time.deltaTime);
                mainCamera.transform.rotation = Quaternion.RotateTowards(mainCamera.transform.rotation, MainMenuController.cameraRotations[2], 30 * Time.deltaTime);

                if (mainCamera.transform.position == MainMenuController.cameraLocations[2] && mainCamera.transform.rotation == MainMenuController.cameraRotations[2])
                {
                    // only stops updating once the camera completes its transition
                    updated = true;
                }
            }
            else if (currentState == 4)
            {
                //disable other canvases, enable bgacanvas

                MapSelect.SetActive(false);
                BGAMenu.SetActive(true);

                if (seedInput.GetComponent <InputField>().text != "")
                {
                    currentSeed = int.Parse(seedInput.GetComponent <InputField>().text);
                }

                if (state == STATE.AUDIO_CLIP_LOADED && inputAudioClip != null)
                {
                    float songLength = inputAudioClip.length;
                    songDurationText.GetComponent <Text>().text = (int)songLength / 60 + ":" + (int)(songLength % 60);
                    //load album art of song
                    try {
                        byte[]    bytes     = System.IO.File.ReadAllBytes(path + ".png");
                        Texture2D texture2D = new Texture2D(1, 1);
                        texture2D.LoadImage(bytes);
                        Sprite sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), new Vector2(0, 0));
                        if (sprite != null)
                        {
                            songArt.GetComponent <Image>().sprite = sprite;
                        }
                    }
                    catch (IOException e) {
                        Debug.Log("err");
                        Debug.Log(e);
                    }
                    songArt.SetActive(true);
                    state = STATE.AUDIO_CLIP_PRESENTED;
                }

                //if generateBGA button is hit
                if (state == STATE.START_BGA)
                {
                    Debug.Log("Starting BGA");
                    print(currentSeed);
                    state = STATE.BGA_STARTED;
                    bga_settings settings;
                    if (difficulty == DIFFICULTY.EASY)
                    {
                        settings = new bga_settings(1024, 0.3f, 1.5f, 30f, 30f, 1f, 25f, 0.8f, 5f, currentSeed);
                    }
                    else if (difficulty == DIFFICULTY.HARD)
                    {
                        settings = new bga_settings(1024, 0.3f, 1.5f, 30f, 30f, 1f, 25f, 0.33f, 5f, currentSeed);
                    }
                    else
                    {
                        settings = new bga_settings(1024, 0.3f, 1.5f, 30f, 30f, 1f, 25f, 0.5f, 5f, currentSeed);
                    }
                    bga.StartBGA(ref inputAudioClip, ref webInfo, settings, song, path);
                }
                if (state == STATE.BGA_STARTED)
                {
                    //animation for loading
                    BGAMenu.SetActive(false);
                    generatingCanvas.SetActive(true);
                    okButton.SetActive(false);
                    if (loadingAnimationText.GetComponent <Text>().text.Length < 12)
                    {
                        loadingAnimationText.GetComponent <Text>().text += ".";
                    }
                    else
                    {
                        loadingAnimationText.GetComponent <Text>().text = "";
                    }
                }
                if (bga.state == BGA.STATE.DONE)
                {
                    //set bga's state to ready so that beatmaps can be generated more than once
                    bga.state = BGA.STATE.READY;
                    state     = STATE.BGA_FINISHED;
                }
                if (state == STATE.BGA_FINISHED)
                {
                    BGAMenu.SetActive(false);
                    loadingAnimationText.GetComponent <Text>().text = "";
                    generatingText.GetComponent <Text>().text       = "BeatMap Generated";
                    okButton.SetActive(true);
                }
            }
        }
    }