c++, SDL- Method/Function issue

Hey there.
I am making this 2D game, like tiggy. You must catch the other guy. It is two player either on the same keyboard or AI. I have trouble making the CPU enemy to move or to complete any of his methods. He has his own class and the draw() method worked, which renders him to the screen, but the movement doesn't.

This is the bot's class so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class botAI_it
{
  float botx;
  float boty ;
  float botWidth ;
  float botHeight;
//colors biatch
  float r3;
  float g3 ;
  float b3;
//check if he collided with p1, or p2
  bool col3;

  public:
  void draw();
  void collide(float, float, float, float, bool);
  void set(float, float, float, float);
  void setColor(float, float, float);
  float move(float );
};

The "set()", "setColor()" and "move()" worked fine... but collide or move doesnt. But they should because they worked when i didnt have a bot class and just had the same "move()" code in the main.cpp. But when i try to pass arguements or just call this function, it doesnt work.
This works:
1
2
3
4
5
float botAI_it::move(float i)
{
  boty-=i;

}

and i passed 30 in for the "i" and the Y position moved less 30. So that worked. It should work because in SDL I have a main game loop. So when i say -=0.9; it will keep looping and keep going 0.9 across smoothly, not just once because its in a loop. but when i do it here through a m=class function, it only does it once. even though I call the function in the loop, it does it once.


SUMMARY.....MAIN QUESTION:
The same code works in the main.ccp, but doesnt work when i put it in a function and call it in the same spot i normally would.

1
2
3
4
5
6
7
8
9
10
11
12
while (run ==true)
{
botAI_it bot;

cout <<"dsf"; //fine
if (press left key)
{
// x-=0.9; //fine coz its in loop and keep going 0.9 across each time
bot.move//doesnt work;
}

}

You forgot to put () after the function name bot.move();
Last edited on
Topic archived. No new replies allowed.