GameStage intergration and cleanup

This commit is contained in:
Administrator committed 2014-02-18 15:55:17 +01:00
1 parent e01836e91c
commit a303e6afc6
6 files changed
+46 -36

No files matched your search

BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+46 -36
View File
@@ -272,10 +272,6 @@ public class CanvasView extends View
int NewBlock = 0; int NewBlock = 0;
int NewBlockPossition = 0; int NewBlockPossition = 0;
boolean goingDown = false;
boolean NextWillLock = false;
Bitmap bitmapl1, bitmapl2, bitmapt, bitmapb, bitmaps, bitmapz, bitmapi1, bitmapi2, bitmapi3, bitmapi4, Bitmap bitmapl1, bitmapl2, bitmapt, bitmapb, bitmaps, bitmapz, bitmapi1, bitmapi2, bitmapi3, bitmapi4,
bitmapi1r, bitmapi2r, bitmapi3r, bitmapi4r, bitmapblockline, bitmapscore, bitmapcontroller, bitmapgameover; bitmapi1r, bitmapi2r, bitmapi3r, bitmapi4r, bitmapblockline, bitmapscore, bitmapcontroller, bitmapgameover;
@@ -284,14 +280,10 @@ public class CanvasView extends View
// Score. // Score.
public int startLevel = 0; public int startLevel = 0;
int level = 0; int level = 0;
int lines = 0; int lines = 0;
int score = 0; int score = 0;
// Game State. // Game State.
boolean GamePlaying = false;
boolean GameOver = false;
final int GS_STOPPED = 0; final int GS_STOPPED = 0;
final int GS_LOADING = 1; final int GS_LOADING = 1;
final int GS_PLAYING = 2; final int GS_PLAYING = 2;
@@ -355,28 +347,54 @@ public class CanvasView extends View
Width = outMetrics.widthPixels; Width = outMetrics.widthPixels;
// Load Bitmap's. // Load Bitmap's.
LoadSprites(); LoadSprites();
LoadFont(); LoadFont();
// Initlialize. // Initlialize.
NewBlock = (int)(Math.random() * (7)); // Audio
mp = MediaPlayer.create(activity, R.raw.tetris_a);
// Start Game.
StartGame();
}
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); NewBlock = Tetrimino.get(0);
Tetrimino.remove(0); Tetrimino.remove(0);
NewBlockPossition = 0; NewBlockPossition = 0;
SpawnBlock();
// Audio // Audio
mp = MediaPlayer.create(activity, R.raw.tetris_a);
mp.setLooping(true); mp.setLooping(true);
mp.start(); mp.start();
// Start Game.
GamePlaying = true;
GameState = GS_PLAYING; GameState = GS_PLAYING;
handler.removeCallbacksAndMessages(null); handler.removeCallbacksAndMessages(null);
@@ -605,7 +623,6 @@ public class CanvasView extends View
public void onPause() public void onPause()
{ {
mp.pause(); mp.pause();
GamePlaying = false;
GameState = GS_PAUSED; GameState = GS_PAUSED;
} }
@@ -741,7 +758,7 @@ public class CanvasView extends View
} }
} }
if (GameOver) if (GameState == GS_GAMEOVER)
{ {
canvas.drawBitmap(bitmapgameover, (int)GetRealPixelSize(DIP_W, dpWidth, GameSpaceLeft), canvas.drawBitmap(bitmapgameover, (int)GetRealPixelSize(DIP_W, dpWidth, GameSpaceLeft),
(int)GetRealPixelSize(DIP_H, dpHeight, GameSpaceTop), null); (int)GetRealPixelSize(DIP_H, dpHeight, GameSpaceTop), null);
@@ -1240,7 +1257,7 @@ public class CanvasView extends View
if (!Released) if (!Released)
{ {
if (!GameOver) if (GameState != GS_GAMEOVER)
{ {
if (moveX >= 28 && moveX <= 55 && moveY >= 143 && moveY <= 155) // Start if (moveX >= 28 && moveX <= 55 && moveY >= 143 && moveY <= 155) // Start
{ {
@@ -1249,19 +1266,20 @@ public class CanvasView extends View
else else
{ {
mp.start(); mp.start();
GamePlaying = true;
GameState = GS_PLAYING; GameState = GS_PLAYING;
} }
} }
} }
} }
if (!goingDown)
{
if (GameState == GS_PLAYING) if (GameState == GS_PLAYING)
{ {
InputsGamePlaying(x, y, Released); InputsGamePlaying(x, y, Released);
} }
if (GameState == GS_GAMEOVER)
{
StartGame();
} }
} }
@@ -1332,10 +1350,6 @@ public class CanvasView extends View
{ {
if (GameState == GS_PLAYING) if (GameState == GS_PLAYING)
{ {
if (!GameOver)
{
goingDown = true;
/// Can the Block go down? /// Can the Block go down?
if (CanBlockGoDown()) if (CanBlockGoDown())
{ {
@@ -1344,8 +1358,6 @@ public class CanvasView extends View
} }
else else
{ {
NextWillLock = false;
ParseBlockArrayToDrawArray(); ParseBlockArrayToDrawArray();
CheckForCompletedRows(); CheckForCompletedRows();
@@ -1353,10 +1365,6 @@ public class CanvasView extends View
//spawn new block //spawn new block
if (!SpawnBlock()) if (!SpawnBlock())
{ {
// GameOver
GameOver = true;
GamePlaying = false;
GameState = GS_GAMEOVER; GameState = GS_GAMEOVER;
mp.stop(); mp.stop();
@@ -1367,9 +1375,6 @@ public class CanvasView extends View
this.postInvalidate(); this.postInvalidate();
} }
} }
goingDown = false;
}
} }
} }
@@ -1776,8 +1781,7 @@ public class CanvasView extends View
} }
ArrayList<Integer> Tetrimino; ArrayList<Integer> Tetrimino;
private void CheckTetriminoSpawnArray()
private boolean SpawnBlock()
{ {
// Pseudo random // Pseudo random
if (Tetrimino == null || Tetrimino.size() <= 0) if (Tetrimino == null || Tetrimino.size() <= 0)
@@ -1789,6 +1793,12 @@ public class CanvasView extends View
Tetrimino.add(newTetrimino); Tetrimino.add(newTetrimino);
}while (Tetrimino.size() < 7); }while (Tetrimino.size() < 7);
} }
}
private boolean SpawnBlock()
{
CheckTetriminoSpawnArray();
CurrentBlock = NewBlock; CurrentBlock = NewBlock;
CurrentBlockPossition = NewBlockPossition; CurrentBlockPossition = NewBlockPossition;