GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 23-May-2004, 15:05
darkzerox darkzerox is offline
New Member
 
Join Date: May 2004
Posts: 7
darkzerox is on a distinguished road

SDL + Classes Question


CPP / C++ / C Code:
class cSprite
{
      SDL_Surface *sprite;

    public:
      // initialize
      cSprite()
      {
         sprite = SDL_LoadBMP(img);
         SDL_SetColorKey(sprite, SDL_SRCCOLORKEY, SDL_MapRGB(sprite->format, 255, 255, 255));
      }

      // general
      char name[100];

      int hp[2];
      int mp[2];

      // graphics
      char img[100];

      int x;
      int y;
      int w;
      int h;

      void draw()
      {
         DrawIMG(sprite, x, y);
      }
};

I'm going to read in sprite.img from a file...

The problem is that I will have to construct cSprite sprite before I can read in sprite.img which means that it will try to load a non-existant image...

Would there by any easy way to read in sprite.img before having it try to load sprite.img? Or should I just change my constructor to something like init() then read in all my information, and then call that?
  #2  
Old 23-May-2004, 17:36
darkzerox darkzerox is offline
New Member
 
Join Date: May 2004
Posts: 7
darkzerox is on a distinguished road
Question

...great.. I just lost everything I just typed. I hate browsers!

So yah.. no edit button huh? Or am I blind?

I've come up with somewhat of a solution. I'm going to read the file in the constructor itself.

But I'm having a dumb moment and I can't seem to figure out how to get it to read properly.

Here's the contents of my file

Code:
$NAME Angela; $IMG img/char/temp.bmp; $NAME Carlie; $IMG img/char/carlie.bmp;

Basically I want it to search for the '$' character, then once it finds that, it reads in a string, ie, 'NAME'

Once it finds 'NAME' it calls this function

CPP / C++ / C Code:
void getl(char *tmp)
{  while (isspace(fin.peek())) fin.get();
   fin.getline(tmp,255,';');
}

to read in 'Angela' (the function just removes all the white spaces before it.. it works)

And then it stops reading as soon as it gets to the next '$NAME'. I need it to leave the cursor just before '$NAME' so that when I call this function again, it continues where it left off.. reading in the next character. I assume I'll need to use something like fin.unget().

I've done stuff like this before, but I can't seem to get it to read properly at all this time.

Any help would be appreciated..

CPP / C++ / C Code:
         char ch, str[32];
  #3  
Old 23-May-2004, 19:38
darkzerox darkzerox is offline
New Member
 
Join Date: May 2004
Posts: 7
darkzerox is on a distinguished road
CPP / C++ / C Code:
         char ch, str[32];

         while(strcmpi(str,"name")!=0 && !fin.eof())
         {  fin >> ch;
            while(ch != '$' && !fin.eof())
               fin >> ch;
            fin >> str;
         }
         if(!fin.eof())
         {
            getl(name);
            strcpy(str,"");
            while(strcmpi(str,"name")!=0 && !fin.eof())
            {  strcpy(str,"");
               fin >> ch;
               while(ch != '$' && !fin.eof())
                  fin >> ch;
               fin >> str;
               if(strcmpi(str,"img")==0)
                  getl(img);
               else if(strcmpi(str,"trans")==0)
               {  fin >> trans[0];
                  fin >> trans[1];
                  fin >> trans[2];
               }
               else if(strcmpi(str,"hp")==0)
               {  fin >> hp[1];
                  hp[0] = hp[1];
               }
               else if(strcmpi(str,"mp")==0)
               {  fin >> mp[1];
                  mp[0] = mp[1];
               }
            }
         }

this will read name and image... but nothing else
 
 

Recent GIDBlogBelkin Laptop Cooler by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A question about message forums... Straga Free Web Hosting 2 07-Apr-2004 04:54
question of practice magiccreative C++ Forum 1 06-Feb-2004 07:17
ClassView not showing my classes (VC++, namespace, headers) ?!?!? djovanov C++ Forum 1 13-Jan-2004 04:54
a C input question tmike C Programming Language 1 16-Sep-2003 02:31
a noobish compiler question Charunks C++ Forum 5 03-Sep-2003 02:18

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:10.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.