void Initialization (HDC DeviceContext, char *Argv)
{
 //Get Block File
 char Block_Str[25*25+1] = {0};
 FILE *Fp = fopen (Argv, "r");
 fscanf (Fp, "[(%hd,%hd)%hd(%hd,%hd)]", &User_Def_X_0, &User_Def_Y_0, &User_Def_Direction, &User_Def_X_1, &User_Def_Y_1);
 fread (Block_Str, sizeof (char), 625, Fp);
 int Cnt = 0, Num = 0;
 for (Cnt = 0; Cnt < 625; Cnt++)
 {
  if (Block_Str[Cnt] == '1')
  {
   Block[Num].X = Cnt%25;
   Block[Num].Y = (short)(Cnt/25);
   Draw_Square (Block[Num].X, Block[Num].Y, DN, RGB (255,255,0), -1, -1, DN, RGB (255,255,255), 0, DeviceContext);
   Num++;
  }
 }
 Block_Length = Num;
 //
 Clear_String ();
 Move.Condition = Read;
 Move.Snake_Length = 2;
 Move.Position[1].X = User_Def_X_1;
 Move.Position[1].Y = User_Def_Y_1;
 Draw_Square (User_Def_X_1, User_Def_Y_1, User_Def_Direction, RGB(255,255,255), -1, -1, UP, RGB(255,255,255), User_Def_Delay, DeviceContext);
 Move.Position[0].X = User_Def_X_0;
 Move.Position[0].Y = User_Def_Y_0;
 Draw_Square (User_Def_X_0, User_Def_Y_0, User_Def_Direction, RGB(255,255,255), -1, -1, UP, RGB(255,255,255), User_Def_Delay, DeviceContext);
 Draw.Direction = User_Def_Direction;
 Create_Cookie (DeviceContext);
}
void Redraw_Screen (HDC DeviceContext)
{
 Flag_Pause = True;
 Sleep (User_Def_Delay*6);
 int Cnt;
 for (Cnt = 0; Cnt < Block_Length; Cnt++)
  Draw_Square (Block[Cnt].X, Block[Cnt].Y, DN, Color_Set[Yellow], -1, -1, DN, Color_Set[Unset], 0, DeviceContext);
 for (Cnt = 0; Cnt <= 8; Cnt = Cnt + 2)
  Draw_Square (Wormhole[Cnt].X, Wormhole[Cnt].Y, DN, Color_Set[Blue], -1, -1, DN, Color_Set[Unset], 0, DeviceContext);
 for (Cnt = 1; Cnt <= 9; Cnt = Cnt + 2)
  Draw_Square (Wormhole[Cnt].X, Wormhole[Cnt].Y, DN, Color_Set[Red], -1, -1, DN, Color_Set[Unset], 0, DeviceContext);
 Draw_Square (Cookie.X, Cookie.Y, DN, Color_Set[Green], -1, -1, DN, Color_Set[Unset], 0, DeviceContext);
 Flag_Pause = False;
}
void Create_Cookie (HDC DeviceContext)
{
 Unfilled_Func ();
 int Rand = clock()%Unfilled_Length;
 Cookie.X = Unfilled[Rand].X;
 Cookie.Y = Unfilled[Rand].Y;
 Draw_Square (Cookie.X, Cookie.Y, UP, RGB( 0 ,255, 0 ), -1, -1, UP, RGB(255,255,255), 0, DeviceContext);
}
void Create_Cookie (HDC DeviceContext)
{
 Unfilled_Func ();
 int Rand = clock()%Unfilled_Length;
 Cookie.X = Unfilled[Rand].X;
 Cookie.Y = Unfilled[Rand].Y;
 Draw_Square (Cookie.X, Cookie.Y, UP, Color_Set[Green], -1, -1, UP, Color_Set[Unset], 0, DeviceContext);
}
示例#5
0
// draw with RAIO
// ---------------------------------------------
void example_DrawWithRAIO( void )
{
	// rectangle
	Draw_Square (0, 0, 319, 239);
	Text_Foreground_Color ( COLOR_BLACK );
	RAIO_StartDrawing ( SQUARE_FILL );
	Text_Foreground_Color ( COLOR_BLUE );
	Draw_Square (210, 150, 260, 200);

	// line
	Draw_Line ( 10, 230, 310, 10 );
	Text_Foreground_Color ( COLOR_GREEN );
	RAIO_StartDrawing ( LINE );

	// circle
	Draw_Circle ( 90, 65, 25 );
	Text_Foreground_Color ( COLOR_RED );
	RAIO_StartDrawing ( CIRCLE_FILL );
}
示例#6
0
void D3(){
    glTranslatef(0, 0, -30);
    glRotatef(rotate_y, 0, 1, 0);
    glRotatef(rotate_z, 0, 0, 1);


    int i = 0, squares = 15;
    float red = 0, blue = 1;
    for (; i < squares; ++i)
    {
        glRotatef(360.0/squares, 0, 0, 1);

        red += 1.0/12;
        blue -= 1.0/12;
        Draw_Square(red, .6, blue);
    }
    //glPopMatrix();
}
示例#7
0
void Draw(void)
{
    // reset view matrix
    glLoadIdentity();
    // move view back a bit
    glTranslatef(0, 0, -30);
    // apply the current rotation
    glRotatef(rotate_y, 0, 1, 0);
    glRotatef(rotate_z, 0, 0, 1);
    // by repeatedly rotating the view matrix during drawing, the
    // squares end up in a circle
    int i = 0, squares = 15;
    float red = 0, blue = 1;
    for (; i < squares; ++i)
    {
        glRotatef(360.0 / squares, 0, 0, 1);
        // colors change for each square
        red += 1.0f / 12;
        blue -= 1.0f / 12;
        Draw_Square(red, .6f, blue);
    }
}
int main (int argc, char *argv[]) 
{
 //Get a console handle
 HWND ConsoleWindow = GetConsoleWindow();
 
 //Get a STD handle
 HWND StdHandle = GetStdHandle (STD_OUTPUT_HANDLE);

 //Set cursor invisible
 CONSOLE_CURSOR_INFO CURSOR;
 CURSOR.dwSize = 1;
 CURSOR.bVisible = FALSE;
 SetConsoleCursorInfo (StdHandle, &CURSOR);
 
 //Get Current Font
 for (;;)
 {
  CONSOLE_FONT_INFO GETFONT;
  GetCurrentConsoleFont (StdHandle, FALSE, &GETFONT);
  COORD Fontsize = GetConsoleFontSize (StdHandle, GETFONT.nFont);
  SHORT Font_X = Fontsize.X;
  SHORT Font_Y = Fontsize.Y;
  if (Font_X != 8 || Font_Y != 12)
  {
   system ("chcp 437 > NUL");
   MessageBox (ConsoleWindow, "Please change Console Font to Raster Font  ( 8 x 12 ).", "Notice", MB_TOPMOST | MB_OK | MB_ICONINFORMATION);
   Envir_Error ();
   printf ("\rPress any key to continue...");
   system ("pause>nul");
  }
  else
   break;
 }
 
 //Change Settings
 //SetWindowLong (ConsoleWindow, GWL_STYLE, WS_THICKFRAME);
 //SetWindowLong (ConsoleWindow, GWL_STYLE, WS_CAPTION);
 //SetWindowPos  (ConsoleWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_SHOWWINDOW);
 SetWindowPos  (ConsoleWindow, HWND_TOP, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_SHOWWINDOW);

 //Get a handle to device context
 HDC DeviceContext = GetDC (ConsoleWindow);
 
 //Color
 COLORREF Color_White = RGB (255,255,255);
 COLORREF Color_Black = RGB ( 0 , 0 , 0 );
 
 //Title and Resize
 system ("mode con cols=75 lines=50");
 system ("title Console Snake     [ Developer: KVD 2013 ]");
 system ("color 0A");
 
 //Multi-Thread
 pthread_t Key_Stroke_Func;
 pthread_create (&Key_Stroke_Func, NULL, (void*)Get_Key_Stroke, NULL);
 
 //Initialization
 Initialize:;
 Initialization (DeviceContext, argv[1]);
 
 //Main
 for (;;)
 {
  //Terminate / PlayAgain
  if (Flag_Terminate == True)
  {
   return 0;
  }
  else if (Flag_PlayAgain == True)
  {
   Flag_PlayAgain = False;
   Clear_Screen (DeviceContext);
   goto Initialize;
  }
  //Draw
  if (Move.Condition == UnRead)
  {
   Move.Condition = Read;
   Change_Str (DeviceContext, ConsoleWindow);
   Draw_Square (Draw.X, Draw.Y, Draw.Direction, Color_White, Erase.X, Erase.Y, Erase.Direction, Color_Black, User_Def_Delay, DeviceContext);
  }
  else
  {
   Predict_Func (Draw.Direction);
   Change_Str (DeviceContext, ConsoleWindow);
   Draw_Square (Draw.X, Draw.Y, Draw.Direction, Color_White, Erase.X, Erase.Y, Erase.Direction, Color_Black, User_Def_Delay, DeviceContext);
  }
  //End
  if (Is_Snake (Draw.X, Draw.Y) == True || Is_Block (Draw.X, Draw.Y) == True)
  {
   MessageBox (ConsoleWindow, "GAME OVER", "Notice", MB_TOPMOST | MB_OK | MB_ICONSTOP);
   Clear_String ();
   Clear_Screen (DeviceContext);
   goto Initialize;
  }
 }
 
 //End
 system ("pause>nul");
 return 0;
}
void Initialization (HDC DeviceContext, char *Argv)
{
 //Clear
 Clear_String ();
 
 //Default
 Move.Condition = Read;
 Move.Snake_Length = 2;
 Move.Position[0].X = 12;
 Move.Position[0].Y = 12;
 Move.Position[1].X = 12;
 Move.Position[1].Y = 13;
 
 //Get Block File
 int  Num = 0;
 char Input;
 FILE *Fp = fopen (Argv, "rb");
 if (Fp)
 {
  for (;;)
  {
   fscanf (Fp, "[%hd:%hd]",&User_Def_Tag, &User_Def_Delay);
   fseek (Fp, 2, SEEK_CUR);
   int Cnt_Y = 0, Cnt_X = 0;
   if (User_Def_Tag == Intro)
   {
    for (Cnt_Y = 0; Cnt_Y < 25; Cnt_Y++)
    {
     for (Cnt_X = 0; Cnt_X < 25; Cnt_X++)
     {
      fread (&Input, 1, 1, Fp);
      if (Input >= '0' && Input <= '9')
       Draw_Square (Cnt_X, Cnt_Y, DN, Color_Set[Input-'0'], -1, -1, DN, Color_Set[Unset], 0, DeviceContext);
      else if (Input == ' ' || Input == '.')
       continue;
      else
       Cnt_X --;
     }
    }
    fseek (Fp, 2, SEEK_CUR);
    Sleep (User_Def_Delay*1000);
   }
   else if (User_Def_Tag == GameMap)
   {
    for (Cnt_Y = 0; Cnt_Y < 25; Cnt_Y++)
    {
     for (Cnt_X = 0; Cnt_X < 25; Cnt_X++)
     {
      fread (&Input, 1, 1, Fp);
      if (Input == '*')
      {
       Block[Num].X = Cnt_X;
       Block[Num].Y = Cnt_Y;
       Num++;
      }
      else if (Input >= '0' && Input <= '9')
      {
       Wormhole[Input-'0'].X = Cnt_X;
       Wormhole[Input-'0'].Y = Cnt_Y;
      }
      else if (Input == 'H')
      {
       Move.Position[0].X = Cnt_X;
       Move.Position[0].Y = Cnt_Y;
       Draw_Square (Cnt_X, Cnt_Y, UP, Color_Set[Set_Head_Color], -1, -1, UP, Color_Set[Set_Tail_Color], 0, DeviceContext);
      }
      else if (Input == 'T')
      {
       Move.Position[1].X = Cnt_X;
       Move.Position[1].Y = Cnt_Y;
       Draw_Square (Cnt_X, Cnt_Y, UP, Color_Set[Set_Head_Color], -1, -1, UP, Color_Set[Set_Tail_Color], 0, DeviceContext);
      }
      else if (Input == ' ' || Input == '.')
       continue;
      else
       Cnt_X --;
     }
    }
    break;
   }
   else
    break;
  }
 }
 Block_Length = Num;
 Draw.Direction = Get_Direction (Move.Position[0].X, Move.Position[0].Y, Move.Position[1].X, Move.Position[1].Y);
 Last_Key_Stroke = Get_Direction (Move.Position[0].X, Move.Position[0].Y, Move.Position[1].X, Move.Position[1].Y);;
 Create_Cookie (DeviceContext);
 Redraw_Screen (DeviceContext);
}