Nearly there.
class Thing{
public:
Thing (int, int);
int x;
int y;
SDL_Rect ThingRec;
void DrawMe(SDL_Surface* pic, SDL_Surface* vid)
{
SDL_BlitSurface(pic, 0, vid, &ThingRec);
}
};
Thing::Thing (int a, int b)
{
x = a;
y = b;
ThingRec.x = x;
ThingRec.y = y;
ThingRec.w = (x + 32);
ThingRec.h = (y + 32);
list<Thing*> MyList;
MyList.push_back(this);
}
And the next part where all the errors start:
for ( list<obj*> LocalList = MyList; LocalList != list.end(); ++it )
{
obj.DrawMe(wallGFX, screen);
}
It says I need to define obj but I thought using it in the local scope meant it didn't need to exist. I tried editing the above two sections again to keep the list outside the class definition and hopefully it's like a global variable, available everywhere:
class Thing{
public:
Thing (int, int);
int x;
int y;
SDL_Rect ThingRec;
void DrawMe(SDL_Surface* pic, SDL_Surface* vid)
{
SDL_BlitSurface(pic, 0, vid, &ThingRec);
}
};
list<Thing*> MyList; // Here's the list
Thing::Thing (int a, int b)
{
x = a;
y = b;
ThingRec.x = x;
ThingRec.y = y;
ThingRec.w = (x + 32);
ThingRec.h = (y + 32);
MyList.push_back(this);
}
Second section. I'm sure this now makes more sense than the previous one. Obviously it still doesn't make sense to the compiler :unsure:
As you can see I have no idea what I'm doing. I'm taking lines of code of random websites and pasting them into my program, then when it doesn't compile I move parts around so that stuff is (I hope) in the scope it's meant to be in. This is the technique I used to learn Blitz Max, and it works, because I can use Blitz today and instantly make a program which uses OOP, even though I haven't used Blitz since 2006 :lol:
Do you know how many weeks I spent copying and pasting before I found a way to make it work? If I remember it took about 1, 2 or perhaps 3 months until I had a working game that used OOP. I played it in maths class against my teacher but I accidentally planted a bomb and then moved into an alcove, trapping myself. Good times. I get confused with C++ because there is example code on how classes work, there's example code on how lists work, and there's example code on how pointers work, and there's explanations about how scopes work but I'm trying to combine all 4 and there's no tutorial on that. If I can get this program to run I'll expand it and make it into a tutorial for people even stupider and more clueless than me.
Btw about my other thread, I found that it's easy to set up SDL if I copy the .a and .lib files into C:\Program Files (x86)\CodeBlocks\MinGW so that the MinGW compiler can find them instantly. All I need to do really is go "create new SDL project" in Code Blocks lol too easy.