예제 #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();
        }
    }
예제 #2
0
    internal void OnSetTarget(Item pItem, PlaygroundField pTarget)
    {
        bool isValidTarget = pTarget != null && pItem != null;

        actionItem.SetTexture(isValidTarget ? pItem.icon : null);
        actionItem.SetActive(isValidTarget);
    }
예제 #3
0
 public void SetNeighbours(PlaygroundField pUp, PlaygroundField pRight,
                           PlaygroundField pDown, PlaygroundField pLeft)
 {
     up    = pUp;
     right = pRight;
     down  = pDown;
     left  = pLeft;
 }
예제 #4
0
 private void PlaceAt(PlaygroundField playgroundField)
 {
     foreach (BodyPart part in bodyParts)
     {
         part.field = playgroundField;
         playgroundField.bodyPart = head;
     }
     Draw();
 }
예제 #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;
 }
예제 #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);
    }
예제 #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);
    }
예제 #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);
    }
예제 #9
0
파일: Game.cs 프로젝트: ja003/SnakeFight
    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();
    }
예제 #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;
    }
예제 #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);
    }
예제 #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);
    }
예제 #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;
    }
예제 #14
0
파일: Game.cs 프로젝트: ja003/SnakeFight
 private void SetTargetToLocalSnake(PlaygroundField pTargetField)
 {
     localSnake.SetTarget(pTargetField);
 }
예제 #15
0
 internal void SetTarget(PlaygroundField pTargetField)
 {
     itemController.SetTarget(pTargetField);
 }