pong ball [Archive] - C Board

PDA

View Full Version : pong ball


lambs4
07-01-2002, 07:29 PM
I'm trying to create a text clone pong and would like some help on creating the function for the ball. I've found some source code and tried to modify it for my use only for it to not work.


struct playerData {
int x,y,score;
int oldy;
};

struct ballData {
int x,y;
int oldy, oldx;
};

struct playerData player1 = {3,10}, player2 = {78,10};
struct ballData ball = {40,10};


void drawBall(void)
{
int xinc,yinc;
if(ball.x < 0)
player2.score++;
if(ball.x > 79)
player1.score++;
if(ball.x == 3)
xinc = 1;
if(ball.x == 23)
xinc= -1;
if(ball.y == 23)
xinc= -1;

if(player1.x <= 3 && 3 < player1.x && player1.y == 2)
yinc = 1;
if(player2.x <= 3 && 3 < player2.x && player2.y == 78)
yinc = -1;
gotoxy(ball.oldx,ball.oldy);
printf(" ",BALL);
gotoxy(ball.x,ball.y);
printf("%c",BALL);
ball.oldx = ball.x;
ball.oldy = ball.y;
ball.x += xinc;
ball.y += yinc;

}

TechWins
07-02-2002, 12:49 AM
personally if i were you i wouldn't spend the time creating pong for the console. you would be much more satisfied when your game is finished if the game were in 2D rather than text.

allegro is a very good API to use for your case, IMO. it's very simple, and gets the job done.

go to allegro.cc for more info on it.

seriously, though, why waste your time creating a game like that in console? go out and do it in 2D...come on!:)

lambs4
07-02-2002, 05:59 AM
I know that it would be better if it were programmed using graphics, but I've already tried that by using the BGI and failed. So I thought by using text I'd atleast have the game itself working.

Paninaro
07-02-2002, 10:13 AM
I know BGI fairly good because I have used it to program my first game. You can see my game ballwar with source code which uses the BGI in this post (http://www.cprogramming.com/cboard/showthread.php?s=&threadid=20765)
Still, I think allegro is better and I'm moving onto it.

Spleeneraclingy
07-12-2002, 06:57 PM
BGImaster? Oh yeah, ballwars is so polished it shines:p (I'm just kiddin') and yes, Allegro is great...BUT on the other hand, OpenGL just plain ownz :)

civix
07-18-2002, 10:53 PM
I think im gonna learn allegro....