Skip to content

Commit

Permalink
started working on pausing
Browse files Browse the repository at this point in the history
  • Loading branch information
treiter committed Feb 26, 2014
1 parent 4fd323b commit 7e305eb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
Binary file not shown.
Binary file modified bin/classes/com/example/avalanchegame/CustomSurfaceView.class
Binary file not shown.
Binary file modified bin/classes/com/example/avalanchegame/MainActivity.class
Binary file not shown.
15 changes: 10 additions & 5 deletions src/com/example/avalanchegame/CustomSurfaceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class GameThread

private final int MIN_BLOCKS_ABOVE = 40;

private boolean firstTime = true;


// ----------------------------------------------------------
/**
Expand Down Expand Up @@ -310,6 +312,9 @@ public void pause()
{
if (mMode == STATE_RUNNING)
setState(STATE_PAUSE);

mRun = false;

}
}

Expand Down Expand Up @@ -516,17 +521,14 @@ public void setSurfaceSize(int width, int height)
*/
public void unpause()
{
// Move the real time clock up to now
synchronized (mSurfaceHolder)
{
setState(STATE_RUNNING);
mRun = true;
}
setState(STATE_RUNNING);
}

boolean firstTime = true;


// TODO: some blocks don't actually get cleared
public void restart()
{
boxes.clear();
Expand Down Expand Up @@ -759,6 +761,8 @@ public void onWindowFocusChanged(boolean hasWindowFocus)
{
if (!hasWindowFocus)
thread.pause();
else//TODO: make this open pause screen
thread.unpause();
}


Expand Down Expand Up @@ -809,4 +813,5 @@ public void surfaceDestroyed(SurfaceHolder holder)
}
}
}

}
15 changes: 14 additions & 1 deletion src/com/example/avalanchegame/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.avalanchegame;

import android.content.pm.ActivityInfo;
import android.util.Log;
import android.app.Activity;
import android.content.Context;
Expand Down Expand Up @@ -36,6 +37,10 @@ protected void onCreate(Bundle savedInstanceState)
// tell system to use the layout defined in our XML file
setContentView(R.layout.activity_main);

// lock in portrait mode? TODO: test this
super
.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
SensorManager sensorManager;
Sensor accelerometer;
Expand All @@ -62,8 +67,16 @@ protected void onCreate(Bundle savedInstanceState)
@Override
protected void onPause()
{
screenContainer.getThread().pause(); // pause game when Activity pauses
super.onPause();
screenContainer.getThread().pause(); // pause game when Activity pauses
}


@Override
protected void onResume()
{
super.onResume();
screenContainer.getThread().unpause();// TODO:make this open paused menu
}


Expand Down

0 comments on commit 7e305eb

Please sign in to comment.