Jump to content
  • Advertisement

Archived

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

Stanley Foo

Connecting figures to my C++ code

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

I know this is a dumb question, but I''m swamped with work, and I really don''t know how to answer it. Ok, I''m going to start games programming with a simple Tetris-like thing, or anything with blocks. I can write the C++ algorithms for it, no problem. But how do I use C++ to draw those different colored blocks? Or, more generally, how do I connect my figures (soldiers, martians, etc) to my C/C++ code? Stanley

Share this post


Link to post
Share on other sites
Advertisement
Well, you could make each of your figures a class and then make an array or linked list of the class.

For tetris, you would also want a two dimentional array which contains the blocks that have already been "set". When your figure reaches the bottom where it can''t drop any more, load the figure''s blocks into the array and delete/reset the figure.

E:cb woof!

Share this post


Link to post
Share on other sites
quote:
Original post by dog135

Well, you could make each of your figures a class and then make an array or linked list of the class.
E:cb woof!


Hi, dog,

I can make a class very easily, but how do I make this class a graphic? In other words, what do I have to do to make

class Block{
//what''s needed
}

I can get a block of ''*'' or "#'' or whatever, I cannot, as yet, get this to become a green-colored block (or something with graphics). So my question is how I can do it.

Share this post


Link to post
Share on other sites
I can''t help you with colors, because that''s not too easy. But I can help you with positioning and screen updates.

I assume you''re trying to do this as a "Win32 Console Application" from when you said you could display a "*" or "#". If so, this is how you''d go about doing this...

The DOS console screen is 80 by 25. So, you''d have an array like this:

char screen[80 * 25];

And you''d fill it with spaces. Then, to draw something to it, like an exclamation point at position (x,y), you''d do this:

screen[x + y*80] = ''!'';

Then, to draw to the screen, you''d do this:

system("cls"); // Clears the dos screen
cout << screen; // Print out the screen buffer

You can replace the cout part with printf() or whatever you like. And I think you have to include to use system().

You''ll also have to erase what you drew last frame before you draw the current frame so things don''t leave trails. You''d just fill the screen buffer with spaces like you did in the first place.


lntakitopi@aol.com | http://geocities.com/guanajam/

Share this post


Link to post
Share on other sites
quote:
Original post by SHilbert

Oh, and use printf()... cout has some sort of problem with this idea...

lntakitopi@aol.com / http://geocities.com/guanajam/


Hi, Shilbert,

I can already do all that, but I''m talking about a professional drawing, like what you see in a games CD - like how do I draw a spaceship? If I use Paint of whatever, how does my C++ tell it to move?

Stanley

Share this post


Link to post
Share on other sites
Hi Stanley,

Sorry, but I think your question is very ambiguous, and it will take forever to explain, you would be better off buying a book in game programing. Why? because its is not like blowing and getting bottles, you first have to set a video mode, create a primary and back buffer, write the images to the back buffer (which usually involves writting some PCX or BMP format decoder), figuring out where the next move will put your ship/block/alien/character/meanie/goodie/whatever and start all over, so my recomendation is buy a book, study the direct draw documentation and tutorials on the net, once you know how to plot a pixel with direct draw or good old Mode 13h at least, I am sure you can make a more direct question.

Kwizatz

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!