Saturday, October 3, 2009

How do people come up

with creative titles? Sometimes I just know one and use that, or I am simply stumped and write something stupid like just using it as the beginning of the first sentence.


Anyways, I've been watching the Matrix-trilogy while I had no internet. I had a few problems at first, since I could watch other DVDs, but not that movie. Turned out - using my fathers laptop - that movie-DVDs usually use an extra encryption called CSS.
Well, I downloaded the packed and then the problems were gone :D

I've noticed that I've gotten much more critical and demanding from movies.
While when watching them the first time I did spot a few weird things, but didn't care about that. But this time it just felt wrong; why didn't the machienes - as they knew that they'll wake up - put them in another Matrix in which they'd think to be in reality?
And another biggie: they can't reset the Matrix, lol.
Also, if the humans have enough energy to power Zion to have lights and warmth, to fly around with hovercrafts, power computers and these war machienery, why don't the machienes use it? And why don't they just built a floating powerstation to go above the artificial clouds?

But oh well, still a great idea and a neat-o movie.


And another thing I did to waste time while not having Internet is downloading the NCurses-library and a tutorial via my fathers laptop and working a little with it.
I planned on making a rogue-like at first, but I thought Tetris would be easier.

For some reason I don't quite remember I'm coding in standard C90 and so far only used one POSIX-function (nanosleep). Everything else is portable (I'm compiling with -pedandic-errors ffs - and -ansi for that matter (gcc)).
Well, the exception being NCurses ;)

And, well, I ran into a little design-issue concerning rotating pieces. At first I was having a 4x4 color-map inside a tetris-tile.
On creation it would simply take a 4x4-array of a form (I call them L, inverse L, T, S, Z, I and box), represented as 1s and 0s like
0, 1, 0, 0, /*I*/
0, 1, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0
and multiply a random color with each element to store it in the tetris-tile color-array.

While rotating the I can be done with a bunch of xors and the T simply by moving each edge one further, the L and inverse L are more of a problem.
At first I even forgot about S and Z lol. Anyways, it was easy to add them, as - although being hacky to be quite efficient - it is modular.
It kinda bugged me that I'd need a variable indicating the rotation just for L, invL, S and Z and having dumb functions for them to rotate.

So then I though of another approach, which at least is the same for every piece (well... almost):
Having all formes in a const array, at first the non-rotating box, then the two-state I, S and Z and finally L, invL and T with 4 states.
A pointer to a function will take care of rotating correctly then.
Each tile has a color-variable and on rendering both, the color and the form, will be brought together.

My current solution is having a state variable and depending on that reading the array in another way, such as swapping the two indecies or reading from back to front and thus flipping the tile.
Not too sure it'll work correctly, because I didn't code the render-function yet, but I'll see.

If that doesn't work I'll use function-pointers so the tiles themselves decide how to render (these will be called on rendering, so that function renderes them, not the render-function itself).
...I'm not really too well educated about C concepts :S

Since I was working with bit-fields, which means that you decide how many bits to use per variable, it seems fitting to store two tiles in one struct to have 8 bits full.
That's pretty much perfect, since you have one tile you control and a preview to the next tile.

Hacky, therefore efficient. Not really proud about it being hacky, but at least it shows that I make up my mind :P


Also, inline-functions in headers are very wierd in C90 :S

No comments: