Thread: I can't explain this

  1. #31
    Registered User
    Join Date
    Jun 2002
    Posts
    151
    There's no attachment. Where are you loading the AniFrame and lit fields of the tile struct? Are they part of the file? Also, this shouldn't be related to your problem but you should use strcpy() for your MapName.

  2. #32
    I should've commented those lines out.

    I am not done with LoadMap() yet. I want to get THIS done b4 I start working on lighting effects or animation (those two variables are for that purpose).

    And I thought I did attach it. Well, I'll try again.

  3. #33
    Registered User
    Join Date
    Jun 2002
    Posts
    151
    I suspect your problems are either something due to Allegro or from something you haven't posted as my cut and paste job from your snipets appears to work -

    Code:
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    using namespace std;
    
    #define MTX 60
    #define MTY 45    // Max Deminsions
    #define ML 3
    
    
    struct tile
    {
      int type;
      int AniFrame;
      bool lit;
    };
    
    
    class map
    {
    private:
      tile tiles[MTX][MTY][ML];
      int width, height;
      int camerax, cameray;
      char *MapFileName;
      char MapName[256];
      bool ExcludeSecondLayer;
    public:
      void LoadMap(char *file);
      int GetTileType(int positX, int positY, int positL);
    };
    
    int map::GetTileType(int positX, int positY, int positL)
    {
      return tiles[positX][positY][positL].type;
    }
    
    void map::LoadMap(char *FileToLoad)
    {
      MapFileName = FileToLoad;
      ExcludeSecondLayer = false;
      char buffer[256];
      ifstream MapFile(FileToLoad);
    
      while (!MapFile.eof() && strcmp(buffer,"[INITIALIZATION]"))
      {
        MapFile >> buffer;
      }
      while (!MapFile.eof() && strcmp(buffer,"[TILES]"))
     {
        MapFile >> buffer;
        if (!strcmp(buffer,"WIDTH"))
        {
           MapFile >> buffer;
           width = atoi(buffer);
        }
        else if (!strcmp(buffer,"HEIGHT"))
        {
           MapFile >> buffer;
           height = atoi(buffer);
        }
        else if (!strcmp(buffer,"S_CAMX"))
        {
           MapFile >> buffer;
           camerax = atoi(buffer);
        }
        else if (!strcmp(buffer,"S_CAMY"))
        {
           MapFile >> buffer;
           cameray = atoi(buffer);
        }
        else if (!strcmp(buffer,"EX_LAYER2"))
           ExcludeSecondLayer = true;
        else if (!strcmp(buffer,"MAPNAME"))
        {
           MapFile.getline(buffer,256);
           MapName = buffer;
        }
      }
      while (!MapFile.eof() && strcmp(buffer,"ENDMAP"))
      {
        MapFile >> buffer;
    
        if (!strcmp(buffer,"LAYER1"))
        {
          MapFile >> buffer;
          int LoadPositionX = 0;
          int LoadPositionY = 0;
    
          for (int i=0; i < width; i++)
          {
            for (int j=0; j < height; j++)
            {
               MapFile >> buffer;
               tiles[LoadPositionX][LoadPositionY][0].type = atoi(buffer);
               cout << tiles[LoadPositionX][LoadPositionY][0].type;
               LoadPositionX++;
            }
    
            LoadPositionX = 0;
            LoadPositionY++;
          }
          MapFile >> buffer;
        }
      }
      MapFile.close();
    }
    
    int main()
    {
      map CurrentMap;
      CurrentMap.LoadMap("test.txt");
      cout <<  "\nGetTileType:" << CurrentMap.GetTileType(4,3,0);
      return 0;
    }

  4. #34
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well it all seems to work when I swapped width and height over

    You'll notice that I made your test data unique in the corners, to make sure it matched up with the corners when the data was being read in.

  5. #35
    you didn't modify it at all and it still worked?

    WTF?

    And no it's not allegro, because it doesn't have anything to do with allegro, plus it IS working right in the loadmap function just not outside that function.

    This is weird.

    PS: I already tried flipping, but it loops forever doing that

  6. #36
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > you didn't modify it at all and it still worked?
    All I swapped over was width and height in the for loops, and made the condition < instead of <=

    Also swapped over the array to make it [row][column] not [column][row]

    My zip file contains code, input and results - and it seems to work compiled with DJGPP.

    puzzling....

  7. #37
    what in the hell?

    now it works.

    You said you just flipped around the x and the y. I tried that a half hour ago, but it didn't work.

    I think it is just because you are magic!

  8. #38
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > I think it is just because you are magic!
    <fx: bows>

    void hat ( const char *rabbit );

  9. #39
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    void hat ( const char *rabbit );
    ...except "const" implies that the value is unchanging. I believe your prototype would be "virtual void hat ( char *rabbit );"
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you explain these bitwise operations?
    By 6tr6tr in forum C++ Programming
    Replies: 6
    Last Post: 10-29-2008, 01:19 PM
  2. Please explain?
    By neo_phyte in forum C Programming
    Replies: 3
    Last Post: 08-25-2006, 05:23 AM
  3. Can someone explain to me what this code means
    By Shadow12345 in forum C++ Programming
    Replies: 3
    Last Post: 12-22-2002, 12:36 PM
  4. Replies: 4
    Last Post: 11-19-2002, 09:18 PM
  5. Can someone explain "extern" to me?
    By valar_king in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2001, 12:22 AM