Пример #1
0
    public LocationUpdate(GameClient client, ReceivablePacket packet)
    {
        // Read data.
        float posX       = (float)packet.ReadDouble(); // TODO: Client WriteFloat
        float posY       = (float)packet.ReadDouble(); // TODO: Client WriteFloat
        float posZ       = (float)packet.ReadDouble(); // TODO: Client WriteFloat
        float heading    = (float)packet.ReadDouble(); // TODO: Client WriteFloat
        int   animState  = packet.ReadShort();
        int   waterState = packet.ReadByte();

        // Update player location.
        Player         player   = client.GetActiveChar();
        LocationHolder location = player.GetLocation();

        location.SetX(posX);
        location.SetY(posY);
        location.SetZ(posZ);
        location.SetHeading(heading);

        // Broadcast movement.
        foreach (Player nearby in WorldManager.GetVisiblePlayers(player))
        {
            nearby.ChannelSend(new MoveToLocation(player, heading, animState, waterState));
        }
    }
Пример #2
0
    /*
     * public bool IsThereSomethingUnderMe(List<GameObject> list)
     * {
     *  bool isThere = false;
     *  foreach(GameObject gum in list)
     *  {
     *      if (locHol.getY() - gum.GetComponent<LocationHolder>().getY() != 1)
     *      {
     *          //alla ei ole mitään, liiku
     *
     *          isThere = true;
     *      }
     *      else
     *      {
     *          isThere = false;
     *      }
     *
     *  }
     *
     *  return isThere;
     * }
     *
     */



    public IEnumerator MoveTowardsThis(int direction, int amount)
    {
        Vector3 moveHere;

        amIMoving = true;

        //   Debug.Log("gum " + gameObject + " liikkuuko");
        switch (direction)
        {
        case 0:             //alas
            if (locHol.getY() > 0)
            {
                moveHere = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y - amount, gameObject.transform.position.z);
                while (transform.position != moveHere)
                {
                    if (gameObject.GetComponent <MovingScript>() == true)
                    {
                        transform.position = Vector3.MoveTowards(transform.position, moveHere, (speed * Time.deltaTime));
                        yield return(new WaitForEndOfFrame());
                    }
                }
                locHol.SetY(locHol.getY() - amount);
                amIMoving = false;

                // print("kasky lahtee2");
            }
            break;


        case 1:             //ylös
            if (locHol.getY() < 9)
            {
                moveHere = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y + amount, gameObject.transform.position.z);
                while (transform.position != moveHere)
                {
                    if (gameObject.GetComponent <MovingScript>() == true)
                    {
                        transform.position = Vector3.MoveTowards(transform.position, moveHere, (speed * Time.deltaTime));
                        yield return(new WaitForEndOfFrame());
                    }
                }
                locHol.SetY(locHol.getY() + 1);
                amIMoving = false;
            }


            break;

        case 2:             //vasen
            if (locHol.getX() > 0)
            {
                moveHere = new Vector3(gameObject.transform.position.x - 1, gameObject.transform.position.y, gameObject.transform.position.z);
                while (transform.position != moveHere)
                {
                    if (gameObject.GetComponent <MovingScript>() == true)
                    {
                        transform.position = Vector3.MoveTowards(transform.position, moveHere, (speed * Time.deltaTime));
                        yield return(new WaitForEndOfFrame());
                    }
                }
                locHol.SetX(locHol.getX() - 1);
                amIMoving = false;
            }
            break;

        case 3:             //oikea
            if (locHol.getX() < 9)
            {
                moveHere = new Vector3(gameObject.transform.position.x + 1, gameObject.transform.position.y, gameObject.transform.position.z);

                while (transform.position != moveHere)
                {
                    if (gameObject.GetComponent <MovingScript>() == true)
                    {
                        transform.position = Vector3.MoveTowards(transform.position, moveHere, (speed * Time.deltaTime));
                        yield return(new WaitForEndOfFrame());
                    }
                }
                locHol.SetX(locHol.getX() + 1);
                amIMoving = false;
            }
            break;

        case 4:             //kun pallo tuhotaa, liikutetaan se ensin pois kentästä efektin vuoksi
            moveHere = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z - 1);
            while (transform.position != moveHere)
            {
                if (gameObject.GetComponent <MovingScript>() == true)
                {
                    transform.position = Vector3.MoveTowards(transform.position, moveHere, (speed * Time.deltaTime) * 2);
                    yield return(new WaitForEndOfFrame());
                }
            }

            break;
        }

        gridManag.ListSorter();
    }