|
This thread is locked; no one can reply to it. |
1
2
|
How to make balls coming from the top? |
vilafranca
Member #8,647
May 2007
|
Hey buddies, I have the following program that I made [college homework]
*** My doubt is in the "Void Principal" part of the program! [take a look, please] Thank u so much!!! |
Paul whoknows
Member #5,081
September 2004
|
Use code tags [CODE][/CODE](tags must be in lower case). Also, it would be nice if you translate your variables and functions names to English. ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
vilafranca
Member #8,647
May 2007
|
Hey Paul, thanks for your help! Could u explain that to me, or someone else?! |
Mark Oates
Member #1,146
March 2001
|
in the text box where you reply to posts, click the help button. It'll show you there a tag for source code. You should edit your first post and use the code tags. It makes it easier to read -- |
vilafranca
Member #8,647
May 2007
|
Ok, I edited it Now, could u help meeeeee?! |
Paul whoknows
Member #5,081
September 2004
|
Remove the while (!(key[KEY_ESC]) in principal(). Does that work? ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
CGamesPlay
Member #2,559
July 2002
|
This is the code in question. It is called your "main loop". If you look at what's happening, it's not at all what you need to be happening. The while part is good. You want your code to run until the escape key is pressed. In other words, while the escape key is not pressed. That's fine. Inside the loop, You need to separate your code into logic and drawing. First, make a list of what you need to keep track of. In this case, it's the ball's position. Store these variables outside of the loop: // ... int ball_x, ball_y; while(!(key[KEY_ESC])) { // Logic: // Drawing: } Then, in the logic section, move the ball by changing ball_x and ball_y. Also check if the player has moved the mouse over the ball in this section. And finally, in the drawing section, draw the player's ball using mouse_x and mouse_y and draw the ball using the stored ball_x and ball_y. I hope that all makes sense. Don't worry if the ball zooms off-screen faster than you can hover over it. You'll need to get into timers to fix that issue. -- Ryan Patterson - <http://cgamesplay.com/> |
vilafranca
Member #8,647
May 2007
|
Actually, there's no error when I compile the program! for(i=0; !(key[KEY_ESC]); i=i+1) { circlefill(buffer, i, i, RAIO+8, makecol(200,0,10)); circlefill(buffer, mouse_x, mouse_y, RAIO, makecol(0,120,160)); textprintf_right_ex(buffer, font, 515, 10, makecol(255,255,255), 0, "Posicao X: %3.0d Posicao Y: %3.0d", mouse_x, mouse_y); draw_sprite(screen, buffer, 0,0); clear(buffer); if ((mouse_x == i) && (mouse_y == i)) { finaliza(); exit(-1); } } When the red ball disappears of the screen, it must appear a new one! But this for command seems never stop, so, when i create another for command for another red ball, it doesn't work, cos the 1st FOR is still running... so the next ball never comes... that's the problem! what do i do? is there a way to do these balls coming one by one without using FOR?! |
Paul whoknows
Member #5,081
September 2004
|
Try this:
However, this: won't work as a collision detection. ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
vilafranca
Member #8,647
May 2007
|
Doesn't work Paul! My gosh, I have no IDEA how to do that...
|
Paul whoknows
Member #5,081
September 2004
|
Quote: but this code just makes the same ball coming always in the same direction Yes of course, what did you expect? I posted that just to 'stop' your neverending for(). If you want balls in different directions you should use vectors, something like this:
____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
vilafranca
Member #8,647
May 2007
|
Hey buddies, I fixed some part of the program! The matter now is... the program must finish when the blue ball [mouse cursor] hits the red ball! I made this instruction for it: But this command will only work if the mouse cursor hits EXACTLY the center of the red ball (coordinates i,j), which is not pretty good! the best thing to do is to finish the program if the blue ball hits ANY part of the red ball, not exactly the center, cos it makes more difficult to hit it! Any help to fix it, please?! |
Paul whoknows
Member #5,081
September 2004
|
Put a bounding box in each ball, do the collision detection between both boxes using this function: x1,y1 +----+ |RED | |BALL| +----+x2,y2 xx1,yy1 +----+ |BLUE| |BALL| +----+xx2,yy2
inline bool collide(int x1, int y1, int x2, int y2, int xx1, int yy1, int xx2, int yy2) { if (x2 <= xx1) return false; else if (x1 >= xx2) return false; else if (y2 <= yy1) return false; else if (y1 >= yy2) return false; else return true; }
____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
miran
Member #2,407
June 2002
|
@paul: That's just stupid. Why would you use bounding box collision detection for detecting collisions between circles? Use circle/circle collision detection for that instead: 1. calculate distance between the centre of red ball and blue ball float x1, y1, r1; float x2, y2, r2, float dx = x2 - x1; float dy = y2 - y1; float d = dx*dx + dy*dy; if (d <= (r1+r2)*(r1+r2)) { // collision! } @vilafranca: Do EXACTLY what CGamesPlay tells you to do and get completely and totally rid of your for loop! -- |
Paul whoknows
Member #5,081
September 2004
|
Quote: That's just stupid. Why would you use bounding box collision detection for detecting collisions between circles?
Box collision is easier to understand than circle/cirlcle collision, that's why I showed him the b. box collision function. Also, I think he does not need so much precision in his program. ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
miran
Member #2,407
June 2002
|
Quote: Box collision is easier to understand than circle/cirlcle collision, that's why I showed him the b. box collision function. Also, I think he does not need so much precision in his program. Uhm, maybe that's just me, but circle-circle collision is the simplest, easiest, most basic type of collision test there is. -- |
Johan Halmén
Member #1,550
September 2001
|
No, it's me too. Even when you go into bouncing reaction, the circle-circle thing is not very difficult. You can define a line from one circle to the other (middle points), you can find out the collision point on this line, you can define the tangential line through this point. Now you have an imaginary wall that both circles collide against. And so on. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
Paul whoknows
Member #5,081
September 2004
|
Quote: Uhm, maybe that's just me, but circle-circle collision is the simplest, easiest, most basic type of collision test there is. Damn! you got me.>:( I just wanted to draw some ASCII boxes! are you happy now? ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
Johan Halmén
Member #1,550
September 2001
|
Yes. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
CGamesPlay
Member #2,559
July 2002
|
Quote: Try this: Hmm, give a man a fish, teach a man to fish... -- Ryan Patterson - <http://cgamesplay.com/> |
Tobias Dammers
Member #2,604
August 2002
|
Quote: Hmm, give a man a fish, teach a man to fish...
My thought exactly. Here are a few things to google / forum-search: Set up a main loop. This should do logic and drawing. --- |
Paul whoknows
Member #5,081
September 2004
|
Quote:
Quote: Try this: Hmm, give a man a fish, teach a man to fish... A fish is better than nothing. Also, learning to fish takes some time, meanwhile, he needs something to eat. ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
CGamesPlay
Member #2,559
July 2002
|
Quote: Hey buddies, I have the following program that I made [college homework] ... -- Ryan Patterson - <http://cgamesplay.com/> |
Tobias Dammers
Member #2,604
August 2002
|
That reads: OMG WTF PLZ DO MY HOMEWORK 4 ME LOLZ --- |
vilafranca
Member #8,647
May 2007
|
No Tobias, I didn't ask anyone to DO my homework... I just asked for HELP! Anyway, I wanna thank everyone who came here to gimme a help! Thank u guys... |
|
1
2
|