I have created a header file and a main.cpp file in Visual Studio C++.
I have the concept down but i'm not sure that my program is written correctly as it is failing with teh following error;

error C2447: '{' : missing function header (old-style formal list?)

I want to create a shape and have it move throughout the screen by recognizing when it has hit the edge of the screen. All functions listed are required functions that i must use. Draw object, move object and erase object.

Here is the Main.cpp

#include <allegro.h>
#include "Shapemover.h"



//Function to build a shape of a circle

void drawShape( )
{
int xPos;
int yPos;
 
int x =10;
int y =25;

//get new x and y positions
xPos = shape.x;
yPos = shape.y;

//body color
shape.color = COLOR_1;

//draw the body here..
circlefill(screen, x+22, y+20, 20, COLOR_1);
}

///////////////////////////////////////////////////////////////////////////////
//Move Shape function
//////////////////////////////////////////////////////////////////////////////

void moveShape();
{

//initialize x and y direction and point of reference with current position of shape

dirX = x + 10;   			//x direction
dirY = y + 10;				//y direction
int x = 10;					//current x position
int y = 20;					//current y position


//calculate new x position with current direction
x = (x + dirX);

//is the shape going beyond the right border?
if (x > SCREEN_W - LENGTH)			//no ; is needed?
{									//THEN 
	x = SCREEN_W - LENGTH;  		//only bump against side
    	dirX = dirX - DIRECTION;  	//then change direction
}									//END IF


//is the shape going beyond the left border?
if x < LENGTH
{									//THEN 
	x = LENGTH;						//only bump against side
   	dirX = DIRECTION;  				//then change direction
}									//END IF

//update the y position, keep within screen
//calculate new y position with current direction
y = y + dirY;

//is the shape going below the bottom border?
if y > SCREEN_H - HEIGHT
{									//THEN
     y = SCREEN_H - HEIGHT;			//only bump against the bottom
     dirY = dirY - DIRECTION;  		//then change direction
}									//END IF

//Is the shape going above the top border?
if y < HEIGHT + TOP_OFFSET
{									//THEN
     y = HEIGHT + TOP_OFFSET;		//only bump against the bottom
     dirY = DIRECTION;				//then change direction
}									//END IF

//update shape to new position and direction
x = 25;
y = 35;
dirX = x +15;
dirY = y +15;

}



/////////////////////////////////////////////////////////////////////////
// eraseShape function
// erase the shape using rectfill
/////////////////////////////////////////////////////////////////////////
void eraseShape( )
{
//calculate box to encompass the tank
    int left = shape.x +10;
    int top = shape.y +20;
    int right = shape.x + 60;
    int bottom = shape.y + 60;

    //erase the tank
    rectfill(screen, left, top, right, bottom, 0);

    //erase the circle
  //  rectfill(screen, 225,230,275,150,0); //Creates a filled rectangle that is black (test this using YELLOW)
}


/////////////////////////////////////////////////////////////////////////
// setupscreen function
// set up the graphics mode and game screen
/////////////////////////////////////////////////////////////////////////
void setupscreen()
{
    //set video mode
    int ret = set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);
    if (ret != 0) {
        allegro_message(allegro_error);
        return;
    }

    //print title
    textprintf_ex(screen, font, 1, 1, BURST, 0,
        "Move Target - %dx%d", SCREEN_W, SCREEN_H);

    //draw screen border
    rect(screen, 0, 12, SCREEN_W-1, SCREEN_H-1, TAN);
    rect(screen, 1, 13, SCREEN_W-2, SCREEN_H-2, TAN);

}


int main(void)
{
     //initialize everything
     allegro_init();
     install_keyboard();
     install_timer();
     setupscreen();

     //wait for keypress
     while(!key[KEY_ESC])
     { 
          //erase shape
          eraseShape( );
          //move shape
          moveShape( );
          //draw shape
          drawShape( );
          //pause a moment
          rest(1);  //you may need to play with this value
     }//end while

     allegro_exit();
     return 0;
} //end main
END_OF_MAIN()

and here is the header file

#ifndef _SHAPEMOVER_H
#define _SHAPEMOVER_H
#include "allegro.h" //include Allegro's libraries

//define screen constants
#define MODE GFX_AUTODETECT_WINDOWED
#define WIDTH 640
#define HEIGHT 480

//define shape constants
#define LENGTH 70 //put the length of your shape here
#define TALLNESS 10 //put the height of your shape here
#define DIRECTION 20 //put your direction constant here
#define TOP_OFFSET 15 //put your offset distance from the top here
#define COLOR_1 makecol(118,225,200) //put red, green, and blue values here
#define COLOR_2 makecol(202,105,100) //put red, green, and blue values here
#define TAN makecol(255,242,169)
#define BURST makecol(255,189,73)
#define ORANGE makecol(180,75,32)
#define BLACK makecol(0,0,0)
#define YELLOW makecol(255,255,0)

//define shape structure
struct tagShape
{
int x,y; //center point of shape
int dirX; //direction constant for left and right
int dirY; //direction constant for up and down
int color; //color of shape
int radius;  //radius of my circle
int xMov;
int yMov;
} shape; //name of structure

//function prototypes
void setupscreen(); //set up screen
void drawShape(); //draw the shape
void eraseShape(); //erase the shape
void moveShape(); //move the shape
#endif

>>error C2447: '{' : missing function header (old-style formal list?)

That error usually means that you put a semicolon after the name of the function, like you did on line 31.

>>error C2447: '{' : missing function header (old-style formal list?)

That error usually means that you put a semicolon after the name of the function, like you did on line 31.

THANK YOU! I can't believe i totally missed that. I corrected that and then hit about 10 more errors which I've whittled down to 2 errors. Then i finally cleaned that up and now my program is compiling but it's not doing what its supposed to do. :?:
My circle is supposed to move around randomly without hitting the margins. But all I'm getting is a flicker.

Main.cpp

/*********************************************************************
Title: Vector Graphics Program
Author: Valecia Goodnow
Date: Friday, September 9, 2011
Course & Section: CSC 222, 001W
Description: Create a program that demonstrates movign an object
Data Requirements:

Input:  None
Output:  A circle and a rectangle

Graphic Files: None
Sound Files: None
    
Formulas: 
dirX = x + 10   			
dirY = y + 10				
x = (x + dirX)
x > SCREEN_W - LENGTH)		
x = SCREEN_W - LENGTH
dirX = dirX - DIRECTION
if x < LENGTH
y = y + dirY
y > SCREEN_H - HEIGHT
y = SCREEN_H - HEIGHT
dirY = dirY - DIRECTION
y < HEIGHT + TOP_OFFSET
y = HEIGHT + TOP_OFFSET
dirX = x +15
dirY = y +15


Refined Algorithm (Pseudo-code of the specific steps on how each function or method performs)

1. Draw a circle
2. Erase the circle by creating a rectangle that will
     display over the circle as a black box.
3. Move the circle around the screen, when/if the circle
    hits the right or left margin move the circle back 
    the window.
4. Repeat until user hits escape.
5. Setup the console display to be window mode, draw a
    tan border around the window and display a title
    at the top of the screen.  "Move Target" along with
     the screen size.
6. End program with ESC key.
*********************************************************************/

#include <allegro.h>
#include "Shapemover.h"



//Function to build a shape of a circle

void drawShape( )
{
int xPos;
int yPos;
 
int x =10;
int y =25;

//get new x and y positions
xPos = shape.x;
yPos = shape.y;

//body color
shape.color = COLOR_1;

//draw the body here..
circlefill(screen, x+22, y+20, 20, COLOR_1);
}

///////////////////////////////////////////////////////////////////////////////
//Move Shape function
//////////////////////////////////////////////////////////////////////////////

void moveShape()
{

//initialize x and y direction and point of reference with current position of shape

int x = 10;					//current x position
int y = 20;					//current y position
int dirX = x + 10;   			//x direction
int dirY = y + 10;				//y direction
				

//calculate new x position with current direction
x = (x + dirX);

//is the shape going beyond the right border?
if (x > SCREEN_W - LENGTH)			
{									//THEN 
	x = SCREEN_W - LENGTH;  		//only bump against side
    	dirX = dirX - DIRECTION;  	//then change direction
}									//END IF


//is the shape going beyond the left border?
if (x < LENGTH)
{									//THEN 
	x = LENGTH;						//only bump against side
   	dirX = DIRECTION;  				//then change direction
}									//END IF

//update the y position, keep within screen
//calculate new y position with current direction
y = (y + dirY);

//is the shape going below the bottom border?
if (y > SCREEN_H - HEIGHT)
{									//THEN
     y = SCREEN_H - HEIGHT;			//only bump against the bottom
     dirY = dirY - DIRECTION;  		//then change direction
}									//END IF

//Is the shape going above the top border?
if (y < HEIGHT + TOP_OFFSET)
{									//THEN
     y = HEIGHT + TOP_OFFSET;		//only bump against the bottom
     dirY = DIRECTION;				//then change direction
}									//END IF

//update shape to new position and direction
x = 25;
y = 35;
dirX = x +15;
dirY = y +15;

}



/////////////////////////////////////////////////////////////////////////
// eraseShape function
// erase the shape using rectfill
/////////////////////////////////////////////////////////////////////////
void eraseShape( )
{
//calculate box to encompass the tank
    int left = shape.x +10;
    int top = shape.y +20;
    int right = shape.x + 60;
    int bottom = shape.y + 60;

    //erase the tank
    rectfill(screen, left, top, right, bottom, 0);

    //erase the circle
  //  rectfill(screen, 225,230,275,150,0); //Creates a filled rectangle that is black (test this using YELLOW)
}


/////////////////////////////////////////////////////////////////////////
// setupscreen function
// set up the graphics mode and game screen
/////////////////////////////////////////////////////////////////////////
void setupscreen()
{
    //set video mode
    int ret = set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);
    if (ret != 0) {
        allegro_message(allegro_error);
        return;
    }

    //print title
    textprintf_ex(screen, font, 1, 1, BURST, 0,
        "Move Target - %dx%d", SCREEN_W, SCREEN_H);

    //draw screen border
    rect(screen, 0, 12, SCREEN_W-1, SCREEN_H-1, TAN);
    rect(screen, 1, 13, SCREEN_W-2, SCREEN_H-2, TAN);

}


int main(void)
{
     //initialize everything
     allegro_init();
     install_keyboard();
     install_timer();
     setupscreen();

     //wait for keypress
     while(!key[KEY_ESC])
     { 
          //erase shape
          eraseShape( );
          //move shape
          moveShape( );
          //draw shape
          drawShape( );
          //pause a moment
          rest(1);  //you may need to play with this value
     }//end while

     allegro_exit();
     return 0;
} //end main
END_OF_MAIN()

Header file

#ifndef _SHAPEMOVER_H
#define _SHAPEMOVER_H
#include "allegro.h" //include Allegro's libraries

//define screen constants
#define MODE GFX_AUTODETECT_WINDOWED
#define WIDTH 640
#define HEIGHT 480

//define shape constants
#define LENGTH 70 //put the length of your shape here
#define TALLNESS 10 //put the height of your shape here
#define DIRECTION 20 //put your direction constant here
#define TOP_OFFSET 15 //put your offset distance from the top here
#define COLOR_1 makecol(118,225,200) //put red, green, and blue values here
#define COLOR_2 makecol(202,105,100) //put red, green, and blue values here
#define TAN makecol(255,242,169)
#define BURST makecol(255,189,73)
#define ORANGE makecol(180,75,32)
#define BLACK makecol(0,0,0)
#define YELLOW makecol(255,255,0)

//define shape structure
struct tagShape
{
int x,y; //center point of shape
int dirX; //direction constant for left and right
int dirY; //direction constant for up and down
int color; //color of shape
int radius;  //radius of my circle
int xMov;
int yMov;
} shape; //name of structure

//function prototypes
void setupscreen(); //set up screen
void drawShape(); //draw the shape
void eraseShape(); //erase the shape
void moveShape(); //move the shape
#endif

I did some quick web searches for "allegro page flipping" and found a page that shows how to do page flipping.

For smooth animation of this sort, you can't just draw and hope for the best. You need two copies of the screen. The 'front' buffer is the one the user sees. The 'back' buffer is the buffer where you do the drawing.

See http://wiki.allegro.cc/index.php?title=Page_flipping

1) create the two video bitmap objects
2) show one of them
3) keep track of which one you are not showing that is usable instead of 'screen' when drawing, perhaps a global variable back_buffer.
4) make a function that "page flips" by showing the one you've been drawing to, and changing back_buffer to point to the "other" video bitmap.

This is how real renderers (i.e. games) do animation.

Thanks for the reply. I took a look at the page and it looks interesting, I believe that is something that is coming later in my class but we haven't covered it as of yet. It will definitely be helpful though as it will give me a heads up on whats coming.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.