Jump to content
  • Advertisement
Sign in to follow this  
beebs

Ball...

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by smart_idiot
That'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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by beebs
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!


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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!