Jump to content

Pong Game info

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
shadowhound

shadowhound

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
i have been learning C and i have got most of the basics down and i would like to start my first project and i would like to start a pong game in C and was wondering how i would go about making it from scratch and its for my pc where i use the mouse as the paddle

so any idear how i could start ? please thank u

also any other idears on starting projects since im still only coding in the console

#2
Phoenixz

Phoenixz

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 256 posts
^_^ I just started learning this myself, you'll need things like:

                                                                     
                                                                     
                                                                     
                                             
#include <allegro.h>

int x = 10;
int y = 10;

int main()
{
   /* we need to use allegro_init to install the files we need. */
   allegro_init();
   /* install_keyboard allows the user 
   install_keyboard();
   /*  this changes the resolution 640x480 */
   set_gfx_modoe( GFX_AUTODETECT, 640, 480, 0, 0);

   /* this reads which keys are pressed. */
   while ( !key[KEY_ESC] ){
  
      /* clear_keybuf is like fflush(stdin) it's to clear all saved buttons pressed.
      clear_keybuf();
     
      /* acquire_screen is used to let allegro know that we need to draw to the screen. */
      acquire_screen();
    
      textout_ex( screen, font, " ", x, y, makecol( 0, 0, 0), makecol( 0, 0, 0) );
     
      
      /* the --y ++y ++x --x refer to the axis like from graphs. */
      if (key[KEY_UP]) --y; /* --y means up */
      else if (key[KEY_DOWN]) ++y; /* ++y means down */
      else if (key[KEY_RIGHT]) ++x; /* ++x means right */
      else if (key[KEY_LEFT) --x; /* --x means left */

      /* textout_ex will draw text to the screen
       * it requires seven parameters, the first is where you want it to right too
       * second is type of font to be used, third is what text to draw to the screen
       * next two parameters are where you want it to be drawn. 
       * 0, 0 would be top left, x will move it right/y will mmove it down.
       * next is colour of text, makecol() which takes 3 parameters.
       * first is the intensity of the red, the green, and the blue.
       * the final parameter is background colour! 
       */

      textout_ex( screen, font "@", x, y, makecol( 255, 0, 0), makecol( 0, 0, 0) );

      /* release_screen is used to let go of the screen, so we are no longer drawing to it. */
      release_screen();
    
      /* Rest is used to pause the program for a set amount of milliseconds */

      rest(50);

   }


   return 0;

}
END_OF_MAIN();

Oh, and

    //circle and circlefill both draw circles, the difference is that circlefill
    //will fill with the colour specified in the last parameter, while circle()
    //simply draws the outline. The second and third paramater specifies the position
    //the fourth defines the radius of the circle.

    circle( screen, 20, 20, 10, makecol( 255, 0, 0));
    circlefill( screen, 50, 50, 25, makecol( 0,255, 0));

Posted Image

#3
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
Drawing directly to the screen, even if you acquire it, has enormous speed penalties. It's better to create a bitmap, draw to that, and blit the complete frame to the screen. That way is faster and in between draw operations, you won't have frames where, eg, the paddles are drawn but the score isn't.
Watches: Nanoha, Haruhi, AzuDai. Listens to: E-Type, Dj Melodie, Nightcore.
"When people are wrong they need to be corrected. And then when they can't accept it, an argument ensues." - MeTh0Dz

#4
shadowhound

shadowhound

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
okay got a little problem im coding this pong game via a console app i dunno if this is right but when i complie it it tells me in the debug section.

Pong Demo - Debug" uses an invalid compiler. Skipping...
Nothing to be done.


also im coding in code::blocks so do i need anything adding like plugins or librays or anything ?

#5
Phoenixz

Phoenixz

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 256 posts
you need a specific library, google for allegro library for <your C++ compiler>
Posted Image

#6
shadowhound

shadowhound

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
okay i figured an easy way to download the libray files using Dev C++ all i do is go to Tools> Check for updates/packegs > check the devpacks

and find it in there and download :D:D:D so i know now that works :) but i tryed compileing it and got an error on

textout_ex( screen, font "@", x, y, makecol( 255, 0, 0), makecol( 0, 0, 0) );

the error is
25 C:\Dev-Cpp\Marks Projects\main2.c syntax error before string constant

i don't know what it means i understand the code sort of

#7
Muted

Muted

    Learning Programmer

  • Members
  • PipPipPip
  • 86 posts
textout_ex

Hope it helps.

Edited by Muted, 29 January 2009 - 10:43 AM.

“You may be disappointed if you fail, but you are doomed if you don't try.”
- Beverly Sills

#8
shadowhound

shadowhound

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
the link has a bit of usefull information im understanding the programming better now the only thing that needs adding is adding of the bitmaps i recon but im searching around for informaction