Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing in Java using Hexadecimal

Tags:

java

hex

drawing

I've seen this in a code of tetris game and I'm wondering how these values are able to draw the line, T-shape, S-shape, Z-shape, L-shape, inverted-L and a sqaure.

I get the four parametes maybe because of the four blocks needed per piece. But how did they come up with values like that? Have those something to do with the color too?

int blocks[][] = {
    {0x0f00, 0x4444, 0x0f00, 0x4444}, // LINE
    {0x04e0, 0x0464, 0x00e4, 0x04c4}, // T
    {0x4620, 0x6c00, 0x4620, 0x6c00}, // S
    {0x2640, 0xc600, 0x2640, 0xc600}, // Z
    {0x6220, 0x1700, 0x2230, 0x0740}, // 7
    {0x6440, 0x0e20, 0x44c0, 0x8e00}, // inverted 7
    {0x0660, 0x0660, 0x0660, 0x0660}, // square
}


I'm new in Java and I want to learn to "draw" using those values. Thank you very much!

like image 309
Sugar Spice Avatar asked Sep 17 '26 10:09

Sugar Spice


1 Answers

Each row of the table is one shape. Each column is a different rotation for the shape. The square, for instance, is the same no matter how you rotate it. The line (first row) flips between two patterns. I found this in a web search:

http://codeincomplete.com/posts/2011/10/10/javascript_tetris/

like image 98
ChrisCantrell Avatar answered Sep 18 '26 23:09

ChrisCantrell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!