Advertisement

puting a picture on a screen with user input from keyboard to move it

Started by December 31, 2001 11:52 PM
4 comments, last by postulate 22 years, 8 months ago
how would I put a picture, like a character, on the screen and have it move with the keyboard? I''ve been reading c++ books but haven''t quite understood game programming but would really like to get it. I''ll be using MSVC++ 6.0 if you have code that will help me out, or a site that explains it. thanks
First off, are you using DirectX, OpenGl, WindowsAPI, or what?

I will try to answer your question the best I can for if you want to do it in directx.

After you create a window (there are many tutorials for doing that here) and initialize the directdraw or direct3d device (depending on what version of directx you are using), you need to load the bitmap to a surface (there are plenty of tutorials for this also-- post another reply here if you want me to go into more detail on that).

Then the function that you need to use to copy it to the screen in directx7 is blt(); The blt() function copies the surface to a specified part of the screen. One of the arguements is a destination rectangle (I.E. the screen coordinate).

In order to implement the keyboard, you could do this (not real code, just pseduocode)

if (KEYDOWN(VK_LEFT)) { // if they press the left arrow
dest_rect.left -= 5; // move the left of the dest rect 5 to the left
dest_rect.right -=5; //move the right of the dest rect 5 to the left
}
if (KEYDOWN(VK_UP)) {
dest_rect.top -= 5;
dest_rect.bottom -=5;
}
Then call the blt() function again.

If you want more help from me regarding any functions feel free to email me at Yankees135@yahoo.com .

Also a good book I can reccomend for beginning game programming is Tricks of the Windows Game Programming Gurus

Hope this helped

Feel free to email me at NYYanks432@hotmail.com if you have any questions
Advertisement
face the facts guys, you gotta go thru a lot of learning before you can do anything reasonably simple (looking) with directx...
postulate, i suggest u get a directx book... or opengl or whatever you want to work with..

...go on and live with no regrets, you only have one life...
...go on and live with no regrets, you only have one life...
I haven''t used any opengl or directx before. so I guess I''m starting from the beginning.
Hey.

Tricks is definitely a great book to learn although it uses 8 bit graphics and DirectX 6. You could also look up the Interactive Hands-On Game Development Tutorial on the forums here.

Minion
My first graphical program started with what you just described. I used the simple geometrical figure of a square.

I used Allegro so the graphical stuff was easy.

Had two variables, one for the square''s x-value and the other for the y-value. The square was drawn in the middle of the screen, and with a keypress the values increased or decreased and changed it''s position, ie:

if (KEY_RIGHT)
square_x++;
if (KEY_LEFT)
square_x--;
if (KEY_UP)
square_y++;
if (KEY_RIGHT)
square_y--;

This topic is closed to new replies.

Advertisement