1) food[c].exists might be false (how are you confirming it is true?)
2) the if statement actually is working, but your Rectangle() line is broken and isn't drawing anything (or is drawing it offscreen).
To further diagnose:
1) Put a breakpoint on the if statment, and on the following Rectangle() line and confirm the breakpoints trip when you expect them to.
2) While in the debugger, watch food[c].exists to make sure it contains a value you expect
3) If neither of the above reveal your problem, examine all food[c] members to make sure you're drawing the rectangle on screen.
here's the thing: I've already used breakpoints to confirm that the rectangle line is never executed, also, according to a watch, food[c].exists is true when it encounters the if statement. the only odd thing about food[c]'s member variables is that it's xpos and ypos always contain apparent garbage, even though I specifically set the entire array to random values of x and y on the screen
here is WM_CREATE
case WM_CREATE:
SetTimer(hWnd,1,100,NULL);
class Food
{
public:
int xpos,ypos;//position
bool exists;//should it be painted or taken account of for collision detection?
void Generate_Food(int xpos, int ypos)//for initial creation and regeneration, but needs some work; apparently
{
Food::exists=true;//makes food exist
Food::xpos=xpos;//sets position
Food::ypos=ypos;//also sets position
};//END Generate_Food
void Terminate_Food()//when eaten
{
Food::exists=false;
};//END Terminate_Food
bool Paint_Food(int xpos, int ypos, bool existence)//for constant repainting
{
Food::xpos=xpos;
Food::ypos=ypos;
if(Food::exists==true)//tests whether food should be painted or not
{
return true;
}
else
{
return false;
};
};//END Paint_Food
If I'm understanding this correctly... you have a scope problem. I'm surprised this was compiled without errors.
Your 'food' array is declared as a local variable inside your WM_CREATE handler. Local variables go out of scope and die at the next closing brace (for you, it seems this would be the end of the switch statement).
So yeah... you are initializing your 'food' array in a WM_CREATE message. But then as soon as WM_CREATE finishes, that entire array gets thrown away. Then when you get a WM_PAINT message, an entirely new 'food' array is made (but not initialized!)
The compiler really should be throwing an error about this. Typically the error comes in the form "construction of food skipped by case label" or something along those lines. I don't know how this slipped by it.
The solution here is to move your 'food' array so it has a broader scope and survives past the end of this message handling function. The quick and dirty way to do this is to make it global.
On a side note, please put your code in code tags:
If you are at all interested in helping with this simulation further, I hit a plethora of bugs with the Bacteria class, look at the post "Very buggy simulation". If this counts as spam, sorry, I'm new to the site. Also I think my VS 2010 express might be a little weird, I mess with my settings all the time!