-
pong ball
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.
Code:
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;
}
-
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!:)
-
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.
-
BGI master
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
Still, I think allegro is better and I'm moving onto it.
-
Boing
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 :)
-
I think im gonna learn allegro....