Exemplo n.º 1
0
 private void Awake()
 {
     // PresentX = int.Parse(transform.position.x.ToString()) + 10;
     // PresentY = int.Parse(transform.position.y.ToString()) + 5;
     PresentX = int.Parse(transform.position.x.ToString());
     PresentY = int.Parse(transform.position.y.ToString());
     MapManager.AddObject(PresentX, PresentY, Cell.CellObjectType.LongerBox);  // 单元格添加物体
 }
Exemplo n.º 2
0
 // Start is called before the first frame update
 void Start()
 {
     SnakeHead = GameObject.Find("SnakeHead");
     // PresentX = int.Parse(transform.position.x.ToString()) + 10;
     // PresentY = int.Parse(transform.position.y.ToString()) + 5;
     PresentX = int.Parse(transform.position.x.ToString());
     PresentY = int.Parse(transform.position.y.ToString());
     MapManager.AddObject(PresentX, PresentY, Cell.CellObjectType.SnakeBody);
 }
Exemplo n.º 3
0
 public int m_Status = 0;    //判断蛇头是否与自身位置重叠
 // Start is called before the first frame update
 void Start()
 {
     SnakeHead = GameObject.Find("SnakeHead").GetComponent <SnakeManager>();
     // PresentX = int.Parse(transform.position.x.ToString()) + 10;
     // PresentY = int.Parse(transform.position.y.ToString()) + 5;
     PresentX = int.Parse(transform.position.x.ToString());
     PresentY = int.Parse(transform.position.y.ToString());
     MapManager.AddObject(PresentX, PresentY, Cell.CellObjectType.Key);  // 单元格添加物体
 }
Exemplo n.º 4
0
 private void Move()
 {
     // if (Input.GetKey(KeyCode.Space))
     // {
     //     if (Input.GetKeyDown(KeyCode.UpArrow) && m_PresentLength < m_MaxLength && m_Map.EasyMap[PresentX, PresentY + 1] == 0)
     //     {
     //         PresentY++;
     //         m_PresentLength++;
     //         transform.position += UpMove;
     //         Instantiate(m_Body, m_HeadPosition, ZeroQuaternion);
     //         m_HeadPosition = transform.position;
     //         m_Map.EasyMap[PresentX, PresentY] = 1;
     //     }
     //     if (Input.GetKeyDown(KeyCode.DownArrow) && m_PresentLength < m_MaxLength && m_Map.EasyMap[PresentX, PresentY - 1] == 0)
     //     {
     //         PresentY--;
     //         m_PresentLength++;
     //         transform.position -= UpMove;
     //         Instantiate(m_Body, m_HeadPosition, ZeroQuaternion);
     //         m_HeadPosition = transform.position;
     //         m_Map.EasyMap[PresentX, PresentY] = 1;
     //     }
     //     if (Input.GetKeyDown(KeyCode.RightArrow) && m_PresentLength < m_MaxLength && m_Map.EasyMap[PresentX + 1, PresentY] == 0)
     //     {
     //         PresentX++;
     //         m_PresentLength++;
     //         transform.position += RightMove;
     //         Instantiate(m_Body, m_HeadPosition, ZeroQuaternion);
     //         m_HeadPosition = transform.position;
     //         m_Map.EasyMap[PresentX, PresentY] = 1;
     //     }
     //     if (Input.GetKeyDown(KeyCode.LeftArrow) && m_PresentLength < m_MaxLength && m_Map.EasyMap[PresentX - 1, PresentY] == 0)
     //     {
     //         PresentX--;
     //         m_PresentLength++;
     //         transform.position -= RightMove;
     //         Instantiate(m_Body, m_HeadPosition, ZeroQuaternion);
     //         m_HeadPosition = transform.position;
     //         m_Map.EasyMap[PresentX, PresentY] = 1;
     //     }
     // }
     if (Input.GetKey(KeyCode.Space) && m_PresentLength < m_MaxLength)
     {
         Vector3Int moveDir = Vector3Int.zero;
         if (Input.GetKeyDown(KeyCode.UpArrow))
         {
             moveDir = new Vector3Int(0, 1, 0);
         }
         if (Input.GetKeyDown(KeyCode.DownArrow))
         {
             moveDir = new Vector3Int(0, -1, 0);
         }
         if (Input.GetKeyDown(KeyCode.RightArrow))
         {
             moveDir = new Vector3Int(1, 0, 0);
         }
         if (Input.GetKeyDown(KeyCode.LeftArrow))
         {
             moveDir = new Vector3Int(-1, 0, 0);
         }
         if (moveDir.magnitude == 0)
         {
             return;
         }
         if (MapManager.CanMoveOn(PresentX + moveDir.x, PresentY + moveDir.y))
         {
             PresentX += moveDir.x; PresentY += moveDir.y;
             m_PresentLength++;
             transform.position += moveDir;
             Instantiate(m_Body, m_HeadPosition, ZeroQuaternion);
             m_HeadPosition = transform.position;
             MapManager.AddObject(PresentX, PresentY, Cell.CellObjectType.SnakeBody);
         }
     }
     if (Input.GetKeyUp(KeyCode.Space))
     {
         m_PresentLength = 1;
     }
 }