home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / volume_3.zip / DRAW2.CPP < prev    next >
C/C++ Source or Header  |  1995-11-03  |  9KB  |  447 lines

  1. #include "C:\tc\mouse.h"
  2. #include "C:\tc\misc.h"
  3. #include "C:\tc\keyboard.h"
  4. #include "C:\tc\graphvga.h"
  5. #include "C:\tc\pcx.cpp"
  6.  
  7. #define NEWLINE "\n"
  8.  
  9. void PerformGame(void);
  10. void Perform_Exit(void);
  11. void Perform_Save_Load(void);
  12.  
  13.  
  14. void main(void)
  15. {
  16.  // Detects if Mouse Present
  17. Detect_Mouse();
  18.   //  Initialize VGA graphics.
  19. InitGraphics(9);
  20.   //  clears graphics screen
  21. cleardevice();
  22.  //  Draws Screen
  23. Display_PCX("draw2.pcx");
  24.  // Performs game till ESC is Pressed
  25. PerformGame();
  26.  // Reset's Graphics to original mode before InitGraphics()
  27. closegraph();
  28.  // Returns to DOS
  29. return;
  30. }
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. void PerformGame(void)
  43. {
  44. // Used for Keyboard Routines
  45. char char_ch = NULL;
  46. int Scan1,Alt_Ctrl = NULL;
  47. int int_ch;
  48. // Mouse Position
  49. int X,tempX;
  50. int Y,tempY;
  51. // Drawing Color
  52. int Drawing_Color  = 1;
  53. // Toggle Switch to cut on text writing
  54. int Text_Switch = FALSE;
  55. // Line Drawing size
  56. int Drawing_Size = 20;
  57. // Used to Clear the Screen
  58. int Clear_Y;
  59. // Cuts on and Displays Mouse Arrow
  60. Display_Mouse();
  61. Cursor_Shape(6);
  62. //mouse
  63. int Button_Check;
  64.  
  65.  
  66.  
  67.  
  68. // Start Loop untill ESCAPE is Pressed
  69. //while((int_ch = Key_Press(&char_ch))  != ESC)
  70. // {
  71. while((int_ch = Key_Press(&char_ch,&Scan1,&Alt_Ctrl))  != ESC)
  72.     {
  73.       Mouse_Position(&X,&Y); // Returns Current Mouse Location
  74.  
  75. //***********************************************
  76. // Beggining of Key Board Routine
  77. //************************************************
  78.       switch(Scan1) //Acts upon Key pressed
  79.         {
  80.         case UP:
  81.         if((Y > 40) AND (Text_Switch != TRUE))
  82.             {
  83.             Y = Y - 5;  //Up arrow key pressed
  84.             Move_Mouse(X,Y);
  85.             DrawBox(X,Y,Drawing_Size,Drawing_Size,Drawing_Color,1);
  86.             }
  87.         break;
  88.  
  89.         case DOWN:
  90.         if((Y > 40) AND (Text_Switch != TRUE))
  91.             {
  92.             Y = Y + 5; //Down arrow key pressed
  93.             Move_Mouse(X,Y);
  94.             DrawBox(X,Y,Drawing_Size,Drawing_Size,Drawing_Color,1);
  95.             }
  96.         break;
  97.  
  98.         case LEFT:
  99.         if((Y > 40) AND (Text_Switch != TRUE))
  100.             {
  101.              X = X - 5; //Left arrow key pressed
  102.             Move_Mouse(X,Y);
  103.             DrawBox(X,Y,Drawing_Size,Drawing_Size,Drawing_Color,1);
  104.             }
  105.         break;
  106.  
  107.         case RIGHT:
  108.         if((Y > 40) AND (Text_Switch != TRUE))
  109.             {
  110.             X = X + 5; //Right arrow key pressed
  111.             Move_Mouse(X,Y);
  112.             DrawBox(X,Y,Drawing_Size,Drawing_Size,Drawing_Color,1);
  113.             }
  114.         break;
  115.  
  116.         //**********************
  117.         // Clears Drawing Screen
  118.         //**********************
  119.         case SPACEBAR:
  120.         Hide_Mouse();
  121.         for(Clear_Y = 31;Clear_Y < (Max_Y + 1) ;Clear_Y++)
  122.             {
  123.             setcolor(0);
  124.             line(0,Clear_Y, Max_X, Clear_Y);
  125.             setcolor(8);
  126.             line(0,Clear_Y, Max_X, Clear_Y);
  127.             }
  128.         flush_buffer();
  129.         Display_Mouse();
  130.         break;
  131.  
  132.         default:
  133.         if((Y > 40) AND (Text_Switch != TRUE))
  134.             {
  135.            //    itoa(int_ch,ct,10);
  136.            //    outtextxy(10,40,ct);
  137.             sound(Scan1/5);
  138.             delay(20);
  139.             nosound();
  140.             }
  141.         break;
  142.         }
  143. //**************************************************
  144. // End of Keyboard Routine
  145. //**************************************************
  146.  
  147.  
  148.  
  149. //*************************************************
  150. // Beggining of TEXT DRAW Routine
  151. //*************************************************
  152.       if((Text_Switch == TRUE) AND (Y > 45))
  153.         {
  154.         while((Mouse_Status() != 1) AND (Y > 45)) //Allows Mouse to be moved till
  155.             {
  156.             Mouse_Position(&X,&Y);
  157.             flush_buffer();
  158.             }
  159.         while((Mouse_Status() == 1) AND (Y > 45))//You press a mouse button & then
  160.             {                             //is where text starts
  161.              Mouse_Position(&X,&Y);
  162.             flush_buffer();
  163.             }
  164.             sound(500);
  165.             delay(30);
  166.             nosound();
  167.             flush_buffer();                                 //Enter
  168.         while(((int_ch = Key_Press(&char_ch,&Scan1,&Alt_Ctrl))  != 13) AND (Mouse_Status() == 0))
  169.             {
  170.             if((int_ch != 0) AND (Y > 40))
  171.                 {
  172.                  Hide_Mouse();
  173.                  setcolor(Drawing_Color);
  174.             //Makes sound for everything except spaces
  175.                 if(char_ch != ' ')
  176.                     {
  177.                     sound(150);
  178.                     Slow_Down(10);
  179.                     nosound();
  180.                     }
  181.                  outtextxy(X,Y - 10,&char_ch);
  182.                  X = X + 10;
  183.                  if(X > Max_X)
  184.                     {
  185.                     for(int temp2=0;temp2<20;temp2++)
  186.                         {
  187.                         Basic_Sound(temp2*10,12);
  188.                         }
  189.                     Basic_Sound(700,70);
  190.                     X = 5;
  191.                     if(Y < Max_Y) Y = Y + 10;//New
  192.                     }
  193.                  Display_Mouse();
  194.                  Move_Mouse(X,Y);//Moves mouse to new X,Y position.
  195.                 }
  196.             }
  197.         Cursor_Shape(6);
  198.         Text_Switch = FALSE;
  199.         Hide_Mouse();
  200.         setcolor(BLACK);
  201.         line(2,26,34,26);
  202.         line(34,26,34,3);
  203.         setcolor(WHITE);
  204.         line(34,3,2,3);
  205.         line(2,3,2,26);
  206.         setcolor(Drawing_Color);
  207.         Display_Mouse();
  208.         flush_buffer();
  209.         Button_Up();
  210.         }
  211.  
  212. //************************************************
  213. // End of TEXT DRAW Routine
  214. //************************************************
  215.  
  216.  
  217.  //*************************************************
  218.  // Beggining of Mouse Routine
  219.  //*************************************************
  220. if(Button_Press_XY(&tempX,&tempY,Button_Check))
  221.     {
  222.     if(Y < 30)
  223.         {
  224. //        if((Y == tempY) AND (X == tempX))
  225. // Under Windows 95 Button_Press_XY will not set
  226. //tempY or tempX to the button release position
  227. //this works great under dos 6.22 so it must be
  228. //a bug with windows 95 not allowing correct dos
  229. //mouse routines?
  230.         if((Y != tempY) AND (X != tempX))
  231.             {
  232.             sound(100);
  233.             delay(10);
  234.             nosound();
  235.             //Exit
  236.             if((X > 572) AND (X < 605) )
  237.                 {
  238.                 Hide_Mouse();
  239.                 setcolor(WHITE);
  240.                 line(572,26,605,26);
  241.                 line(605,26,605,3);
  242.                 setcolor(BLACK);
  243.                 line(605,3,572,3);
  244.                 line(572,3,572,26);
  245.                 setcolor(Drawing_Color);
  246.                 Button_Up();
  247.  
  248.                 Perform_Exit();
  249.  
  250.                 setcolor(BLACK);
  251.                 line(572,26,605,26);
  252.                 line(605,26,605,3);
  253.                 setcolor(WHITE);
  254.                 line(605,3,572,3);
  255.                 line(572,3,572,26);
  256.                 setcolor(Drawing_Color);
  257.                 Display_Mouse();
  258.  
  259.  
  260.                 }
  261.             if((X > 523) AND (X < 556) )
  262.                 {
  263.                 Hide_Mouse();
  264.                 setcolor(WHITE);
  265.                 line(523,26,556,26);
  266.                 line(556,26,556,3);
  267.                 setcolor(BLACK);
  268.                 line(556,3,523,3);
  269.                 line(523,3,523,26);
  270.                 setcolor(Drawing_Color);
  271.                 Button_Up();
  272.  
  273.                 Perform_Save_Load();
  274.  
  275.  
  276.                 setcolor(BLACK);
  277.                 line(523,26,556,26);
  278.                 line(556,26,556,3);
  279.                 setcolor(WHITE);
  280.                 line(556,3,523,3);
  281.                 line(523,3,523,26);
  282.                 setcolor(Drawing_Color);
  283.                 Display_Mouse();
  284.                 }
  285.             //Clears Screen
  286.             if((X > 471) AND (X < 504) )
  287.                 {
  288.                 Button_Up();
  289.                 Hide_Mouse();
  290.                 setcolor(WHITE);
  291.                 line(471,26,504,26);
  292.                 line(504,26,504,3);
  293.                 setcolor(BLACK);
  294.                 line(504,3,471,3);
  295.                 line(471,3,471,26);
  296.                 setcolor(Drawing_Color);
  297.  
  298.                 for(Clear_Y = 31;Clear_Y < (Max_Y + 1) ;Clear_Y++)
  299.                     {
  300.                     setcolor(0);
  301.                     line(0,Clear_Y, Max_X, Clear_Y);
  302.                     setcolor(8);
  303.                     line(0,Clear_Y, Max_X, Clear_Y);
  304.                     }
  305.                 flush_buffer();
  306.                 setcolor(BLACK);
  307.                 line(471,26,504,26);
  308.                 line(504,26,504,3);
  309.                 setcolor(WHITE);
  310.                 line(504,3,471,3);
  311.                 line(471,3,471,26);
  312.                 setcolor(Drawing_Color);
  313.  
  314.                 Display_Mouse();
  315.                 }
  316.             //Toggles text Mode
  317.             else if((X > 0) AND (X <  40) AND (Text_Switch != TRUE))
  318.                 {
  319.                 Button_Up();
  320.                 Hide_Mouse();
  321.                 Text_Switch = TRUE;
  322.                 Cursor_Shape(5);
  323.                 setcolor(WHITE);
  324.                 line(2,26,34,26);
  325.                 line(34,26,34,3);
  326.                 setcolor(BLACK);
  327.                 line(34,3,2,3);
  328.                 line(2,3,2,26);
  329.                 setcolor(Drawing_Color);
  330.                 Display_Mouse();
  331.                 }
  332.             // Line Drawing Size
  333.             else if((X > 418) AND (X < 456))
  334.                 {
  335.                 Button_Up();
  336.                 switch(Drawing_Size)
  337.                     {
  338.                     case 20:
  339.                         Drawing_Size = 10;
  340.                         break;
  341.  
  342.                     case 10:
  343.                         Drawing_Size = 5;
  344.                         break;
  345.  
  346.                     case 5:
  347.                         Drawing_Size = 2;
  348.                         break;
  349.  
  350.                     case 2:
  351.                         Drawing_Size = 20;
  352.                         break;
  353.  
  354.                     }
  355.  
  356.                 }
  357.             //Color Selection
  358.             else if(X > 41)
  359.                  {
  360.                  if(X < 404)
  361.                     {
  362.                     if(Y > 2)
  363.                         {
  364.                         if(Y < 27)
  365.                             {
  366.                             if( X > 386)
  367.                                 {
  368.                                 Drawing_Color = 8;//ERASE
  369.                                 Button_Up();
  370.                                 }
  371.                             else if( (getpixel(X,Y)) != 8)
  372.                                 {
  373.                                 Hide_Mouse();
  374.                                 Drawing_Color = getpixel(X,Y);
  375.                                 Button_Up();
  376.                                 Display_Mouse();
  377.                                 }
  378.  
  379.                             }
  380.                         }
  381.                     }
  382.                  }
  383.                //    CheckForColor(X,&Drawing_Color);
  384.                 //    }
  385.             //else if
  386.  
  387.             }
  388.         }
  389.     }
  390.  
  391.  
  392.  
  393.      switch(Mouse_Status())
  394.         {
  395.         case 1: //Left Mouse Button
  396.         //******************************
  397.         //Draws only if in drawing page
  398.         //******************************
  399.         if(Y > 30)
  400.             {
  401.             DrawBox(X,Y,Drawing_Size,Drawing_Size,Drawing_Color,1);
  402.             }
  403.         break;
  404.  
  405.         case 2: // If Right Mouse Button Held Down
  406.         sound(100);
  407.         delay(10);
  408.         nosound();
  409.         break;
  410.  
  411.  
  412.         default: break;
  413.         }
  414. //***************************************************
  415. // End of Mouse Routine
  416. //***************************************************
  417.  
  418.  }//End of While of Loop
  419.  
  420.  
  421. return;
  422. }
  423.  
  424.  
  425. void Perform_Exit(void)
  426. {
  427. sound(500);
  428. delay(60);
  429. nosound();
  430.  
  431.  
  432. return;
  433. }
  434.  
  435.  
  436.  
  437.  
  438. void Perform_Save_Load(void)
  439. {
  440. sound(500);
  441. delay(60);
  442. nosound();
  443.  
  444.  
  445. return;
  446. }
  447.