Author SHA1 Message Date
Administrator a7dd68476d sprite cleanup and new sprites added.
code made compatible with not samsung devices again.
added pause menu.
bugfix in startlevel.
2014-04-22 13:23:47 +02:00
Administrator fa997fb77a cleanup 2014-04-17 14:32:25 +02:00
Administrator c4cc0517f6 gameover working again 2014-04-17 12:22:29 +02:00
16 changed files with 235 additions and 126 deletions
+5 -4
View File
@@ -244,10 +244,11 @@ containing a value of this type.
public static final int sprite_i4r=0x7f020033;
public static final int sprite_l1=0x7f020034;
public static final int sprite_l2=0x7f020035;
public static final int sprite_s=0x7f020036;
public static final int sprite_score=0x7f020037;
public static final int sprite_t=0x7f020038;
public static final int sprite_z=0x7f020039;
public static final int sprite_pause=0x7f020036;
public static final int sprite_s=0x7f020037;
public static final int sprite_score=0x7f020038;
public static final int sprite_t=0x7f020039;
public static final int sprite_z=0x7f02003a;
}
public static final class id {
public static final int action_settings=0x7f050005;
Binary file not shown.
Binary file not shown.
@@ -163,4 +163,10 @@ public class GameMenu extends GameStateInterface
{
Rect(canvas, 0f, 160f, 0f, 90f, Color.parseColor("lime"));
}
@Override
public void SendMove(int angle, int speed) {
// TODO Auto-generated method stub
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 161 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

+10 -21
View File
@@ -13,7 +13,6 @@ public class CanvasView extends View // Dev2
Resources r;
GameStateInterface Foreground = null;
GameStateInterface Gamemenu = null;
GameStateInterface Gameplay = null;
// Score.
@@ -32,18 +31,15 @@ public class CanvasView extends View // Dev2
public void SetActivity(Activity activity)
{
Gameplay = new GamePlay(activity);
Gamemenu = new GameMenu(activity);
Gamemenu.SetCanvas(this);
Gamemenu.SetPayedVersion(PayedVersion);
Gamemenu.Load();
Gamemenu.Start();
Gameplay.SetCanvas(this);
Gameplay.SetPayedVersion(PayedVersion);
Foreground = Gamemenu;
((GamePlay)Gameplay).SetStartLevel(startLevel);
Gameplay.Load();
Gameplay.Start();
Foreground = Gameplay;
}
@Override
@@ -79,24 +75,17 @@ public class CanvasView extends View // Dev2
Foreground = Gameplay;
break;
}
case GameStateInterface.GS_PAUSED:
{
Gamemenu.SetGameState(Foreground.GetGameState(), true);
Foreground = Gamemenu;
break;
}
case GameStateInterface.GS_RESUME:
{
Gameplay.SetGameState(Foreground.GetGameState(), true);
Foreground = Gameplay;
break;
}
case GameStateInterface.GS_GAMEOVER:
{
Gamemenu.SetGameState(Foreground.GetGameState(), true);
Foreground = Gamemenu;
break;
}
}
}
public void sendMove(int angle, int speed)
{
Foreground.SendMove(angle, speed);
}
}
+156 -100
View File
@@ -31,8 +31,13 @@ public class GamePlay extends GameStateInterface
public void onPause()
{
mp.pause();
if (GameState != GS_GAMEOVER)
SetGameState(GS_PAUSED, false);
else
{
SetGameState(GS_PAUSED, false);
}
canvasView.postInvalidate();
}
@Override
@@ -82,7 +87,7 @@ public class GamePlay extends GameStateInterface
}
}
if (!isPostBack)
if ((!isPostBack) && (GameState != GS_GAMEOVER))
canvasView.OnGameStateChanged(GameState);
}
@@ -368,6 +373,7 @@ public class GamePlay extends GameStateInterface
bitmapi1r, bitmapi2r, bitmapi3r, bitmapi4r, bitmapblockline, bitmapscore, bitmapcontroller, bitmapgameover;
Bitmap Font0, Font1, Font2, Font3, Font4, Font5, Font6, Font7, Font8, Font9;
Bitmap bitmappause;
// Audio.
MediaPlayer mp;
@@ -444,7 +450,6 @@ public class GamePlay extends GameStateInterface
handler.postDelayed(runnable, 100);
}
// TODO game state
@Override
public void Load()
{
@@ -601,6 +606,13 @@ public class GamePlay extends GameStateInterface
bitmapgameover = Bitmap.createScaledBitmap(bitmapgameover,
(int)GetRealPixelSize(DIP_W, dpWidth, (GameSpaceRight - GameSpaceLeft)),
(int)GetRealPixelSize(DIP_H, dpHeight, (GameSpaceBottom - GameSpaceTop)), false);
bitmappause = BitmapFactory.decodeResource(r,
R.drawable.sprite_pause);
bitmappause = Bitmap.createScaledBitmap(bitmappause,
(int)GetRealPixelSize(DIP_W, dpWidth, (GameSpaceRight - GameSpaceLeft)),
(int)GetRealPixelSize(DIP_H, dpHeight, (GameSpaceBottom - GameSpaceTop)), false);
}
private void LoadFont()
@@ -689,114 +701,117 @@ public class GamePlay extends GameStateInterface
if (PayedVersion)
{
// Scores.
DrawLines(canvas, lines);
DrawLevel(canvas, startLevel + level);
DrawLevel(canvas, level);
DrawScore(canvas, score);
// Next Coming Tetrimino.
ShowNextComingTetrimino(canvas);
}
for (int x=0; x<10; x++)
if(GameState == GS_PLAYING)
{
for (int y=0; y<18; y++)
for (int x=0; x<10; x++)
{
switch (drawArray[y][x] + (blockArray[y][x] >= 0 ? blockArray[y][x] : 0))
for (int y=0; y<18; y++)
{
case 0:
break;
case 1:
switch (drawArray[y][x] + (blockArray[y][x] >= 0 ? blockArray[y][x] : 0))
{
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;
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:
{
// In case of error.
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;
}
}
}
}
@@ -807,6 +822,12 @@ public class GamePlay extends GameStateInterface
canvas.drawBitmap(bitmapgameover, (int)GetRealPixelSize(DIP_W, dpWidth, GameSpaceLeft),
(int)GetRealPixelSize(DIP_H, dpHeight, GameSpaceTop), null);
}
if (GameState == GS_PAUSED)
{
canvas.drawBitmap(bitmappause, (int)GetRealPixelSize(DIP_W, dpWidth, GameSpaceLeft),
(int)GetRealPixelSize(DIP_H, dpHeight, GameSpaceTop), null);
}
}
private void ShowNextComingTetrimino(Canvas canvas)
@@ -1875,4 +1896,39 @@ public class GamePlay extends GameStateInterface
return true;
}
@Override
public void SendMove(int angle, int speed)
{
if (angle <= 315 && angle >= 225 ) // Left
{
if(CanBlockGoLeft())
{
MoveBlockLeft();
canvasView.postInvalidate();
}
}
else if (angle <= 135 && angle >= 45 ) // Right
{
if(CanBlockGoRight())
{
MoveBlockRight();
canvasView.postInvalidate();
}
}
else if (angle <= 225 && angle >= 135 ) // Rotate Right
{
RotateBlockRight();
canvasView.postInvalidate();
}
else if ((angle <= 30 || angle >= 330 ) && (speed >= 80)) // go down
{
// Hard Drop
while (CanBlockGoDown())
{
MoveBlockDown();
}
canvasView.postInvalidate();
}
}
}
@@ -122,4 +122,6 @@ public abstract class GameStateInterface
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
public abstract void SendMove(int angle, int speed);
}
+56 -1
View File
@@ -4,12 +4,19 @@ package mangavalk.tetris;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.samsung.android.sdk.SsdkUnsupportedException;
import com.samsung.android.sdk.gesture.Sgesture;
import com.samsung.android.sdk.gesture.SgestureHand;
import com.samsung.android.sdk.gesture.SgestureHand.Info;
import android.app.Activity;
import android.graphics.PointF;
import android.os.Bundle;
import android.os.Looper;
import android.util.Log;
import android.util.SparseArray;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.widget.FrameLayout;
public class MainActivity extends Activity
@@ -17,10 +24,40 @@ public class MainActivity extends Activity
CanvasView canvasClass;
private AdView adView;
private Sgesture mGesture;
private SgestureHand mHand;
private boolean SamsungDevice = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Gesture. Samsung only
mGesture = new Sgesture();
try {
mGesture.initialize(this);
SamsungDevice = true;
} catch (IllegalArgumentException e) {
//Error Handling
Log.d("MangaValk", "mark1");
SamsungDevice = false;
} catch (SsdkUnsupportedException e2) {
//Error Handling
Log.d("MangaValk", "mark2");
SamsungDevice = false;
}
if (SamsungDevice)
{
if(mGesture.isFeatureEnabled(Sgesture.TYPE_HAND_PRIMITIVE)){
mHand = new SgestureHand(Looper.getMainLooper(), mGesture);
mHand.start(Sgesture.TYPE_HAND_PRIMITIVE, mChangeListener);
}
}
FrameLayout ll;
ll = new FrameLayout(this);
@@ -37,6 +74,8 @@ public class MainActivity extends Activity
.addTestDevice("2CA96A8B6B805B3323F65A934FB31DC7") // Samsung Galaxy S5
.build();
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
canvasClass = new CanvasView(this);
canvasClass.PayedVersion = true; // Set payment status
@@ -63,16 +102,32 @@ public class MainActivity extends Activity
canvasClass.SetActivity(this);
}
private final SgestureHand.ChangeListener mChangeListener =
new SgestureHand.ChangeListener() {
@Override
public void onChanged(Info info) {
Log.d("gesture", "Hand : angle = " + info.getAngle());
// do something with data
canvasClass.sendMove(info.getAngle(), info.getSpeed());
}
};
@Override
public void onPause() {
super.onPause();
canvasClass.onPause();
}
@Override
public void onStop() {
super.onStop();
}
@Override
public void onResume() {
super.onResume();
//canvasClass.onResume();
}
@Override
Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 KiB