tetris example update

This commit is contained in:
Vadim Lopatin 2014-12-24 15:09:04 +03:00
parent b52284a7fc
commit 666c27edf1
2 changed files with 30 additions and 3 deletions

View File

@ -108,12 +108,15 @@ Win32 builds
* Executable size for release Win32 API based build is 830K.
Build and run using DUB:
Build and run demo app using DUB:
git clone https://github.com/buggins/dlangui.git
cd dlangui
dub run dlangui:example1 --build=release
Run Tetris game example
dub run dlangui:tetris --build=release
To develop using Visual-D, download sources for dlabgui and dependencies into some directory:

View File

@ -281,6 +281,32 @@ class CupWidget : Widget {
}
}
bool rotate(int delta) {
int newOrientation = (_currentFigureOrientation + 4 + delta) & 3;
if (isPositionFree(_currentFigure, newOrientation, _currentFigureX, _currentFigureY)) {
if (_state == CupState.FallingFigure && !isPositionFree(_currentFigure, newOrientation, _currentFigureX, _currentFigureY - 1)) {
if (isPositionFreeBelow())
return false;
}
_currentFigureOrientation = newOrientation;
return true;
}
return false;
}
bool move(int deltaX) {
int newx = _currentFigureX + deltaX;
if (isPositionFree(_currentFigure, _currentFigureOrientation, newx, _currentFigureY)) {
if (_state == CupState.FallingFigure && !isPositionFree(_currentFigure, _currentFigureOrientation, newx, _currentFigureY - 1)) {
if (isPositionFreeBelow())
return false;
}
_currentFigureX = newx;
return true;
}
return false;
}
protected void onAnimationFinished() {
switch (_state) {
case CupState.NewFigure:
@ -288,7 +314,6 @@ class CupWidget : Widget {
setState(CupState.HangingFigure, 75);
break;
case CupState.FallingFigure:
// TODO
if (isPositionFreeBelow()) {
_currentFigureY--;
setState(CupState.HangingFigure, 75);
@ -300,7 +325,6 @@ class CupWidget : Widget {
}
break;
case CupState.HangingFigure:
// TODO
setState(CupState.FallingFigure, 25);
break;
case CupState.DestroyingRows: