2014-01-25 4 views
0

Im C#/XNA 학생이고 최근에 아이소 메트릭 타일 엔진에서 작업 해왔고 지금까지 꽤 잘 작동합니다.XNA 아이소 메트릭 타일 충돌

  • 이미지에서 세계를 그립니다 내 이미지에 어떤 색상에 따라 타일을 배치 : 그러나 문제의 충돌을 수행하는 방법에 알아 내려고을 가진 메신저, 이건 내 타일 엔진이 순간에 무엇이다 . 예를 들어 빨강 색은 잔디 타일을 그립니다. (타일은 64x32입니다.)

  • 플레이어 다음 카메라는 카메라가 보는 것을 그립니다. enter image description here

    나는 충돌의 종류가 가장 적합한 것이 무엇인지 모른다 :

이 그 어떤 도움이 될 것입니다 경우 내 게임이 모습입니다. 충돌 지점이나 교차 지점 또는 다른 종류의 충돌을 수행해야합니까? 저는 Worldtoscreen/Screentoworld를 할 수있는 곳을 읽었습니다.하지만 경험이 부족한 곳에서 어떻게 작동하는지, 어떻게 코드가 어떻게 생겼는지 모릅니다.

다음

내 코드 끌고있다 타일 등 :

class MapRow 
    { 
     public List<MapCell> Columns = new List<MapCell>(); 
    } 



    class TileMap 
    { 
     public List<MapRow> Rows = new List<MapRow>(); 

     public static Texture2D image; 
     Texture2D tileset; 


     TileInfo[,] tileMap; 


     Color[] pixelColor; 


     public TileMap(string TextureImage, string Tileset) 
     { 
      tileset = Game1.Instance.Content.Load<Texture2D>(Tileset); 

      image = Game1.Instance.Content.Load<Texture2D>(TextureImage); 
      pixelColor = new Color[image.Width * image.Height]; // pixelColor array that is holding all pixel in the image 
      image.GetData<Color>(pixelColor); // Save all the pixels in image to the array pixelColor 

      tileMap = new TileInfo[image.Height, image.Width]; 

      int counter = 0; 
      for (int y = 0; y < image.Height; y++) 
      { 
       MapRow thisRow = new MapRow(); 
       for (int x = 0; x < image.Width; x++) 
       { 
        tileMap[y, x] = new TileInfo(); 


        if (pixelColor[counter] == new Color(0, 166, 81)) 
        { 
         tileMap[y, x].cellValue = 1;//grass 

        } 
        if (pixelColor[counter] == new Color(0, 74, 128)) 
        { 

         tileMap[y, x].cellValue = 2;//water 
        } 

        if (pixelColor[counter] == new Color(255, 255, 0)) 
        { 
         tileMap[y, x].cellValue = 3;//Sand 
        } 


        tileMap[y, x].LoadInfoFromCellValue();//determine what tile it should draw depending on cellvalue 
        thisRow.Columns.Add(new MapCell(tileMap[y, x])); 


        counter++; 
       } 
       Rows.Add(thisRow); 
      } 
     } 


     public static int printx; 
     public static int printy; 

     public static int squaresAcross = Settings.screen.X/Tile.TileWidth; 
     public static int squaresDown = Settings.screen.Y/Tile.TileHeight; 

     int baseOffsetX = -32; 
     int baseOffsetY = -64; 

      public void draw(SpriteBatch spriteBatch) 
     { 
      printx = (int)Camera.Location.X/Tile.TileWidth; 
      printy = (int)Camera.Location.Y/Tile.TileHeight; 

      squaresAcross = (int)Camera.Location.X/Tile.TileWidth + Settings.screen.X/Tile.TileWidth; 
      squaresDown = 2*(int)Camera.Location.Y/Tile.TileHeight + Settings.screen.Y/Tile.TileHeight + 7; 


      for (printy = (int)Camera.Location.Y/Tile.TileHeight; printy < squaresDown; printy++) 
      { 
       int rowOffset = 0; 
       if ((printy) % 2 == 1) 
        rowOffset = Tile.OddRowXOffset; 

       for (printx = (int)Camera.Location.X/Tile.TileWidth; printx < squaresAcross; printx++) 
       { 
        if (tileMap[printy, printx].Collides(MouseCursor.mousePosition)) 
         Console.WriteLine(tileMap[printy, printx].tileRect); 

        foreach (TileInfo tileID in Rows[printy].Columns[printx].BaseTiles) 
        { 

         spriteBatch.Draw(

          tileset, 
          tileMap[printy, printx].tileRect = new Rectangle(
           (printx * Tile.TileStepX) + rowOffset + baseOffsetX, 
           (printy * Tile.TileStepY) + baseOffsetY, 
           Tile.TileWidth, Tile.TileHeight), 
          Tile.GetSourceRectangle(tileID.cellValue), 
          Color.White, 
          0.0f, 
          Vector2.Zero, 
          SpriteEffects.None, 
          tileID.drawDepth); 





        } 



       } 

      } 

      } 

     } 

답변

0

왜 그냥 단지 일반 타일 기반 게임에서 같은 물건을 그릴 수 없습니다, 그리고 45도으로 카메라를 회전 한 후합니까? 물론 그래픽을 조금 이상하게 만들 필요가 있지만 타일을 다루기가 더 쉬울 것입니다.

당신이 당신의 방식을 선호한다면 간단한 수학을 사용하여 "오른쪽 타일", "왼쪽 타일", "위쪽 타일"및 "아래쪽 타일"을 계산할 것을 제안합니다. 플레이어 (또는 다른 타일) 주위의 타일을 알 수 있습니다. 목록으로 간단히 작업 할 수 있으며, 다음 수학 수업을받는 것과 같은 수학을 기본 수학을 사용하면 아주 간단합니다.

편집 :
당신은 이런 코드 뭔가 플레이어의 다음 위치의 타일 값을 얻을 수 :

tileMap[Math.Floor((player.y+playerVelociy.Y)/tileHeight)] 
     [Math.Floor((player.x+playerVelocity.X)/tileWidth)] 

이 코드에서, 나는 '최초의 타일 0,0 당신에 있다고 가정 오른쪽 및 아래로 다시 그리기. (그렇지 않다면 Math.Floor를 Math.Ceil로 변경하십시오.)
링크를 사용하면 아이디어를 얻을 수 있지만 AS3.0에서는 구문 만 다릅니다.

+0

그래, 내가 할 수 있다고 생각해. (alt nr.2). 하지만 그것은 정상적인 사각형 충돌을 사용하는 것입니까? 그리고 내 타일이 등각 투영되어 있기 때문에 모퉁이가 투명하다는 것을 의미하지 않을 것입니다. 프로그램은 또한 모퉁이도 충돌의 일부라고 생각합니까? – Iskalder

관련 문제