Skip to content

Commit

Permalink
v0.18.2
Browse files Browse the repository at this point in the history
- Немного поменял gamecustomactivity
- Начал делать бота для игры одному
- Вынес настройки в класс settings
  • Loading branch information
InvalidNickname committed May 20, 2018
1 parent 434666d commit c93e535
Show file tree
Hide file tree
Showing 34 changed files with 461 additions and 443 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="hockey.airhockey"
android:versionName="0.18.1">
android:versionName="0.18.2">

<application
android:allowBackup="true"
Expand Down
20 changes: 8 additions & 12 deletions app/src/main/java/hockey/airhockey/CreditsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
import android.widget.ScrollView;
import android.widget.Space;

import static hockey.airhockey.MainActivity.baseVolume;
import static hockey.airhockey.MainActivity.gateHeight;
import static hockey.airhockey.MainActivity.height;
import static hockey.airhockey.MainActivity.HIDE_FLAGS;
import static hockey.airhockey.MainActivity.settings;
import static hockey.airhockey.MainActivity.volume;
import static hockey.airhockey.MainActivity.width;

public class CreditsActivity extends AppCompatActivity implements Runnable {

Expand All @@ -36,12 +34,12 @@ protected void onCreate(Bundle savedInstanceState) {
setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaPlayer = new MediaPlayer();
mediaPlayer = MediaPlayer.create(this, R.raw.night_runner);
mediaPlayer.setVolume(baseVolume * volume, baseVolume * volume);
mediaPlayer.setVolume(settings.baseVolume * volume, settings.baseVolume * volume);
mediaPlayer.setLooping(true);
overridePendingTransition(0, 0);
scrollView = findViewById(R.id.scrollView);
Space space = findViewById(R.id.space);
LinearLayout.LayoutParams spaceParams = new LinearLayout.LayoutParams(0, height);
LinearLayout.LayoutParams spaceParams = new LinearLayout.LayoutParams(0, settings.height);
space.setLayoutParams(spaceParams);
sec = System.currentTimeMillis();
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Expand All @@ -51,15 +49,13 @@ protected void onCreate(Bundle savedInstanceState) {

private void hideSystemUI() {
View view = getWindow().getDecorView();
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION //
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION //
| View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
view.setSystemUiVisibility(HIDE_FLAGS);
}

@Override
public void run() {
while (isRunning) {
if (System.currentTimeMillis() - sec > 16000 / height) {
if (System.currentTimeMillis() - sec > 16000 / settings.height) {
scrollView.smoothScrollBy(0, 1);
sec = System.currentTimeMillis();
}
Expand Down Expand Up @@ -121,14 +117,14 @@ public void onBackPressed() {
private void drawGates() {
ImageView upperGate = findViewById(R.id.upperGate);
ImageView lowerGate = findViewById(R.id.lowerGate);
ConstraintLayout.LayoutParams upperParams = new ConstraintLayout.LayoutParams((int) (0.48 * width), gateHeight);
ConstraintLayout.LayoutParams upperParams = new ConstraintLayout.LayoutParams((int) (0.48 * settings.width), settings.gateHeight);
upperParams.leftToLeft = R.id.mainCredits;
upperParams.rightToRight = R.id.mainCredits;
upperParams.topToTop = R.id.mainCredits;
upperParams.bottomToBottom = R.id.mainCredits;
upperParams.verticalBias = 0;
upperGate.setLayoutParams(upperParams);
ConstraintLayout.LayoutParams lowerParams = new ConstraintLayout.LayoutParams((int) (0.48 * width), gateHeight);
ConstraintLayout.LayoutParams lowerParams = new ConstraintLayout.LayoutParams((int) (0.48 * settings.width), settings.gateHeight);
lowerParams.leftToLeft = R.id.mainCredits;
lowerParams.rightToRight = R.id.mainCredits;
lowerParams.topToTop = R.id.mainCredits;
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/hockey/airhockey/GameActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hockey.airhockey;

import android.content.Intent;
import android.media.AudioManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -16,6 +17,8 @@ public class GameActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gameField = new GameField(GameActivity.this);
Intent intent = getIntent();
gameField.setMultiplayer(intent.getBooleanExtra("multiplayer",true));
setVolumeControlStream(AudioManager.STREAM_MUSIC);
setContentView(gameField);
overridePendingTransition(0, 0);
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/hockey/airhockey/GameCustomActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import static hockey.airhockey.MainActivity.HIDE_FLAGS;

public class GameCustomActivity extends AppCompatActivity {

private GameCustomField gameCustomField;
Expand All @@ -21,9 +23,7 @@ protected void onCreate(Bundle savedInstanceState) {

private void hideSystemUI() {
View view = getWindow().getDecorView();
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION //
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION //
| View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
view.setSystemUiVisibility(HIDE_FLAGS);
}

@Override
Expand Down
89 changes: 53 additions & 36 deletions app/src/main/java/hockey/airhockey/GameCustomField.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
Expand All @@ -11,40 +12,39 @@
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import static hockey.airhockey.MainActivity.height;
import static hockey.airhockey.MainActivity.numberOfPlayers;
import static hockey.airhockey.MainActivity.numberOfPucks;
import static hockey.airhockey.MainActivity.playerScale;
import static hockey.airhockey.MainActivity.puckScale;
import static hockey.airhockey.MainActivity.startAnimStopTime;
import static hockey.airhockey.MainActivity.width;
import static hockey.airhockey.MainActivity.APP_PREFERENCES;
import static hockey.airhockey.MainActivity.settings;

public class GameCustomField extends SurfaceView implements Runnable {

private static final String APP_PREFERENCES_MULTIPLAYER = "multiplayer";
static int player1Chosen, puckChosen, player2Chosen;
static int[] puckArray, playerArray;
private final Context context;
private final SurfaceHolder holder;
private final SharedPreferences preferences;
private Thread thread;
private boolean isDrawing, isSpeedSet, animStop;
private boolean isDrawing, isSpeedSet, animStop, multiplayer;
private Bitmap background;
private Player player1, player2;
private Gate lowerGate, upperGate;
private Puck puck;
private long psec;
private Button start, puckLeft, puckRight, player1Left, player1Right, player2Left, player2Right;
private Button start, puckLeft, puckRight, player1Left, player1Right, player2Left, player2Right, mode;

public GameCustomField(Context context) {
super(context);
this.context = context;
preferences = context.getSharedPreferences(APP_PREFERENCES, Context.MODE_PRIVATE);
multiplayer = preferences.getBoolean(APP_PREFERENCES_MULTIPLAYER, true);
player1Chosen = 0;
player2Chosen = 0;
puckChosen = 0;
puckArray = new int[numberOfPucks + 1];
puckArray = new int[settings.numberOfPucks + 1];
puckArray[0] = R.drawable.puck_default;
puckArray[1] = R.drawable.puck_green;
puckArray[2] = R.drawable.puck_blue;
playerArray = new int[numberOfPlayers + 1];
playerArray = new int[settings.numberOfPlayers + 1];
playerArray[0] = R.drawable.player_default;
playerArray[1] = R.drawable.player_black;
thread = new Thread();
Expand All @@ -62,14 +62,14 @@ private void update() {
psec = sec;
if (!isSpeedSet & delta < 1000) {
isSpeedSet = true;
puck.v.setVector((width / 2d - puck.x) / startAnimStopTime, 0);
player1.v.setVector((width / 2d - player1.x) / startAnimStopTime, 0);
player2.v.setVector((width / 2d - player2.x) / startAnimStopTime, 0);
puck.v.setVector((settings.width / 2d - puck.x) / settings.startAnimStopTime, 0);
player1.v.setVector((settings.width / 2d - player1.x) / settings.startAnimStopTime, 0);
player2.v.setVector((settings.width / 2d - player2.x) / settings.startAnimStopTime, 0);
}
player1.update(delta, true);
player2.update(delta, true);
puck.update(delta, true);
if (puck.x <= width / 2 + puckScale / 2 & !animStop) {
if (puck.x <= settings.width / 2 + settings.puckScale / 2 & !animStop) {
player1 = new Player(playerArray[player1Chosen], context, 1);
player2 = new Player(playerArray[player2Chosen], context, 2);
puck = new Puck(puckArray[puckChosen], context);
Expand All @@ -80,28 +80,30 @@ private void update() {
// загрузка графики
private void loadGraphics() {
background = BitmapFactory.decodeResource(context.getResources(), R.drawable.background);
background = Bitmap.createScaledBitmap(background, width, height, true);
start = new Button(R.drawable.start_button, R.drawable.start_button_pressed, context, (int) (0.9074 * width), width, (int) (0.4375 * height), (int) (0.5625 * height));
puckLeft = new Button(R.drawable.arrow_left, context, (int) (width / 2 - 1.7 * playerScale - 20), width / 2 - playerScale - 20, (int) (height / 2 - 0.7 * playerScale), (int) (height / 2 + 0.7 * playerScale));
puckRight = new Button(R.drawable.arrow_right, context, width / 2 + playerScale + 20, (int) (width / 2 + 1.7 * playerScale + 20), (int) (height / 2 - 0.7 * playerScale), (int) (height / 2 + 0.7 * playerScale));
player1Left = new Button(R.drawable.arrow_left, context, (int) (width / 2 - 1.7 * playerScale - 20), width / 2 - playerScale - 20, (int) (0.7 * playerScale), (int) (2.1 * playerScale));
player1Right = new Button(R.drawable.arrow_right, context, width / 2 + playerScale + 20, (int) (width / 2 + 1.7 * playerScale + 20), (int) (0.7 * playerScale), (int) (2.1 * playerScale));
player2Left = new Button(R.drawable.arrow_left, context, (int) (width / 2 - 1.7 * playerScale - 20), width / 2 - playerScale - 20, (int) (height - 2.1 * playerScale), (int) (height - 0.7 * playerScale));
player2Right = new Button(R.drawable.arrow_right, context, width / 2 + playerScale + 20, (int) (width / 2 + 1.7 * playerScale + 20), (int) (height - 2.1 * playerScale), (int) (height - 0.7 * playerScale));
background = Bitmap.createScaledBitmap(background, settings.width, settings.height, true);
start = new Button(R.drawable.start_button, R.drawable.start_button_pressed, context, (int) (settings.width - 0.0419921875 * settings.height), settings.width, (int) (0.4375 * settings.height), (int) (0.5625 * settings.height));
mode = new Button(R.drawable.mode_button, R.drawable.mode_button_pressed, context, 0, (int) (0.0419921875 * settings.height), (int) (0.4375 * settings.height), (int) (0.5625 * settings.height));
puckLeft = new Button(R.drawable.arrow_left, context, (int) (settings.width / 2 - 1.7 * settings.playerScale - 20), settings.width / 2 - settings.playerScale - 20, (int) (settings.height / 2 - 0.7 * settings.playerScale), (int) (settings.height / 2 + 0.7 * settings.playerScale));
puckRight = new Button(R.drawable.arrow_right, context, settings.width / 2 + settings.playerScale + 20, (int) (settings.width / 2 + 1.7 * settings.playerScale + 20), (int) (settings.height / 2 - 0.7 * settings.playerScale), (int) (settings.height / 2 + 0.7 * settings.playerScale));
player1Left = new Button(R.drawable.arrow_left, context, (int) (settings.width / 2 - 1.7 * settings.playerScale - 20), settings.width / 2 - settings.playerScale - 20, (int) (0.7 * settings.playerScale), (int) (2.1 * settings.playerScale));
player1Right = new Button(R.drawable.arrow_right, context, settings.width / 2 + settings.playerScale + 20, (int) (settings.width / 2 + 1.7 * settings.playerScale + 20), (int) (0.7 * settings.playerScale), (int) (2.1 * settings.playerScale));
player2Left = new Button(R.drawable.arrow_left, context, (int) (settings.width / 2 - 1.7 * settings.playerScale - 20), settings.width / 2 - settings.playerScale - 20, (int) (settings.height - 2.1 * settings.playerScale), (int) (settings.height - 0.7 * settings.playerScale));
player2Right = new Button(R.drawable.arrow_right, context, settings.width / 2 + settings.playerScale + 20, (int) (settings.width / 2 + 1.7 * settings.playerScale + 20), (int) (settings.height - 2.1 * settings.playerScale), (int) (settings.height - 0.7 * settings.playerScale));
player1 = new Player(playerArray[player1Chosen], context, 1);
player1.x = width + playerScale * 2;
player1.x = settings.width + settings.playerScale * 2;
player2 = new Player(playerArray[player2Chosen], context, 2);
player2.x = width + playerScale * 2;
player2.x = settings.width + settings.playerScale * 2;
puck = new Puck(puckArray[puckChosen], context);
puck.x = width + puckScale * 2;
puck.x = settings.width + settings.puckScale * 2;
lowerGate = new Gate(R.drawable.lower_gate, context, 1);
upperGate = new Gate(R.drawable.upper_gate, context, 2);
}

// рисование
private void drawOnCanvas(Canvas canvas) {
canvas.drawBitmap(background, 0, 0, new Paint(Paint.ANTI_ALIAS_FLAG));
canvas.drawBitmap(background, 0, 0, new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG));
start.draw(canvas);
mode.draw(canvas);
lowerGate.draw(canvas);
upperGate.draw(canvas);
if (animStop) {
Expand All @@ -126,49 +128,49 @@ public boolean onTouchEvent(MotionEvent event) {
int y = (int) event.getY();
if (start.isClicked(x, y)) {
start.setPressed(true);
Intent intent = new Intent(context, GameActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}
if (mode.isClicked(x, y)) {
mode.setPressed(true);
}
if (puckLeft.isClicked(x, y)) {
puckChosen -= 1;
if (puckChosen < 0) {
puckChosen = numberOfPucks;
puckChosen = settings.numberOfPucks;
}
puck = new Puck(puckArray[puckChosen], context);
System.out.println(puckChosen);
}
if (puckRight.isClicked(x, y)) {
puckChosen++;
if (puckChosen > numberOfPucks) {
if (puckChosen > settings.numberOfPucks) {
puckChosen = 0;
}
puck = new Puck(puckArray[puckChosen], context);
}
if (player1Left.isClicked(x, y)) {
player1Chosen -= 1;
if (player1Chosen < 0) {
player1Chosen = numberOfPlayers;
player1Chosen = settings.numberOfPlayers;
}
player1 = new Player(playerArray[player1Chosen], context, 1);
}
if (player1Right.isClicked(x, y)) {
player1Chosen++;
if (player1Chosen > numberOfPlayers) {
if (player1Chosen > settings.numberOfPlayers) {
player1Chosen = 0;
}
player1 = new Player(playerArray[player1Chosen], context, 1);
}
if (player2Left.isClicked(x, y)) {
player2Chosen -= 1;
if (player2Chosen < 0) {
player2Chosen = numberOfPlayers;
player2Chosen = settings.numberOfPlayers;
}
player2 = new Player(playerArray[player2Chosen], context, 2);
}
if (player2Right.isClicked(x, y)) {
player2Chosen++;
if (player2Chosen > numberOfPlayers) {
if (player2Chosen > settings.numberOfPlayers) {
player2Chosen = 0;
}
player2 = new Player(playerArray[player2Chosen], context, 2);
Expand All @@ -177,6 +179,21 @@ public boolean onTouchEvent(MotionEvent event) {
}
case MotionEvent.ACTION_UP: {
start.setPressed(false);
mode.setPressed(false);
int x = (int) event.getX();
int y = (int) event.getY();
if (start.isClicked(x, y)) {
Intent intent = new Intent(context, GameActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("multiplayer", multiplayer);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(APP_PREFERENCES_MULTIPLAYER, multiplayer);
editor.apply();
context.startActivity(intent);
}
if (mode.isClicked(x, y)) {
multiplayer = !multiplayer;
}
}
}
return true;
Expand Down
Loading

0 comments on commit c93e535

Please sign in to comment.