Jump to content
  • Advertisement

Archived

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

Android_s

Console Programming - Tetris

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

Right! Due to my lack of knowledge I have been forced to take a step back to try to make a console Tetris instead of the Win32/OGL one i was trying earlier. Things now seem to proceed fast but i still have a couple of questions about this. First one is about movement. In my Win32/OGL project i was using bool keys[VK_LEFT/VK_RIGHT] for the horizontal movement, all acording to NeHe standards . But now when I try it in console nothing happens. My question is then, Dosn''t VK_LEFT/VK_RIGHT work in console? My second, that is some sort of a thought. I have seen people here suggest the 4x4-array method for making the shapes of the four blocks. I read somewhere that it is a way to dynamically link the blocks together instead. Is there anyone that have made this and if so, can you perhaps post some info about this method? Thanks in advance! ----------------------------------------------------------- ----------------------------------------------------------- "Ask not what humanity can do for you, ask what you can do for humanity." - By: Richard D. Colbert Jr. http://www.gametutorials.com

Share this post


Link to post
Share on other sites
Advertisement
#1 - VK_LEFT/VK_RIGHT are win32 only. They are used in the windows message procedure but, dos does not have one. You would have to implement some form of input. ( Such as getch() or getchar() )

#2 - 1 way to dynamicaly link blocks is with linked lists. Read up on how linked lists work and that should do the trick.

Share this post


Link to post
Share on other sites
The bool keys thing is a concoction of Jeff''s that has nothing to do with console mode. That array gets updated in the generic WinProc code whenever an appropriate message is received (you can look through the source if you don''t believe me). Anyways, you''ll probably want to look into the getch() family of functions for your input. Just remember that this won''t be event driven, but procedural (is that the right terminology?) in nature.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

Share this post


Link to post
Share on other sites
About the VK_LEFT/RIGHT I suspected something like that. I will try an old code I remember from one of the GameTutorial lessions, and if that dosn''t do the trick i will look into getch().

And about the other question, I have always wondered what linked lists are for. Perhaps now I find the answear to that

Thanks!

Share this post


Link to post
Share on other sites
Heres most of the input function in my ASCII tetris, hopefully this will help you a little ...

void UserInput(void)
{
input = false;

if(_kbhit())
{

bInput = true;

int key = _getch();

if(toupper(key) == 'Q')
{

//blah blah

}
else if(toupper(key) == 'P')
{

//blah blah

}

QueryPerformanceCounter(&previousTicks); // reset the time


}

else if(key == 32) // pressed the spacebar

{
//blah blah

}
else if(key == 224) // it's a cursor key!

{
switch(_getch())
{

case 75:
bLeft = true;
//left

break;
case 77:
bRight = true;
//right

break;
case 72:
bRotCounterClock = true;
//up

break;
case 80:
bRotClock = true;
//down

break;
}
}
}

}



An ASCII tetris clone... | AsciiRis

[edited by - Tiffany Smith on August 6, 2003 12:11:28 PM]

Share this post


Link to post
Share on other sites
I will start on a Win32/OpenGL/DirectX one soon. But not today. Maybe tomorrow. I will give out the source when I am done.

Scott Simontis
Big Joke: C#

Share this post


Link to post
Share on other sites
quote:
Original post by Android_s
And about the other question, I have always wondered what linked lists are for. Perhaps now I find the answear to that



A linked list is where one object contains a pointer to the next object. It is great if you''re going to insert or remove lots of objects in the list, but you can''t jump to any object you want, you always have to go through them in order.

I doubt you''ll need a linked list for tetris, though.

Share this post


Link to post
Share on other sites
As for "dynamically linking blocks together", I don''t see what you mean. If, however, you mean to reserve memory only for the needed blocks (as oposed to a 4x4 array, where you allocate four times as much memory as is really needed), you could simply solve it by placing all the currently falling blocks in a CGroup class or something like that.

If you need some other help about the game logics, you can check out the full source of my Tetris game here. It uses Win32 for input and stuff, and OpenGL for the graphics, but the logics are the same wether you use OpenGL or ASCII graphics. The code is heavily commented, at least if you compare it to what my code usually looks like.


"For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!"
"If anyone sees a suspicious, camouflaged factory being carried across the desert, they should report it immediately."

Share this post


Link to post
Share on other sites
Thanks for all the help!

I havn''t had mutch time to try all the methods that have been suggested here, but I hope I can sit down and try some tonight.

I still have one question for Tiffany Smith about her Tetris clone. Why is it that you write for example _getch() and _kbhit()? Is it the same as to write getch() and kbhit()?
Hmm, is it possible I can see the code to that Tetris you made? I would like to see how you did that drop-funktion.

And for Valderman. I ain''t sure exactly WHAT i meant by linking them together dynamically, it was just something I read a while ago. The thought is that when you want a speciffic shape, for example one of those straight lines, you could group 4 blocks together in a line. I don''t know if it''s possible without too mutch code, but it would be fun to see how it''s done.

Share this post


Link to post
Share on other sites
quote:
The thought is that when you want a speciffic shape, for example one of those straight lines, you could group 4 blocks together in a line. I don't know if it's possible without too mutch code, but it would be fun to see how it's done.
Check out the CGroup and CBlock classes in the link I posted before, that's one way to do it. Although it's most likely not the best way, it works fine for me.

Oh, here's the link again: Clicky

Oh yeah, the code for rotating the blocks is pretty ugly, if I remember correctly.


"For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!"
"If anyone sees a suspicious, camouflaged factory being carried across the desert, they should report it immediately ."


[edited by - Valderman on August 7, 2003 1:02:23 PM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!