GDI C# Help
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.
maps are much much much more managable when included through openning text files.
however, I haven't a clue what GDI is. sorry.
however, I haven't a clue what GDI is. sorry.
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.
Check out the nettrix game in this book since it's a game written using gdi+.
Sounds what you were looking for.
Sounds what you were looking for.
Thanks for the reply about this book. I'm looking for websites because I spent over $500 already on C# books.
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 likepublic 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
and then use this method when we update the snake, to see if it has collided with a wall.public bool IsWall(int x, int y) { return mapData[x][y] == 1; }
Thank you for your reply, if anyone else has any other help they can provide please do, thanks!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement