# Ball...

## Recommended Posts

Hi all, At the moment I have a 2-player pong clone that display and moves paddles, and it all looks very slick (IMHO). However - I don't have a ball implemented yet. *cough*. The ball will be a simple square of maybe 5x5 pixels (on 640x480 surface). What I cannot fathom, however, is how to track how it is moving and move it. At the moment I have; struct ball { int x; int y; int side_length = 5; int color_index = 0; }; I really want to find out by myself how to make it move, but if anyone can give me a (very small) push in the right direction I would be very grateful. Thanks :) [EDIT] Im thinking of using xv and yv for velocity, and then translate the ball xv and yv pixels in the x and y direction respectively. Is this on the right track?

##### Share on other sites
Your going to have to create a Dx and a Dy. Basically what you'll have to do is give Dx a value of how many x values you want it to move per loop, and same for Dy for y values. Then what you'll do is just wipe out the previous one and then draw the new ball at your new (x,y) coordinates.

##### Share on other sites
So what I said was right! Im so pleased I got it by myself... gives you a real sense of achievement even if it is a simple problem. :)

##### Share on other sites
640x480?
What are you programming for? DOS? It sounds a little low-res to me...
If you wanted to be even slicker you could have a few extra bits in your struct:
int rotation;
int d_rotation;
int speed;

and draw a rotated sprite for the ball - that way you could add speed*sin(rotation) to the X and speed*cos(rotation) to the Y and have a ball that you could put weird spin on [grin]

##### Share on other sites
This is my first game. Perhaps when its all working Il do a 1600x1400 3D version with gourad shading, full lightning and 6DOF just for you. How about it?

##### Share on other sites
Well said Beebs =P, yeah thought that this was your first game. Don't worry I truthfully have only really completed 2 graphically used games myself =P everything else for me has been text based. But I'm getting back into things and once you get this one down pat you'll be donig well.

##### Share on other sites
That'll work, but you'll probably need to use floating point numbers instead of integers.

##### Share on other sites
Quote:
 Original post by smart_idiotThat'll work, but you'll probably need to use floating point numbers instead of integers.

Sorry; I'm used to a world where sin(64) = 127 [grin]

Quote:
 This is my first game. Perhaps when its all working Il do a 1600x1400 3D version with gourad shading, full lightning and 6DOF just for you. How about it?

Sounds good! How about internet-multiplayer too? [smile]
Sorry; I just find it odd to choose 640x480 in this day and age; 'tis all. Apart from Doom3, *grumble* that is...
Anyhow; good luck with the project!

##### Share on other sites
Good news - in the last30 mins I have pixel perfect collision between paddles and walls, a point system, and (fairly_ crude bouncing. Yay! The more you get done, the faster you progress!

##### Share on other sites
Quote:
 Original post by beebsGood news - in the last30 mins I have pixel perfect collision between paddles and walls, a point system, and (fairly_ crude bouncing. Yay! The more you get done, the faster you progress!

Cool [grin]
How is the bouncing crude?
Are you just inverting the dx or dy depending on whether you hit a horizontal or vertical barrier? That's the most accurate way to do it... and the simplest.

##### Share on other sites
Quote:
 Original post by benryvesCool [grin]How is the bouncing crude?Are you just inverting the dx or dy depending on whether you hit a horizontal or vertical barrier? That's the most accurate way to do it... and the simplest.

hahaha.. Ur Right.....

##### Share on other sites
I am reversing yv (Y-Axis Velocity). like so

yv*=-1;

When you lauch the ball it randomly goes up, straight or down at random angles <-- looks cool :)

##### Share on other sites
Quote:
 Original post by beebsI am reversing yv (Y-Axis Velocity). like soyv*=-1;When you lauch the ball it randomly goes up, straight or down at random angles <-- looks cool :)

Cool; any screenshots/demos soon? *looks around hungrily*

##### Share on other sites
Il be sure to post a link to the beginners forum! Should be done tonight, maybe early tomoro at the latest.

##### Share on other sites
Quote:
 Original post by beebsI am reversing yv (Y-Axis Velocity). like soyv*=-1;When you lauch the ball it randomly goes up, straight or down at random angles <-- looks cool :)

Its look like the ball going crazy up and down, am i right?

try this formula...

this is for 2d animation.. the ball will looks run like spiral..

for (float a=0;a<=1;a+=0.1){       x=-1800*pow(a,3) + 2700*pow(a,2) - 900*a;       y=450*pow(a,3) - 1200*pow(a,2) + 900*a -200;       drawBall(x,y);}

starts at coordinates (0,-200)
the ball will ending at coordinate(0,-50)

happy trying.

[Edited by - gohacker82 on August 17, 2004 1:33:04 PM]

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627665
• Total Posts
2978524

• 10
• 10
• 12
• 22
• 13