Пример #1
0
    /**
     * Use this for initialization
     */
    void Start()
    {
        GameObject mouthGUI = GameObject.Find("MouthGUI");                              // find the mouth GUI

        score       = mouthGUI.GetComponent <MouthScore>();                             // get the score off the gui
        foodSpawner = GameObject.Find("FoodSpawner").GetComponent <SpawnFood>();        // find the foodSpawner
    }
Пример #2
0
    IEnumerator StartGame(StartGame startMessage)
    {
        id = startMessage.id;

        SceneManager.LoadScene("game");

        yield return(new WaitForFixedUpdate()); //Wait a fixed update cycle to make sure that all new objects can init

        MessageSystem.instance.DispatchMessage(new CreatePlayer(startMessage.playerName, startMessage.playerColor, startMessage.startPos, startMessage.startDir));

        foreach (var snake in startMessage.otherSnakes)
        {
            SpawnNPSnake spawnMessage = new SpawnNPSnake(snake);
            MessageSystem.instance.DispatchMessage(spawnMessage);
        }

        foreach (var food in startMessage.foodInGame)
        {
            SpawnFood spawnMessage = new SpawnFood(food);
            MessageSystem.instance.DispatchMessage(spawnMessage);
        }



        gameRunning = true; //Now start doing all the game processes since things are inited

        MessageSystem.instance.DispatchMessage(new GameRunning());
    }
Пример #3
0
    // Use this for initialization
    void Start()
    {
        food  = FindObjectOfType <SpawnFood>();
        alive = true;
        snakeMaterial.SetColor("_Color", Color.white);

        snakeSegmentPrefab.localScale = Vector3.one * nodeSize;
        gridBounds = new Vector2Int();
        direction  = Vector2Int.up;

        for (float y = -gridSize / 2f; y < (gridSize / 2f) + gridSpacing; y += gridSpacing)
        {
            gridBounds += new Vector2Int(1, 1);
            for (float x = -gridSize / 2f; x < (gridSize / 2f) + gridSpacing; x += gridSpacing)
            {
                coordinates.Add(new Vector2(x, y));
            }
        }

        for (int i = 0; i < gridBounds.x; i++)
        {
            for (int j = 0; j < gridBounds.y; j++)
            {
                openIndexes.Add(new Vector2Int(i, j));
            }
        }

        snakeHeadIndex = new Vector2Int(gridBounds.x / 2, gridBounds.y / 2);
        snakeIndexes.Add(snakeHeadIndex);
        openIndexes.Remove(snakeHeadIndex);

        snakeSegment.Enqueue(Instantiate(snakeSegmentPrefab, coordinates[snakeHeadIndex.x + snakeHeadIndex.y * gridBounds.x], Quaternion.identity, snakeSegmentHolder));

        StartCoroutine(MovementUpdater());
    }
Пример #4
0
 void MakeInstance()
 {
     if (instance == null)
     {
         instance = this;
     }
 }
Пример #5
0
 void Awake()
 {
     // Register the singleton
     if (Instance != null)
     {
         Debug.LogError("Multiple instances of SpecialEffectsHelper!");
     }
     Instance = this;
 }
Пример #6
0
    // Use this for initialization
    void Start()
    {
        HeadSprite.GetComponent <SpriteRenderer>().color    = GameController.control.PlayerData.SnakeColor;
        lichaamPrefab.GetComponent <SpriteRenderer>().color = GameController.control.PlayerData.SnakeColor;

        foodSpawner = GetComponent <SpawnFood>();
        // Move the Snake every 300ms
        InvokeRepeating("Move", 0.3f, snelheid);
    }
    void Start()
    {
        PV        = GetComponent <PhotonView>();
        spawnFood = GetComponent <SpawnFood>();
        joy       = FindObjectOfType <Joystick>();
        boost     = FindObjectOfType <Booster>();
        gameSet   = FindObjectOfType <GameSetup>();

        Debug.Log(gameSet.Master.tag.ToString());
        Debug.Log(PhotonNetwork.IsMasterClient.ToString());
    }
Пример #8
0
    void Start()
    {
        //component that plays a sound effect when food is eaten
        eatSound = GetComponent <AudioSource>();

        //snake width
        width          = (int)GetComponent <BoxCollider2D>().size.x;
        waitAfterPause = baseSpeed;
        foodScript     = gameManager.GetComponent <SpawnFood>();
        bordersKill    = GameOptions.bordersKill;
    }
Пример #9
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
 }
Пример #10
0
    void Start()
    {
        //Mutes sound according to sound preference
        soundPlayer = this.GetComponent <AudioSource>();
        if (!GameOptions.soundOn)
        {
            SwitchSound();
        }

        //gets script that controls food
        foodScript           = this.GetComponent <SpawnFood>();
        extravaganzaDuration = foodScript.extravaganzaDuration;
    }
Пример #11
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     Debug.Log("OnTriggerEnter2D");
     if (collision.name.StartsWith("Food"))
     {
         ate = true;
         Destroy(collision.gameObject);
         SpawnFood.EatOne();
     }
     else
     {
         GameController.FailGame();
         audioSource2.clip = audioClips [3];
         audioSource2.Play();
     }
 }
Пример #12
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     Debug.Log("OnTriggerEnter2D");
     //CAN BE IMPROVE WITH TAG PROPERTY
     if (collision.name.StartsWith("Food"))
     {
         ate = true;
         Destroy(collision.gameObject);
         SpawnFood.EatOne();
     }
     else if (collision.tag.Contains("Border"))
     {
         GameController.FailGame();
         //TODO:YOU LOSE SCREEN
     }
 }
    public void GameStart_S()
    {
        Text.GetComponent <TimeBoxScript>().timeCountStart(time);
        SpawnFood spfood = camera.GetComponent <SpawnFood>();

        spfood.FoodSpawnStart();

        for (int i = 0; i < person_num; i++)
        {
            if (WormLightList[i] != null)
            {
                WormLightList[i].SetActive(false);
            }
        }


        WorldLight.SetActive(true);
        SFXplayer.PlayGameBGM();
    }
Пример #14
0
    private void SpawnFood(SpawnFood food)
    {
        GameObject newFood;

        if (deadFoodObjects.Count <= 0)
        {
            newFood = Instantiate(foodPrefab, transform);
        }
        else
        {
            newFood = deadFoodObjects.Dequeue();
            newFood.SetActive(true);
        }

        newFood.name = "Food " + food.id;
        foodObjects.Add(food.id, newFood);

        newFood.transform.position = food.pos;
    }
Пример #15
0
    void Start()
    {
        uiManager = FindObjectOfType <UIManager>();
        spawner   = GetComponentInChildren <SpawnFood>();

        foreach (Enemy enemy in enemies)
        {
            enemy.IgnorePlayer();
            remainingEnemies++;
        }

        foreach (Enemy enemy in leapEnemies)
        {
            enemy.gameObject.SetActive(false);
            remainingEnemies++;
        }

        spawner.gameObject.SetActive(false);
        cameraBehaviour = FindObjectOfType <CameraBehaviour>();
    }
Пример #16
0
    // Use this for initialization
    private void Start()
    {
        GameCamera      = GameObject.Find("Camera");
        SpawnFoodScript = GameCamera.GetComponent <SpawnFood>();
        rb = gameObject.GetComponent <Rigidbody>();
        rb.transform.localScale         = new Vector3(Global.head_size, Global.head_size, Global.head_size);
        tailPrefab.transform.localScale = new Vector3(Global.tail_size, Global.tail_size, Global.tail_size);

        WormLight = GameObject.Find("BotLight[" + Head_index + "]");
        Debug.Log("Head_index : " + Head_index + ", is light exist : " + (WormLight != null));

        thisMesh = gameObject.GetComponent <MeshRenderer>();

        for (int i = 0; i < 1; i++)
        {
            TailCreate(rb.position);
        }

        headspeed_mult = Global.init_botHeadSpeed;
    }
Пример #17
0
    // I changed the "Layer" of the "Head" in "SNAKE" to SNAKE (using unity editor)
    // So that if a collison happens in the Head, it will pass that signal to the nearest Rigidbody, in this case it is the "SNAKE"'s Rigidbody
    // I also turned off the Sphere Collider in Sphere Prefab (using unity-editor)
    // So that if the tail touches the food it DO NOT destroy the food
    void OnCollisionEnter(Collision collision)
    {
        ifColided = true;
        // Create an instance, which links to SpawnFood.cs script
        // Because SpawnFood.cs script is attached to "Camera", we find "Camera" and get the component
        SpawnFood foodController = platform.GetComponent <SpawnFood>();

        Debug.Log("You collided with " + collision.gameObject);

        if (collision.gameObject.tag == "Food")
        {
            Destroy(collision.gameObject);
            AddBody();
            foodController.LetSpawnFood();
        }

        if (collision.gameObject.tag == "Obstacle")
        {
            ifAlive = false;
        }
    }
Пример #18
0
 void Start()
 {
     _foodSpawner = GetComponentInParent <SpawnFood>();
 }
Пример #19
0
 void Start()
 {
     foodController = platform.GetComponent <SpawnFood>();
     StartGame(initLength);
 }
Пример #20
0
 // Use this for initialization
 void Start()
 {
     sFood = GameObject.Find("Game Manager").GetComponent<SpawnFood>();
 }
Пример #21
0
 // Use this for initialization
 void Start()
 {
     sFood = GameObject.Find("Game Manager").GetComponent <SpawnFood>();
 }
Пример #22
0
    private void Move()
    {
        if (_dirList.Count == 0)
        {
            return;
        }

        ArrayPosHandler oldPosInArray = _currPosInArray,
                        newPosInArray;


        if (_dirList.Count > 1)
        {
            newPosInArray = _currPosInArray + _dirList.Last();
            _dirList.RemoveAt(_dirList.Count - 1);
        }
        else
        {
            newPosInArray = _currPosInArray + _dirList.First();
        }

        ArrayPosHandler inputValue = newPosInArray - _currPosInArray;

        if (_inputs.Count > 0)
        {
            _inputs.Insert(0, new Vector2(inputValue.x, inputValue.y));
        }
        else
        {
            _inputs.Insert(0, new Vector2(inputValue.x, inputValue.y));
            _inputs.Insert(0, new Vector2(inputValue.x, inputValue.y));
        }


        if (ArrayPosHandler.IsLeftBorderCrossed(newPosInArray))
        {
            _currPosInArray = new ArrayPosHandler(_currPosInArray.x, _gs.gameArray.GetLength(1) - 1);
        }
        else if (ArrayPosHandler.IsRightBorderCrossed(newPosInArray, _gs.gameArray.GetLength(1) - 1))
        {
            _currPosInArray = new ArrayPosHandler(_currPosInArray.x, 0);
        }
        else if (ArrayPosHandler.IsTopBorderCrossed(newPosInArray))
        {
            _currPosInArray = new ArrayPosHandler(_gs.gameArray.GetLength(0) - 1, _currPosInArray.y);
        }
        else if (ArrayPosHandler.IsBottomBorderCrossed(newPosInArray, _gs.gameArray.GetLength(0) - 1))
        {
            _currPosInArray = new ArrayPosHandler(0, _currPosInArray.y);
        }
        else
        {
            _currPosInArray = newPosInArray;
        }

        transform.position = _gs.GetPosition(_currPosInArray);

        MoveEvent?.Invoke();
        _steps.Insert(0, _currPosInArray);
        _gs.ChangGameArray(_currPosInArray, 1);

        if (_ateFood)
        {
            EatEvent?.Invoke();
            SpawnFood?.Invoke();
            _gs.ChangGameArray(oldPosInArray, 2);
            SpawnTail(oldPosInArray);
            _ateFood = false;
        }
        else if (_ateBonus)
        {
            BonusEvent?.Invoke();
            SpawnTail(oldPosInArray);
            _gs.ChangGameArray(oldPosInArray, 2);
            _ateBonus = false;
        }
        else if (_tail.Count > 0)
        {
            TailLastToFirst(oldPosInArray);
        }
        else
        {
            _gs.ChangGameArray(oldPosInArray, 0);
        }

        if (_steps.Count > 2)
        {
            _steps.RemoveAt(_steps.Count - 1);
        }

        if (_inputs.Count > 2)
        {
            _inputs.RemoveAt(_inputs.Count - 1);
        }
    }
Пример #23
0
 void OnDisable()
 {
     instance = null;
 }
Пример #24
0
    // Use this for initialization
    void Start()
    {
        sFood = GameObject.Find("Game Manager").GetComponent<SpawnFood>();

        scoreSYS = GameObject.Find("Game Manager").GetComponent<ScoreSystem>();
    }
Пример #25
0
    // Use this for initialization
    void Start()
    {
        sFood = GameObject.Find("Game Manager").GetComponent <SpawnFood>();

        scoreSYS = GameObject.Find("Game Manager").GetComponent <ScoreSystem>();
    }