Ran into strange problem. I'm trying to create bullet controller class that is responsible for keeping track of bullets, moving them etc. However when I try to create class something weird happens. Specifically asteroids all start to head more or less in same direction(here's print from debug file where I insert velocities of each asteroids):
asteroid 10 x: 0.494975 asteroid y:0.494975
asteroid 11 x: 0.492377 asteroid y:0.497559
asteroid 12 x: 0.507374 asteroid y:0.482257
asteroid 13 x: 0.479598 asteroid y:0.509888
asteroid 14 x: 0.511739 asteroid y:0.477623
asteroid 15 x: 0.487302 asteroid y:0.502530
asteroid 16 x: 0.487533 asteroid y:0.502307
asteroid 17 x: 0.511902 asteroid y:0.477447
asteroid 18 x: 0.472106 asteroid y:0.516832
As you can see they have all very similar x and y components. Also lot more decimals than I would expect. If I remove line that creates new bullet controller they vary more and there's less decimals.
Here's the constructor whose calling starts the problems. As you can see it just initialises private variable to right value.
bulletController::bulletController() {
currentID=BULLET_MIN;
}
And here's the main block of code(I removed all that don't have something to do with the asteroids). First line is the one which causes the problems(or atleast commenting it fixes problems).
bulletController *bullets = new bulletController;
vector <ownObject> asteroids(50);
vector<ownObject>::iterator it;
ownObject *asteroid;
for ( int i = ASTEROID_MIN; i < ASTEROID_MIN+asteroidsInGame; i++ )
{
int j=dbRnd(4);
asteroid=new ownObject(models[j], i, 2+j); // grabs the values from array I have for model file names)
asteroids.push_back(*asteroid);
delete asteroid;
}
for (it=asteroids.begin(); it!=asteroids.end();++it) {
int temp=dbRnd(1);
int x=dbRnd(100)+3;
int y=dbRnd(100)+3;
if(temp==1) { // 50-50 toss wether position is negative or positive. Ship starts at 0,0
x=0-x;
}
temp=dbRnd(1);
if(temp==1) {
y=0-y;
}
it->setPos ( x,y);
vector2d newThrust;
newThrust.x=(float)dbRnd(4)+1;
newThrust.y=(float)dbRnd(4)+1;
newThrust.x=newThrust.x/100;
newThrust.y=newThrust.y/100;
int i;
i=dbRnd(1);
if(i==1) { //same thing as with position. 50-50 wether component is negative or positive
newThrust.x=0-newThrust.x;
}
i=dbRnd(1);
if(i==1) {
newThrust.y=0-newThrust.y;
}
it->applyThrust(newThrust); // applyThrust simply adds the thrust into velocities
}
Any ideas where the issue might come? Class variables are all private so they shouldn't be able to interfere. Maybe something about pointer handling?