Advertisement

Another newbie on TETRIS

Started by May 28, 2002 02:15 PM
9 comments, last by JinJo 22 years, 5 months ago
You are all probably sick of people like me but I just cant get this. I am doing my tetris in C and OpenGL. I know C quite well and know enough OpenGL to do this game. When i started this I just used a lot of NeHe''s GL code but I do understand it all and when (if ever) I get my main game logic working I will re-write all the code that is not mine. I have been doing this game for about 3 months now and I have posted a few messages and i''ve been thankful for the replies, but I am now getting lost completely, I can get the different bricks to draw on screen and move with keyboard (slow), I can also get them to rotate using hand coded matrix stuff but when it comes to collision I just cant seem to get anything done. And now with me tweaking so many bits of code it is got quite a few wrongs in it, these are not compile errors but Im sure they may be making the bricks act wierd. Now what I would really appreciate is if someone could lok through all my code, or at least the game logic parts and help me sort things out, also any problems you find with my C I would also be happy to know. The graphics are quite horrible but when I get the logic done Im going to change all of them. If you would like to help leave your email in this forum and i will send you my source. Please help, THANKS!
Your doing it the wrong way. First write your code. How ugly the code may be, it works. After you got the raw parts of the game working you should start cleaning the code and optimize. Not optimize while developing because you always change the code later. And for the collision detection part, just scan the row where the bottom of the block is. Take the row underneath it and test for collision.

Sand HAwk


----------------
-Earth is 98% full. Please delete anybody you can.
----------------(Inspired by Pouya)
Advertisement
Thanks Sand_Hawk that is a simpler way of doing the collision than I was.

However I would still be really grateful if some one looked at the code as when I cant seem to get the brick thats just been used to copy onto the main game array.

Thanks!
Sorry guys, this program just got worse.

I am thinking of starting agai and planning the game properly this time (not just mock up screenshots).

However the current program may only have a few obvious mistakes in it that are really easy to fix (which I am positive thats all it is) but I just cant spot them. So I would be happy for anyone to read the code.

just give me your email and i will send it to you straight away.

Thanks for your time!
3 months on tetris?
wow.

you must be striking a few problems.
if you want, you could go to www.geocities.com/realgamez_dev/articles.htm and find the tetris one.

that has a couple little bugs but it works and only took 3 *hours* to code.

half the problem as i see it is that people do their data structures wrong. if you just implement the thing as an array, and keep a reference to the current block (8 ints ax,ay,bx,by,cx,cy,dx,dy).

my two cents'' worth....
die or be died...i think
Thanks! I''ll take a look.

The reason its been taking so long as i pretty much got the problem 3 months ago and have left it for a long time.
I look at it now and agian and cant sort it.

I really want to finish this as i want to move onto breakout (dont laugh), I have already started work on a level editor for it.

Thanks again!
Advertisement
If you look at the other tetris thread currently running, i''ve put a link in to some code. Its not pretty but it works fine.

http://jeannie.zelos/btinternet.co.uk/tetriscpp.zip
(I think)

,Jay
Hey,

If you still want someone to look through your code send me an email at Doulin@softhome.net

I will see what I can find in it, and I can send you a copy of my simple tetris game I made. The big thing here is not to over complicate matters. There are only a possible 10x20 or so positions for all bricks...so why not just make that a 2D array, and when a block moves check whether the space in the array is taken or not, if not then move the block.

The other big thing is that it has taken you 3 months so far. This is VERY bad, it is obviously because you have a lack of spare time rather than the fact you have spent 3 months solid on the game. Even the best programmers find it hard to code a bit, go off and come back and code. Even with perfect commenting etc you forget all the thoughts you had conjured up when you were coding away, so you may have forgotten or changed some of the underlying ways you were coding your game.

I work full-time as a programmer and make games in my spare time so i know exactly what your problem is, you really have to make time, otherwise you are making the whole thing far to complicated.

Anyways, enough rambling, send me an email if you want me to look at it.

Doolwind
A simple way of detecting collision is to keep an array updated for the game screen with solid/empty flags.
Each shape should have a SOLID/EMPTY definition for each rotation too (ie. a 4x4 grid for each rotation).

One simple function that takes one of these shape definitons (4x4) and a x/y coord and tests if any of the shapes SOLIDs overlaps with any SOLID in the game array.

If it does overlap then the shape won''t fit in that x/y position at that rotation.

Make any sense?
<a href="http://www.purplenose.com>purplenose.com
The best method I've heard of (and used) is as follows:
//Varsint MainArray[10][20];int GameArray[4][4];int Xpos; // position of gamearray relative to mainarrayint Ypos; 


//To rotate 90 degreesfor (int Y=0;Y<4;Y++)    for (int X=0;X<4;X++)        TempGameArray[3-Y][X] = GameArray[X][Y];//Then eliminate empty rows/columns at beginning of temp array// to get I, J =first filled row/column// then copy TempGameArray back to GameArray to x=0 to 3-i,y= 0 // to 3-j from i+x,j+y (I think  ) 


// To check collisionfor (int Y=0;Y<4;Y++)    for (int X=0;X<4;X++)        if (GameArray[X][Y] & MainArray[Xpos+X][Ypos+Y]) Collide=true; 


// To move DownYpos++;// Left/RightXpos--; / Xpos++; 


Dead simple, check the link I posted for the full source.

,Jay

Edit: code smashed together.

[edited by - Jason Zelos on May 30, 2002 1:59:24 PM]

This topic is closed to new replies.

Advertisement