Jump to content
  • Advertisement
Sign in to follow this  
Jettoz

GDI C# Help

This topic is 4403 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, I have been programming in C# for a while now and I can make X and O's, Guess the number and some Text Games in Console or Windows Forms using a Text Box. However now I want to move onto making 2D Games but not taking too much of a leap into it yet, I would like to be able to make small Maze Games like Pac Man using GDI. My problems are I have no idea how to make maps, for example I have a Bitmap or a Picture Box with an Image, but I have no idea how to make a map using Code. I have seen some text files in other peoples games with 011021100, ect... each number calling an image however I'm looking to make maps within the code itself not with text files. I have done some reading on GDI but the code I view really isn't something that’s good for learning but for someone who knows GDI but wants to make that kind of game. If anyone can direct me to a website that can answer these questions: - How to make maps - How to move a picture box with image or bitmap file - To move on a grid and not be able to walk through walls on that grid Thanks for anyone able to spend their time helping, it's greatly appreciated.

Share this post


Link to post
Share on other sites
Advertisement
maps are much much much more managable when included through openning text files.

however, I haven't a clue what GDI is. sorry.

Share this post


Link to post
Share on other sites
GDI stands for Graphics Device Interface or Graphical Device Interface. Instead of using DirectX or openGL I wanted to start with GDI for games until I get the hang of some things.

Share this post


Link to post
Share on other sites
Thanks for the reply about this book. I'm looking for websites because I spent over $500 already on C# books.

Share this post


Link to post
Share on other sites
You probably don't want to use GDI directly if you use C#. For C# (in Windows) you should go with the System.Drawing namespace.
  • - How to make maps

    To make a map, you need a way of representing the map in code. For instance, if we want our maps to consist of a simple grid (for a simple Snake game for example) we could represent a map with a grid of numbers, where 0 represents "not a wall" and 1 represents "a wall".

    Something like

    public class SnakeMap
    {
    private int width;
    private int heightM
    private int mapData[][];

    public SnakeMap(int width, int height)
    {
    this.width = width;
    this.height = height;

    mapData = new int[width][height];
    }

    punlic void CreateMap( /* Pass map data */ )
    {
    // Use the passed mape data to initialize the map arrray
    }
    }


  • - How to move a picture box with image or bitmap file

    Well, if you want to make a somewhat serious attempt at a game, you should try to render the graphics onto a single device (which is much more similar to the way you do rendering in DirectX or OpenGL), instead of creating lots of instances of Bitmaps and moving those around.

    Refer to the documentation of System.Drawing and you will find how to do this.


  • - To move on a grid and not be able to walk through walls on that grid

    You could for example have a method on your map class that tests for collions. For a simple Snake game, we could add a method to the SnakeMap that would look something like

    public bool IsWall(int x, int y)
    {
    return mapData[x][y] == 1;
    }
    and then use this method when we update the snake, to see if it has collided with a wall.

Share this post


Link to post
Share on other sites
I've been thinking for a while now and I believe going with GDI+ wouldn't be worth the time that I could better invest in MDX. If you have any info on MDX that would be great.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!