I'm new to c++ and I'm writing a 2D game with SDL right now and i want to make a game where you're being followed by a tornado. So you can move ans the tornado move towards you. But when I use the x coordinates of the boy in the move section of the tornado it sais that te xboy is not declared so I can i do that
Here's the code so far
after this, I have the other functions and then I create the Tornado classCode:///The boy that will move around on the screen class Boy { private: //The X and Y offsets of the boy int xboy, yboy; //The velocity of the boy int xVelboy, yVelboy; public: //Initializes the variables Boy(); //Takes key presses and adjusts the boy's velocity void handle_input(); //Moves the boy void move(); //Shows the boy on the screen void show(); }; Boy::Boy() { //Initialize the offsets xboy = 40; yboy = 40; //Initialize the velocity xVelboy = 0; yVelboy = 0; }
The game works when I place a number in stead of xboy and yboy but then the tornado moves towards that point and then stays right there.Code://The Tornado that will move around on the screen class Tornado { private: //The X and Y offsets of the Tornado int xtor, ytor; //The velocity of the Tornado int xVeltor, yVeltor; public: //Initializes the variables Tornado(); //Moves the Tornado void move(); //Shows the Tornado on the screen void show(); }; Tornado::Tornado() { //Initialize the offsets xtor = 800; ytor = 400; //Initialize the velocity xVeltor = 0; yVeltor = 0; } void Tornado::move() { //Move the Tornado left or right xtor += xVeltor; //If the Tornado is at the right side of the boy if( xtor > xboy ) { //move to the left xVeltor = -5; } //If the Tornado is at the left side of the boy if( xtor < xboy ) { //move to the left xVeltor = 5; } //Move the Tornado up or down ytor += yVeltor; //If the Tornado is above the boy if( ytor < yboy ) { //move to the left yVeltor= 5; } //If the Tornado is under the boy if( ytor > yboy ) { //move to the left yVeltor = -5; } }
Please help me



LinkBack URL
About LinkBacks


