Here's the (very simple) initial code i have I was able to create a program that makes a circle. Now i want to add in a function that adds in a horizontal line and eventually a vertical line.
#include <allegro.h>
void docircle(BITMAP *bmp, int x, int y, int color)
{
putpixel(bmp, x, y, color);
putpixel(bmp, x+1, y+1, color);
rest(1); //replaced sleep()
}
int main(void)
{
int x,y,x1,x2,radius;
int red,green,blue,color;
int ret;
//initialize Allegro
allegro_init();
//initialize the keyboard
install_keyboard();
install_timer();
//initialize video mode to 640x480
ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
if (ret != 0) {
allegro_message(allegro_error);
return 1;
}
//display message
textprintf_ex(screen, font, 80, 8, 35, -1,
"Do you like my object? Hit ESC to exit the window.",
SCREEN_W, SCREEN_H);
//wait for keypress
while(!key[KEY_ESC])
{
//set a location and size for the circle
x = 100; //(SCREEN_W-10);
y = 80; //(SCREEN_H-120);
radius = 10;
//set a random color
red = rand() % 255;
green = rand() % 255;
blue = rand() % 255;
color = makecol(red,green,blue);
//draw the circle
do_circle(screen, x, y, radius, color, *docircle);
}
void hline(BITMAP *bmp, int x1, int y, int x2, int color)
{
//set random location for horizontal line
x1 = 10 + rand()%(SCREEN_W-20);
y = 10 + rand()%(SCREEN_H-20);
x2 = 10 + rand()%(SCREEN_W-20);
//set a random color
red = rand() % 255;
green = rand() % 255;
blue = rand() % 255;
color = makecol(red,green,blue);
//draw the line
hline(screen, x1, y, x2, color);
}
//end program
allegro_exit();
return 0;
}
END_OF_MAIN()
What am i doing wrong in regards to the placement of my functions? What goes where so that my variables are specific to each function?


Sign In
Create Account

Back to top









