Beispiel #1
0
    void Update()
    {
        if (IsEvaluating)
        {
            return;
        }

        EDirection dir = GetSnakeDirection();

        if (dir != EDirection.None)
        {
            OnSetDirection(dir);
        }

        PlaygroundField targetField = GetTarget();

        if (targetField != null)
        {
            OnSetTarget(targetField);
        }

        bool confirm = GetActionsConfirmed();

        if (confirm)
        {
            ConfirmActions();
        }

        if (Input.GetKeyDown(KeyCode.Tab))
        {
            OnSwapLocalSnake();
        }
    }
Beispiel #2
0
    internal void OnSetTarget(Item pItem, PlaygroundField pTarget)
    {
        bool isValidTarget = pTarget != null && pItem != null;

        actionItem.SetTexture(isValidTarget ? pItem.icon : null);
        actionItem.SetActive(isValidTarget);
    }
Beispiel #3
0
 public void SetNeighbours(PlaygroundField pUp, PlaygroundField pRight,
                           PlaygroundField pDown, PlaygroundField pLeft)
 {
     up    = pUp;
     right = pRight;
     down  = pDown;
     left  = pLeft;
 }
Beispiel #4
0
 private void PlaceAt(PlaygroundField playgroundField)
 {
     foreach (BodyPart part in bodyParts)
     {
         part.field = playgroundField;
         playgroundField.bodyPart = head;
     }
     Draw();
 }
Beispiel #5
0
 internal void EvaluateItem(Snake pOwner, PlaygroundField pTarget)
 {
     if (pTarget == null)
     {
         //Debug.Log($"{id} doesnt attack");
         return;
     }
     Debug.Log($"{pOwner.Id} EvaluateItem");
     pTarget.bodyPart?.OnAttacked(10);
     pTarget = null;
 }
Beispiel #6
0
    public void SetTarget(PlaygroundField pTargetField)
    {
        bool isItemActive = ActiveItem != null;

        Debug.Log($"{owner} SetTarget {pTargetField} | {isItemActive}");

        target?.SetSelected(false);
        target = pTargetField;
        target?.SetSelected(isItemActive);

        uiAction.OnSetTarget((Item)ActiveItem, pTargetField);
    }
Beispiel #7
0
    private PlaygroundField GetTarget()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            //Debug.DrawRay(ray.origin, ray.direction * 1000, Color.red, 1);

            bool hitField = Physics.Raycast(ray, out RaycastHit hitInfo, Mathf.Infinity, Playground.layerMask);
            if (hitField)
            {
                PlaygroundField field = hitInfo.collider.GetComponent <PlaygroundField>();
                return(field);
            }
        }
        return(null);
    }
Beispiel #8
0
    public void Init(int pId, bool pIsLocal, NetworkMessanger pNetworkMessanger, PlaygroundField playgroundField, GameUI pUi)
    {
        Id               = pId;
        IsLocal          = pIsLocal;
        networkMessanger = pNetworkMessanger;
        bodyParts        = new List <BodyPart>();
        for (int i = 0; i < bodyPartsCount; i++)
        {
            AddBodyPart(100 - i * 10);
        }

        PlaceAt(playgroundField);

        itemController    = new ItemController(this, pUi.ItemPanel, pUi.ActionPanel);
        powerUpController = new PowerUpController(this, pUi.PowerUpPanel, pUi.ActionPanel);
    }
Beispiel #9
0
    void Start()
    {
        playground.Init();
        obstacleGenerator.Init();
        //networkMessanger.Setup();

        for (int i = 1; i <= snakeCount; i++)
        {
            Snake           newSnake   = Instantiate(snakePrefab);
            PlaygroundField startField = i == 1 ?
                                         playground.GetField(3, 8) : playground.GetField(3, 3);
            newSnake.Init(i, i == 1, networkMessanger, startField, ui);

            //newSnake.AddItem(itemManager.GenerateItem(EItemId.Gun, 2));
            //newSnake.AddItem(itemManager.GenerateItem(EItemId.Knife, 1));

            //newSnake.AddPowerUp(powerUpManager.GeneratePowerUp(EPowerUpId.Specal, 1));
            //newSnake.AddPowerUp(powerUpManager.GeneratePowerUp(EPowerUpId.Specal2, 1));
            snakes.Add(newSnake);
        }

        localSnake = GetSnake(1);

        snakes[1].AddItem(itemManager.GenerateItem(EItemId.Gun, 1));
        snakes[1].AddItem(itemManager.GenerateItem(EItemId.Knife, 1));
        snakes[1].AddPowerUp(powerUpManager.GeneratePowerUp(EPowerUpId.Specal2, 1));

        snakes[0].AddPowerUp(powerUpManager.GeneratePowerUp(EPowerUpId.Specal, 1));
        snakes[0].AddItem(itemManager.GenerateItem(EItemId.Gun, 2));
        snakes[0].AddItem(itemManager.GenerateItem(EItemId.Gun, 2));


        StartCoroutine(StartDebug());
        gameStarted = true;

        input.Init(
            SetDirectionToLocalSnake,
            SetConfirmToLocalSnake,
            SetTargetToLocalSnake,
            SwapLocalSnake,
            CancelAction);

        SetDirectionToLocalSnake(EDirection.Right);

        ui.Init();
    }
Beispiel #10
0
    private void Move()
    {
        if (currentDirection == EDirection.None)
        {
            currentDirection = lastDirection;

            /*Debug.LogError("Direction not set");
             * return;*/
        }
        PlaygroundField target = head.field.GetNeighbour(currentDirection);

        if (target?.bodyPart != null)
        {
            target.bodyPart.nextPart?.Destroy();
        }
        head.Move(target);
        lastDirection = currentDirection;
    }
Beispiel #11
0
    public List <PlaygroundField> GetEmtyFields(int pCount)
    {
        List <PlaygroundField> fields = new List <PlaygroundField>();

        for (int i = 0; i < pCount; i++)
        {
            bool selected = false;
            while (!selected)
            {
                PlaygroundField randomField = GetRandomField();
                if (randomField.IsEmty() && !fields.Contains(randomField))
                {
                    fields.Add(randomField);
                    selected = true;
                }
            }
        }
        return(fields);
    }
Beispiel #12
0
    internal void Move(PlaygroundField pToField)
    {
        field.bodyPart = null;
        PlaygroundField newField = pToField;

        if (newField == null)
        {
            field.bodyPart = this;
            Debug.Log("OOB!");
            return;
        }
        if (nextPart != null)
        {
            nextPart.Move(field);
        }

        field          = newField;
        field.bodyPart = this;
        field.TryPickUpObject(owner);
    }
Beispiel #13
0
    public void Init()
    {
        if (width % 2 == 0)
        {
            width += 1;
        }
        if (height % 2 == 0)
        {
            height += 1;
        }

        topLeftCorner = new Vector3(-width / 2 * STEP_SIZE, 0, height / 2 * STEP_SIZE);

        fields = new PlaygroundField[width, height];
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                Vector3 position = topLeftCorner + new Vector3(x * STEP_SIZE, 0, -y * STEP_SIZE);

                PlaygroundField newField = Instantiate(fieldPrefab, position, fieldPrefab.transform.rotation, transform);
                newField.Init(x, y, position);
                fields[x, y] = newField;
            }
        }

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                fields[x, y].SetNeighbours(GetField(x, y - 1), GetField(x + 1, y), GetField(x, y + 1), GetField(x - 1, y));
            }
        }

        //calculated 'good' size
        //not exact for higher numbers => todo: precalculate
        //sizes for multiple widths and interpolate
        Camera.main.orthographicSize = width - 2;
    }
Beispiel #14
0
 private void SetTargetToLocalSnake(PlaygroundField pTargetField)
 {
     localSnake.SetTarget(pTargetField);
 }
Beispiel #15
0
 internal void SetTarget(PlaygroundField pTargetField)
 {
     itemController.SetTarget(pTargetField);
 }