Gamemenu intergration.
This commit is contained in:
@@ -40,6 +40,7 @@ public class CanvasView extends View
|
|||||||
Gamemenu.SetActivity(activity);
|
Gamemenu.SetActivity(activity);
|
||||||
Gamemenu.SetCanvas(this);
|
Gamemenu.SetCanvas(this);
|
||||||
Gamemenu.SetPayedVersion(PayedVersion);
|
Gamemenu.SetPayedVersion(PayedVersion);
|
||||||
|
Gamemenu.SetGameState(GamePlay.GS_LOAD, true);
|
||||||
|
|
||||||
Gameplay.SetActivity(activity);
|
Gameplay.SetActivity(activity);
|
||||||
Gameplay.SetCanvas(this);
|
Gameplay.SetCanvas(this);
|
||||||
@@ -47,13 +48,16 @@ public class CanvasView extends View
|
|||||||
|
|
||||||
Foreground = Gamemenu;
|
Foreground = Gamemenu;
|
||||||
|
|
||||||
|
//temp
|
||||||
|
//this.gameStateChanged(GameStateInterface.GS_MENU_START);
|
||||||
|
|
||||||
// Game Start. First Load
|
// Game Start. First Load
|
||||||
((GamePlay)Gameplay).SetStartLevel(startLevel);
|
//((GamePlay)Gameplay).SetStartLevel(startLevel);
|
||||||
((GamePlay)Gameplay).SetGameState(GamePlay.GS_LOAD, true);
|
//((GamePlay)Gameplay).SetGameState(GamePlay.GS_LOAD, false);
|
||||||
|
|
||||||
// Start Game.
|
// Start Game.
|
||||||
if (((GamePlay)Gameplay).GetGameState() == GameStateInterface.GS_READY)
|
//if (((GamePlay)Gameplay).GetGameState() == GameStateInterface.GS_READY)
|
||||||
((GamePlay)Gameplay).SetGameState(GameStateInterface.GS_START, true);
|
// ((GamePlay)Gameplay).SetGameState(GameStateInterface.GS_START, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,18 +81,19 @@ public class CanvasView extends View
|
|||||||
gameStateChanged(gameState);
|
gameStateChanged(gameState);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public void OnGameStateChanged(int gameState, boolean isPostBack)
|
|
||||||
{
|
|
||||||
if (isPostBack == false)
|
|
||||||
gameStateChanged(gameState);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private void gameStateChanged(int gameState)
|
private void gameStateChanged(int gameState)
|
||||||
{
|
{
|
||||||
switch(gameState)
|
switch(gameState)
|
||||||
{
|
{
|
||||||
|
case GameStateInterface.GS_MENU_START:
|
||||||
|
{
|
||||||
|
((GamePlay)Gameplay).SetStartLevel(startLevel);
|
||||||
|
((GamePlay)Gameplay).SetGameState(GamePlay.GS_LOAD, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case GameStateInterface.GS_READY:
|
case GameStateInterface.GS_READY:
|
||||||
{
|
{
|
||||||
|
((GamePlay)Gameplay).SetGameState(GameStateInterface.GS_START, true);
|
||||||
Foreground = Gameplay;
|
Foreground = Gameplay;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
package mangavalk.tetris;
|
package mangavalk.tetris;
|
||||||
|
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Paint.Style;
|
||||||
|
import android.media.MediaPlayer;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
import android.view.Display;
|
||||||
|
|
||||||
public class GameMenu extends GameStateInterface
|
public class GameMenu extends GameStateInterface
|
||||||
{
|
{
|
||||||
@@ -14,8 +21,6 @@ public class GameMenu extends GameStateInterface
|
|||||||
@Override
|
@Override
|
||||||
public void DrawFrame(Canvas canvas)
|
public void DrawFrame(Canvas canvas)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
switch(GameState)
|
switch(GameState)
|
||||||
{
|
{
|
||||||
case GS_PAUSED:
|
case GS_PAUSED:
|
||||||
@@ -24,16 +29,21 @@ public class GameMenu extends GameStateInterface
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//canvasView.postInvalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void SendMove(float x, float y, boolean pointerUp)
|
public void SendMove(float x, float y, boolean pointerUp)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
switch(GameState)
|
switch(GameState)
|
||||||
{
|
{
|
||||||
|
case GS_MENU_READY:
|
||||||
|
{
|
||||||
|
if (!pointerUp)
|
||||||
|
{
|
||||||
|
SetGameState(GS_MENU_START, false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case GS_PAUSED:
|
case GS_PAUSED:
|
||||||
{
|
{
|
||||||
if (!pointerUp)
|
if (!pointerUp)
|
||||||
@@ -52,6 +62,16 @@ public class GameMenu extends GameStateInterface
|
|||||||
|
|
||||||
switch(GameState)
|
switch(GameState)
|
||||||
{
|
{
|
||||||
|
case GS_LOAD:
|
||||||
|
{
|
||||||
|
Load();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GS_READY:
|
||||||
|
{
|
||||||
|
canvasView.postInvalidate();
|
||||||
|
break;
|
||||||
|
}
|
||||||
case GS_PAUSED:
|
case GS_PAUSED:
|
||||||
{
|
{
|
||||||
canvasView.postInvalidate();
|
canvasView.postInvalidate();
|
||||||
@@ -83,10 +103,93 @@ public class GameMenu extends GameStateInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Internal.
|
// Internal.
|
||||||
|
|
||||||
|
// Variabelen.
|
||||||
|
Resources r;
|
||||||
|
|
||||||
|
// Display
|
||||||
|
float dpHeight;
|
||||||
|
float dpWidth;
|
||||||
|
|
||||||
|
float Height;
|
||||||
|
float Width;
|
||||||
|
|
||||||
|
// Audio.
|
||||||
|
MediaPlayer mp;
|
||||||
|
|
||||||
|
// Load
|
||||||
|
|
||||||
|
private void Load()
|
||||||
|
{
|
||||||
|
SetGameState(GS_LOADING, false);
|
||||||
|
|
||||||
|
// Set Display Info.
|
||||||
|
Display display = activity.getWindowManager().getDefaultDisplay();
|
||||||
|
DisplayMetrics outMetrics = new DisplayMetrics ();
|
||||||
|
display.getMetrics(outMetrics);
|
||||||
|
|
||||||
|
r = activity.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.
|
||||||
|
|
||||||
|
// Audio
|
||||||
|
mp = MediaPlayer.create(activity, R.raw.tetris_a);
|
||||||
|
|
||||||
|
SetGameState(GS_MENU_READY, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw functions.
|
||||||
private void ShowPauseMenu()
|
private void ShowPauseMenu()
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ public class GamePlay extends GameStateInterface
|
|||||||
// Variabelen
|
// Variabelen
|
||||||
Resources r;
|
Resources r;
|
||||||
|
|
||||||
// Sizes
|
// Display
|
||||||
float dpHeight;
|
float dpHeight;
|
||||||
float dpWidth;
|
float dpWidth;
|
||||||
|
|
||||||
|
|||||||
@@ -8,15 +8,17 @@ public abstract class GameStateInterface
|
|||||||
//public GameStateInterface Instance;
|
//public GameStateInterface Instance;
|
||||||
|
|
||||||
// GameState Parameters
|
// GameState Parameters
|
||||||
final static int GS_STOPPED = 0;
|
final static int GS_STOPPED = 0;
|
||||||
final static int GS_LOADING = 1;
|
final static int GS_LOADING = 1;
|
||||||
final static int GS_PLAYING = 2;
|
final static int GS_PLAYING = 2;
|
||||||
final static int GS_GAMEOVER = 3;
|
final static int GS_GAMEOVER = 3;
|
||||||
final static int GS_PAUSED = 4;
|
final static int GS_PAUSED = 4;
|
||||||
final static int GS_START = 5;
|
final static int GS_START = 5;
|
||||||
final static int GS_LOAD = 6;
|
final static int GS_LOAD = 6;
|
||||||
final static int GS_READY = 7;
|
final static int GS_READY = 7;
|
||||||
final static int GS_RESUME = 8;
|
final static int GS_RESUME = 8;
|
||||||
|
final static int GS_MENU_START = 9;
|
||||||
|
final static int GS_MENU_READY = 10;
|
||||||
|
|
||||||
// Variabelen.
|
// Variabelen.
|
||||||
CanvasView canvasView;
|
CanvasView canvasView;
|
||||||
|
|||||||
Reference in New Issue
Block a user