Hi all. This is my first topic here.
I have one problem. I am writing a 3D variant of tetris.
There is update method for tetris field
public void update(float tpf)
{
_timeSinceLastUpdate += tpf;
if (_timeSinceLastUpdate >= SDAOptions.stepInterval / getSpeed()
&& !isPause())
{
if (canMoveDown())
{
moveDown();
}
else
{
// game over
if (_tetPos.y == _initTetPos.y)
{
setPause(true);
for (ISDAFieldListener listener : getListeners())
{
listener.gameOver(this);
}
}
// place tetramino
else
{
placeTetramino();
if (isLine())
{
int numberOfNewLines = _lineProcessor.processLines(_data, getRootNode());
for (ISDAFieldListener listener : getListeners())
{
listener.lineCompleted(this, numberOfNewLines);
}
}
useNextTetramino();
}
}
_timeSinceLastUpdate = 0;
}
}
The problematic block is near _lineProcessor.processLines(). Line processor is a class that clears a line(s) and shifts down all boxes. Here is main routines of lineprocessor
public int processLines(Box[][] data, final Node rootNode)
{
int result = 0;
int maxY = SDAConstants.fieldSize.y;
_animateble.clear();
for (int y = 0; y < maxY; y++)
{
if (isCompleted(y, data))
{
detachLine(y, data, rootNode);
shiftDown(y, data);
y--;
maxY--;
result++;
}
}
return result;
}
Now assuming I want add animation for field shifting. My idea is collect all detached boxes into some collection (e.i.
Map<Box, Vector3f>
The main problem this is that if you see at
Field#update
Field#update
Couldn’t you offer some idea to resolve this challenge? :? Maybe there is some other method to implement update cycle in such (per-second) games.
I hope my explanations are distinct. :D If you want access full code, it’s available at http://code.google.com/p/sdatetris/source/checkout