Esempio n. 1
0
 //Calculate speed for all gears in level
 public void CalculateSpeed()
 {
     for (int i = 0; i < 10; i++)
     {
         for (int j = 0; j < 5; j++)
         {
             _gearSpeed [i, j] = 0;
         }
     }
     _gearSpeed [0, 0] = _startingSpeed;
     CalculateSpeedForAllGears(0, 0);
     for (int i = 0; i < 10; i++)
     {
         for (int j = 1; j < 5; j++)
         {
             _grid.AttachItem(i, j);
         }
     }
     for (int i = 9; i >= 0; i--)
     {
         for (int j = 4; j >= 0; j--)
         {
             if (!_gameBreak)
             {
                 CheckIfGameBreaker(i, j);
             }
         }
     }
     //CalculateSenderSpeeds ();
 }
Esempio n. 2
0
 public void OnEndDrag(PointerEventData data)
 {
     if (_previewPiece != null)
     {
         Destroy(_previewPiece);
     }
     ConstantHandler.Instance.ComponentDragged = false;
     if (ConstantHandler.Instance.ComponentAdded)
     {
         IVector3 pos = ConstantHandler.Instance.PositionAdded;
         if (_grid.GetTileType(pos.x, pos.y, pos.z) == GridHandler.Item.EMPTY)
         {
             if (_grid.isOnGrid(pos.x - 1, pos.y, pos.z) &&
                 _grid.GetTileType(pos.x - 1, pos.y, pos.z) == GridHandler.Item.EMPTY)
             {
                 _grid.SetTileToType(pos.x - 1, pos.y, pos.z, GridHandler.Item.DISAPPEAR);
                 _grid.AttachItem(pos.x - 1, pos.y, pos.z);
                 _grid.SetTileToType(pos.x, pos.y, pos.z, _itemType);
                 _grid.SetDirectionOfTile(pos.x, pos.y, pos.z, GridHandler.ItemDirection.LEFT);
                 _grid.AttachItem(pos.x, pos.y, pos.z);
             }
             else if (_grid.isOnGrid(pos.x, pos.y + 1, pos.z) &&
                      _grid.GetTileType(pos.x, pos.y + 1, pos.z) == GridHandler.Item.EMPTY)
             {
                 _grid.SetTileToType(pos.x, pos.y + 1, pos.z, GridHandler.Item.DISAPPEAR);
                 _grid.AttachItem(pos.x, pos.y + 1, pos.z);
                 _grid.SetTileToType(pos.x, pos.y, pos.z, _itemType);
                 _grid.SetDirectionOfTile(pos.x, pos.y, pos.z, GridHandler.ItemDirection.UP);
                 _grid.AttachItem(pos.x, pos.y, pos.z);
             }
             else if (_grid.isOnGrid(pos.x + 1, pos.y, pos.z) &&
                      _grid.GetTileType(pos.x + 1, pos.y, pos.z) == GridHandler.Item.EMPTY)
             {
                 _grid.SetTileToType(pos.x + 1, pos.y, pos.z, GridHandler.Item.DISAPPEAR);
                 _grid.AttachItem(pos.x + 1, pos.y, pos.z);
                 _grid.SetTileToType(pos.x, pos.y, pos.z, _itemType);
                 _grid.SetDirectionOfTile(pos.x, pos.y, pos.z, GridHandler.ItemDirection.RIGHT);
                 _grid.AttachItem(pos.x, pos.y, pos.z);
             }
             else if (_grid.isOnGrid(pos.x, pos.y - 1, pos.z) &&
                      _grid.GetTileType(pos.x, pos.y - 1, pos.z) == GridHandler.Item.EMPTY)
             {
                 _grid.SetTileToType(pos.x, pos.y - 1, pos.z, GridHandler.Item.DISAPPEAR);
                 _grid.AttachItem(pos.x, pos.y - 1, pos.z);
                 _grid.SetTileToType(pos.x, pos.y, pos.z, _itemType);
                 _grid.SetDirectionOfTile(pos.x, pos.y, pos.z, GridHandler.ItemDirection.DOWN);
                 _grid.AttachItem(pos.x, pos.y, pos.z);
             }
         }
         ConstantHandler.Instance.PositionAdded  = IVector3.zero;
         ConstantHandler.Instance.ComponentAdded = false;
     }
 }
Esempio n. 3
0
    //Change position of sender
    void OnMouseUp()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            if (hit.transform.gameObject.tag == "Grid")
            {
                IVector3 posNew = new IVector3((int)(hit.transform.position.x * 2), (int)(hit.transform.position.y * 2), 0);
                if (_grid.GetTileType(posNew.x, posNew.y) != GridHandler.Gear.ORANGE_CHECK &&
                    _grid.GetTileType(posNew.x, posNew.y) != GridHandler.Gear.GREEN_CHECK &&
                    _grid.GetTileType(posNew.x, posNew.y) != GridHandler.Gear.BLUE_CHECK)
                {
                    _grid.SetTileToType(posNew.x, posNew.y, _type);
                    _sHandler.SetGearTeethValue(posNew.x, posNew.y, _type);
                    _grid.AttachItem(posNew.x, posNew.y);

                    _grid.SetTileToType(_position.x, _position.y, GridHandler.Gear.EMPTY);
                    _sHandler.SetGearTeethValue(_position.x, _position.y, GridHandler.Gear.EMPTY);
                    _sHandler.CalculateSpeed();
                    //_sHandler.CalculateSenderSpeeds ();
                    _grid.AttachItem(_position.x, _position.y);
                }
                else
                {
                    gameObject.GetComponent <Renderer> ().enabled     = true;
                    gameObject.GetComponent <LineRenderer> ().enabled = true;
                }
            }
            else
            {
                gameObject.GetComponent <Renderer> ().enabled     = true;
                gameObject.GetComponent <LineRenderer> ().enabled = true;
            }
        }
        gameObject.GetComponent <Renderer> ().enabled     = true;
        gameObject.GetComponent <LineRenderer> ().enabled = true;
    }
Esempio n. 4
0
 //APply gear/component on gridspot
 public void OnEndDrag(PointerEventData data)
 {
     if (_previewPiece != null)
     {
         Destroy(_previewPiece);
     }
     ConstantHandler.Instance.ComponentDragged = false;
     if (ConstantHandler.Instance.ComponentAdded)
     {
         IVector3 pos = ConstantHandler.Instance.PositionAdded;
         _grid.SetTileToType(pos.x, pos.y, _itemType);
         _sHandler.SetGearTeethValue(pos.x, pos.y, _itemType);
         _sHandler.CalculateSpeed();
         _grid.AttachItem(pos.x, pos.y);
     }
 }
Esempio n. 5
0
 //Left click get speed of gear, right click delete and recalcuate speed
 void OnMouseOver()
 {
     if (Input.GetMouseButton(1))
     {
         _grid.SetTileToType(_pos.x, _pos.y, GridHandler.Gear.EMPTY);
         PrefabHandler.Instance.SHandler.SetGearTeethValue(_pos.x, _pos.y, GridHandler.Gear.EMPTY);
         _grid.SetSpeedOfTile(_pos.x, _pos.y, 0);
         _grid.SetSpeedOfTile(_pos.x - 1, _pos.y, 0);
         _grid.SetSpeedOfTile(_pos.x + 1, _pos.y, 0);
         _grid.SetSpeedOfTile(_pos.x, _pos.y - 1, 0);
         _grid.SetSpeedOfTile(_pos.x, _pos.y + 1, 0);
         PrefabHandler.Instance.SHandler.CalculateSpeed();
         PrefabHandler.Instance.SHandler.CalculateSenderSpeeds();
         _grid.AttachItem(_pos.x, _pos.y);
     }
     if (Input.GetMouseButton(0))
     {
         Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(Camera.main, new Vector3(_pos.x, _pos.y, _pos.z) / 2);
         PrefabHandler.Instance.GearDetails.GetComponent <RectTransform> ().anchoredPosition = screenPoint - PrefabHandler.Instance.UI.GetComponent <RectTransform>().sizeDelta / 2 + new Vector2(80, 18);
         PrefabHandler.Instance.GearDetails.text = _speed + " RPM";
     }
 }
Esempio n. 6
0
    //Set piece at gridspot
    public void OnEndDrag(PointerEventData data)
    {
        if (_previewPiece != null)
        {
            Destroy(_previewPiece);
        }
        ConstantHandler.Instance.ComponentDragged = false;
        if (ConstantHandler.Instance.ComponentAdded)
        {
            IVector3 pos = ConstantHandler.Instance.PositionAdded;
            if (_grid.GetTileType(pos.x, pos.y, pos.z) == GridHandler.Item.EMPTY)
            {
                if (_grid.isOnGrid(pos.x, pos.y, pos.z + 1) && _grid.isOnGrid(pos.x + 1, pos.y, pos.z) && _grid.isOnGrid(pos.x + 1, pos.y, pos.z + 1) &&
                    _grid.GetTileType(pos.x, pos.y, pos.z + 1) == GridHandler.Item.EMPTY && _grid.GetTileType(pos.x + 1, pos.y, pos.z + 1) == GridHandler.Item.EMPTY &&
                    _grid.GetTileType(pos.x + 1, pos.y, pos.z) == GridHandler.Item.EMPTY)
                {
                    _grid.SetTileToType(pos.x + 1, pos.y, pos.z, GridHandler.Item.DISAPPEAR);
                    _grid.SetTileToType(pos.x + 1, pos.y + 1, pos.z, GridHandler.Item.DISAPPEAR);
                    _grid.SetTileToType(pos.x, pos.y + 1, pos.z, GridHandler.Item.DISAPPEAR);
                    _grid.AttachItem(pos.x + 1, pos.y, pos.z);
                    _grid.AttachItem(pos.x + 1, pos.y + 1, pos.z);
                    _grid.AttachItem(pos.x, pos.y + 1, pos.z);
                    _grid.SetTileToType(pos.x, pos.y, pos.z, _itemType);
                    _grid.SetDirectionOfTile(pos.x, pos.y, pos.z, GridHandler.ItemDirection.UP);
                    _grid.AttachItem(pos.x, pos.y, pos.z);
                }
                else if (_grid.isOnGrid(pos.x, pos.y, pos.z - 1) && _grid.isOnGrid(pos.x + 1, pos.y, pos.z) && _grid.isOnGrid(pos.x + 1, pos.y, pos.z - 1) &&
                         _grid.GetTileType(pos.x, pos.y, pos.z - 1) == GridHandler.Item.EMPTY && _grid.GetTileType(pos.x + 1, pos.y, pos.z - 1) == GridHandler.Item.EMPTY &&
                         _grid.GetTileType(pos.x + 1, pos.y, pos.z) == GridHandler.Item.EMPTY)
                {
                    _grid.SetTileToType(pos.x + 1, pos.y, pos.z, GridHandler.Item.DISAPPEAR);
                    _grid.SetTileToType(pos.x + 1, pos.y + 1, pos.z, GridHandler.Item.DISAPPEAR);
                    _grid.SetTileToType(pos.x, pos.y + 1, pos.z, GridHandler.Item.DISAPPEAR);
                    _grid.AttachItem(pos.x + 1, pos.y, pos.z);
                    _grid.AttachItem(pos.x + 1, pos.y + 1, pos.z);
                    _grid.AttachItem(pos.x, pos.y + 1, pos.z);
                    _grid.SetTileToType(pos.x, pos.y, pos.z, _itemType);
                    _grid.SetDirectionOfTile(pos.x, pos.y, pos.z, GridHandler.ItemDirection.RIGHT);
                    _grid.AttachItem(pos.x, pos.y, pos.z);
                }
                else if (_grid.isOnGrid(pos.x, pos.y, pos.z - 1) && _grid.isOnGrid(pos.x - 1, pos.y, pos.z) && _grid.isOnGrid(pos.x - 1, pos.y, pos.z - 1) &&
                         _grid.GetTileType(pos.x, pos.y, pos.z - 1) == GridHandler.Item.EMPTY && _grid.GetTileType(pos.x - 1, pos.y, pos.z - 1) == GridHandler.Item.EMPTY &&
                         _grid.GetTileType(pos.x - 1, pos.y, pos.z) == GridHandler.Item.EMPTY)
                {
                    _grid.SetTileToType(pos.x, pos.y, pos.z - 1, GridHandler.Item.DISAPPEAR);
                    _grid.SetTileToType(pos.x - 1, pos.y, pos.z, GridHandler.Item.DISAPPEAR);
                    _grid.SetTileToType(pos.x - 1, pos.y + 1, pos.z, GridHandler.Item.DISAPPEAR);
                    _grid.SetTileToType(pos.x, pos.y + 1, pos.z, GridHandler.Item.DISAPPEAR);
                    _grid.AttachItem(pos.x - 1, pos.y, pos.z);
                    _grid.AttachItem(pos.x - 1, pos.y + 1, pos.z);
                    _grid.AttachItem(pos.x, pos.y + 1, pos.z);
                    _grid.SetTileToType(pos.x, pos.y, pos.z, _itemType);
                    _grid.SetDirectionOfTile(pos.x, pos.y, pos.z, GridHandler.ItemDirection.DOWN);
                    _grid.AttachItem(pos.x, pos.y, pos.z);
                }
                else if (_grid.isOnGrid(pos.x, pos.y, pos.z + 1) && _grid.isOnGrid(pos.x - 1, pos.y, pos.z) && _grid.isOnGrid(pos.x - 1, pos.y, pos.z + 1) &&
                         _grid.GetTileType(pos.x, pos.y, pos.z + 1) == GridHandler.Item.EMPTY &&
                         _grid.GetTileType(pos.x - 1, pos.y, pos.z + 1) == GridHandler.Item.EMPTY &&
                         _grid.GetTileType(pos.x - 1, pos.y, pos.z) == GridHandler.Item.EMPTY)
                {
                    _grid.SetTileToType(pos.x - 1, pos.y, pos.z, GridHandler.Item.DISAPPEAR);
                    _grid.SetTileToType(pos.x - 1, pos.y + 1, pos.z, GridHandler.Item.DISAPPEAR);
                    _grid.SetTileToType(pos.x, pos.y + 1, pos.z, GridHandler.Item.DISAPPEAR);
                    _grid.AttachItem(pos.x - 1, pos.y, pos.z);
                    _grid.AttachItem(pos.x - 1, pos.y + 1, pos.z);
                    _grid.AttachItem(pos.x, pos.y + 1, pos.z);
                    _grid.SetTileToType(pos.x, pos.y, pos.z, _itemType);
                    _grid.SetDirectionOfTile(pos.x, pos.y, pos.z, GridHandler.ItemDirection.LEFT);
                    _grid.AttachItem(pos.x, pos.y, pos.z);
                }
            }
            switch (_itemType)
            {
            case GridHandler.Item.FULL_BLOCK:
                _grid.GetObj(pos.x, pos.y, pos.z + 2).GetComponent <Renderer> ().enabled               = true;
                _grid.GetObj(pos.x, pos.y, pos.z + 2).GetComponent <SphereCollider> ().enabled         = true;
                _grid.GetObj(pos.x + 1, pos.y, pos.z + 2).GetComponent <Renderer> ().enabled           = true;
                _grid.GetObj(pos.x + 1, pos.y, pos.z + 2).GetComponent <SphereCollider> ().enabled     = true;
                _grid.GetObj(pos.x, pos.y + 1, pos.z + 2).GetComponent <Renderer> ().enabled           = true;
                _grid.GetObj(pos.x, pos.y + 1, pos.z + 2).GetComponent <SphereCollider> ().enabled     = true;
                _grid.GetObj(pos.x + 1, pos.y + 1, pos.z + 2).GetComponent <Renderer> ().enabled       = true;
                _grid.GetObj(pos.x + 1, pos.y + 1, pos.z + 2).GetComponent <SphereCollider> ().enabled = true;
                Debug.Log(new Vector3(pos.x, pos.y, pos.z + 1) + "activated");
                break;

            case GridHandler.Item.HALF_BLOCK_H:
                _grid.GetObj(pos.x, pos.y, pos.z + 2).GetComponent <Renderer> ().enabled               = true;
                _grid.GetObj(pos.x, pos.y, pos.z + 2).GetComponent <SphereCollider> ().enabled         = true;
                _grid.GetObj(pos.x + 1, pos.y, pos.z + 2).GetComponent <Renderer> ().enabled           = true;
                _grid.GetObj(pos.x + 1, pos.y, pos.z + 2).GetComponent <SphereCollider> ().enabled     = true;
                _grid.GetObj(pos.x, pos.y + 1, pos.z + 2).GetComponent <Renderer> ().enabled           = true;
                _grid.GetObj(pos.x, pos.y + 1, pos.z + 2).GetComponent <SphereCollider> ().enabled     = true;
                _grid.GetObj(pos.x + 1, pos.y + 1, pos.z + 2).GetComponent <Renderer> ().enabled       = true;
                _grid.GetObj(pos.x + 1, pos.y + 1, pos.z + 2).GetComponent <SphereCollider> ().enabled = true;
                Debug.Log(new Vector3(pos.x, pos.y, pos.z + 1) + "activated");
                break;
            }
            ConstantHandler.Instance.PositionAdded  = IVector3.zero;
            ConstantHandler.Instance.ComponentAdded = false;
        }
    }