   Novice Programmer Looking to improve
  Hello,I would like to first introduce myself. My name is Doug and I am currently attending college to receive a degree in Computer Science. Throughout my young life I had always been fascinated by computers and wanted to know what made them tick. However, it wasn't until my Freshmen year of high school that I had really started to understand the concept of computer programming. It all seemed to out of this world, overwhelming and far out of my reach. My first year of college I had a class in C programming and I liked it so much that I had eventually gotten to the point where I made a very poor imitation of Mario and a Vertical Shooter using Allegro with devcpp. I took a long break and recently started getting back into it.I've been reading through cprogramming.com trying to understand as much as I can before actually attempting to write another program. I am very interested in programming to develop different kinds of games. Now, I'm not expecting to create some out of this world extraordinary game, but I want to at least work towards something.I love programming, but I was hoping that someone here could be so kind as to point me in the right direction. I know a lot about the language and am somewhat lacking in experience. I will post here the most complicated thing I've written so you can get some idea of where I am at right now. I'd appreciate any help.Sorry if it appears long. I'm not sure how everyone is getting the code in the boxes.!Vertical Shooter!#include <allegro.h>volatile long speed_counter = 0; void increment_speed_counter(){   speed_counter++; }END_OF_FUNCTION(increment_speed_counter); int main(){    allegro_init();    install_keyboard();    install_timer();    detect_midi_driver(MIDI_AUTODETECT);    install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL);    LOCK_VARIABLE(speed_counter);    LOCK_FUNCTION(increment_speed_counter);    install_int_ex(increment_speed_counter, BPS_TO_TIMER(60));    set_color_depth(16);    set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1024,768, 0, 0);   MIDI *theme = load_midi("theme.mid");    BITMAP *buffer = create_bitmap(1024, 768);    BITMAP *saucer = load_bitmap("saucer.bmp", NULL);    BITMAP *boom = load_bitmap("boom.bmp", NULL);    BITMAP *cloud1 = load_bitmap("cloud.bmp", NULL);    BITMAP *csaucer = saucer;    BITMAP *csaucer2 = saucer;    BITMAP *csaucer3 = saucer;   play_midi(theme, TRUE);   if (install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL) != 0)  {  allegro_message("ERROR: Couldn't initialize sound hardware!");  }    if (!theme)  {  allegro_message("ERROR loading MIDI!");  } int tri_x1=602, tri_y1=650, tri_x2=555, tri_y2=700, tri_x3=650, tri_y3=700;    int rec_x1=tri_x1, rec_y1=tri_y1, rec_x2=tri_x1+5, rec_y2=tri_y1+10, fire=0;    int cx[3],cy[3], ex[3], ey[3], end=0;   ex[0]=50, ey[0]=-400;    ex[1]=500, ey[1]=-400;   //________________This is bounding box stuff!_____________   int saucer_bb_left =  ex[0];    int saucer_bb_top =  ey[0];   int saucer_bb_right = (saucer_bb_left + csaucer->w);    int saucer_bb_bottom = (saucer_bb_top + csaucer->h);    //_______________________________________________________   //________________This is bounding box stuff!_____________   int saucer2_bb_left =  ex[1];    int saucer2_bb_top =  ey[1];   int saucer2_bb_right = (saucer2_bb_left + csaucer2->w);    int saucer2_bb_bottom = (saucer2_bb_top + csaucer2->h);    //_______________________________________________________   cx[0]=10, cy[0]=0;    cx[1]=600, cy[1]=100;    cx[2]=400, cy[2]=300;   while(!key[KEY_ESC])  {   while(speed_counter > 0)  {  clear_to_color(buffer, makecol(0, 100, 200));  //________________More bounding box stuff! UPDATE_____________  saucer_bb_left =  ex[0];  saucer_bb_top =  ey[0];  saucer_bb_right = (saucer_bb_left + csaucer->w);  saucer_bb_bottom = (saucer_bb_top + csaucer->h);  //____________________________________________________________    //________________More bounding box stuff! UPDATE_____________  saucer2_bb_left =  ex[1];  saucer2_bb_top =  ey[1];  saucer2_bb_right = (saucer2_bb_left + csaucer2->w);  saucer2_bb_bottom = (saucer2_bb_top + csaucer2->h);  //____________________________________________________________    if(end < 10){  if(key[KEY_UP]) tri_y1-=9, tri_y2-=9, tri_y3-=9;  if(key[KEY_DOWN]) tri_y1+=9, tri_y2+=9, tri_y3+=9;  if(key[KEY_LEFT]) tri_x1-=9, tri_x2-=9, tri_x3-=9;  if(key[KEY_RIGHT]) tri_x1+=9, tri_x2+=9, tri_x3+=9;  if(key[KEY_SPACE]) fire=1;    if(saucer_bb_top <= rec_y2 && saucer_bb_bottom >= rec_y2 && saucer_bb_right >= rec_x1 && saucer_bb_left <= rec_x2)   {csaucer = boom;}    if(csaucer == boom)ey[0] += 15;  if(ey[0] >= 800) csaucer = saucer, ey[0]=-90, ex[0]+=100, end++;  if(ex[0] >= 900) ex[0] = 50;    ey[0]+=4;    if(saucer2_bb_top <= rec_y2 && saucer2_bb_bottom >= rec_y2 && saucer2_bb_right >= rec_x1 && saucer2_bb_left <= rec_x2)   {csaucer2 = boom;}    if(csaucer2 == boom)ey[1] += 15;  if(ey[1] >= 800) csaucer2 = saucer, ey[1]=-90, ex[1]+=100, end++ ;  if(ex[1] >= 900) ex[1] = 500;   ey[1]+=4; if(fire==1)rec_y1-=30,rec_y2-=30, rectfill(buffer, rec_x1, rec_y1, rec_x2, rec_y2, makecol(255, 255, 0));  if(rec_y1 <= 0 || saucer_bb_top >= rec_y2 && saucer_bb_right >= rec_x1 && saucer_bb_left <= rec_x2) fire=0;  if(rec_y1 <= 0 || saucer2_bb_top >= rec_y2 && saucer2_bb_right >= rec_x1 && saucer2_bb_left <= rec_x2) fire=0;  if(fire == 0)rec_x1=tri_x1, rec_y1=tri_y1, rec_x2=tri_x1+5, rec_y2=tri_y1+10;  }  if(key[KEY_R])end =0;    if(cy[0] >= 830)cy[0]=-350;  if(cy[1] >= 875)cy[1]=-230;  if(cy[2] >= 1200)cy[2]=-600;    cy[1]+=6, cy[0]+=5, cy[2]+=7;    draw_sprite(buffer, cloud1, cx[0],cy[0]);  draw_sprite(buffer, cloud1, cx[1],cy[1]);  draw_sprite(buffer, cloud1, cx[2],cy[2]);    triangle(buffer, tri_x1, tri_y1, tri_x2, tri_y2, tri_x3, tri_y3, makecol(255,0,0));    draw_sprite(buffer, csaucer, ex[0], ey[0]);  draw_sprite(buffer, csaucer2, ex[1], ey[1]);    speed_counter--;  }  if(end >= 10)textout_ex(buffer, font, "You Win! (R to Try Again!)", 512, 334, makecol(100, 255, 100), -1);  textout_ex(buffer, font, "Kill 10 to Win!" , 50, 758, makecol(0, 0, 0), -1);  vsync();  draw_sprite(screen,buffer, 0,0);  }    destroy_bitmap(buffer);  destroy_bitmap(cloud1);}END_OF_MAIN();!Mario!#include <allegro.h>#include "mario.h"//Sets up a global variable for use with timer.volatile long speed_counter = 0;//This function increases the speed counter but 1.void mechanics(){//Declaring the images and loading them.   DATAFILE *mariodata = load_datafile("mario.dat");    MIDI *theme = load_midi("marjazz.mid");   /*Mario1 and Mario2 are empty bitmap variables assigned a value so  that mario can change directions while animated. It's a vairable  for images*/    int mario1 = marior;    int mario2 = marior1;   //Images are drawn to the buffer and then the buffer is drawn to the screen.    BITMAP *buffer = NULL;    buffer = create_bitmap(1280, 800);   play_midi(theme, TRUE);   //This series of if statements checks proper loading of the images.    if (install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL) != 0)  {  allegro_message("ERROR: Couldn't initialize sound hardware!");  }    if (!theme)  {  allegro_message("ERROR loading MIDI!");  }    if(buffer == NULL)  {  set_gfx_mode(GFX_TEXT,0,0,0,0);  allegro_message("Could not make buffer!");  exit(EXIT_FAILURE);  }    if(mariodata == NULL)  {  set_gfx_mode(GFX_TEXT,0,0,0,0);  allegro_message("Could not load Mario Datafile.");  exit(EXIT_FAILURE);  }   //Declaring all the variables non-image variables.    int x=0, y=600, block_x=400, block_y=505, frame_counter=0, jump = 0, jump2 =0;    int time = 0, keyright=0, keyleft;   //This loops decides if the programs ends when a key is pressed (ESC).    while(!key[KEY_ESC])    {    //First draws the world background and then starts the speed counter.    //draw_sprite(buffer, world, 0, 0);draw_sprite(buffer, (BITMAP*)mariodata[world].dat, 0, 0);  while(speed_counter > 0)  {    //Moves mario based on which direction is pressed and changed image.  if(keyright == 1 && jump == 0) mario1 = marior, mario2 = marior1;  if(keyleft == 1 && jump == 0) mario1 = mariol, mario2 = mariol1;    if(key[KEY_RIGHT]) {  x +=5;  mario1 = marior, mario2 = marior1;  keyright = 1;  keyleft = 0;if(x >= 1281)  {x = -88;  }}  else if(key[KEY_LEFT]) {x -=5;mario1 = mariol, mario2 = mariol1;keyleft = 1;keyright = 0;if(x <= -89)  {   x = 1280;  }}    if(key[KEY_UP] && time == 0) jump = 1, time = 1;if(jump == 1)  {  if(keyleft == 1){mario1 = mariojl;mario2 = mariojl;}  if(keyright == 1){mario1 = marioj;mario2 = marioj;}  // d = vstart T + 1/2 a T^2   //y = y - (  (.5 * time*1) - ( .009 * time * time))) ;   y = y - (  (7) - ( .009 * time * time)) ;  time++;    if (y >= 600) {y = 600;jump = 0;time = 0;}  } //Decrease speed counter and increase frame counter.    speed_counter--;    frame_counter++;   //This sets up the animations to work in sync with the BPS.if(frame_counter > 30) { frame_counter = 0; } }   //Only animate if Left or Right is pressed.    if(key[KEY_LEFT] || key[KEY_RIGHT]) {   if(frame_counter < 15)   {   draw_sprite(buffer, (BITMAP*)mariodata[mario1].dat, x, y);    } else if(frame_counter >=15 && frame_counter < 30)   {    draw_sprite(buffer, (BITMAP*)mariodata[mario2].dat, x, y);  } else   {   draw_sprite(buffer, (BITMAP*)mariodata[mario1].dat, x, y);   } }    else {   draw_sprite(buffer, (BITMAP*)mariodata[mario1].dat, x, y); }//Finally drawing the sprites to the buffer, then the buffer to the buffer. draw_sprite(buffer, (BITMAP*)mariodata[block].dat, block_x, block_y);draw_sprite(screen, buffer, 0, 0);clear_bitmap(buffer);    }   //Removing images from memory before closing the program.    destroy_bitmap(buffer);    destroy_midi(theme);    unload_datafile(mariodata);}void increment_speed_counter(){speed_counter++;}END_OF_FUNCTION(increment_speed_counter);int main ()   {    //Initialize allegro, keyboard, and the timer.    allegro_init();    install_keyboard();    install_timer();    detect_midi_driver(MIDI_AUTODETECT);install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL);    //Locking in the speed counter and function for historical reasons.    LOCK_VARIABLE(speed_counter);    LOCK_FUNCTION(increment_speed_counter);   //This determines how many Beats per second are sent to the speed counter.    install_int_ex(increment_speed_counter, BPS_TO_TIMER(80));   //The color depth and resolution.    set_color_depth(16);    set_gfx_mode(GFX_AUTODETECT, 1280, 800,0,0);    mechanics();   return 0;    }END_OF_MAIN();
  Hello!I'm not sure what the problem is. Just pick a small project and start working. When you have problems search Google and these forums, and if you still don't find the answer, go ahead and ask.You can also read books like Code Complete on the side to improve your coding.Also, you might want to check out some alternatives to C and C++. I personally enjoy Python and I think you definitely should spend at least a few hours checking it out. There are free books and all sorts of resources out there.Good luck!   ;  Hi Doug, welcome to GameDev.net.I would like to note that there is a 'for beginners' section available. Code wise, it looks like you have a decent start on things. Over time you'll develop your own style of programming and layout. For example, your brace brackets are sometimes indented and sometimes they are not. Consistency in code is one rule programmers live by. You have a large number of comments in your code, this is a HUGE plus. Many programmers thing its cool to write very complex code and not document it. It makes them think that they are uber leet or something.As a start, get in there and get dirty. Make a few crappy little applications (like tetris or a side scroller) and figure out how things work. The more time you spend in the trenches, the better. Once you finish one, start on a bigger project, and so on. Eventually you will refine your skill and style and might take a stab at writing something big and juicy.For now, why don't you try refactoring your code to make it more modular. Separate the graphics from the game logic. The math from the input logic, etc. Think about how you can design it so that you can add a new graphics engine and not totally screw up the entire game. Look into C++ and classes. Read other people's code and then apply the things you like to your own style.   ;  Thank you. That's that direction I was looking for. I am fairly weak in the use of functions which directly affects my ability to use classes and so on. My last attempt at this same program was making it more modular but I lost the code when the portable hard drive I had stopped functioning. This code is from the most recent back up.I will check out the beginners section more thoroughly and check out code complete. I haven't heard much about python and it doesn't sound all too appealing to me, but maybe I'll look into it.   