Loading app/src/main/AndroidManifest.xml +5 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,11 @@ <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".PopUpWindow" android:configChanges="orientation" android:screenOrientation="portrait"> </activity> </application> </manifest> No newline at end of file app/src/main/java/com/example/a8_bitinvader/MainActivity.java +91 −3 Original line number Diff line number Diff line package com.example.a8_bitinvader; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ImageView; import android.widget.Button; import android.content.Context; import android.media.AudioManager; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Toast; import java.util.Timer; import java.util.TimerTask; import android.os.Handler; public class MainActivity extends AppCompatActivity { Animation animation; boolean play; /** * Displays the menu and checks for user input to click play * @param savedInstanceState The cached state of the game Loading @@ -25,19 +36,86 @@ public class MainActivity extends AppCompatActivity { getSupportActionBar().hide(); } // initalizes 8-bit Invaders Logo ImageView myImageView = (ImageView) findViewById(R.id.image_logo); myImageView.setImageResource(R.drawable.logobit); ImageView logo = (ImageView) findViewById(R.id.image_logo); logo.setImageResource(R.drawable.logobit); // Creates new Intent and starts GameActivity if 'play' is pressed on MainActivity screen. findViewById(R.id.play_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_animation); // logo.startAnimation(animation); startActivity(new Intent(MainActivity.this, GameActivity.class)); play = true; } }); // Creates new Intent and Mutes Device Audio if mute button is pressed on MainActivity screen // Reference: https://www.youtube.com/watch?v=_Klq62-me8s&ab_channel=AppleCoders // Reference: https://developer.android.com/reference/android/media/MediaPlayer findViewById(R.id.mute_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Declare an audio manager AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); // ADJUST_MUTE => mutes the device // FLAG_SHOW_UI => Show changes made to the volume bar audioManager.adjustVolume (AudioManager.ADJUST_MUTE, AudioManager.FLAG_SHOW_UI); } }); // Creates new Intent and stars LeaderboardView if the leaderboard button is pressed on the MainActivity Screen // As of 4/14 12:51 AM, this is not implemented with LeaderboardView -- Krish Shah findViewById(R.id.leaderboard_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { openPopUpWindow(); } }); //Code to show the toast every 5 seconds. For Preliminary Issue: Repeated event Timer timer = new Timer(); Context context = getApplicationContext(); CharSequence text = "Hello toast!"; int duration = 5000; timer.schedule(new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { final Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT); toast.show(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { toast.cancel(); } }, duration); } }); } }, 0, duration); } private void openPopUpWindow() { Intent popupwindow = new Intent(MainActivity.this, PopUpWindow.class); startActivity(popupwindow); } /** * Start the game Loading Loading @@ -86,4 +164,14 @@ public class MainActivity extends AppCompatActivity { protected void onRestart() { super.onRestart(); } @Override public void onBackPressed() { // Call super.onBackPressed() to perform default back button behavior super.onBackPressed(); } } No newline at end of file app/src/main/java/com/example/a8_bitinvader/PopUpWindow.java 0 → 100644 +38 −0 Original line number Diff line number Diff line package com.example.a8_bitinvader; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.Gravity; import android.view.WindowManager; import android.widget.ImageView; import android.widget.Button; import android.content.Context; import android.media.AudioManager; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.util.DisplayMetrics; public class PopUpWindow extends AppCompatActivity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.popup_window); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics (dm); int width = dm.widthPixels; int height = dm.heightPixels; getWindow().setLayout((int)(width*.7), (int)(height*.5)); WindowManager.LayoutParams params = getWindow().getAttributes(); params.gravity = Gravity.CENTER; params.x = 0; params.y = -20; getWindow().setAttributes(params); } } app/src/main/java/com/example/a8_bitinvader/ReverseInterpolator.java 0 → 100644 +10 −0 Original line number Diff line number Diff line package com.example.a8_bitinvader; import android.view.animation.Interpolator; public class ReverseInterpolator implements Interpolator { @Override public float getInterpolation(float paramFloat) { return Math.abs(paramFloat -1f); } } app/src/main/res/anim/blink_animation.xml 0 → 100644 +9 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:interpolator="@android:anim/accelerate_interpolator" android:duration="500" android:repeatMode="reverse" android:repeatCount="infinite"/> </set> Loading
app/src/main/AndroidManifest.xml +5 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,11 @@ <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".PopUpWindow" android:configChanges="orientation" android:screenOrientation="portrait"> </activity> </application> </manifest> No newline at end of file
app/src/main/java/com/example/a8_bitinvader/MainActivity.java +91 −3 Original line number Diff line number Diff line package com.example.a8_bitinvader; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ImageView; import android.widget.Button; import android.content.Context; import android.media.AudioManager; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Toast; import java.util.Timer; import java.util.TimerTask; import android.os.Handler; public class MainActivity extends AppCompatActivity { Animation animation; boolean play; /** * Displays the menu and checks for user input to click play * @param savedInstanceState The cached state of the game Loading @@ -25,19 +36,86 @@ public class MainActivity extends AppCompatActivity { getSupportActionBar().hide(); } // initalizes 8-bit Invaders Logo ImageView myImageView = (ImageView) findViewById(R.id.image_logo); myImageView.setImageResource(R.drawable.logobit); ImageView logo = (ImageView) findViewById(R.id.image_logo); logo.setImageResource(R.drawable.logobit); // Creates new Intent and starts GameActivity if 'play' is pressed on MainActivity screen. findViewById(R.id.play_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_animation); // logo.startAnimation(animation); startActivity(new Intent(MainActivity.this, GameActivity.class)); play = true; } }); // Creates new Intent and Mutes Device Audio if mute button is pressed on MainActivity screen // Reference: https://www.youtube.com/watch?v=_Klq62-me8s&ab_channel=AppleCoders // Reference: https://developer.android.com/reference/android/media/MediaPlayer findViewById(R.id.mute_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Declare an audio manager AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); // ADJUST_MUTE => mutes the device // FLAG_SHOW_UI => Show changes made to the volume bar audioManager.adjustVolume (AudioManager.ADJUST_MUTE, AudioManager.FLAG_SHOW_UI); } }); // Creates new Intent and stars LeaderboardView if the leaderboard button is pressed on the MainActivity Screen // As of 4/14 12:51 AM, this is not implemented with LeaderboardView -- Krish Shah findViewById(R.id.leaderboard_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { openPopUpWindow(); } }); //Code to show the toast every 5 seconds. For Preliminary Issue: Repeated event Timer timer = new Timer(); Context context = getApplicationContext(); CharSequence text = "Hello toast!"; int duration = 5000; timer.schedule(new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { final Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT); toast.show(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { toast.cancel(); } }, duration); } }); } }, 0, duration); } private void openPopUpWindow() { Intent popupwindow = new Intent(MainActivity.this, PopUpWindow.class); startActivity(popupwindow); } /** * Start the game Loading Loading @@ -86,4 +164,14 @@ public class MainActivity extends AppCompatActivity { protected void onRestart() { super.onRestart(); } @Override public void onBackPressed() { // Call super.onBackPressed() to perform default back button behavior super.onBackPressed(); } } No newline at end of file
app/src/main/java/com/example/a8_bitinvader/PopUpWindow.java 0 → 100644 +38 −0 Original line number Diff line number Diff line package com.example.a8_bitinvader; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.Gravity; import android.view.WindowManager; import android.widget.ImageView; import android.widget.Button; import android.content.Context; import android.media.AudioManager; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.util.DisplayMetrics; public class PopUpWindow extends AppCompatActivity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.popup_window); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics (dm); int width = dm.widthPixels; int height = dm.heightPixels; getWindow().setLayout((int)(width*.7), (int)(height*.5)); WindowManager.LayoutParams params = getWindow().getAttributes(); params.gravity = Gravity.CENTER; params.x = 0; params.y = -20; getWindow().setAttributes(params); } }
app/src/main/java/com/example/a8_bitinvader/ReverseInterpolator.java 0 → 100644 +10 −0 Original line number Diff line number Diff line package com.example.a8_bitinvader; import android.view.animation.Interpolator; public class ReverseInterpolator implements Interpolator { @Override public float getInterpolation(float paramFloat) { return Math.abs(paramFloat -1f); } }
app/src/main/res/anim/blink_animation.xml 0 → 100644 +9 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:interpolator="@android:anim/accelerate_interpolator" android:duration="500" android:repeatMode="reverse" android:repeatCount="infinite"/> </set>