package mangavalk.tetris; import android.app.Activity; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.media.MediaPlayer; import android.os.Handler; import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.Display; import android.view.View; import java.util.ArrayList; import java.util.TimerTask; public class CanvasView extends View { // Variabelen Resources r; // Sizes float dpHeight; float dpWidth; float Height; float Width; // 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}; int GameSpaceLeft = 4; int GameSpaceTop = 0; int GameSpaceRight = 53; int GameSpaceBottom = 115;//125 int CurrentBlock = 0; int CurrentBlockPossition = 0; int NewBlock = 0; int NewBlockPossition = 0; boolean goingDown = false; boolean NextWillLock = false; 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; // Score. public int startLevel = 0; int level = 0; int lines = 0; int score = 0; // Game State. boolean GamePlaying = false; boolean GameOver = false; final int GS_STOPPED = 0; final int GS_LOADING = 1; final int GS_PLAYING = 2; final int GS_GAMEOVER = 3; final int GS_PAUSED = 4; int GameState = GS_STOPPED; // Add Settings. public 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(); } }; MediaPlayer mp; /// Init functions public CanvasView(Context context) { super(context); super.setBackgroundColor(Color.BLACK); SpawnBlock(); this.postInvalidate(); } public void SetActivity(Activity activity) { // Set Display Info. Display display = activity.getWindowManager().getDefaultDisplay(); DisplayMetrics outMetrics = new DisplayMetrics (); display.getMetrics(outMetrics); r = getResources(); float density = r.getDisplayMetrics().density; dpHeight = outMetrics.heightPixels / density; dpWidth = outMetrics.widthPixels / density; Height = outMetrics.heightPixels; Width = outMetrics.widthPixels; // Load Bitmap's. LoadSprites(); LoadFont(); // Initlialize. NewBlock = (int)(Math.random() * (7)); NewBlock = Tetrimino.get(0); Tetrimino.remove(0); NewBlockPossition = 0; // Audio mp = MediaPlayer.create(activity, R.raw.tetris_a); mp.setLooping(true); mp.start(); // Start Game. GamePlaying = true; GameState = GS_PLAYING; handler.removeCallbacksAndMessages(null); handler.postDelayed(runnable, 100); } 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); } /// Draw functions @Override protected void onDraw(Canvas canvas) { DrawGameSpace(canvas); } public void onPause() { mp.pause(); GamePlaying = false; GameState = GS_PAUSED; } public void onResume() { } 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 (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; } } int OldInputTime=0; /// 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 (!GameOver) { if (moveX >= 28 && moveX <= 55 && moveY >= 143 && moveY <= 155) // Menu { if (GameState == GS_PLAYING) onPause(); else { mp.start(); GamePlaying = true; GameState = GS_PLAYING; } } } } if (!goingDown) { if (GameState == GS_PLAYING) { if (!GameOver) { if (!Released) { if (moveX >= 1 && moveX <= 11 && moveY >= 122 && moveY <= 133) // Left { if(CanBlockGoLeft()) { MoveBlockLeft(); this.postInvalidate(); } } else if (moveX >= 55 && moveX <= 70 && moveY >= 122 && moveY <= 137) // Rotate Left { RotateBlockLeft(); this.postInvalidate(); } else if (moveX >= 74 && moveX <= 88 && moveY >= 115 && moveY <= 137) // Rotate Right { RotateBlockRight(); this.postInvalidate(); } else if (moveX >= 21 && moveX <= 33 && moveY >= 122 && moveY <= 133) // Right { if(CanBlockGoRight()) { MoveBlockRight(); this.postInvalidate(); } } } if (moveX >= 11 && moveX <= 21 && moveY >= 133 && moveY <= 144) // Down { if (!Released) { // Soft Drop if (CanBlockGoDown()) { MoveBlockDown(); this.postInvalidate(); } OldInputTime = (int)System.currentTimeMillis(); } else { int CurrentTime = (int)System.currentTimeMillis(); if ((CurrentTime - OldInputTime) >= 250) { // Hard Drop while (CanBlockGoDown()) { MoveBlockDown(); } this.postInvalidate(); } } } } } } } /// Game Logic private void GoDown() { if (GameState == GS_PLAYING) { if (!GameOver) { goingDown = true; /// Can the Block go down? if (CanBlockGoDown()) { MoveBlockDown(); this.postInvalidate(); } else { NextWillLock = false; ParseBlockArrayToDrawArray(); CheckForCompletedRows(); //spawn new block if (!SpawnBlock()) { // GameOver GameOver = true; GamePlaying = false; GameState = GS_GAMEOVER ; mp.stop(); this.postInvalidate(); } else { this.postInvalidate(); } } goingDown = false; } } } 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 Tetrimino; private boolean SpawnBlock() { // Pseudo random if (Tetrimino == null || Tetrimino.size() <= 0) { Tetrimino = new ArrayList(); do{ int newTetrimino = (int)(Math.random() * (7)); if (!Tetrimino.contains(newTetrimino)) Tetrimino.add(newTetrimino); }while (Tetrimino.size() < 7); } 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; } /// other logic private void Rect(Canvas canvas, float Top, float Bottom, float Left, float Right, int Color) { Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color); paint.setStyle(Style.FILL); canvas.drawRect( GetRealPixelSize(DIP_W, dpWidth, Left), GetRealPixelSize(DIP_H, dpHeight, Top), GetRealPixelSize(DIP_W, dpWidth, Right), GetRealPixelSize(DIP_H, dpHeight, Bottom), paint); } final static int DIP_H = 0; final static int DIP_W = 1; private float GetRealPixelSize(int wH, float dpWH, double DIP) { if (wH == DIP_H) return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float)(dpWH * ( DIP / 160 )), r.getDisplayMetrics()); else if (wH == DIP_W) return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float)(dpWH * ( DIP / 90 )), r.getDisplayMetrics()); else return 0; } float map(float x, float in_min, float in_max, float out_min, float out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } }