Sign in to follow this  

Ball...

This topic is 4865 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
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
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
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
Quote:
Original post by benryves

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.


hahaha.. Ur Right.....

Share this post


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


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

Share this post


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


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]

Share this post


Link to post
Share on other sites

This topic is 4865 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this