//edit after running it through the debugger it turned out i had the display function set to x,x...TIL how to use a debugger
I've been trying to teach myself C++ SDL with the lazyfoo tutorial and seem to have run into a roadblock. The code below is the movement function of my Dot class, which controls the ball. The ball seems to ignore yvel and moves with xvel to the bottom right. The code should be pretty readable, the rest of the relevant facts are:
- All variables are names
- Constants are in caps
dotradis the radius of my dotyvelandxvelare set to 5 in the constructor- The dot is created at
xandyequal to 100 When I comment out the x movement block it doesn't move, but if i comment out the y movement block, it keeps on going down to the right.
void Dot::move() { if(((y+yvel+dotrad) <= SCREEN_HEIGHT) && (0 <= (y-dotrad+yvel))) { y+=yvel; } else { yvel = -1*yvel; } if(((x+xvel+dotrad) <= SCREEN_WIDTH) && (0 <= (x-dotrad+xvel))) { x +=xvel; } else { xvel = -1*xvel; } }
Dot::move()look like? – K.G. Mar 23 '12 at 18:03