I need help making a grid!

This is a discussion on I need help making a grid! within the Windows Programming forums, part of the Platform Specific Boards category; Greetings! I am making a level editor for a game of mine, and I wish to use a grid to ...

  1. #1
    Unregistered
    Guest

    Angry I need help making a grid!

    Greetings!

    I am making a level editor for a game of mine, and I wish to use a grid to define an overhead view of the level. My questions are:
    A. How do I make a grid using the win32 API (I'm using win 98)
    B How can I make certain parts of the grid a differnt color (like to highlight the boundries of a room)
    C. How can I place small pictures in a square formed in the grid (as to indicate the placement of an item or NPC)

    I'm actually well into the game engine, but I really am stuck on those three things for my editor. The rest of the game and editor are easy, but that is not. I am not using a graphics API for it because I favor this method, and I don't belive many games use this editor. Any ideas or code for those things would be appreciated. I am not asking anyone to do it for me, just give me a bit of help. Thanks for your time everyone.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571

    Re: I need help making a grid!

    Originally posted by Unregistered
    Greetings!

    I am making a level editor for a game of mine, and I wish to use a grid to define an overhead view of the level. My questions are:
    A. How do I make a grid using the win32 API (I'm using win 98)
    B How can I make certain parts of the grid a differnt color (like to highlight the boundries of a room)
    C. How can I place small pictures in a square formed in the grid (as to indicate the placement of an item or NPC)

    I'm actually well into the game engine, but I really am stuck on those three things for my editor. The rest of the game and editor are easy, but that is not. I am not using a graphics API for it because I favor this method, and I don't belive many games use this editor. Any ideas or code for those things would be appreciated. I am not asking anyone to do it for me, just give me a bit of help. Thanks for your time everyone.
    A) A trivial way to make a grid is to make the grid a bitmap and just blt it on the screen. If you want you can use MoveToEx and LineTo functions to draw lines. For different colors look up CreatePen.

    B) Store the status of the squares in a 2-dimensional array and then update them in WM_PAINT or wherever. Multiply the dimenions by constants for the size of each square. Then use something like FillRect( ) to uh fill with color.

    C) Look up BitBlt. It will let you specify where you want the image to be drawn.

    Hope that helps a little! These may certainly not be the best way but I was trying to think of simple ways to do this. Good Luck sir.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    Remember when using GDI objects (pens, brushes, DC ect) that they are special memory. If you do not free the memory it will crash your PC.

    If you 'Get' an object 'Release' it.

    If you 'Create' an object 'Delete' it.

    Always catch the returned GDI object from SelectObject() to replace them later.

    roughly
    Code:
    #define    BLACK     RGB(0,0,0)
    #define    WHITE     RGB(255,255,255)
    
    hdc=GetDC(hWnd);// get the DC to draw on and create the objects to draw with
    hdPen=CreatePen(PS_SOLID,iLineThickness,BLACK);
    hBrush=CreateSolidBrush(WHITE);
    GetClientRect(hWnd,&ClientRect);
    hOriginalPen=(HPEN)SelectObject(hdc,hPen);//catch the pen already in the DC
    //do the drawing
    FrameRect(hdc,&ClientRect,hBrush);
    //clean up by putting the DC back the way we got it
    SelectObject(hdc,hOriginalPen);
    //then delete the pen
    DeleteObject(hPen);
    //the brush was not in a DC so can just delete
    DeleteObject(hBrush);
    //the DC was 'Get'ed so 'Release' it
    ReleaseDC(hWnd,hdc);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tips for drawing a grid
    By countchocula in forum C Programming
    Replies: 12
    Last Post: 04-19-2008, 07:47 AM
  2. More Windows Trouble
    By samGwilliam in forum Windows Programming
    Replies: 9
    Last Post: 04-12-2005, 10:02 AM
  3. Cleaning up a Grid of Memory
    By Epo in forum C++ Programming
    Replies: 9
    Last Post: 02-25-2005, 09:23 AM
  4. Find a word in a 2d grid
    By The_Kingpin in forum C++ Programming
    Replies: 2
    Last Post: 02-24-2005, 04:38 PM
  5. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21