Hi!
How do I prevent my xangle variable from equaling 0.....
Here is some of my code:
PHP Code:int Game_Main(void *parms)
{
// check of user is trying to exit
if (KEY_DOWN(VK_ESCAPE))
PostMessage(main_window_handle, WM_DESTROY,0,0);
// Move paddle left
if (KEY_DOWN(VK_LEFT)) {
lkpress = true;
if (paddle.x >5) {
paddle.x = paddle.x -4;
Move_BOB(&paddle);
}
} else if(KEY_DOWN(VK_RIGHT)) { // Move paddle right
rkpress = true;
if(paddle.x + paddle.width < SCREEN_WIDTH) {
paddle.x = paddle.x +4;
Move_BOB(&paddle);
}
}
// start the timing clock
Start_Clock();
// clear the drawing surface
DD_Fill_Surface(lpddsback, 0);
Draw_BOB(&paddle,lpddsback);
Draw_BOB(&ball,lpddsback);
for (int draw = 0; draw<28; draw++)
Draw_BOB(&box[draw],lpddsback);
ball.xv = xangle;
ball.yv = yangle;
Move_BOB(&ball);
//the ball is going outside the screen
if(ball.x <= 0) {
lasthit = LAST_HIT_LEFT;
xangle = -xangle;
}
if( ball.x >= SCREEN_WIDTH - ball.width ){
lasthit = LAST_HIT_RIGHT;
xangle = -xangle;
}
// the ball is going outside the screen
if(ball.y <= 0) {
lasthit = LAST_HIT_TOP;
yangle = -yangle;
if(xangle <0){
xangle = xangle;
}
if(xangle > 0){
xangle = -xangle;
}
}
if(ball.y > SCREEN_HEIGHT){
yangle = -yangle;
}
// the ball has hit the paddle
if(Collision_BOBS(&ball,&paddle)){
yangle=-yangle; // change direction
lasthit = LAST_HIT_BOTTOM;
// This collision detection determine where the ball hits the paddle and
// calculates a new direction
if(ball.x == paddle.x && ball.y == paddle.height){
if(lkpress){
if(xangle > 0){
xangle = -3.5;
lkpress =false;
}
else if(xangle <0){
xangle = 3.5;
lkpress = false;
}
}
}
if(ball.x > paddle.x && paddle.x <=19){
if(xangle >0){
xangle = 2;
}
else if(xangle <0){
xangle = -2;
}
}
if(ball.x > paddle.x +19 && paddle.x <=38){
if(xangle > 0){
xangle = 1;
}
else if(xangle <0){
xangle = -1;
}
}
if(ball.x >= paddle.x +38 && paddle.x <=57){
if(xangle > 0){
xangle = 0.5;
}
else if(xangle < 0){
xangle = -0.5;
}
}
if(ball.x > paddle.x +57 && paddle.x <=76){
if(xangle < 0){
xangle = -0.5;
}
else if(xangle > 0){
xangle = 0.5;
}
}
if(ball.x > paddle.x +76 && paddle.x <=95){
if(xangle <0){
xangle =-1;
}
else if(xangle >0){
xangle = 1;
}
}
if(ball.x > paddle.x +95 && paddle.x <115){
if(xangle <0){
xangle = -2;
}
else if(xangle >0){
xangle = 2;
}
}
if(ball.x == paddle.x + paddle.width && ball.y == paddle.height){
if(rkpress){
if(xangle < 0){
xangle = -3.5;
rkpress = false;
}
else if(xangle >0){
xangle = 3.5;
rkpress = false;
}
}
}
}
// flip the surfaces
DD_Flip();
// sync to 10ish fps
Wait_Clock(10);
// Perform collision detection with the blocks
for(counter = 0; counter<28; counter++)
if(Collision_BOBS(&ball,&box[counter])){
if(xangle < 0){
xangle = xangle;
}
if(xangle > 0){
xangle = -xangle;
}
if(xangle ==0){
if(lasthit == LAST_HIT_LEFT){
xangle=+rand()%2;
}
if(lasthit == LAST_HIT_RIGHT){
xangle=-rand()%-2;
}
}
if(yangle < 0){
yangle = -yangle;
}
if(yangle > 0){
yangle = yangle;
}
}
// return success
return(1);
} // end Game_Main




Reply With Quote