-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|702|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Article Home -> Basic Game Engines


 
Jayenkai
Created : 05 January 2008
 
System : Windows
Language : Blitz

Tetris Part Four : Spin and Block

A rather messy tutorial to help people make decent Tetris games.

How to make a decent Tetris game.
Part Four - Spin and Block

This tutorial is half created to help Garand, but also because I'm sick of playing rubbish Tetris clones.
You can find part one of this tutorial here, part two here and part three here.

Everyone knows that "Gameboy Tetris" was the best one going, but no-one ever seems to make them like that anymore.

So here's a list of things you'll need in order to make the game well, as well as chunks of code, and a few moans and gripes along the way.

I'll be doing this in Blitz, but the rules are about the same for all languages, and you should be able to follow them along with whichever language you're using. (maybe! Although it is a bit of a mess! I'm not very good at describing code!)



Spin me Right Round
OK, so in the last tutorial we got things pretty much done, but if you spin the blocks around you'll get them shoving themselves into each other unexpectedly.
To stop this from happening, we need to be sure the player isn't going to spin into anything, but at the same time we don't want to completely stop the player from spinning around when they absolutely need to.

First up, whenever the player hits the Spin button, we check the next rotation of the block where it is, but also 2 left, 1 left, 1 right and 2 right to the position it's at.
The Reason?
If the rotation doesn't fit right here, but does fit 1 to the left, we'll actually shift the block 1 to the left.
Take for example the I bar. If the level's empty, you have the bar in it's I rotation, shift over to the left, and hit rotate to make the - rotation.. You expect the block to spin.
The game should fit the bar in, but if it did, the bar would be 2 tiles in the wall!
You need to shuffle it across so that it fits.

Try it in Gameboy Tetris. That's how it works!

The only tile the I doesn't spin is when it's trapped inbetween two objects.
So, first we do a X -2,-1,0,+1,+2 check, and if it CAN fit, we rotate, and then fit it in.
It's not as complex as it sounds.

First up, check it'll fit.

Give us a small array we can play with. Dim Fits(5)
Next, create a checking function.


Don't forget to add this check to the two rotation keys, and insert PlayerRotate+1 and PlayerRotate-1 where applicable.
Try building yourself a nice little 1-tile tube, and spinning an I bar between it. It should no longer be able to spin, where it can't possibly fit.

But if you spin it near the edge, it'll still clump it's way into the wall. So next we have to fix that.



Bump and Grind
For the mostpart, our FitMe function is about the same as the CanFit one. The difference comes at the end.
Copy and paste coding! Woot!



The difference is that bit at the end.
We check the available slots, and whichever one's closer to the middle and fits nice, is the one we'll use.
Find the gap, keep the X value, shift the PlayerX by X positions, then return.

To fit it in, keep track of when the player's rotated a block, then call the new FitMe function which should fit the newly rotate block into place.


Got all that?
Good!

Give it a play, and you should find that by now you've got a pretty decent game of Tetris going on.
There's plenty of simple additions, from adding scores, line counting and things like that..
There's complex stuff like nicer line transitions, sound effects and some particles.
And then if you really want to play about, you can try making 3D Tetris, adding Bombs like Bombliss, or even making a whole new type of Tetris that no-one's seen before.

I'm sure you'll do fine!
Enjoy playing with your nice half-finished tetris game.

Download things up to this point!

 

Comments