Thread: Tetris Questions

  1. #16
    Registered User harryP's Avatar
    Join Date
    Sep 2002
    Posts
    124
    Sure thing. A quick example:
    Code:
    // Assume that a map has been loaded into a file the characters
    // used are stored in a MAP struct (assume it has two 2D arrays:
    // one to hold the map's characters and the other holding the
    // respective colours)
    MAP mp;
    
    // The size of the map
    COORD size = { mapSizeX, mapSizeY };
    // The location in the array to start drawing from (usually 0,0)
    COORD coord = { 0, 0 };
    // WriteConsoleOutput needs to use a CHAR_INFO structure as
    // it's source buffer (where it's taking the data from), which makes
    // things more complicated.  I suppose they do it for just that
    // reason.
    CHAR_INFO *buffer = new CHAR_INFO[mapSizeX * mapSizeY];
    // That ^ declared a 1-dimensional CHAR_INFO array.  I guess
    // they use CHAR_INFO because it can hold character information
    // and colour attributes.  Anyways, this made the array be the size
    // of the picture (or in this case, map) to draw
    // Now set up the region on-screen where we will draw
    SMALL_RECT rect;
    rect.Top = 0;
    rect.Left = 0; // Upper-left corner will be 0,0 (adjust this to your
    // needs)
    rect.Bottom = mapSizeY;
    rect.Right = mapSizeX;
    // Standard output handle
    HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
    // Now fill the array with the data from the map
    int offset = 0;
    for(int i = 0; i < height; i++)
    {
         for(int j = 0; j < width; j++,offset++)
         {
              buffer[offset].Char.AsciiChar = mp.mapChars[i][j];
              buffer[offset].Attributes = mp.mapColours[i][j];
         }
    }
    
    // Now output the data all at once with WriteConsoleOutput
    WriteConsoleOutput(stdOut, // The output handle
         buffer, // The source array
         size, // The size of the block to draw
         coord, // The place to start copying from the source buffer (0,0)
         &rect); // The block on-screen to write to
    
    // Erase the buffer
    delete [] buffer;
    See? It's quite a bit of work. I recommend sticking to one of those libraries, it'll save boatloads of time. But if you really want to do it, more power to you .

    Brendan

    EDIT: I have AIM. My sn is HPotter385. And the newest CGL won't quite work, so I'll upload the fixed version here. Again, the documentation won't help you at all, just IM me or email me at [email protected] for information, cos a LOT has changed.
    Last edited by harryP; 10-27-2003 at 11:20 PM.
    Draco dormiens nunquam titallandus.
    Console Graphics Library: http://www.geocities.com/steve_alberto/cgl.html

  2. #17
    Registered User harryP's Avatar
    Join Date
    Sep 2002
    Posts
    124
    Ok, here it is. Now this is JUST the two required header files. No documentation, no Blitmap Creator, nothing. But this SHOULD work now.
    Draco dormiens nunquam titallandus.
    Console Graphics Library: http://www.geocities.com/steve_alberto/cgl.html

  3. #18
    Registered User
    Join Date
    May 2003
    Posts
    195
    HarryP:

    Did you take out the M_BUTTON_CLICKED identifier from CGL? cause when i try to run the sample documentation code for the buttons, it gives me the error that M_BUTTON_CLICKED is undeclared... help lar lol

  4. #19
    Registered User harryP's Avatar
    Join Date
    Sep 2002
    Posts
    124
    Lol yeah. It's now 'M_LEFT_BUTTON_CLICKED' and 'M_RIGHT_BUTTON_CLICKED'. Sorry -sheepish grin-.

    Brendan
    Draco dormiens nunquam titallandus.
    Console Graphics Library: http://www.geocities.com/steve_alberto/cgl.html

  5. #20
    Registered User harryP's Avatar
    Join Date
    Sep 2002
    Posts
    124
    Also, I don't know if you're there yet, but a lot of the graphical functions there now have been superceded with a new class. The GraphicObject class lets you do everything you could before, plus lots more. It takes a reference to a Window object when you create a GraphicObject object. For example:
    Code:
    GraphicObject gfxObj(wnd);
    From there, you can do loads of stuff. Draw lines with the MoveTo and LineTo functions (use MoveTo to specify the end point of the line, and LineTo to specify the beginning point). You can also use MoveTo to set the location of where to draw a point with the PointTo function.

    Lines are modified through pens. Use the GraphicObject function CreatePen to make a new pen.
    Code:
    GraphicObject gfxObj(wnd);
    // Make a new pen
    gfxObj.CreatePen(2, // 2 characters wide\tall
         STYLE_DOT, // Dotted line (use STYLE_SOLID for a solid line or
         // STYLE_DASH for a dashed line
         F_BLUE | B_BLUE); // Blue
    // If you draw a line, point, or rectangle without creating a pen, a 
    // default pen is used (1 point width, solid, black)
    // Draw a line
    gfxObj.MoveTo(10,20);
    gfxObj.LineTo(0,0);
    // Draws a line from 0,0 to 10,20
    Yeah there's a lot more but I don't want to clog this thread with this stuff, so email me and I'll send you some information (I'm still working on updates to the documentation).

    Brendan
    Draco dormiens nunquam titallandus.
    Console Graphics Library: http://www.geocities.com/steve_alberto/cgl.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM