Ball...

Started by
13 comments, last by gohacker82 19 years, 8 months ago
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?
Check out my first game here.
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.
--Ter'Lenth
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. :)
Check out my first game here.
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]

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

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?
Check out my first game here.
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.
--Ter'Lenth
That'll work, but you'll probably need to use floating point numbers instead of integers.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
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!

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

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!
Check out my first game here.
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.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

This topic is closed to new replies.

Advertisement