Archived

This topic is now archived and is closed to further replies.

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

This topic is 5826 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

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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--;

Share this post


Link to post
Share on other sites