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