From 861f11c6d2da45df73af6b85b2c51c907ea9b318 Mon Sep 17 00:00:00 2001
From: Camil Staps
Date: Wed, 22 Apr 2015 12:48:22 +0200
Subject: Added car sound on drive
---
.idea/workspace.xml | 123 ++++++++++++++-------
.../main/java/com/camilstaps/rushhour/Board.java | 7 ++
app/src/main/java/com/camilstaps/rushhour/Car.java | 2 -
.../com/camilstaps/rushhour/DriveListener.java | 8 ++
.../camilstaps/rushhour/FullscreenActivity.java | 22 +++-
5 files changed, 120 insertions(+), 42 deletions(-)
create mode 100644 app/src/main/java/com/camilstaps/rushhour/DriveListener.java
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 44c669b..11a6c42 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -39,25 +39,32 @@
-
+
-
-
+
+
-
-
+
+
+
+
+
+
-
+
-
-
-
+
+
+
+
+
+
@@ -65,8 +72,8 @@
-
-
+
+
@@ -1349,9 +1356,10 @@
-
+
+
@@ -1485,10 +1493,12 @@
-
+
+
+
@@ -1719,8 +1729,12 @@
-
-
+
+
+
+
+
+
@@ -1757,8 +1771,12 @@
-
-
+
+
+
+
+
+
@@ -1795,8 +1813,12 @@
-
-
+
+
+
+
+
+
@@ -1833,8 +1855,12 @@
-
-
+
+
+
+
+
+
@@ -1878,8 +1904,12 @@
-
-
+
+
+
+
+
+
@@ -1993,17 +2023,6 @@
-
-
-
-
-
-
-
-
-
-
-
@@ -2014,8 +2033,8 @@
-
-
+
+
@@ -2023,14 +2042,40 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/java/com/camilstaps/rushhour/Board.java b/app/src/main/java/com/camilstaps/rushhour/Board.java
index f59cc59..e99c438 100644
--- a/app/src/main/java/com/camilstaps/rushhour/Board.java
+++ b/app/src/main/java/com/camilstaps/rushhour/Board.java
@@ -17,6 +17,8 @@ public class Board {
public static final int DIMENSION = 6;
+ private DriveListener driveListener;
+
private MoveListener moveListener = new MoveListener() {
@Override
public void onMove(Car car, int offset) {
@@ -29,6 +31,7 @@ public class Board {
}
}
car.move(offset);
+ driveListener.onDrive();
}
};
@@ -55,4 +58,8 @@ public class Board {
}
}
+ public void setDriveListener(DriveListener dl) {
+ driveListener = dl;
+ }
+
}
diff --git a/app/src/main/java/com/camilstaps/rushhour/Car.java b/app/src/main/java/com/camilstaps/rushhour/Car.java
index 4b0d99b..aa654f8 100644
--- a/app/src/main/java/com/camilstaps/rushhour/Car.java
+++ b/app/src/main/java/com/camilstaps/rushhour/Car.java
@@ -64,8 +64,6 @@ public class Car {
public ImageView getImageView(Context context, float widthPerCell) {
- Log.d("Car", Float.toString(widthPerCell));
-
this.widthPerCell = widthPerCell - MARGIN;
calculatedWidth = (int) ((endCoordinate.getX() - startCoordinate.getX() + 1) * (this.widthPerCell + MARGIN) - MARGIN);
calculatedHeight = (int) ((endCoordinate.getY() - startCoordinate.getY() + 1) * (this.widthPerCell + MARGIN) - MARGIN);
diff --git a/app/src/main/java/com/camilstaps/rushhour/DriveListener.java b/app/src/main/java/com/camilstaps/rushhour/DriveListener.java
new file mode 100644
index 0000000..f3a83e7
--- /dev/null
+++ b/app/src/main/java/com/camilstaps/rushhour/DriveListener.java
@@ -0,0 +1,8 @@
+package com.camilstaps.rushhour;
+
+/**
+ * Created by camilstaps on 22-4-15.
+ */
+public abstract class DriveListener {
+ public abstract void onDrive();
+}
diff --git a/app/src/main/java/com/camilstaps/rushhour/FullscreenActivity.java b/app/src/main/java/com/camilstaps/rushhour/FullscreenActivity.java
index 614176a..620f2b2 100644
--- a/app/src/main/java/com/camilstaps/rushhour/FullscreenActivity.java
+++ b/app/src/main/java/com/camilstaps/rushhour/FullscreenActivity.java
@@ -2,6 +2,8 @@ package com.camilstaps.rushhour;
import android.app.Activity;
import android.graphics.Color;
+import android.media.AudioManager;
+import android.media.SoundPool;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewTreeObserver;
@@ -19,6 +21,10 @@ import com.camilstaps.rushhour.util.SystemUiHider;
*/
public class FullscreenActivity extends Activity {
+ private SoundPool soundPool;
+ private boolean soundBackgroundLoaded = false;
+ private int soundBackgroundId;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -51,6 +57,20 @@ public class FullscreenActivity extends Activity {
}
});
- //board.addToLayout(this, boardLayout);
+ soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
+ soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
+ @Override
+ public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
+ soundBackgroundLoaded = true;
+ }
+ });
+ soundBackgroundId = soundPool.load(this, R.raw.car_drive, 1);
+
+ board.setDriveListener(new DriveListener() {
+ @Override
+ public void onDrive() {
+ soundPool.play(soundBackgroundId, 1, 1, 1, 0, 1f);
+ }
+ });
}
}
--
cgit v1.2.3