Files
Tetris/src/mangavalk/tetris/GamePlay.java
T
2014-02-21 17:08:48 +01:00

1879 lines
81 KiB
Java

package mangavalk.tetris;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Handler;
import java.util.ArrayList;
import java.util.TimerTask;
public class GamePlay extends GameStateInterface
{
// GameState.
protected int GameState = GS_STOPPED;
public GamePlay(Activity activity)
{
super(activity);
}
// Methods.
@Override
public void DrawFrame(Canvas canvas) {
DrawGameSpace(canvas);
}
@Override
public void onPause()
{
mp.pause();
SetGameState(GS_PAUSED, false);
}
@Override
public void SendMove(float x, float y, boolean pointerUp) {
int moveX = (int)((x / Width) * 90);
int moveY = (int)((y / Height) * 160);
if (!pointerUp)
{
if (GameState != GS_GAMEOVER)
{
if (moveX >= 28 && moveX <= 55 && moveY >= 143 && moveY <= 155) // Start
{
if (GameState == GS_PLAYING)
onPause();
else
{
mp.start();
SetGameState(GS_PLAYING, false);
}
}
}
}
if (GameState == GS_PLAYING)
{
InputsGamePlaying(x, y, pointerUp);
}
if (GameState == GS_GAMEOVER)
{
StartGame();
}
}
@Override
public void SetGameState(int gameState, boolean isPostBack)
{
GameState = gameState;
switch(GameState)
{
case GS_RESUME:
{
Resume();
break;
}
}
if (!isPostBack)
canvasView.OnGameStateChanged(GameState);
}
// Set
@Override
public void SetCanvas(CanvasView _CanvasView)
{
canvasView = _CanvasView;
}
@Override
public void SetActivity(Activity _Activity)
{
activity = _Activity;
}
public void SetStartLevel(int StartLevel)
{
startLevel = StartLevel;
}
@Override
public void SetPayedVersion(boolean payedVersion)
{
PayedVersion = payedVersion;
}
// Get
@Override
public int GetGameState()
{
return GameState;
}
// Variabelen
// Block Array
int[][] blockArray = new int[][]{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
// Draw Array
int[][] drawArray = new int[][]{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
int[][][][] drawBlocks = new int[][][][]{
{
{
{0, 0, 0, 0},
{8, 9, 10, 11},
{0, 0, 0, 0},
{0, 0, 0, 0}
},
{
{0, 0, 12, 0},
{0, 0, 13, 0},
{0, 0, 14, 0},
{0, 0, 15, 0}
},
{
{0, 0, 0, 0},
{0, 0, 0, 0},
{8, 9, 10, 11},
{0, 0, 0, 0}
},
{
{0, 12, 0, 0},
{0, 13, 0, 0},
{0, 14, 0, 0},
{0, 15, 0, 0}
}
},
{
{
{7, 0, 0, 0},
{7, 7, 7, 0},
{0, 0, 0, 0},
{0, 0, 0, -1}
},
{
{0, 7, 7, 0},
{0, 7, 0, 0},
{0, 7, 0, 0},
{0, 0, 0, -1}
},
{
{0, 0, 0, 0},
{7, 7, 7, 0},
{0, 0, 7, 0},
{0, 0, 0, -1}
},
{
{0, 7, 0, 0},
{0, 7, 0, 0},
{7, 7, 0, 0},
{0, 0, 0, -1}
}
},
{
{
{0, 0, 6, 0},
{6, 6, 6, 0},
{0, 0, 0, 0},
{0, 0, 0, -1}
},
{
{0, 6, 0, 0},
{0, 6, 0, 0},
{0, 6, 6, 0},
{0, 0, 0, -1}
},
{
{0, 0, 0, 0},
{6, 6, 6, 0},
{6, 0, 0, 0},
{0, 0, 0, -1}
},
{
{6, 6, 0, 0},
{0, 6, 0, 0},
{0, 6, 0, 0},
{0, 0, 0, -1}
}
},
{
{
{0, 1, 1, 0},
{0, 1, 1, 0},
{0, 0, 0, 0},
{0, 0, 0, -1}
},
{
{0, 1, 1, 0},
{0, 1, 1, 0},
{0, 0, 0, 0},
{0, 0, 0, -1}
},
{
{0, 1, 1, 0},
{0, 1, 1, 0},
{0, 0, 0, 0},
{0, 0, 0, -1}
},
{
{0, 1, 1, 0},
{0, 1, 1, 0},
{0, 0, 0, 0},
{0, 0, 0, -1}
}
},
{
{
{0, 3, 3, 0},
{3, 3, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, -1}
},
{
{0, 3, 0, 0},
{0, 3, 3, 0},
{0, 0, 3, 0},
{0, 0, 0, -1}
},
{
{0, 0, 0, 0},
{0, 3, 3, 0},
{3, 3, 0, 0},
{0, 0, 0, -1}
},
{
{3, 0, 0, 0},
{3, 3, 0, 0},
{0, 3, 0, 0},
{0, 0, 0, -1}
}
},
{
{
{0, 2, 0, 0},
{2, 2, 2, 0},
{0, 0, 0, 0},
{0, 0, 0, -1}
},
{
{0, 2, 0, 0},
{0, 2, 2, 0},
{0, 2, 0, 0},
{0, 0, 0, -1}
},
{
{0, 0, 0, 0},
{2, 2, 2, 0},
{0, 2, 0, 0},
{0, 0, 0, -1}
},
{
{0, 2, 0, 0},
{2, 2, 0, 0},
{0, 2, 0, 0},
{0, 0, 0, -1}
}
},
{
{
{5, 5, 0, 0},
{0, 5, 5, 0},
{0, 0, 0, 0},
{0, 0, 0, -1}
},
{
{0, 0, 5, 0},
{0, 5, 5, 0},
{0, 5, 0, 0},
{0, 0, 0, -1}
},
{
{0, 0, 0, 0},
{5, 5, 0, 0},
{0, 5, 5, 0},
{0, 0, 0, -1}
},
{
{0, 5, 0, 0},
{5, 5, 0, 0},
{5, 0, 0, 0},
{0, 0, 0, -1}
}
}
};
int[] LevelSpeed = { 53, 49, 45, 41, 37, 33, 28, 22, 17, 11, 10, 9, 8, 7, 6, 6, 5, 5, 4, 4, 3};
// Parameters.
int GameSpaceLeft = 4;
int GameSpaceTop = 0;
int GameSpaceRight = 53;
int GameSpaceBottom = 115;
// Tetrmino.
int CurrentBlock = 0;
int CurrentBlockPossition = 0;
int NewBlock = 0;
int NewBlockPossition = 0;
// Sprites.
Bitmap bitmapl1, bitmapl2, bitmapt, bitmapb, bitmaps, bitmapz, bitmapi1, bitmapi2, bitmapi3, bitmapi4,
bitmapi1r, bitmapi2r, bitmapi3r, bitmapi4r, bitmapblockline, bitmapscore, bitmapcontroller, bitmapgameover;
Bitmap Font0, Font1, Font2, Font3, Font4, Font5, Font6, Font7, Font8, Font9;
// Audio.
MediaPlayer mp;
// Score.
int startLevel = 0;
int level = 0;
int lines = 0;
int score = 0;
// Add Settings.
boolean PayedVersion;
// Timer.
TimerTask MoveEvent = new TimerTask() {
@Override
public void run() {
GoDown();
}
};
private Handler handler = new Handler();
private Runnable runnable = new Runnable() {
@Override
public void run() {
level = ( (startLevel + lines)<=200 ? startLevel + (lines / 10) : 20 );
int newSpeed = (int)((1000 / 59.73) * LevelSpeed[level]);
handler.postDelayed(this, newSpeed);
GoDown();
}
};
// Inputs.
int OldInputTime=0;
// Methods.
private void StartGame()
{
// Clear.
for ( int i=0; i<blockArray.length; i++)
{
for ( int i2=0; i2<blockArray[i].length; i2++)
{
blockArray[i][i2] = 0;
}
}
for ( int i=0; i<drawArray.length; i++)
{
for ( int i2=0; i2<drawArray[i].length; i2++)
{
drawArray[i][i2] = 0;
}
}
// Initlialize.
level = 0;
lines = 0;
score = 0;
CheckTetriminoSpawnArray();
NewBlock = Tetrimino.get(0);
Tetrimino.remove(0);
NewBlockPossition = 0;
SpawnBlock();
// Audio
mp.setLooping(true);
mp.start();
SetGameState(GS_PLAYING, false);
handler.removeCallbacksAndMessages(null);
handler.postDelayed(runnable, 100);
}
// TODO game state
@Override
public void Load()
{
// Load Bitmap's.
LoadSprites();
LoadFont();
// Initlialize.
// Audio
mp = MediaPlayer.create(activity, R.raw.tetris_a);
}
@Override
public void Start()
{
StartGame();
}
private void LoadSprites()
{
bitmapl1 = BitmapFactory.decodeResource(r,
R.drawable.sprite_l1);
bitmapl1 = Bitmap.createScaledBitmap(bitmapl1,
(int)GetRealPixelSize(DIP_W, dpWidth, 0.1f + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight))),
(int)GetRealPixelSize(DIP_H, dpHeight, 0.1f + (map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom))), false);
bitmapl2 = BitmapFactory.decodeResource(r,
R.drawable.sprite_l2);
bitmapl2 = Bitmap.createScaledBitmap(bitmapl2,
(int)GetRealPixelSize(DIP_W, dpWidth, 0.1f + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight))),
(int)GetRealPixelSize(DIP_H, dpHeight, 0.1f + (map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom))), false);
bitmapt = BitmapFactory.decodeResource(r,
R.drawable.sprite_t);
bitmapt = Bitmap.createScaledBitmap(bitmapt,
(int)GetRealPixelSize(DIP_W, dpWidth, 0.1f + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight))),
(int)GetRealPixelSize(DIP_H, dpHeight, 0.1f + (map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom))), false);
bitmapb = BitmapFactory.decodeResource(r,
R.drawable.sprite_b);
bitmapb = Bitmap.createScaledBitmap(bitmapb,
(int)GetRealPixelSize(DIP_W, dpWidth, 0.1f + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight))),
(int)GetRealPixelSize(DIP_H, dpHeight, 0.1f + (map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom))), false);
bitmaps = BitmapFactory.decodeResource(r,
R.drawable.sprite_s);
bitmaps= Bitmap.createScaledBitmap(bitmaps,
(int)GetRealPixelSize(DIP_W, dpWidth, 0.1f + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight))),
(int)GetRealPixelSize(DIP_H, dpHeight, 0.1f + (map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom))), false);
bitmapz = BitmapFactory.decodeResource(r,
R.drawable.sprite_z);
bitmapz = Bitmap.createScaledBitmap(bitmapz,
(int)GetRealPixelSize(DIP_W, dpWidth, 0.1f + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight))),
(int)GetRealPixelSize(DIP_H, dpHeight, 0.1f + (map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom))), false);
bitmapi1 = BitmapFactory.decodeResource(r,
R.drawable.sprite_i1);
bitmapi1 = Bitmap.createScaledBitmap(bitmapi1,
(int)GetRealPixelSize(DIP_W, dpWidth, 0.1f + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight))),
(int)GetRealPixelSize(DIP_H, dpHeight, 0.1f + (map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom))), false);
bitmapi2 = BitmapFactory.decodeResource(r,
R.drawable.sprite_i2);
bitmapi2 = Bitmap.createScaledBitmap(bitmapi2,
(int)GetRealPixelSize(DIP_W, dpWidth, 0.1f + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight))),
(int)GetRealPixelSize(DIP_H, dpHeight, 0.1f + (map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom))), false);
bitmapi3 = BitmapFactory.decodeResource(r,
R.drawable.sprite_i3);
bitmapi3 = Bitmap.createScaledBitmap(bitmapi3,
(int)GetRealPixelSize(DIP_W, dpWidth, 0.1f + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight))),
(int)GetRealPixelSize(DIP_H, dpHeight, 0.1f + (map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom))), false);
bitmapi4 = BitmapFactory.decodeResource(r,
R.drawable.sprite_i4);
bitmapi4 = Bitmap.createScaledBitmap(bitmapi4,
(int)GetRealPixelSize(DIP_W, dpWidth, 0.1f + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight))),
(int)GetRealPixelSize(DIP_H, dpHeight, 0.1f + (map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom))), false);
bitmapi1r = BitmapFactory.decodeResource(r,
R.drawable.sprite_i1r);
bitmapi1r = Bitmap.createScaledBitmap(bitmapi1r,
(int)GetRealPixelSize(DIP_W, dpWidth, 0.1f + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight))),
(int)GetRealPixelSize(DIP_H, dpHeight, 0.1f + (map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom))), false);
bitmapi2r = BitmapFactory.decodeResource(r,
R.drawable.sprite_i2r);
bitmapi2r = Bitmap.createScaledBitmap(bitmapi2r,
(int)GetRealPixelSize(DIP_W, dpWidth, 0.1f + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight))),
(int)GetRealPixelSize(DIP_H, dpHeight, 0.1f + (map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom))), false);
bitmapi3r = BitmapFactory.decodeResource(r,
R.drawable.sprite_i3r);
bitmapi3r = Bitmap.createScaledBitmap(bitmapi3r,
(int)GetRealPixelSize(DIP_W, dpWidth, 0.1f + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight))),
(int)GetRealPixelSize(DIP_H, dpHeight, 0.1f + (map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom))), false);
bitmapi4r = BitmapFactory.decodeResource(r,
R.drawable.sprite_i4r);
bitmapi4r = Bitmap.createScaledBitmap(bitmapi4r,
(int)GetRealPixelSize(DIP_W, dpWidth, 0.1f + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight))),
(int)GetRealPixelSize(DIP_H, dpHeight, 0.1f + (map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom))), false);
bitmapblockline = BitmapFactory.decodeResource(r,
R.drawable.sprite_blockline);
bitmapblockline = Bitmap.createScaledBitmap(bitmapblockline,
(int)GetRealPixelSize(DIP_W, dpWidth, 4),
(int)GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom-GameSpaceTop), false);
if (PayedVersion)
{
bitmapscore = BitmapFactory.decodeResource(r,
R.drawable.sprite_score);
}
else
{
bitmapscore = BitmapFactory.decodeResource(r,
R.drawable.sprite_freeversion);
}
bitmapscore = Bitmap.createScaledBitmap(bitmapscore,
(int)GetRealPixelSize(DIP_W, dpWidth, 90-GameSpaceRight-4),
(int)GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom-GameSpaceTop), false);
bitmapcontroller = BitmapFactory.decodeResource(r,
R.drawable.sprite_controler);
bitmapcontroller = Bitmap.createScaledBitmap(bitmapcontroller,
(int)GetRealPixelSize(DIP_W, dpWidth, 90),
(int)GetRealPixelSize(DIP_H, dpHeight, (160 - GameSpaceBottom)), false);
bitmapgameover = BitmapFactory.decodeResource(r,
R.drawable.sprite_gameover);
bitmapgameover = Bitmap.createScaledBitmap(bitmapgameover,
(int)GetRealPixelSize(DIP_W, dpWidth, (GameSpaceRight - GameSpaceLeft)),
(int)GetRealPixelSize(DIP_H, dpHeight, (GameSpaceBottom - GameSpaceTop)), false);
}
private void LoadFont()
{
Font0 = BitmapFactory.decodeResource(r,
R.drawable.f0);
Font0 = Bitmap.createScaledBitmap(Font0,
(int)GetRealPixelSize(DIP_W, dpWidth, 5),
(int)GetRealPixelSize(DIP_H, dpHeight, 6), false);
Font1 = BitmapFactory.decodeResource(r,
R.drawable.f1);
Font1 = Bitmap.createScaledBitmap(Font1,
(int)GetRealPixelSize(DIP_W, dpWidth, 5),
(int)GetRealPixelSize(DIP_H, dpHeight, 6), false);
Font2 = BitmapFactory.decodeResource(r,
R.drawable.f2);
Font2 = Bitmap.createScaledBitmap(Font2,
(int)GetRealPixelSize(DIP_W, dpWidth, 5),
(int)GetRealPixelSize(DIP_H, dpHeight, 6), false);
Font3 = BitmapFactory.decodeResource(r,
R.drawable.f3);
Font3 = Bitmap.createScaledBitmap(Font3,
(int)GetRealPixelSize(DIP_W, dpWidth, 5),
(int)GetRealPixelSize(DIP_H, dpHeight, 6), false);
Font4 = BitmapFactory.decodeResource(r,
R.drawable.f4);
Font4 = Bitmap.createScaledBitmap(Font4,
(int)GetRealPixelSize(DIP_W, dpWidth, 5),
(int)GetRealPixelSize(DIP_H, dpHeight, 6), false);
Font5 = BitmapFactory.decodeResource(r,
R.drawable.f5);
Font5 = Bitmap.createScaledBitmap(Font5,
(int)GetRealPixelSize(DIP_W, dpWidth, 5),
(int)GetRealPixelSize(DIP_H, dpHeight, 6), false);
Font6 = BitmapFactory.decodeResource(r,
R.drawable.f6);
Font6 = Bitmap.createScaledBitmap(Font6,
(int)GetRealPixelSize(DIP_W, dpWidth, 5),
(int)GetRealPixelSize(DIP_H, dpHeight, 6), false);
Font7 = BitmapFactory.decodeResource(r,
R.drawable.f7);
Font7 = Bitmap.createScaledBitmap(Font7,
(int)GetRealPixelSize(DIP_W, dpWidth, 5),
(int)GetRealPixelSize(DIP_H, dpHeight, 6), false);
Font8 = BitmapFactory.decodeResource(r,
R.drawable.f8);
Font8 = Bitmap.createScaledBitmap(Font8,
(int)GetRealPixelSize(DIP_W, dpWidth, 5),
(int)GetRealPixelSize(DIP_H, dpHeight, 6), false);
Font9 = BitmapFactory.decodeResource(r,
R.drawable.f9);
Font9 = Bitmap.createScaledBitmap(Font9,
(int)GetRealPixelSize(DIP_W, dpWidth, 5),
(int)GetRealPixelSize(DIP_H, dpHeight, 6), false);
}
private void DrawGameSpace(Canvas canvas)
{
// Sides
canvas.drawBitmap(bitmapblockline, GetRealPixelSize(DIP_W, dpWidth, 0), GetRealPixelSize(DIP_H, dpHeight, GameSpaceTop), null);
canvas.drawBitmap(bitmapblockline, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight), GetRealPixelSize(DIP_H, dpHeight, GameSpaceTop), null);
canvas.drawBitmap(bitmapcontroller, GetRealPixelSize(DIP_W, dpWidth, 0), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom), null);
// Score
canvas.drawBitmap(bitmapscore, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4), GetRealPixelSize(DIP_H, dpHeight, GameSpaceTop), null);
if (PayedVersion)
{
DrawLines(canvas, lines);
DrawLevel(canvas, startLevel + level);
DrawScore(canvas, score);
// Next Coming Tetrimino.
ShowNextComingTetrimino(canvas);
}
for (int x=0; x<10; x++)
{
for (int y=0; y<18; y++)
{
switch (drawArray[y][x] + (blockArray[y][x] >= 0 ? blockArray[y][x] : 0))
{
case 0:
break;
case 1:
{
canvas.drawBitmap(bitmapb, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 10, GameSpaceLeft, GameSpaceRight)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 18, GameSpaceTop, GameSpaceBottom)), null);
break;
}
case 2:
{
canvas.drawBitmap(bitmapt, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 10, GameSpaceLeft, GameSpaceRight)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 18, GameSpaceTop, GameSpaceBottom)), null);
break;
}
case 3:
{
canvas.drawBitmap(bitmapz, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 10, GameSpaceLeft, GameSpaceRight)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 18, GameSpaceTop, GameSpaceBottom)), null);
break;
}
case 5:
{
canvas.drawBitmap(bitmaps, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 10, GameSpaceLeft, GameSpaceRight)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 18, GameSpaceTop, GameSpaceBottom)), null);
break;
}
case 6:
{
canvas.drawBitmap(bitmapl2, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 10, GameSpaceLeft, GameSpaceRight)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 18, GameSpaceTop, GameSpaceBottom)), null);
break;
}
case 7:
{
canvas.drawBitmap(bitmapl1, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 10, GameSpaceLeft, GameSpaceRight)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 18, GameSpaceTop, GameSpaceBottom)), null);
break;
}
case 8:
{
canvas.drawBitmap(bitmapi1, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 10, GameSpaceLeft, GameSpaceRight)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 18, GameSpaceTop, GameSpaceBottom)), null);
break;
}
case 9:
{
canvas.drawBitmap(bitmapi2, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 10, GameSpaceLeft, GameSpaceRight)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 18, GameSpaceTop, GameSpaceBottom)), null);
break;
}
case 10:
{
canvas.drawBitmap(bitmapi3, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 10, GameSpaceLeft, GameSpaceRight)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 18, GameSpaceTop, GameSpaceBottom)), null);
break;
}
case 11:
{
canvas.drawBitmap(bitmapi4, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 10, GameSpaceLeft, GameSpaceRight)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 18, GameSpaceTop, GameSpaceBottom)), null);
break;
}
case 12: // Rotated
{
canvas.drawBitmap(bitmapi1r, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 10, GameSpaceLeft, GameSpaceRight)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 18, GameSpaceTop, GameSpaceBottom)), null);
break;
}
case 13:
{
canvas.drawBitmap(bitmapi2r, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 10, GameSpaceLeft, GameSpaceRight)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 18, GameSpaceTop, GameSpaceBottom)), null);
break;
}
case 14:
{
canvas.drawBitmap(bitmapi3r, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 10, GameSpaceLeft, GameSpaceRight)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 18, GameSpaceTop, GameSpaceBottom)), null);
break;
}
case 15:
{
canvas.drawBitmap(bitmapi4r, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 10, GameSpaceLeft, GameSpaceRight)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 18, GameSpaceTop, GameSpaceBottom)), null);
break;
}
default:
{
Rect(canvas, map(y, 0, 18, GameSpaceTop, GameSpaceBottom), map(y+1, 0, 18, GameSpaceTop, GameSpaceBottom),
map(x, 0, 10, GameSpaceLeft, GameSpaceRight), map(x+1, 0, 10, GameSpaceLeft, GameSpaceRight),
Color.RED);
break;
}
}
}
}
if (GameState == GS_GAMEOVER)
{
canvas.drawBitmap(bitmapgameover, (int)GetRealPixelSize(DIP_W, dpWidth, GameSpaceLeft),
(int)GetRealPixelSize(DIP_H, dpHeight, GameSpaceTop), null);
}
}
private void ShowNextComingTetrimino(Canvas canvas)
{
int top = 32;
for (int x=0; x<4; x++)
{
for (int y=0; y<4; y++)
{
switch(drawBlocks[NewBlock][NewBlockPossition][y][x])
{
case 1:
canvas.drawBitmap(bitmapb, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 4, GameSpaceRight + 4 + 9, GameSpaceRight + 4 + 9 + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight)) * 4)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 4, (GameSpaceBottom - top), (GameSpaceBottom - top) + ((map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom)) * 4))), null);
break;
case 2:
canvas.drawBitmap(bitmapt, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 4, GameSpaceRight + 4 + 9, GameSpaceRight + 4 + 9 + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight)) * 4)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 4, (GameSpaceBottom - top), (GameSpaceBottom - top) + ((map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom)) * 4))), null);
break;
case 3:
canvas.drawBitmap(bitmapz, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 4, GameSpaceRight + 4 + 9, GameSpaceRight + 4 + 9 + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight)) * 4)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 4, (GameSpaceBottom - top), (GameSpaceBottom - top) + ((map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom)) * 4))), null);
break;
case 5:
canvas.drawBitmap(bitmaps, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 4, GameSpaceRight + 4 + 9, GameSpaceRight + 4 + 9 + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight)) * 4)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 4, (GameSpaceBottom - top), (GameSpaceBottom - top) + ((map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom)) * 4))), null);
break;
case 6:
canvas.drawBitmap(bitmapl2, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 4, GameSpaceRight + 4 + 9, GameSpaceRight + 4 + 9 + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight)) * 4)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 4, (GameSpaceBottom - top), (GameSpaceBottom - top) + ((map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom)) * 4))), null);
break;
case 7:
canvas.drawBitmap(bitmapl1, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 4, GameSpaceRight + 4 + 9, GameSpaceRight + 4 + 9 + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight)) * 4)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 4, (GameSpaceBottom - top), (GameSpaceBottom - top) + ((map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom)) * 4))), null);
break;
case 8:
canvas.drawBitmap(bitmapi1, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 4, GameSpaceRight + 4 + 9, GameSpaceRight + 4 + 9 + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight)) * 4)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 4, (GameSpaceBottom - top), (GameSpaceBottom - top) + ((map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom)) * 4))), null);
break;
case 9:
canvas.drawBitmap(bitmapi2, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 4, GameSpaceRight + 4 + 9, GameSpaceRight + 4 + 9 + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight)) * 4)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 4, (GameSpaceBottom - top), (GameSpaceBottom - top) + ((map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom)) * 4))), null);
break;
case 10:
canvas.drawBitmap(bitmapi3, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 4, GameSpaceRight + 4 + 9, GameSpaceRight + 4 + 9 + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight)) * 4)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 4, (GameSpaceBottom - top), (GameSpaceBottom - top) + ((map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom)) * 4))), null);
break;
case 11:
canvas.drawBitmap(bitmapi4, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 4, GameSpaceRight + 4 + 9, GameSpaceRight + 4 + 9 + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight)) * 4)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 4, (GameSpaceBottom - top), (GameSpaceBottom - top) + ((map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom)) * 4))), null);
break;
case 12:
canvas.drawBitmap(bitmapi1r, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 4, GameSpaceRight + 4 + 9, GameSpaceRight + 4 + 9 + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight)) * 4)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 4, (GameSpaceBottom - top), (GameSpaceBottom - top) + ((map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom)) * 4))), null);
break;
case 13:
canvas.drawBitmap(bitmapi2r, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 4, GameSpaceRight + 4 + 9, GameSpaceRight + 4 + 9 + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight)) * 4)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 4, (GameSpaceBottom - top), (GameSpaceBottom - top) + ((map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom)) * 4))), null);
break;
case 14:
canvas.drawBitmap(bitmapi3r, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 4, GameSpaceRight + 4 + 9, GameSpaceRight + 4 + 9 + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight)) * 4)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 4, (GameSpaceBottom - top), (GameSpaceBottom - top) + ((map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom)) * 4))), null);
break;
case 15:
canvas.drawBitmap(bitmapi4r, (int)GetRealPixelSize(DIP_W, dpWidth, map(x, 0, 4, GameSpaceRight + 4 + 9, GameSpaceRight + 4 + 9 + (map(1, 0, 10, GameSpaceLeft, GameSpaceRight) - map(0, 0, 10, GameSpaceLeft, GameSpaceRight)) * 4)),
(int)GetRealPixelSize(DIP_H, dpHeight, map(y, 0, 4, (GameSpaceBottom - top), (GameSpaceBottom - top) + ((map(1, 0, 18, GameSpaceTop, GameSpaceBottom) - map(0, 0, 18, GameSpaceTop, GameSpaceBottom)) * 4))), null);
break;
}
}
}
}
private void DrawScore(Canvas canvas, int Score)
{
int height = 104-8;
switch ((Score / 100000) % 10)
{
case 0:
canvas.drawBitmap(Font0, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6-5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 1:
canvas.drawBitmap(Font1, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6-5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 2:
canvas.drawBitmap(Font2, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6-5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 3:
canvas.drawBitmap(Font3, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6-5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 4:
canvas.drawBitmap(Font4, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6-5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 5:
canvas.drawBitmap(Font5, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6-5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 6:
canvas.drawBitmap(Font6, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6-5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 7:
canvas.drawBitmap(Font7, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6-5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 8:
canvas.drawBitmap(Font8, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6-5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 9:
canvas.drawBitmap(Font9, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6-5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
}
switch ((Score / 10000) % 10)
{
case 0:
canvas.drawBitmap(Font0, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 1:
canvas.drawBitmap(Font1, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 2:
canvas.drawBitmap(Font2, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 3:
canvas.drawBitmap(Font3, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 4:
canvas.drawBitmap(Font4, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 5:
canvas.drawBitmap(Font5, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 6:
canvas.drawBitmap(Font6, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 7:
canvas.drawBitmap(Font7, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 8:
canvas.drawBitmap(Font8, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 9:
canvas.drawBitmap(Font9, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
}
switch ((Score / 1000) % 10)
{
case 0:
canvas.drawBitmap(Font0, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 1:
canvas.drawBitmap(Font1, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 2:
canvas.drawBitmap(Font2, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 3:
canvas.drawBitmap(Font3, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 4:
canvas.drawBitmap(Font4, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 5:
canvas.drawBitmap(Font5, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 6:
canvas.drawBitmap(Font6, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 7:
canvas.drawBitmap(Font7, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 8:
canvas.drawBitmap(Font8, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 9:
canvas.drawBitmap(Font9, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
}
switch ((Score / 100) % 10)
{
case 0:
canvas.drawBitmap(Font0, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 1:
canvas.drawBitmap(Font1, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 2:
canvas.drawBitmap(Font2, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 3:
canvas.drawBitmap(Font3, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 4:
canvas.drawBitmap(Font4, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 5:
canvas.drawBitmap(Font5, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 6:
canvas.drawBitmap(Font6, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 7:
canvas.drawBitmap(Font7, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 8:
canvas.drawBitmap(Font8, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 9:
canvas.drawBitmap(Font9, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
}
switch ((Score / 10) % 10)
{
case 0:
canvas.drawBitmap(Font0, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 1:
canvas.drawBitmap(Font1, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 2:
canvas.drawBitmap(Font2, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 3:
canvas.drawBitmap(Font3, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 4:
canvas.drawBitmap(Font4, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 5:
canvas.drawBitmap(Font5, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 6:
canvas.drawBitmap(Font6, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 7:
canvas.drawBitmap(Font7, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 8:
canvas.drawBitmap(Font8, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 9:
canvas.drawBitmap(Font9, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
}
switch (Score % 10)
{
case 0:
canvas.drawBitmap(Font0, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 1:
canvas.drawBitmap(Font1, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 2:
canvas.drawBitmap(Font2, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 3:
canvas.drawBitmap(Font3, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 4:
canvas.drawBitmap(Font4, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 5:
canvas.drawBitmap(Font5, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 6:
canvas.drawBitmap(Font6, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 7:
canvas.drawBitmap(Font7, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 8:
canvas.drawBitmap(Font8, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 9:
canvas.drawBitmap(Font9, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
}
}
private void DrawLines(Canvas canvas, int Lines)
{
int height = 55-4;
switch ((Lines / 1000) % 10)
{
case 0:
canvas.drawBitmap(Font0, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 1:
canvas.drawBitmap(Font1, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 2:
canvas.drawBitmap(Font2, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 3:
canvas.drawBitmap(Font3, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 4:
canvas.drawBitmap(Font4, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 5:
canvas.drawBitmap(Font5, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 6:
canvas.drawBitmap(Font6, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 7:
canvas.drawBitmap(Font7, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 8:
canvas.drawBitmap(Font8, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 9:
canvas.drawBitmap(Font9, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
}
switch ((Lines / 100) % 10)
{
case 0:
canvas.drawBitmap(Font0, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 1:
canvas.drawBitmap(Font1, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 2:
canvas.drawBitmap(Font2, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 3:
canvas.drawBitmap(Font3, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 4:
canvas.drawBitmap(Font4, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 5:
canvas.drawBitmap(Font5, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 6:
canvas.drawBitmap(Font6, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 7:
canvas.drawBitmap(Font7, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 8:
canvas.drawBitmap(Font8, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 9:
canvas.drawBitmap(Font9, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
}
switch ((Lines / 10) % 10)
{
case 0:
canvas.drawBitmap(Font0, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 1:
canvas.drawBitmap(Font1, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 2:
canvas.drawBitmap(Font2, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 3:
canvas.drawBitmap(Font3, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 4:
canvas.drawBitmap(Font4, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 5:
canvas.drawBitmap(Font5, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 6:
canvas.drawBitmap(Font6, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 7:
canvas.drawBitmap(Font7, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 8:
canvas.drawBitmap(Font8, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 9:
canvas.drawBitmap(Font9, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
}
switch (Lines % 10)
{
case 0:
canvas.drawBitmap(Font0, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 1:
canvas.drawBitmap(Font1, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 2:
canvas.drawBitmap(Font2, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 3:
canvas.drawBitmap(Font3, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 4:
canvas.drawBitmap(Font4, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 5:
canvas.drawBitmap(Font5, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 6:
canvas.drawBitmap(Font6, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 7:
canvas.drawBitmap(Font7, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 8:
canvas.drawBitmap(Font8, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 9:
canvas.drawBitmap(Font9, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
}
}
private void DrawLevel(Canvas canvas, int Level)
{
int height = 76-6;
switch ((Level / 10) % 10)
{
case 0:
canvas.drawBitmap(Font0, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 1:
canvas.drawBitmap(Font1, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 2:
canvas.drawBitmap(Font2, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 3:
canvas.drawBitmap(Font3, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 4:
canvas.drawBitmap(Font4, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 5:
canvas.drawBitmap(Font5, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 6:
canvas.drawBitmap(Font6, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 7:
canvas.drawBitmap(Font7, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 8:
canvas.drawBitmap(Font8, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 9:
canvas.drawBitmap(Font9, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
}
switch (Level % 10)
{
case 0:
canvas.drawBitmap(Font0, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 1:
canvas.drawBitmap(Font1, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 2:
canvas.drawBitmap(Font2, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 3:
canvas.drawBitmap(Font3, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 4:
canvas.drawBitmap(Font4, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 5:
canvas.drawBitmap(Font5, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 6:
canvas.drawBitmap(Font6, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 7:
canvas.drawBitmap(Font7, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 8:
canvas.drawBitmap(Font8, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
case 9:
canvas.drawBitmap(Font9, GetRealPixelSize(DIP_W, dpWidth, GameSpaceRight+4+6+5+5+5), GetRealPixelSize(DIP_H, dpHeight, GameSpaceBottom - height), null);
break;
}
}
// Input
public void sendMove(float x, float y, boolean Released)
{
int moveX = (int)((x / Width) * 90);
int moveY = (int)((y / Height) * 160);
if (!Released)
{
if (GameState != GS_GAMEOVER)
{
if (moveX >= 28 && moveX <= 55 && moveY >= 143 && moveY <= 155) // Start
{
if (GameState == GS_PLAYING)
onPause();
else
{
SetGameState(GS_RESUME, false);
}
}
}
}
if (GameState == GS_PLAYING)
{
InputsGamePlaying(x, y, Released);
}
if (GameState == GS_GAMEOVER)
{
StartGame();
}
}
private void Resume()
{
mp.start();
SetGameState(GS_PLAYING, false);
canvasView.postInvalidate();
}
private void InputsGamePlaying(float x, float y, boolean Released)
{
int moveX = (int)((x / Width) * 90);
int moveY = (int)((y / Height) * 160);
if (!Released)
{
if (moveX >= 1 && moveX <= 11 && moveY >= 122 && moveY <= 133) // Left
{
if(CanBlockGoLeft())
{
MoveBlockLeft();
canvasView.postInvalidate();
}
}
else if (moveX >= 55 && moveX <= 70 && moveY >= 122 && moveY <= 137) // Rotate Left
{
RotateBlockLeft();
canvasView.postInvalidate();
}
else if (moveX >= 74 && moveX <= 88 && moveY >= 115 && moveY <= 137) // Rotate Right
{
RotateBlockRight();
canvasView.postInvalidate();
}
else if (moveX >= 21 && moveX <= 33 && moveY >= 122 && moveY <= 133) // Right
{
if(CanBlockGoRight())
{
MoveBlockRight();
canvasView.postInvalidate();
}
}
}
if (moveX >= 11 && moveX <= 21 && moveY >= 133 && moveY <= 144) // Down
{
if (!Released)
{
// Soft Drop
if (CanBlockGoDown())
{
MoveBlockDown();
canvasView.postInvalidate();
}
OldInputTime = (int)System.currentTimeMillis();
}
else
{
int CurrentTime = (int)System.currentTimeMillis();
if ((CurrentTime - OldInputTime) >= 250)
{
// Hard Drop
while (CanBlockGoDown())
{
MoveBlockDown();
}
canvasView.postInvalidate();
}
}
}
}
// Game Logic
private void GoDown()
{
if (GameState == GS_PLAYING)
{
/// Can the Block go down?
if (CanBlockGoDown())
{
MoveBlockDown();
canvasView.postInvalidate();
}
else
{
ParseBlockArrayToDrawArray();
CheckForCompletedRows();
//spawn new block
if (!SpawnBlock())
{
SetGameState(GS_GAMEOVER, false);
mp.stop();
canvasView.postInvalidate();
}
else
{
canvasView.postInvalidate();
}
}
}
}
private boolean CanBlockGoDown()
{
//blockArray
for (int x=0; x<10; x++)
{
for (int y=0; y<18; y++)
{
if (blockArray[y][x] != 0)
{
if (y + 1 == 18)
return false;
else if (drawArray[y+1][x] != 0)
return false;
}
}
}
return true;
}
private boolean CanBlockGoLeft()
{
//blockArray
for (int y=0; y<18; y++)
{
for (int x=1; x<10; x++)
{
if (blockArray[y][x] >= 1)
{
if (drawArray[y][x-1] != 0)
return false;
}
if (blockArray[y][0] >= 1)
return false;
}
}
return true;
}
private boolean CanBlockGoRight()
{
//blockArray
for (int y=0; y<18; y++)
{
for (int x=0; x<9; x++)
{
if (blockArray[y][x] >= 1)
{
if (drawArray[y][x+1] != 0)
return false;
}
if (blockArray[y][9] >= 1)
return false;
}
}
return true;
}
private void MoveBlockDown()
{
for (int x=0; x<10; x++)
{
for (int y=17; y>0; y--)
{
blockArray[y][x] = blockArray[y-1][x];
blockArray[y-1][x] = 0;
}
}
}
private void MoveBlockLeft()
{
for (int y=0; y<18; y++)
{
for (int x=1; x<10; x++)
{
blockArray[y][x-1] = blockArray[y][x];
blockArray[y][x] = 0;
}
}
}
private void MoveBlockRight()
{
for (int y=0; y<18; y++)
{
for (int x=8; x>=0; x--)
{
blockArray[y][x+1] = blockArray[y][x];
blockArray[y][x] = 0;
}
}
}
private void RotateBlockRight()
{
if (drawBlocks[CurrentBlock][CurrentBlockPossition][3][3] != -1)
{
for (int y=0; y<18-3; y++)
{
for (int x=0; x<10-3; x++)
{
boolean foundPossition = true;
for (int i=0; i<4; i++)
{
for (int i2=0; i2<4; i2++)
{
if (!(blockArray[y+i][x+i2] == drawBlocks[CurrentBlock][CurrentBlockPossition][i][i2]))
{
foundPossition = false;
}
}
}
if (foundPossition)
{
if (CurrentBlockPossition < 3)
CurrentBlockPossition++;
else
CurrentBlockPossition = 0;
}
// Test for collision !!!
boolean Collision = false;
for (int i=0; i<4; i++)
{
for (int i2=0; i2<4; i2++)
{
if (drawBlocks[CurrentBlock][CurrentBlockPossition][i][i2] >= 1)
{
if (drawArray[y+i][x+i2] != 0)
{
Collision = true;
}
}
}
}
if (!Collision)
{
if (foundPossition)
{
for (int i=0; i<4; i++)
{
for (int i2=0; i2<4; i2++)
{
blockArray[y+i][x+i2] = drawBlocks[CurrentBlock][CurrentBlockPossition][i][i2];
}
}
}
}
}
}
}
else
{
for (int y=0; y<18-2; y++)
{
for (int x=0; x<10-2; x++)
{
boolean foundPossition = true;
for (int i=0; i<3; i++)
{
for (int i2=0; i2<3; i2++)
{
if (!(blockArray[y+i][x+i2] == drawBlocks[CurrentBlock][CurrentBlockPossition][i][i2]))
{
foundPossition = false;
}
}
}
if (foundPossition)
{
if (CurrentBlockPossition < 3)
CurrentBlockPossition++;
else
CurrentBlockPossition = 0;
}
// Test for collision !!!
boolean Collision = false;
for (int i=0; i<3; i++)
{
for (int i2=0; i2<3; i2++)
{
if (drawBlocks[CurrentBlock][CurrentBlockPossition][i][i2] >= 1)
{
if (drawArray[y+i][x+i2] != 0)
{
Collision = true;
}
}
}
}
if (!Collision)
{
if (foundPossition)
{
for (int i=0; i<3; i++)
{
for (int i2=0; i2<3; i2++)
{
blockArray[y+i][x+i2] = drawBlocks[CurrentBlock][CurrentBlockPossition][i][i2];
}
}
}
}
}
}
}
}
private void RotateBlockLeft()
{
if (drawBlocks[CurrentBlock][CurrentBlockPossition][3][3] != -1)
{
for (int y=0; y<18-3; y++)
{
for (int x=0; x<10-3; x++)
{
boolean foundPossition = true;
for (int i=0; i<4; i++)
{
for (int i2=0; i2<4; i2++)
{
if (!(blockArray[y+i][x+i2] == drawBlocks[CurrentBlock][CurrentBlockPossition][i][i2]))
{
foundPossition = false;
}
}
}
// Test for collision !!!
boolean Collision = false;
if (foundPossition)
{
if (CurrentBlockPossition > 0)
CurrentBlockPossition--;
else
CurrentBlockPossition = 3;
}
for (int i=0; i<4; i++)
{
for (int i2=0; i2<4; i2++)
{
if (drawBlocks[CurrentBlock][CurrentBlockPossition][i][i2] != 0)
{
if (drawArray[y+i][x+i2] != 0)
{
Collision = true;
}
}
}
}
if (!Collision)
{
if (foundPossition)
{
for (int i=0; i<4; i++)
{
for (int i2=0; i2<4; i2++)
{
blockArray[y+i][x+i2] = drawBlocks[CurrentBlock][CurrentBlockPossition][i][i2];
}
}
}
}
}
}
}
else
{
for (int y=0; y<18-2; y++)
{
for (int x=0; x<10-2; x++)
{
boolean foundPossition = true;
for (int i=0; i<3; i++)
{
for (int i2=0; i2<3; i2++)
{
if (!(blockArray[y+i][x+i2] == drawBlocks[CurrentBlock][CurrentBlockPossition][i][i2]))
{
foundPossition = false;
}
}
}
// Test for collision !!!
boolean Collision = false;
if (foundPossition)
{
if (CurrentBlockPossition > 0)
CurrentBlockPossition--;
else
CurrentBlockPossition = 3;
}
for (int i=0; i<3; i++)
{
for (int i2=0; i2<3; i2++)
{
if (drawBlocks[CurrentBlock][CurrentBlockPossition][i][i2] != 0)
{
if (drawArray[y+i][x+i2] != 0)
{
Collision = true;
}
}
}
}
if (!Collision)
{
if (foundPossition)
{
for (int i=0; i<3; i++)
{
for (int i2=0; i2<3; i2++)
{
blockArray[y+i][x+i2] = drawBlocks[CurrentBlock][CurrentBlockPossition][i][i2];
}
}
}
}
}
}
}
}
private void ParseBlockArrayToDrawArray()
{
for (int x=0; x<10; x++)
{
for (int y=0; y<18; y++)
{
drawArray[y][x] += blockArray[y][x];
blockArray[y][x] = 0;
}
}
}
private void CheckForCompletedRows()
{
int LinesCleared = 0;
//drawArray
for (int y=17; y>1; y--)
{
boolean isComplete = true;
for (int x=0; x<10; x++)
{
if (drawArray[y][x] == 0)
isComplete = false;
}
if (isComplete)
{
for (int i=y; i>1; i--)
for (int x=0; x<10; x++)
{
drawArray[i][x] = drawArray[i-1][x];
}
LinesCleared++;
lines++;
level = ( (startLevel + lines)<=200 ? startLevel + (lines / 10) : 20 );
y++;
}
}
// Do Score here
switch (LinesCleared)
{
case 1:
score += 40 * ( level + 1 );
break;
case 2:
score += 100 * ( level + 1 );
break;
case 3:
score += 300 * ( level + 1 );
break;
case 4:
score += 1200 * ( level + 1 );
break;
}
}
ArrayList<Integer> Tetrimino;
private void CheckTetriminoSpawnArray()
{
// Pseudo random
if (Tetrimino == null || Tetrimino.size() <= 0)
{
Tetrimino = new ArrayList<Integer>();
do{
int newTetrimino = (int)(Math.random() * (7));
if (!Tetrimino.contains(newTetrimino))
Tetrimino.add(newTetrimino);
}while (Tetrimino.size() < 7);
}
}
private boolean SpawnBlock()
{
CheckTetriminoSpawnArray();
CurrentBlock = NewBlock;
CurrentBlockPossition = NewBlockPossition;
NewBlock = Tetrimino.get(0);
Tetrimino.remove(0);
NewBlockPossition = 0;
for (int x=0; x<4; x++)
{
for (int y=0; y<4; y++)
{
if (drawBlocks[CurrentBlock][CurrentBlockPossition][y][x] != 0)
if (drawArray[y][x+3] != 0)
return false;
}
}
for (int x=0; x<4; x++)
{
for (int y=0; y<4; y++)
{
if (drawBlocks[CurrentBlock][CurrentBlockPossition][y][x] >= 0)
blockArray[y][x+3] = drawBlocks[CurrentBlock][CurrentBlockPossition][y][x];
}
}
return true;
}
}