The problem is that the program creates two copies of the underBlock variable, and in the bandid.cpp file it only test the underBlock variable to the last block/last line of code I declared in main.cpp . |
What makes you think it's creating two copies of the
underBlock variable?
In the code you've posted, there is one, and only one, instance of the
enemy class. This instance has one, and only one, data member called
underBlock. The value of that data member changes each time you call
eCollision().
If you need to check the value of
underBlock after the first call to
eCollision(), then you should do that. There's no point setting the value of it, then overwriting that with a new value, because then you lose the old value.
Consider the following code:
1 2 3 4 5
|
int x;
x = 1; // Assign a value to x
x = 5; // Overwrite the value of x with another value
// ...
std::cout << x << std::endl; // What will this print out?
|
Have you created two copies of
x? No. All you've done is assigned a value to
x, then changed it again to a new value When you print it out, you'll only get the new value.
That's exactly the equivalent to what you're doing:
1 2 3 4
|
bandit->eCollision(1000,screenHeight-170,200,40); // Assigns a value to bandit->underBlock
bandit->eCollision(200,screenHeight-170,200,40); // Overwrites the value of bandit->underBlock with another value
// ...
bandit->eMovement(someValue); // Checks the current value of bandit->underBlock
|
It sounds like you need to reorganize your code so that you handle the results of one call to
eCollision() before you make the next call.