Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added first-pass at shields. Has shield bar, and shield stats that mi… #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/.idea/workspace.xml
/.idea/vcs.xml
/.idea/libraries
/.idea/caches/
/.idea/codeStyles/
.DS_Store
/build
/captures
Expand Down
9 changes: 5 additions & 4 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 65 additions & 11 deletions app/src/main/java/com/simplecoil/simplecoil/FullscreenActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public class FullscreenActivity extends AppCompatActivity implements PopupMenu.O
private TextView mHealthLabelTV = null;
private TextView mPlayerNameTV = null;
private ProgressBar mHealthBar = null;
private ProgressBar mShieldBar = null;
private ProgressBar mReloadBar = null;
private ImageView mHitIV = null;
private ImageView mBatteryLevelIV = null;
Expand All @@ -149,6 +150,7 @@ public class FullscreenActivity extends AppCompatActivity implements PopupMenu.O

private CountDownTimer mSpawnTimer = null;
private CountDownTimer mReloadTimer = null;
private CountDownTimer mShieldTimer = null;
private CountDownTimer mGameCountdownTimer = null;
private CountDownTimer mConnectFailTimer = null;
private boolean mGameTimerRunning = false;
Expand All @@ -160,13 +162,17 @@ public class FullscreenActivity extends AppCompatActivity implements PopupMenu.O

private static final int MAX_EMPTY_TRIGGER_PULLS = 3; // automatically reloads if the trigger is pulled this many times while empty (for young players)

private float mShieldTickTime = 1.0f;
private int mShieldTickAmount = 1;

private boolean mScanning = false;
private volatile boolean mConnected = false;
private boolean mCommunicating = false; // Used to make sure that we start receiving telemetry data after initial connection
private String mDeviceAddress = ""; // MAC address of the tagger
private static byte mLastTeam = 0;
private int mHitsTaken = 0; // total hits taken regardless of lives
private static int mHealth = Globals.MAX_HEALTH;
private static int mShield = Globals.MAX_SHIELDS;
private byte mLastShotCount = 0;
private byte mLastTriggerCount = 0;
private byte mLastReloadButtonCount = 0;
Expand Down Expand Up @@ -531,9 +537,8 @@ public void onClick(View v) {
mShotModeTV = findViewById(R.id.shot_mode_tv);
mHealthLabelTV = findViewById(R.id.health_label_tv);
mHealthBar = findViewById(R.id.health_pb);
mHealth = Globals.getInstance().mFullHealth;
mHealthBar.setMax(mHealth);
mHealthBar.setProgress(mHealth);
mShieldBar = findViewById(R.id.shield_pb);
resetVitalStatBars();
mReloadBar = findViewById(R.id.reload_pb);
mEliminatedTV = findViewById(R.id.eliminated_tv);
mEliminatedByTV = findViewById(R.id.eliminated_by_tv);
Expand Down Expand Up @@ -1114,6 +1119,16 @@ private void initBatteryQueue() {
mBatteryTotal = 16;
}

private void resetVitalStatBars() {
mHealth = Globals.getInstance().mFullHealth;
mHealthBar.setMax(mHealth);
mHealthBar.setProgress(mHealth);

mShield = Globals.getInstance().mFullShields;
mShieldBar.setMax(mShield);
mShieldBar.setProgress(mShield);
}

private void startGame() {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().getDecorView().setSystemUiVisibility(
Expand All @@ -1129,9 +1144,7 @@ private void startGame() {
else
mEliminationCount = 0;
mEliminationCountTV.setText("" + mEliminationCount);
mHealth = Globals.getInstance().mFullHealth;
mHealthBar.setMax(mHealth);
mHealthBar.setProgress(mHealth);
resetVitalStatBars();
mEliminatedTV.setText(R.string.starting_game_label);
mStartGameButton.setVisibility(View.GONE);
mTeamMinusButton.setVisibility(View.INVISIBLE);
Expand Down Expand Up @@ -1209,6 +1222,8 @@ private void endGame() {
mGameTimerRunning = false;
if (mGameCountdownTimer != null)
mGameCountdownTimer.cancel();
if (mShieldTimer != null)
mShieldTimer.cancel();
mStartGameButton.setVisibility(View.VISIBLE);
mPlayerSettingsButton.setVisibility(View.VISIBLE);
mTeamMinusButton.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -1352,6 +1367,8 @@ private void setShotsRemaining(byte shotsRemaining) {
private void startSpawn(String eliminatedBy) {
if (mReloadTimer != null)
mReloadTimer.cancel();
if (mShieldTimer != null)
mShieldTimer.cancel();
Globals.getInstance().mGameState = Globals.GAME_STATE_ELIMINATED;
startReload(RELOADING_STATE_ELIMINATED);
mHitIV.setVisibility(View.GONE);
Expand All @@ -1373,8 +1390,7 @@ public void onFinish() {
mEliminatedTV.setText(R.string.eliminated_label);
mEliminatedByTV.setVisibility(View.INVISIBLE);
mSpawnInTV.setVisibility(View.GONE);
mHealth = Globals.getInstance().mFullHealth;
mHealthBar.setProgress(mHealth);
resetVitalStatBars();
Globals.getInstance().mGameState = Globals.GAME_STATE_RUNNING;
playSound(R.raw.spawn, getApplicationContext());
finishReload();
Expand All @@ -1392,6 +1408,27 @@ public void onFinish() {
}.start();
}

private void startShieldCountdown(float tickTime) {
if (mShieldTimer != null)
mShieldTimer.cancel();

mShieldTimer = new CountDownTimer((long)(tickTime * 1000), (long)(tickTime * 1000)) {
@Override
public void onTick(long millisUntilFinished) {
// Nothing
}

@Override
public void onFinish() {
mShield += mShieldTickAmount;
mShieldBar.setProgress(mShield);
if (mShield < Globals.getInstance().mFullShields) {
startShieldCountdown(mShieldTickTime);
}
}
}.start();
}

private void startGameCountdown() {
startGameCountdown(Globals.getInstance().mTimeLimit * 60);
}
Expand Down Expand Up @@ -1915,6 +1952,22 @@ public void onCompletion(MediaPlayer mp) {
mp.setLooping(false);
}

private boolean wouldDie(int damage) {
return (mShield + mHealth + damage) > 0;
}

private boolean takeDamage(int damage) {
if (mShield + damage < 0) {
damage += mShield;
mHealth += damage;
return true;
}
mShield += damage;

startShieldCountdown((long)(mShieldTickTime * 4));
return false;
}

/* Telemetry data is 20 bytes of raw data in the following format:
00 seems to be part of a continuous counter, first byte always 0 and second byte counts 0 to F, increments with each packet sent
01 player ID, 01, 02, 03, etc. 00 when not set
Expand Down Expand Up @@ -2194,8 +2247,9 @@ else if (averageBattery >= BATTERY_LEVEL_PISTOL_YELLOW)
}
if (healthRemoved != 0) {
if (Globals.getInstance().mGameState == Globals.GAME_STATE_RUNNING) {
mHealth += healthRemoved;
takeDamage(healthRemoved);
mHealthBar.setProgress(mHealth);
mShieldBar.setProgress(mShield);
if (mHealth > 0) {
if (mHitIV != null && mHitAnimation == null) {
// Show the "you're being hit" animation
Expand Down Expand Up @@ -2287,12 +2341,12 @@ public void run() {
}
}
// Handy utility code if you want to see the raw data
/*if (data != null && data.length > 0) {
if (data != null && data.length > 0) {
final StringBuilder stringBuilder = new StringBuilder(data.length);
for(byte byteChar : data)
stringBuilder.append(String.format("%02X ", byteChar));
Log.d(TAG, stringBuilder.toString());
}*/
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/simplecoil/simplecoil/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class Globals {
public volatile int mFullHealth = MAX_HEALTH;
public static final int DAMAGE_PER_HIT = -1;
public volatile int mDamage = DAMAGE_PER_HIT;
public static final int MAX_SHIELDS = 5;
public volatile int mFullShields = MAX_SHIELDS;
public volatile boolean mOverrideLives = false;
public volatile int mOverrideLivesVal = 0;
public volatile boolean mAllowPlayerSettings = true;
Expand Down
Loading