Ejemplo n.º 1
0
    IEnumerator GetPlayer()
    {
        yield return(new WaitForFixedUpdate()); //Wait a fixed update cycle to make sure that all new objects can init

        player     = GameObject.FindGameObjectsWithTag("Player")[0].transform;
        headScript = player.GetComponent <SnakeHead>();
    }
Ejemplo n.º 2
0
 public SnakeBody(SnakeHead head)
 {
     this.head   = head;
     this.tails  = new List <SnakeTail>();
     this.pieces = new List <SnakePiece>();
     this.pieces.Add(head);
 }
Ejemplo n.º 3
0
    void SpawnPlayer(CreatePlayer createPlayer)
    {
        GameObject container = Instantiate(new GameObject());

        container.name             = "Player";
        container.transform.parent = snakesContainer;
        var head = Instantiate(playerHead, container.transform);

        head.name = "PlayerHead";
        SnakeHead snakeHeadManager = head.GetComponent <SnakeHead>();

        snakeHeadManager.playerColor = createPlayer.color;
        snakeHeadManager.name        = createPlayer.name;

        head.GetComponent <TrailRenderer>().colorGradient = GetGradient(snakeHeadManager.playerColor);
        head.GetComponent <SpriteRenderer>().color        = snakeHeadManager.playerColor;



        head.transform.position = createPlayer.pos;
        head.transform.up       = createPlayer.der;

        for (int i = 0; i < GlobalConsts.DEFAULT_LENGTH - 1; i++)
        {
            GameObject newSegment = Instantiate(bodySegment, container.transform);
            newSegment.AddComponent(typeof(SegmentCollision));
            newSegment.GetComponent <TrailRenderer>().colorGradient = GetGradient(snakeHeadManager.playerColor);
            var newColor = snakeHeadManager.playerColor;
            newColor.a = GlobalConsts.SEGMENT_TRANSPARINCY;
            newSegment.GetComponent <SpriteRenderer>().color = newColor;
            snakeHeadManager.segments.Add(newSegment);
        }

        playerHeadTranform = head.transform;
    }
Ejemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        segments = new GameObject[numSegments];
        for (int i = 0; i < numSegments; i++)
        {
            //Transform parent = i > 0 ? segments[i - 1].transform : transform;
            Transform parent = transform;
            segments[i] = Instantiate(segmentPrefab, parent);
            segments[i].transform.localScale = new Vector3(1, 1, 1);
            SnakeSegment seg = segments[i].GetComponent <SnakeSegment>();
            seg.id   = i;
            seg.head = this;
        }
        head = Instantiate(headPrefab, segments[numSegments - 1].transform);
        head.transform.localPosition = new Vector3(0, 0, (oldSegmentLength + segmentLength) / 2);
        head.transform.localRotation = Quaternion.identity;
        head.transform.localScale    = new Vector3(1, 1, 1);
        snakeHead = head.GetComponent <SnakeHead>();

        stump1 = Instantiate(stumpPrefab, transform);
        stump1.GetComponent <SnakeStump>().head = this;
        stump1.SetActive(false);
        stump2 = Instantiate(stumpPrefab, transform);
        stump2.GetComponent <SnakeStump>().head     = this;
        stump2.GetComponent <BoxCollider>().enabled = false;
        stump2.SetActive(false);

        ss = new SnakeSpline(this);

        state  = State.WAITING;
        status = Status.ALIVE;
        cut    = numSegments;
        t      = 0;
    }
Ejemplo n.º 5
0
 public void ScriptFind()
 {
     //find the gameobject that matches the head G.O in the scene
     snakeHead = GameObject.Find("Head" + GameController.snakecount);
     //store it's script for reference
     headScript = snakeHead.GetComponent <SnakeHead> ();
 }
Ejemplo n.º 6
0
 public void EatSpeedFu(float speedPlus)
 {
     if (!isLocalPlayer)
     {
         return;
     }
     foreach (GameObject element in snakeLinkedList)
     {
         SnakeHead sh = element.GetComponent <SnakeHead>();
         if (sh != null)
         {
             sh.AddSpeed(speedPlus);
         }
         SnakeBody sb = element.GetComponent <SnakeBody>();
         if (sb != null)
         {
             sb.AddSpeed(speedPlus);
         }
     }
     speed += speedPlus;
     if (speed > 15f)
     {
         speed = 15f;
     }
     RpcChangeSpeed();
 }
Ejemplo n.º 7
0
    public void ReturnSegmentsToCache()
    {
        // Return eaten/destroyed segments to the cache.
        SnakeSegment seg         = this.head;
        SnakeSegment previousSeg = seg;
        SnakeSegment nextSegment = seg.NextSegment;

        // Sever connection to destroyed segments prior to calling destroy but AFTER hanging a pointer to the next
        // segment, in case previousSeg and seg are the same.
        previousSeg.NextSegment = null;

        // NOTE: Can't return snake head to the snake *body* cache.
        do
        {
            if (seg != this.head)
            {
                Managers.SnakeBodyCache.ReturnObject <SnakeBody>(seg.gameObject);
            }
            seg = nextSegment;
            if (seg == null)
            {
                break;
            }
            nextSegment = seg.NextSegment;
        } while (true);

        // Destroy head prefab and any attached objects - i.e. sprite animations.
        Destroy(this.head.gameObject);
        this.head   = null;
        this.tail   = null;
        this.length = 0;

        UpdateSpeed();
    }
Ejemplo n.º 8
0
    void Start()
    {
        foreach (var player in Player.GetList())
        {
            //Create and setup the starting elements for a match
            SnakeHead newSnake = Object.Instantiate <GameObject>(snakePrefab.gameObject).GetComponent <SnakeHead>();
            player.SetAsActive();

            //La serpiente queda como hijo del Player, para que quede mas ordenada la escena.
            //Ademas, hace que sea mas facil para los componentes de la serpiente encontrar su player,
            //usando GetComponentInParent<Player>();
            newSnake.transform.SetParent(player.transform);

            newSnake.SetPlayer(player);

            //Position and scale the snakes for the game start
            Transform snakeTransform = newSnake.gameObject.GetComponent <Transform>();
            snakeTransform.localScale = Vector3.one * GameMode.SNAKE_SCALE;
            snakeTransform.position   = spawnPoint[player.playerNumber].position;
            snakeTransform.rotation   = spawnPoint[player.playerNumber].rotation;

            //Disable the players while they wait for the round to start
            //player.Disable();
            newSnake.Wait();
        }

        //SoundManager.Instance.PlayGameMusic();
    }
Ejemplo n.º 9
0
 public void OnGameOver(SnakeHead snakeHead)
 {
     audioSource.Stop();
     audioSource.clip = Dimon;
     audioSource.loop = false;
     audioSource.PlayOneShot(audioSource.clip);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Release this instance.
        /// </summary>
        public void Release()
        {
            //Release Component!
            for (int i = 0; i < m_listCompoent.Count; ++i)
            {
                m_listCompoent[i].Release();
            }
            m_listCompoent.Clear();

            //release the snake, head and tail included
            SnakeNode node = m_head;

            while (node != null)
            {
                SnakeNode next = node.Next;
                EntityFactory.ReleaseEntity(node);
                node = next;
            }
            m_head = null;
            m_tail = null;

            if (m_container != null)
            {
                GameObject.Destroy(m_container);
                m_container = null;
            }

            m_context = null;
        }
Ejemplo n.º 11
0
    void OnTriggerEnter(Collider obj)
    {
        if (snakeParameters.dieing)
        {
            return;
        }


        if (obj.transform.tag == "Snake" && obj.transform.root != transform.root)
        {
            SnakeHead snakeHead = obj.transform.GetComponent <SnakeHead>();
            if (snakeHead != null)
            {
                // Collided with an other head

                if (snakeHead.snakeParameters.points < snakeParameters.points)    // Little is stronger
                {
                    Die();
                }
            }
            else
            {
                Die();
            }
        }
    }
Ejemplo n.º 12
0
 // Start is called before the first frame update
 void Start()
 {
     touchTimer = 0f;
     player     = this.gameObject.GetComponent <SnakeHead>();
     clickMove  = PlayerPrefs.GetInt("Touch Control", 0) == 1;
     swipeMove  = PlayerPrefs.GetInt("Touch Control", 0) == 2;
 }
Ejemplo n.º 13
0
    private void SetHeadPosition(SnakeHead head)
    {
        // This resets the head's transform's position which may have been adjusted by sinusoidal code.
        // TODO move out to Snake
        SnakePosition posBefore = this.positions[0];

        head.transform.localPosition = posBefore.Position;
    }
Ejemplo n.º 14
0
    private MazeCell GetCellForHeadPosition()
    {
        SnakeHead head         = this.snake.Head;
        Vector3   headPos      = head.transform.localPosition;
        MazeCell  headMazeCell = this.mazeController.GetCellForPosition(headPos);

        return(headMazeCell);
    }
Ejemplo n.º 15
0
 void Start()
 {
     base.Start();
     playerHead = GameObject.Find("Img_SnakeHead").GetComponent <SnakeHead>();
     gameModel  = GameModel.Game;
     CreateBody();
     CreateBody();
 }
Ejemplo n.º 16
0
    // Use this for initialization
    void Start()
    {
        // get the snake head script
        snakeHead = GameObject.Find("SnakeHead").GetComponent <SnakeHead> ();

        // save the rigidbody component
        rb = GetComponent <Rigidbody> ();
    }
    /// <summary>Data for the standard snake consumable - Increases tail size and score.
    /// </summary>
    public override void OnConsumed(SnakeHead snakehead, Cell targetCell = null)
    {
        SnakeScoreHandler.UpdatedScore?.Invoke(scoreIncrease);
        snakehead.SnakeTail.TailNodesToAdd += tailNodesToAddWhenConsumed;

        OneShotAudioManager.PlayOneShot2D(AudioClipWhenConsumed);
        OneShotPFXManager.PlayPFX(targetCell.Vector2Position, PFXType.StdConsumableExplosion);
    }
Ejemplo n.º 18
0
 void Start()
 {
     m_StartTime  = false;
     m_Tigger     = false;
     m_PressTimer = 0;
     btn_SpeedUpContinue.gameObject.SetActive(false);
     snakeHeadScript = GameObject.FindGameObjectWithTag("PlayerHead").GetComponent <SnakeHead>();
 }
Ejemplo n.º 19
0
        private void AddSnakeHead()
        {
            _snakeHead = new SnakeHead();

            _snakeHead.SetValue(Canvas.LeftProperty, (cvsMain.ActualWidth - _snakeHead.Width) / 2);
            _snakeHead.SetValue(Canvas.TopProperty, (cvsMain.ActualHeight - _snakeHead.Height) / 2);

            cvsMain.Children.Add(_snakeHead);
        }
Ejemplo n.º 20
0
    public SnakeHead BuildSnakeHead()
    {
        SnakeHead snakeHead = snakeHeadPool.Get() as SnakeHead;

        snakeHead.gameObject.SetActive(true);
        //Debug.Log("new snake" + snakeHead.name);
        onSnakeSpawn?.Invoke(snakeHead);
        return(snakeHead);
    }
Ejemplo n.º 21
0
 public void SnakeDie()
 {
     if (!isDie)
     {
         isDie = true;
         SnakeHead.Die();
         MainUIManager.ShowRestartButton();
     }
     GameDataManager.UpdateData(GameMode, SnakeHead.GetBodyLength(), score);
 }
Ejemplo n.º 22
0
 public void CoilCurrentSnakeIfAny()
 {
     if (isAppleBitten)
     {
         snakeHead = currentlyClickedLeaves.GetComponentInChildren <SnakeHead>();
         var joints = snakeHead.GetComponentsInChildren <FixedJoint>();
         joints[1].connectedBody = null;
     }
     StartCoroutine(currentlyClickedLeaves.snakeRenderer.CoilSnake(1f / 60f));
 }
Ejemplo n.º 23
0
    protected override List <Direction> GetAvailableDirections()
    {
        SnakeHead head     = this.snake.Head;
        Vector3   position = head.CurrentDestination;
        MazeCell  cell     = this.mazeController.GetCellForPosition(position);

        List <Direction> availableDirections = cell.UnblockedDirections;

        return(availableDirections);
    }
Ejemplo n.º 24
0
    private void RemoveSnakeFirstHead(float force)
    {
        if (!isLocalPlayer)
        {
            return;
        }
        if (snakeLinkedList.Count < 2)
        {
            return;
        }
        isHungry = false;
        GameObject lastFirst = snakeLinkedList.First.Value;

        snakeLinkedList.RemoveFirst();
        CmdRemoveSnakeBodyInManager(lastFirst.GetComponent <NetworkIdentity>().netId);
        Vector3    position = lastFirst.transform.position;
        Quaternion rotation = lastFirst.transform.rotation;
        bool       isBoom   = lastFirst.tag == "BoomCaptured" ? true : false;

        CmdDestroyInServer(lastFirst.GetComponent <NetworkIdentity>().netId);
        CmdCreateThrowBoom(position, rotation, myClientCamera.transform.forward, myClientCamera.transform.right, force, isBoom);
        //CmdSetThrowBoom(lastFirst.GetComponent<NetworkIdentity>().netId);

        //SnakeHead sh = lastFirst.GetComponent<SnakeHead>();
        //if (sh != null) {
        //    Destroy(sh);
        //}
        //SnakeBody sb = lastFirst.GetComponent<SnakeBody>();
        //if (sb != null) {
        //    Destroy(sb);
        //}
        //ThrowBoom tb = lastFirst.AddComponent<ThrowBoom>();

        //CmdRemoveAuthority(boomGameObject.GetComponent<NetworkIdentity>().netId);

        GameObject newFirst = snakeLinkedList.First.Value;

        newFirst.SendMessage("CancelSetTargetTf");
        SnakeHead shh = newFirst.GetComponent <SnakeHead>();

        if (shh == null)
        {
            shh = newFirst.AddComponent <SnakeHead>();
        }
        shh.myClientCamera = myClientCamera;
        shh.mySnake        = gameObject;
        CmdSetScale(newFirst.GetComponent <NetworkIdentity>().netId, Vector3.one * 1.5f);
        myClientCamera.SendMessage("SetTarget", newFirst);
        if (powerOfDragon)
        {
            snakeLinkedList.First.Value.GetComponent <SnakeHead>().SetThePowerOfDragon(powerOfDragon);
        }
        isHungry = true;
        canBoom  = true;
    }
Ejemplo n.º 25
0
    // Update is called once per frame

    /*<summary>
     * Update is responsible for movement, ar for instantiation of special food.
     * </summary>
     */
    void Update()
    {
        //if game is over don't want snake to move
        if (GameManager.instance.gameOver)
        {
            return;
        }

        //to be sure if game could be continued if for some reason food was not created
        if (GameObject.FindGameObjectsWithTag("NormalFood").Length == 0)
        {
            foodPrefab.GetComponent <Food>().AddNewOne();
        }

        //counting time to instantiate new special food object
        timeToNewSpecialFood -= Time.deltaTime;

        if (timeToNewSpecialFood <= 0) // if all time has passed
        {
            //create new special food object
            SpecialFood sf = specialFoodPrefab.GetComponent <SpecialFood>();
            sf.AddNewOne();

            //random new time to create new special food object
            //range is selected to not create new object before old one is not expired
            timeToNewSpecialFood = Random.Range(2 * sf.timeToDestroy, 2 * sf.timeToDestroy + maxTimeToNewSpecialFood);
        }

        //if there is not a time for a next move
        if (Time.time < nextFrameTime)
        {
            return;
        }

        nextFrameTime += interval;              // set up a new move time

        SnakeElement.MoveTail(snake);           //firstly move a snake tail

        SnakeHead head = snake[0] as SnakeHead; // head will always be firs member

        //check if rotation is set up
        if (isTurningLeft)
        {
            isTurningLeft = false;
            head.RotateHeadCounterClockwise();
        }
        else if (isTurningRight)
        {
            isTurningRight = false;
            head.RotateHeadClockwise();
        }

        SnakeElement.MoveHead(snake); // move head including rotation
    }
Ejemplo n.º 26
0
    /// <summary>
    /// Fills in all the correct types for the head and tail
    /// </summary>
    /// <param name="grid"></param>
    /// <param name="snakeHead"></param>
    void mapGrid(GridType[,] grid, SnakeHead snakeHead)
    {
        grid[(int)currentPositionOfSnakeNormalized.x, (int)currentPositionOfSnakeNormalized.y] = GridType.Head;//set head

        foreach (SnakeTail st in snakeHead.tail)
        {
            int xPos = Mathf.RoundToInt(st.transform.position.x) - xOffset;
            int yPos = Mathf.RoundToInt(st.transform.position.y) - yOffset;

            grid[xPos, yPos] = GridType.Tail;
        }
    }
Ejemplo n.º 27
0
 private void SnakeHeadCreated(GameObject gameObject)
 {
     snakeHead = gameObject.GetComponent <SnakeHead>();
     snakeHead.OnBorderSnakeCollision += SnakeHitSomething;
     snakeHead.OnSnakeAteFood         += snakeAteFood =>
     {
         SetFoodEaten(snakeAteFood);
         foodController.InitializeFood();
         scoreManager.UpdateScore();
     };
     PersistSnakePart(gameObject);
 }
Ejemplo n.º 28
0
    // Loop through all segments and set their positions.
    public void PositionSegments(SnakeHead head)
    {
        SetHeadPosition(head);

        int       positionIndex = 0;
        SnakeBody bodySegment   = head.NextSegment;

        while (bodySegment != null)
        {
            positionIndex = SetSegmentPositionAndRotation(bodySegment, positionIndex);
            bodySegment   = bodySegment.NextSegment;
        }
    }
    void Start()
    {
        base.Start();

        if (nextSegment)
        {
            nextSegmentBody = nextSegment.GetComponent <SnakeBody>();
        }
        if (headObject)
        {
            head = headObject.GetComponent <SnakeHead>();
        }
    }
Ejemplo n.º 30
0
 public Snake(SnakeHead snakeHead, int screenWidth, int screenHeight, SpriteFont scoreBoardFont, Sprite snakeTailSprite, Sprite straightBodySprite,
              Sprite turn0Sprite, Sprite turn1Sprite, Sprite turn2Sprite, Sprite turn3Sprite)
 {
     SnakeHead           = snakeHead;
     _screenWidth        = screenWidth;
     _screenHeight       = screenHeight;
     _scoreBoardFont     = scoreBoardFont;
     _snakeTailSprite    = snakeTailSprite;
     _straightBodySprite = straightBodySprite;
     _turn0Sprite        = turn0Sprite;
     _turn1Sprite        = turn1Sprite;
     _turn2Sprite        = turn2Sprite;
     _turn3Sprite        = turn3Sprite;
 }