Archived

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

DarkAvenger

Tetris game help

Recommended Posts

I decided to start writing a Tetris style game using VC++ and DirectDraw, so I learnt some DirectX programming, and I can now load a bitmap(hooray ). But, now comes the tough part; actually writing the game. I've got just a couple of questions, which are hopelessly newbie. Okay, firstly, on loading the brick bitmap, its obviously gotta move.. now I'm getting a little worried. One, I've got to pause the compiler (I could give it some huge loop to chew on, but that doesn't seem classy) and I've also got to make sure the block moves down.. now, what is the best approach to solve this? Is it a) load the bitmap again, after deleting the other one, or is it b) moving the pixels through a loop? And, let's not forget, I need to pause the compiler. To recap, I need to know: 1. How to pause the game 2. How to move the bricks And, though I haven't already gotten there, I may as well ask the following 3. Is it best to load a brick type as a collection of images or as one single image?(I presume it's the latter, but just in case..) 4. For rotation, is it better to load a separate "rotated" image, or do I call a rotation function of my own? As always, thanks for any help. Edited by - DarkAvenger on 10/8/00 12:58:32 AM

Share this post


Link to post
Share on other sites
i don''t think i''m understanding your questions correctly.. you need to pause the game? why? what are you rotating?
i''d just load one instance of each bitmap you need, and number each, so you know which one to show for a specific block.. i''d also keep track of the playing area as an array, with some code for it being empty, or if it''s not empty, some kind of reference to the bitmap that needs to be shown for it (i used a integer)..
for each screen update, just clear the screen, display the mass in the playing area via a loop, and display the current block. for moving the block, i just used coordinates of the playing area (i.e. 10x20 or whatever), and change the coordinates based on player movement and falling, and have your block drawing function map those coordinates to the screen...

it seems you''re going at it a totally different way than i did, though, so maybe i''m not being much help...

there''s nothing wrong with loops...

------------------------
IUnknown *pUnkOuter

"Just do your best and
don't worry"
--Morrissey

"Try the best you can
try the best you can
the best you can is good enough"
--Radiohead

"Are you looking for new ways
to do better than your worst"
--Nick Drake

Share this post


Link to post
Share on other sites
Sorry, that was pretty ambiguous.. anyway, what I meant by saying I had to pause the game was that I need to make the block move after a specified time frame eg. 1 sec. Maybe pause isn''t the right word, but I think you get the point.

I also need to rotate the blocks, if the user presses Space or whatever; but is that too complex?

I have nothing against loops, it''s just that using them as a "timer" doesn''t seem to be the best solution.. but hey, I''m just a newbie who barely knows any DirectX, so why listen to me ? Thanks for the reply anyway!

Share this post


Link to post
Share on other sites
Sorry, that was pretty ambiguous.. anyway, what I meant by saying I had to pause the game was that I need to make the block move after a specified time frame eg. 1 sec. Maybe pause isn''t the right word, but I think you get the point.

I also need to rotate the blocks, if the user presses Space or whatever; but is that too complex?

I have nothing against loops, it''s just that using them as a "timer" doesn''t seem to be the best solution.. but hey, I''m just a newbie who barely knows any DirectX, so why listen to me ? Thanks for the reply anyway!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
keep teh same bitmap, and put in in a loop untill it hits bottum... what do u eman pasue?? do u mean teh user can pause the game or do u want a pause in the motion of hte brick coming down??
if u want te second one just put

sleep(length of pause);

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
keep teh same bitmap, and put in in a loop untill it hits bottum... what do u eman pasue?? do u mean teh user can pause the game or do u want a pause in the motion of hte brick coming down??
if u want te second one just put

sleep(length of pause);

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
to rotate the blocks, u should look into direct input and direct draw

Share this post


Link to post
Share on other sites
I need to have a gap between the block being rendered, and it being moved down, not a game pause itself. So, I guess I need to use the sleep() function; thanks! And anon., I didn't quit follow.. do you mean there are functions in DDraw/DInput for rotation? Thanks for all the help!

Edited by - DarkAvenger on October 8, 2000 2:48:44 AM

Share this post


Link to post
Share on other sites
I wouldn''t use the sleep function if you really wanna learn so game programming check out the QueryPerformanceTimer, and QueryPerformanceFrequency they are what a lot of commercial games use or used I think. Anyways check out the tutorial here and you will learn how to use an accurate timer which can be used later on for beautiful things, like governing the speed of your game.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you know what the fuck, you should stop programming games, go to your fucking room, stick your face in a pillow until you stop breathing you fucking retard. you cant even figure out what the fuck to do with your fucking meager tetris game. i swear, if i had a dime for every dumb motha fucker who wanted to try and program tetris i would be high as a fucking fucker. so fuck you and go kill yourself.

Share this post


Link to post
Share on other sites
Pay no attention to the anonymous poster above... Some people must find it really amusing to insult others anonymously...

Your first question was a bit strange... But I''ve asked such questions before, when I was in your situation

There are different ways of timing your game... but a simple one is to do something like this:

    
#include < windows.h >
//needed for GetTickCount()
#define UPDATE_INTERVAL 30

DWORD StartTime, CurrentTime;
int main(void)
{
initialize();
StartTime=GetTickCount();
while(1)
{
CurrentTime = GetTickCount();
if(CurrentTime >= StartTime + UPDATE_INTERVAL)
{
get_player_input();
process_input();
render_frame();
StartTime = CurrentTime;
}
}
}

Note: I usually don''t use GetTickCount() and such.... so I''m not sure that this pseudo-code is correct...
Another way of timing your game is to store the speed of all moving objects, and then do something like

current_X += X_speed*delta_time;

Game programming is basically about showing bitmaps at different places... and move them in a certain way...

//Ksero

Share this post


Link to post
Share on other sites
i done a version on me site with source its opengl so it should be pretty easy to understand

http://members.xoom.com/myBollux

Share this post


Link to post
Share on other sites
zedzeek, your site isn't up

DarkAvanger if you're confident in C/C++ ... 'nuff said
Buy a game programming book!!! Or a DirectX Book.
You'll fall in love with Lamothe's "Tricks of the Windows Game Programming Guru's".




Edited by - gi-centerprintf on October 8, 2000 8:56:31 AM

Share this post


Link to post
Share on other sites
it is up just half the time u cant log in (u gotta keep trying), which brings me to my own question are there any decent free webhosting sites around, ive tried geocites,homestead,xoom and theyre all not much cop. my critea? is
*at least 50mb storage
*ability to upload files with ftp
*when i try to login i can log in unlike where i am at the moment xoom,
(click)
website not available
WHY NOT (click)
that page does not exist
YES IT DOES U BASTARD I WAS LOOKING AT IT A MINUTE AGO(click)(click)

http://members.xoom.com/myBollux

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hey I''m new to programming too... But anyway, I think a good book to start with is "Tricks of the Windows Game Programming Gurus" like gi-centerprintf mentioned. In there it recommends using the GetTickCount() function, like Ksero said.
I made a pong clone first, instead of tetris... and I still can''t get the damn ball to bounce the right way off the ends of the paddles! I''ll get it right soon, I tell you. And for rotating the bricks, I guess it depends... you could make different bitmaps for all the different positions of the blocks, or make one square block bitmap and stick them together to make the different shapes... there are a ton of ways to do it.

Share this post


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

I wouldn''t use the sleep function if you really wanna learn so game programming check out the QueryPerformanceTimer, and QueryPerformanceFrequency they are what a lot of commercial games use or used I think. Anyways check out the tutorial here and you will learn how to use an accurate timer which can be used later on for beautiful things, like governing the speed of your game.


I''d stay away from QueryPerformanceTimer unless you _really_ need the precision. For tetris, and most games, GetTickCount will do fine.



Toby Jones
Software Design Engineer
Sonic Foundry, Inc.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Here you have poorly commented tetris clone code. I hope it''ll help you!
http://members.xoom.com/IgaNinja/ClontrisDev.zip
The Clontris.txt file is in spanish, but if you any doubt feel free to ask: iga@wanadoo.es
Good lock with your game!

Share this post


Link to post
Share on other sites