Public Group

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.

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 on other sites
maps are much much much more managable when included through openning text files.

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

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 on other sites
Check out the nettrix game in this book since it's a game written using gdi+.
Sounds what you were looking for.

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 on other sites
Thank you for your reply, if anyone else has any other help they can provide please do, thanks!

Share on other sites
If you want me to clarify or elaborate my hasty written post, feel free to ask.

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.

1. 1
2. 2
Rutin
29
3. 3
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• Forum Statistics

• Total Topics
633648
• Total Posts
3013110
×