How do i get a puck to slide across the screen?
How do i do the rebounds off of walls
how do i get it to go in the goal because there isnt a hole in the white bounding box?
here is my source please show what you mena if making a suggestion thanks a lot!
How do i get a puck to slide across the screen?
Create x-velocity and y-velocity values, then add these to the puck's position each iteration of the loop.
How do i do the rebounds off of walls
If the puck hits the left or right wall, reverse the x-velocity. if it hits the top or bottom wall, reverse the y-velocity.
edit: You're creating the buffer BITMAP every time your loop runs. Just create it once, before the loop.
{
puck_up++ && puck_down++;
}
And what the fairy-tale is that supposed to do? You do realize that && is a logical-and operator? The above statement does the following:
1. Increase puck_up by 1.
2. Check if puck_up is zero; if so, exit, else, continue.
3. Increase puck_down by 1.
4. Check if puck_down is zero; if so, evaluate to false, else to true.
5. Throw away the result of the comparison made in 4.
So effectively, if puck_up is -1, it increases only puck_up, otherwise it increases both puck_up and puck_down.
Then, learn what structs are and how to use them. For example, both player paddles essentially do the same thing, so they can both be of the same struct type, like this (assuming C++):
struct PADDLE { int x; int y; int w; int h; }; PADDLE player[2] = { { 100, 100, 10, 10 }, // player 1 { 100, 500, 10, 10 } // player 2 };
Please learn some C/C++. Pick up a good (e-)book. There are even very good free ones, such as this one.
1. Increase puck_up by 1.
2. Check if puck_up is zero; if so, exit, else, continue.
3. Increase puck_down by 1.
4. Check if puck_down is zero; if so, evaluate to false, else to true.
5. Throw away the result of the comparison made in 4.
No.
1. Check if puck_up is zero
2. Increase puck_up by 1
3. Exit if puck_up was zero when 1 was executed, even if it isn't zero now
4. Check if puck_down is zero
5. Increase puck_down by 1
6. Throw away result from 4.
EXTRANEOUS NITPICK ENDED
How do i get a puck to slide across the screen?
How do i do the rebounds off of walls
how do i get it to go in the goal because there isnt a hole in the white bounding box?
here is my source please show what you mena if making a suggestion thanks a lot!
Some tips from someone who's also learning from these great masters:
1. Don't forget to meditate some on the things the people of this forum are >giving< you.
2. NEVER post your code and ask people to write big things for you, posting code that doesn't work is sometimes a must, but letting other people do your work (and don't even see tip 1) wont get you anywhere unless you don't care about 'cheating' as long as your friends think you did it. What you asked for is pretty much the whole game..
3. there is no tip number 3.
oh: a tip to myself: read what people say before posting "great" tips... ^^
Have a nice day. Albin out.
zavirax:
void playerone(int p1_x, int p1_y, BITMAP *buffer){ textout_ex( buffer, font, "O", p1_x, p1_y, makecol( 255, 0, 0), makecol( 0, 0, 0) ); /* makes a '+' sign and sets the colour as white and to start where x and y are set*/ textout_ex( buffer, font, "O", p1_x, p1_y, makecol( 255, 0, 0), makecol( 0, 0, 0) ); /* create player one's cursor and make him red*/ }
Why do you have two identical textout_ex() calls following each other? The same applies for the playertwo() function.
if ( ( p1_bb_L <= puck_left && p1_bb_R == puck_left) && ( p1_bb_T >= puck_up && p1_bb_B <=puck_down) )
If, at later stages of development, you decide to move either the players or the puck at more than 1 pixel per loop, the type of collision detection you do above will no longer be effective. If player 1 is moving right towards the puck at say 3 pixels per loop, it could go from being 1 pixel to the left of the leftmost side puck to 2 pixels to the right of the leftmost side. The collision check would fail and the player would pass through the puck.
The following collision check works no matter how fast objects are traveling:
if (p1_bb_L <= puck_right && p1_bb_T <= puck_down && p1_bb_R >= puck_left && p1_bb_B >= puck_up)
This won't tell you what side the collision occured from however. But you can determine the result of the collision based on the velocities of the objects colliding.
puck_left++ && puck_right++;
Even if this did what you thought it did, it's better to change puck_x and puck_y rather than the position of the bounding box.
int puck_left=puck_x; /* puck bounding box*/ int puck_up=puck_y; int puck_right=puck_x+width_p; int puck_down=puck_y+height_p;
I would #define those values instead of making them variables. Now, you only need to keep track of the puck_x and puck_y values, and the bounding box values will be updated automatically.
Those who know these things:
textout_centre_ex(buffer, font,"Air Hockey" , 320, 100, makecol(255, 0, 255), -1); rect( buffer, 60, 120, 580, 400, makecol(255, 255, 255));/*playing field*/ rect( buffer, 40, 230, 60, 290, makecol( 0, 255, 0)); /*player one's net to defend*/ rect( buffer, 580, 230, 600, 290, makecol(0, 255, 0)); /*player two's net to defend*/ line( buffer, 320, 120, 320, 400, makecol( 255, 255, 255));/*half way line*/ circle(buffer, 320, 260, 75, makecol(255, 255, 255));/*center circle*/
Would it make an improvement to speed if, instead of doing these drawing routines every redraw, they'd been prerendered to a bitmap which would then be blitted to the buffer before other object were drawn?
edit: You're creating the buffer BITMAP every time your loop runs. Just create it once, before the loop.
I told him of that on his last identical post.
Would it make an improvement to speed if, instead of doing these drawing routines every redraw, they'd been prerendered to a bitmap which would then be blitted to the buffer before other object were drawn?
dam nice point.
oculd you give an example of how i would do the velocity please and how to reverse it...i changed the buffer positioning and now it works properly thanks i wondered why it still flickered.
float x, y; float xv, yv; // move x += xv; y += yv;
I'll leave reversing a direction as an exercise to the reader.
I really don't want to be rude, but it is apparent this this game is far too advanced for you. Try making some simple programs for now, like moving objects across the screen. This is far too many people wasting their time to help you create something that you wont even understand if you apply everything everyone is telling you. Again, I'm not trying to be mean. I'm just trying to steer you in a direction which is more likely to improve your understanding on programming. If you work on the basics, I'm certain you can do a project like this in no time.
Learn how to use vectors, that's the key!:)
Try making some simple programs for now,
Please, not another tetris and/or pong clone!