Public Group

# Ball...

This topic is 5145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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.

1. 1
2. 2
3. 3
Rutin
20
4. 4
frob
18
5. 5

• 32
• 13
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
632562
• Total Posts
3007093

×