Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dozingcat/Vector-Pinball
Browse files Browse the repository at this point in the history
…into version-161-bump
  • Loading branch information
dozingcat committed May 24, 2019
2 parents 4a8938d + 7a5b79a commit bc99419
Show file tree
Hide file tree
Showing 41 changed files with 780 additions and 845 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

public class AboutActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.about);
Expand All @@ -21,16 +20,16 @@ public void onCreate(Bundle savedInstanceState) {
String tableRulesText = null;
try {
String fieldName = "table" + getIntent().getIntExtra("level", 1) + "_rules";
int tableRulesID = (Integer)R.string.class.getField(fieldName).get(null);
int tableRulesID = (Integer) R.string.class.getField(fieldName).get(null);
tableRulesText = getString(tableRulesID);
}
catch(Exception ex) {
catch (Exception ex) {
tableRulesText = null;
}
if (tableRulesText==null) tableRulesText = "";
if (tableRulesText == null) tableRulesText = "";
String displayText = baseText.replace("[TABLE_RULES]", tableRulesText);

TextView tv = (TextView)findViewById(R.id.aboutTextView);
TextView tv = (TextView) findViewById(R.id.aboutTextView);
tv.setText(displayText);
}

Expand All @@ -40,5 +39,4 @@ public static Intent startForLevel(Context context, int level) {
context.startActivity(aboutIntent);
return aboutIntent;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface AudioPlayer {

void playRollover();

public static class NoOpPlayer implements AudioPlayer {
class NoOpPlayer implements AudioPlayer {
private static final NoOpPlayer INSTANCE = new NoOpPlayer();

public static NoOpPlayer getInstance() {
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/com/dozingcatsoftware/bouncy/Ball.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ private Ball(Body body, Color primaryColor, Color secondaryColor) {
this.secondaryColor = secondaryColor;
}

public static Ball create(World world, float x, float y, float radius,
Color primaryColor, Color secondaryColor) {
public static Ball create(
World world, float x, float y, float radius, Color primaryColor, Color secondaryColor) {
Body ballBody = Box2DFactory.createCircle(world, x, y, radius, false);
ballBody.setBullet(true);
// Default is radius of 0.5, if different we want the mass to be the same (could be
// configurable if needed), so adjust density proportional to square of the radius.
if (radius != 0.5f) {
ballBody.getFixtureList().get(0).setDensity((0.5f*0.5f) / (radius*radius));
ballBody.getFixtureList().get(0).setDensity((0.5f * 0.5f) / (radius * radius));
ballBody.resetMassData();
}
return new Ball(ballBody, primaryColor, secondaryColor);
}

public void draw(IFieldRenderer renderer) {
CircleShape shape = (CircleShape)body.getFixtureList().get(0).getShape();
CircleShape shape = (CircleShape) body.getFixtureList().get(0).getShape();
Vector2 center = body.getPosition();
float radius = shape.getRadius();
renderer.fillCircle(center.x, center.y, radius, primaryColor);
Expand Down Expand Up @@ -67,15 +67,16 @@ public Body getBody() {
public Color getPrimaryColor() {
return primaryColor;
}

public void setPrimaryColor(Color primaryColor) {
this.primaryColor = primaryColor;
}

public Color getSecondaryColor() {
return secondaryColor;
}

public void setSecondaryColor(Color secondaryColor) {
this.secondaryColor = secondaryColor;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
*/
public class BaseFieldDelegate implements Field.Delegate {

@Override public void allDropTargetsInGroupHit(Field field, DropTargetGroupElement targetGroup) {}
@Override
public void allDropTargetsInGroupHit(Field field, DropTargetGroupElement targetGroup) {}

@Override public void allRolloversInGroupActivated(Field field, RolloverGroupElement rolloverGroup) {}
@Override
public void allRolloversInGroupActivated(Field field, RolloverGroupElement rolloverGroup) {}

@Override public void flippersActivated(Field field, List<FlipperElement> flippers) {}

@Override public void processCollision(Field field, FieldElement element, Body hitBody, Ball ball) {}
@Override
public void processCollision(Field field, FieldElement element, Body hitBody, Ball ball) {}

@Override public void gameStarted(Field field) {}

Expand Down
56 changes: 28 additions & 28 deletions app/src/main/java/com/dozingcatsoftware/bouncy/BouncyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

public class BouncyActivity extends Activity {

// Using libgdx 1.4.1 with Box2D extension.
static {
Box2D.init();
}
Expand All @@ -42,8 +41,7 @@ public class BouncyActivity extends Activity {
Handler handler = new Handler();

Runnable callTick = new Runnable() {
@Override
public void run() {tick();}
@Override public void run() {tick();}
};

Field field = new Field();
Expand Down Expand Up @@ -73,7 +71,7 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String arch = System.getProperty("os.arch");
Log.i(TAG, "App started, os.arch=" + arch);

requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);

Expand All @@ -82,14 +80,15 @@ public void onCreate(Bundle savedInstanceState) {
field.resetForLevel(this, level);
field.setAudioPlayer(new VPSoundpool.Player());

canvasFieldView = (CanvasFieldView)findViewById(R.id.canvasFieldView);
glFieldView = (GLFieldView)findViewById(R.id.glFieldView);
canvasFieldView = (CanvasFieldView) findViewById(R.id.canvasFieldView);
glFieldView = (GLFieldView) findViewById(R.id.glFieldView);

fieldViewManager.setField(field);
fieldViewManager.setStartGameAction(new Runnable() {@Override
public void run() {doStartGame(null);}});
fieldViewManager.setStartGameAction(new Runnable() {
@Override public void run() {doStartGame(null);}
});

scoreView = (ScoreView)findViewById(R.id.scoreView);
scoreView = (ScoreView) findViewById(R.id.scoreView);
scoreView.setField(field);

fieldDriver.setFieldViewManager(fieldViewManager);
Expand All @@ -99,9 +98,9 @@ public void onCreate(Bundle savedInstanceState) {
scoreView.setHighScores(highScores);

buttonPanel = findViewById(R.id.buttonPanel);
switchTableButton = (Button)findViewById(R.id.switchTableButton);
endGameButton = (Button)findViewById(R.id.endGameButton);
unlimitedBallsToggle = (CheckBox)findViewById(R.id.unlimitedBallsToggle);
switchTableButton = (Button) findViewById(R.id.switchTableButton);
endGameButton = (Button) findViewById(R.id.endGameButton);
unlimitedBallsToggle = (CheckBox) findViewById(R.id.unlimitedBallsToggle);

// TODO: allow field configuration to specify whether tilting is allowed
/*
Expand All @@ -117,8 +116,7 @@ public void receivedOrientationValues(float azimuth, float pitch, float roll) {
// Initialize audio, loading resources in a separate thread.
VPSoundpool.initSounds(this);
(new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
@Override protected Void doInBackground(Void... params) {
VPSoundpool.loadSounds();
return null;
}
Expand All @@ -134,7 +132,8 @@ protected Void doInBackground(Void... params) {
Method setUiMethod = View.class.getMethod("setSystemUiVisibility", int.class);
setUiMethod.invoke(scoreView, 1);
}
catch (Exception ignored) {}
catch (Exception ignored) {
}
}

@Override public void onPause() {
Expand All @@ -152,7 +151,8 @@ protected Void doInBackground(Void... params) {
// If game is in progress, we want to return to the paused menu rather than immediately
// resuming. We need to draw the current field, which currently doesn't work reliably
// for OpenGL views. For now the game will resume immediately when using OpenGL.
if (field.getGameState().isGameInProgress() && glFieldView.getVisibility()==View.GONE) {
if (field.getGameState().isGameInProgress() &&
glFieldView.getVisibility() == View.GONE) {
fieldDriver.drawField();
showPausedButtons();
}
Expand All @@ -165,7 +165,7 @@ protected Void doInBackground(Void... params) {
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {
// When a game is in progress, pause rather than exit when the back button is pressed.
// This prevents accidentally quitting the game.
if (keyCode==KeyEvent.KEYCODE_BACK) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (field.getGameState().isGameInProgress() && !field.getGameState().isPaused()) {
pauseGame();
showPausedButtons();
Expand Down Expand Up @@ -215,7 +215,7 @@ void showPausedButtons() {
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);

switch(requestCode) {
switch (requestCode) {
case ACTIVITY_PREFERENCES:
updateFromPreferences();
break;
Expand All @@ -242,22 +242,22 @@ void updateFromPreferences() {
boolean highQuality = prefs.getBoolean("highQuality", false);
boolean previousHighQuality = fieldViewManager.isHighQuality();
fieldViewManager.setHighQuality(highQuality);
if (previousHighQuality!=fieldViewManager.isHighQuality()) {
if (previousHighQuality != fieldViewManager.isHighQuality()) {
fieldDriver.resetFrameRate();
}
scoreView.setHighQuality(highQuality);

boolean useOpenGL = prefs.getBoolean("useOpenGL", false);
if (useOpenGL) {
if (glFieldView.getVisibility()!=View.VISIBLE) {
if (glFieldView.getVisibility() != View.VISIBLE) {
canvasFieldView.setVisibility(View.GONE);
glFieldView.setVisibility(View.VISIBLE);
fieldViewManager.setFieldView(glFieldView);
fieldDriver.resetFrameRate();
}
}
else {
if (canvasFieldView.getVisibility()!=View.VISIBLE) {
if (canvasFieldView.getVisibility() != View.VISIBLE) {
glFieldView.setVisibility(View.GONE);
canvasFieldView.setVisibility(View.VISIBLE);
fieldViewManager.setFieldView(canvasFieldView);
Expand Down Expand Up @@ -286,8 +286,8 @@ void tick() {
*/
void updateHighScoreAndButtonPanel() {
// We only need to check once when the game is over, before the button panel is visible.
if (buttonPanel.getVisibility()==View.VISIBLE) return;
synchronized(field) {
if (buttonPanel.getVisibility() == View.VISIBLE) return;
synchronized (field) {
GameState state = field.getGameState();
if (!field.getGameState().isGameInProgress()) {
// game just ended, show button panel and set end game timestamp
Expand All @@ -302,7 +302,7 @@ void updateHighScoreAndButtonPanel() {
long score = field.getGameState().getScore();
// Add to high scores list if the score beats the lowest existing high score,
// or if all the high score slots aren't taken.
if (score > highScores.get(this.highScores.size()-1) ||
if (score > highScores.get(this.highScores.size() - 1) ||
highScores.size() < MAX_NUM_HIGH_SCORES) {
this.updateHighScoreForCurrentLevel(score);
}
Expand Down Expand Up @@ -346,7 +346,7 @@ List<Long> highScoresFromPreferences(int theLevel) {
void writeHighScoresToPreferences(int level, List<Long> scores) {
StringBuilder scoresAsString = new StringBuilder();
scoresAsString.append(scores.get(0));
for (int i=1; i<scores.size(); i++) {
for (int i = 1; i < scores.size(); i++) {
scoresAsString.append(",").append(scores.get(i));
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Expand Down Expand Up @@ -380,7 +380,7 @@ void updateHighScoreForCurrentLevel(long score) {
int getInitialLevel() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
int startLevel = prefs.getInt(INITIAL_LEVEL_PREFS_KEY, 1);
if (startLevel<1 || startLevel>FieldLayout.numberOfLevels()) startLevel = 1;
if (startLevel < 1 || startLevel > FieldLayout.numberOfLevels()) startLevel = 1;
return startLevel;
}

Expand Down Expand Up @@ -446,8 +446,8 @@ public void scoreViewClicked(View view) {
}

public void doSwitchTable(View view) {
level = (level==FieldLayout.numberOfLevels()) ? 1 : level+1;
synchronized(field) {
level = (level == FieldLayout.numberOfLevels()) ? 1 : level + 1;
synchronized (field) {
field.resetForLevel(this, level);
}
this.setInitialLevel(level);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import android.view.MotionEvent;

public class BouncyPreferences extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// If multitouch APIs aren't available, don't show preferences which require them.
Expand All @@ -15,8 +14,10 @@ protected void onCreate(Bundle savedInstanceState) {
MotionEvent.class.getField("ACTION_POINTER_INDEX_MASK");
hasMultitouch = true;
}
catch(Exception ignored) {}
catch (Exception ignored) {
}

addPreferencesFromResource(hasMultitouch ? R.xml.preferences : R.xml.preferences_nomultitouch);
addPreferencesFromResource(hasMultitouch ?
R.xml.preferences : R.xml.preferences_nomultitouch);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,26 @@ public CanvasFieldView(Context context, AttributeSet attrs) {

FieldViewManager manager;

Paint paint = new Paint(); {paint.setAntiAlias(true);}
Paint paint = new Paint();

{
paint.setAntiAlias(true);
}

Canvas canvas;

@Override
public void setManager(FieldViewManager value) {
@Override public void setManager(FieldViewManager value) {
this.manager = value;
}


/**
* Called when the view is touched. Activates flippers, starts a new game if one is not in
* progress, and launches a ball if one is not in play.
*/
@Override public boolean onTouchEvent(MotionEvent event) {
return manager.handleTouchEvent(event);
}

@Override public boolean onKeyDown(int keyCode, KeyEvent event) {
return manager.handleKeyDown(keyCode, event);
}
Expand All @@ -60,7 +63,7 @@ public void setManager(FieldViewManager value) {
// call draw() on each FieldElement, draw balls separately
this.canvas = c;

for(FieldElement element : manager.getField().getFieldElementsArray()) {
for (FieldElement element : manager.getField().getFieldElementsArray()) {
element.draw(this);
}

Expand All @@ -74,8 +77,10 @@ public void setManager(FieldViewManager value) {
// Assumes cacheScaleAndOffsets has been called.
@Override public void drawLine(float x1, float y1, float x2, float y2, Color color) {
this.paint.setARGB(color.alpha, color.red, color.green, color.blue);
this.canvas.drawLine(manager.world2pixelX(x1), manager.world2pixelY(y1),
manager.world2pixelX(x2), manager.world2pixelY(y2), this.paint);
this.canvas.drawLine(
manager.world2pixelX(x1), manager.world2pixelY(y1),
manager.world2pixelX(x2), manager.world2pixelY(y2),
this.paint);
}

@Override public void fillCircle(float cx, float cy, float radius, Color color) {
Expand All @@ -92,5 +97,4 @@ void drawCircle(float cx, float cy, float radius, Color color, Paint.Style style
float rad = radius * manager.getCachedScale();
this.canvas.drawCircle(manager.world2pixelX(cx), manager.world2pixelY(cy), rad, paint);
}

}
2 changes: 1 addition & 1 deletion app/src/main/java/com/dozingcatsoftware/bouncy/Clock.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public interface Clock {

long nanoTime();

public static class SystemClock implements Clock {
class SystemClock implements Clock {
private static SystemClock INSTANCE = new SystemClock();

public static SystemClock getInstance() {
Expand Down
Loading

0 comments on commit bc99419

Please sign in to comment.