|
-
Nov 13th, 2002, 04:13 PM
#1
Thread Starter
Frenzied Member
xangle <> 0
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
Last edited by CyberCarsten; Nov 13th, 2002 at 04:19 PM.
-
Nov 15th, 2002, 08:33 AM
#2
transcendental analytic
if(xangle ==0){
if(lasthit == LAST_HIT_LEFT){
xangle=+rand()%2;
}
if(lasthit == LAST_HIT_RIGHT){
xangle=-rand()%-2;
}
}
I don't know what your program does, but this doesn't prevent it...
things like this doesn't do anything either...
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 15th, 2002, 09:06 AM
#3
Now this really confuses me. What sense does it make to calculate modulo a negative number?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 15th, 2002, 09:13 AM
#4
Addicted Member
I take it that if xangle == 0 - you want to change it to be non-zero..?
If this is the case you need to not use the rand() functions - it could return you zero - which would put you in the same situation. You're getting something like rand() % 2 - which could give you 0 or 1 (I think thats how mod works in C).
As kedaman says - the xangle = xangle etc lines could just be omitted - it's unnecessary.
Other than that - theres too much code for me to wade through to find anything else - and I should be working . (Sorry, but it's true).
HD
-
Nov 15th, 2002, 10:16 AM
#5
(I think thats how mod works in C).
Not only in C but everywhere. Modulo is a basic algebraic operation. It means "do an integer division and return the remainder". Which can be anything from 0 to divisor-1.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 15th, 2002, 11:24 AM
#6
Addicted Member
Unfortunately while the theory is true - implementations of mod can vary (or so I was told by my Cryptography lecturer at University a couple of years ago).
Apparently while the modulo theory says 0 - (n-1), the implementations of it can mean 1 - n.
Newer languages have a consistent implementation, but some systems differ.
If this is wrong I would be happy to go back to university to complain to the lecturer )
HD
-
Nov 15th, 2002, 01:00 PM
#7
Frenzied Member
Originally posted by HairyDave
Apparently while the modulo theory says 0 - (n-1), the implementations of it can mean 1 - n.
This is dead wrong, and makes no sense. It essentially says that for any division, you cannot have a remainder of 0, but you can have a remainder of n, which, of course is incorrect. If there are implementations of that operation that behave like that... well, its just wrong.
Z.
-
Nov 15th, 2002, 07:24 PM
#8
Fanatic Member
Code:
if(xangle > 0){
xangle = -xangle;
if(xangle< 0)
xangle=0;
}
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|