A Mentor?

Started by
9 comments, last by GameDweeb 21 years, 6 months ago
The basics behind gfx or any programming is learning how to pass input to functions and how to get it out. Then after you master this, try to make small functions to build something bigger. This way you can reuse code and algorithms. I mean what is so hard? You can make a simple win32 app by just copying and pasting msdn docs code. Once you have the message pump setup then you setup 2D gfx environment thru 2d api. Let the app spin inside the message pump and do your own redrawing of the back ground. Then create bitmap surfaces with 2D api like dx ddraw7, and load them with bitmaps. Then blit the bitmap rectangle onto your background and presto! Then next loop iteration, you move the position of each rect corner to the side a bit by a pixel or so and you have movement. Then make couple of equal sized bitmap surfaces, load them up with different pictures, setup a timer, and on each time interval blit the successive pictures on the same part of the background and you have animation. Then move the blitted rects each loop and you have movement and animation. Look up the blit routine in ddraw sdk. Then after you got all that hook up a keyboard messages to movement code and on each key press you update the blitted rectangle position so that you can move the bitmaps with your keyboard keys or mouse. Then you setup collision system, basically you check whether each rect intersects the other and if they do the bitmaps collide. Etc, etc... just build from the base and up. All you need is "c" part of "c++" for this so don''t go overboard with object oriented programming until later once you get the hang of 2D stuff so you know what kind of objects you need to make to satisfy the implementation. If using ddraw7 make sure you setup a clipper also so that when your bitmaps go out of the side of the screen that the clipper clips them and you don''t get memory corruption errors.

In win32 you do:
1)create window and window class and register it
2)make background brush parameter NULL(so you redraw the window with 2D api instead of win32 api.
3)Setup a message loop with PeekMessage or GetMessage win32 functions
4)Put in message callback function thru which you will get a windows message if something happens like when your window needs repainting windows will send you WM_ERASEBKGND message, or when you hit a keyboard key you check which one by VK_SPACE and other defines
5)Put in shutdown code into your message callback so the window class/window you registered gets shutdown
6)Make couple of global variables to hold ddraw surface pointers as well as the device pointer.
7)In your main() function, load up the surfaces with bitmaps
8)In your msg pump code listen for any msg and if none available then draw or blit your 2D surfaces onto the screen.
9)In your msg callback function on WM_KEYDOWN I think message find out which key was down with VK_BLAH thingy and modify the destination blit rectangle''s coordinates so when the msg pump is ready to draw the gfx again it will blit them to one side a bit thus creating a movement. So your msg pump just blits or draws the same bitmaps onto the screen constantly. I recommend you make your ddraw7 app a window app at first, it''s easier to setup I think. Don''t forget that you can check the msg pump anywhere in your code even multiple of times and you can setup a rendering from anywhere with this msg pump code. I did this with my 2D game. One msg pump was for intro screen/user choices the other was for the game itself.

The important thing is you get something drawing at the get go. There isn''t much more after that unless you want to get fancy. At that point the programming and calling api functions won''t be a problem so only thinking of special effects or unique gameplay will be taking all your time. Read the msdn section on ''windows'' it explains the creation of windows and how msg pumps work, plus you can just copy and paste their win32 code to get up to step quickly. Do not go into MFC/OOP at this point because it will be overwhelming and you don''t need it at this time.

This topic is closed to new replies.

Advertisement