Gamemenu intergration.
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
package mangavalk.tetris;
|
||||
|
||||
import android.content.res.Resources;
|
||||
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
|
||||
{
|
||||
@@ -14,8 +21,6 @@ public class GameMenu extends GameStateInterface
|
||||
@Override
|
||||
public void DrawFrame(Canvas canvas)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
switch(GameState)
|
||||
{
|
||||
case GS_PAUSED:
|
||||
@@ -24,16 +29,21 @@ public class GameMenu extends GameStateInterface
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//canvasView.postInvalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SendMove(float x, float y, boolean pointerUp)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
switch(GameState)
|
||||
{
|
||||
case GS_MENU_READY:
|
||||
{
|
||||
if (!pointerUp)
|
||||
{
|
||||
SetGameState(GS_MENU_START, false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GS_PAUSED:
|
||||
{
|
||||
if (!pointerUp)
|
||||
@@ -52,6 +62,16 @@ public class GameMenu extends GameStateInterface
|
||||
|
||||
switch(GameState)
|
||||
{
|
||||
case GS_LOAD:
|
||||
{
|
||||
Load();
|
||||
break;
|
||||
}
|
||||
case GS_READY:
|
||||
{
|
||||
canvasView.postInvalidate();
|
||||
break;
|
||||
}
|
||||
case GS_PAUSED:
|
||||
{
|
||||
canvasView.postInvalidate();
|
||||
@@ -83,10 +103,93 @@ public class GameMenu extends GameStateInterface
|
||||
}
|
||||
|
||||
// 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()
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user