help with rotation....

Monkey Forums/Monkey Beginners/help with rotation....

dubbsta(Posted January) [#1]
im working on a tetris and cant figure out how to rotate the pieces which is an array of blocks, so i started to simultaneously work on a snake game and ran into the same problem, i drew eyes on the snake with drawcircle commands and am trying to rotate the head so the eyes stay in the right place.. the tetris pieces are png blocks the snake head is a drawn rect. pls give example if possible

Pakz(Posted January) [#2]
The last time I made a tetris a just stored each block in an array. This including the rotated versions of the blocks.

array:block1 up

When pressing the button to rotate I just did currentblock+1 and when at the left side and one further then currentblock-=4

My blitzbasic tetris code is on the blizbasic code archives if you want to look :

dubbsta(Posted January) [#3]
cool thanks pakz i think gerry was saying the same thing but i wasnt to clear

dubbsta(Posted January) [#4]
pakz if you take requests can you do a something like this

Gerry Quinn(Posted January) [#5]
See this thread, especially Mark's comments (included below):

Yep, the matrix ops work 'backwards'.

I like to think of the matrix as a stack of ops, eg:

translate x,y
rotate r
scale h,v

...means 'scale by h,v' THEN 'rotate by r' THEN 'translate by x,y'.

But indeed, it's better rotate stuff 'physically' for Tetris - you would normally only use the graphic matrix operations for animation, and few Tetrises even do that, because the player wants to see the shape rotate by 90 degrees instantly. (Of course, you're strictly speaking using the same math when you rotate your array, but in a very simplified form.)

Even for a snake game, I think most people would use sprites combined with internal rotation of arrays rather than graphic rotation.

(Back when these games came out first, most of the hardware was incapable of - or at least very poorly designed for - rotating sprites anyway!)

Graphic rotation comes into its own with racing car games and such-like.

dubbsta(Posted January) [#6]
ok i see! thanks Gerry. but technically a would matrix work if i wanted animtion? @Pakz alot of your examples from git draw blank screens. is there a fix?

edit: the matrix seems harder than i thought

Gerry Quinn(Posted January) [#7]
I'd advise reading that thread, and experimenting, if you want to use the graphics rotation, scaling etc.

But for Tetris, really you don't need that. Your bricks will 'snap' into new positions when you rotate. There will also be a fractional height difference as they drift slowly down.

(In Tetris there is never any need for bricks to be at a fractional cell position horizontally, unless you want to make the slowest, most unresponsive Tetris in history! Same goes for animated rotation. And as a first approximation, you can even skip the fractional height and have them drop a full step every now and again, instead of falling smoothly.)

dubbsta(Posted January) [#8]
lol ok matrix is out. just wondering though. but didnt work out how i planned but ill leave that for the future.