pong ball

This is a discussion on pong ball within the Game Programming forums, part of the General Programming Boards category; I'm trying to create a text clone pong and would like some help on creating the function for the ball. ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    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;
    
    }

  2. #2
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    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!

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    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.

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    75

    Talking 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.
    ---Programming is like roaming, you never know where you'll end at------

    If 'here' is pronounced as 'hear', why 'there' isnt pronounced as 'dear'??

    paninaro3000@yahoo.com

  5. #5
    Registered User Spleeneraclingy's Avatar
    Join Date
    May 2002
    Posts
    16

    Wink Boing

    BGImaster? Oh yeah, ballwars is so polished it shines (I'm just kiddin') and yes, Allegro is great...BUT on the other hand, OpenGL just plain ownz
    "Life's short and hard, like a bodybuilding elf."

  6. #6
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605
    I think im gonna learn allegro....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to create a bouncing ball?
    By Swerve in forum C++ Programming
    Replies: 7
    Last Post: 09-12-2008, 03:41 AM
  2. Pls repair my basketball program
    By death_messiah12 in forum C++ Programming
    Replies: 10
    Last Post: 12-11-2006, 04:15 AM
  3. Display Lists (OpenGL)
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 06-05-2005, 12:11 PM
  4. Mind-Reading chip for the disabled
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 04-04-2005, 12:44 PM
  5. "Pong" NOTE: In Visual Basics!!! Needed Formula
    By Helpmeplease in forum Game Programming
    Replies: 3
    Last Post: 12-05-2002, 09:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21