home *** CD-ROM | disk | FTP | other *** search
- /////////////////////////////////////////////////////////////////////////
- // Game Programming All In One, Third Edition
- // Chapter 3 - Triangles Program
- /////////////////////////////////////////////////////////////////////////
-
- #include <allegro.h>
-
- int main(void)
- {
- int x1,y1,x2,y2,x3,y3;
- 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 screen resolution
- textprintf_ex(screen, font, 0, 0, 15, -1,
- "Triangles Program - %dx%d - Press ESC to quit",
- SCREEN_W, SCREEN_H);
-
- //wait for keypress
- while(!key[KEY_ESC])
- {
- //set a random location
- x1 = 10 + rand() % (SCREEN_W-20);
- y1 = 10 + rand() % (SCREEN_H-20);
- x2 = 10 + rand() % (SCREEN_W-20);
- y2 = 10 + rand() % (SCREEN_H-20);
- x3 = 10 + rand() % (SCREEN_W-20);
- y3 = 10 + rand() % (SCREEN_H-20);
-
- //set a random color
- red = rand() % 255;
- green = rand() % 255;
- blue = rand() % 255;
- color = makecol(red,green,blue);
-
- //draw the pixel
- triangle(screen,x1,y1,x2,y2,x3,y3,color);
-
- rest(100);
- }
-
- //end program
- allegro_exit();
- return 0;
- }
- END_OF_MAIN()
-
-