Commit 4e2bbd9f authored by Lila NICKLER's avatar Lila NICKLER

Ajout music + update graphique

parent a904da3d
This diff is collapsed.
...@@ -9,6 +9,9 @@ import android.content.Context; ...@@ -9,6 +9,9 @@ import android.content.Context;
import android.graphics.Path; import android.graphics.Path;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.RectF; import android.graphics.RectF;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
...@@ -26,6 +29,8 @@ import android.hardware.SensorEvent; ...@@ -26,6 +29,8 @@ import android.hardware.SensorEvent;
import android.hardware.SensorEventListener; import android.hardware.SensorEventListener;
import android.hardware.SensorManager; import android.hardware.SensorManager;
import java.io.IOException;
public class MainActivity extends AppCompatActivity implements SensorEventListener{ public class MainActivity extends AppCompatActivity implements SensorEventListener{
ImageView padExte; ImageView padExte;
...@@ -63,17 +68,17 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen ...@@ -63,17 +68,17 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
// on associe l ecouteur d’evenements au SensorManager // on associe l ecouteur d’evenements au SensorManager
MediaPlayer music= MediaPlayer.create(MainActivity.this,R.raw.music);
music.setLooping(true);
music.setVolume(100,100);
music.start();
float height = metrics.heightPixels; float height = metrics.heightPixels;
float width = metrics.widthPixels; float width = metrics.widthPixels;
RectF oval = new RectF(100,100, width-180, height/2); RectF oval = new RectF(100,100, width-180, height/2);
tie = findViewById(R.id.tie); tie = findViewById(R.id.tie);
Path arc1 = new Path(); Path arc1 = new Path();
arc1.arcTo(oval,-80,180); arc1.arcTo(oval,-80,180);
ObjectAnimator animator = ObjectAnimator.ofFloat(asteroid1, View.X, View.Y, arc1); ObjectAnimator animator = ObjectAnimator.ofFloat(asteroid1, View.X, View.Y, arc1);
animator.setDuration(3050); animator.setDuration(3050);
...@@ -87,6 +92,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen ...@@ -87,6 +92,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
explosion.setX(tie.getX()); explosion.setX(tie.getX());
explosion.setY(tie.getY()); explosion.setY(tie.getY());
showExplosion(); showExplosion();
} }
} }
}); });
...@@ -106,6 +112,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen ...@@ -106,6 +112,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
explosion.setX(tie.getX()); explosion.setX(tie.getX());
explosion.setY(tie.getY()); explosion.setY(tie.getY());
showExplosion(); showExplosion();
} }
} }
}); });
...@@ -125,6 +132,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen ...@@ -125,6 +132,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
explosion.setX(tie.getX()); explosion.setX(tie.getX());
explosion.setY(tie.getY()); explosion.setY(tie.getY());
showExplosion(); showExplosion();
} }
} }
}); });
...@@ -146,6 +154,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen ...@@ -146,6 +154,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
explosion.setX(tie.getX()); explosion.setX(tie.getX());
explosion.setY(tie.getY()); explosion.setY(tie.getY());
showExplosion(); showExplosion();
} }
} }
}); });
...@@ -179,11 +188,18 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen ...@@ -179,11 +188,18 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
private void showExplosion() { private void showExplosion() {
explosion.setVisibility(View.VISIBLE); explosion.setVisibility(View.VISIBLE);
SoundPool sounds;
int sExplosion;
sounds = new SoundPool(10, AudioManager.STREAM_MUSIC,0);
sExplosion = sounds.load(this, R.raw.hit, 1);
explosion.postDelayed(new Runnable() { explosion.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
explosion.setVisibility(View.INVISIBLE); explosion.setVisibility(View.INVISIBLE);
// sounds.play(sExplosion, 1.0f, 1.0f, 0, 0, 1.5f);
;
} }
}, 500); // produce 5 sec delay in button visibility }, 500); // produce 5 sec delay in button visibility
} }
......
This diff is collapsed.
...@@ -10,16 +10,9 @@ ...@@ -10,16 +10,9 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/main" android:id="@+id/main"
android:layout_marginBottom="4dp"> android:layout_marginBottom="4dp"
android:background="@drawable/fond">
<ImageView
android:id="@+id/fond"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
app:srcCompat="@drawable/etoilefond" />
<FrameLayout <FrameLayout
android:id="@+id/gameSpace" android:id="@+id/gameSpace"
...@@ -30,7 +23,7 @@ ...@@ -30,7 +23,7 @@
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_marginStart="0dp" android:layout_marginStart="0dp"
android:layout_marginLeft="0dp" android:layout_marginLeft="0dp"
android:layout_marginBottom="0dp" > android:layout_marginBottom="0dp">
<ImageView <ImageView
...@@ -51,6 +44,22 @@ ...@@ -51,6 +44,22 @@
android:visibility="visible" android:visibility="visible"
app:srcCompat="@drawable/pad_exterior" /> app:srcCompat="@drawable/pad_exterior" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"
android:text="Joystick"
app:backgroundTint="#9C27B0" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:text="Capteurs"
app:backgroundTint="#9C27B0" />
</FrameLayout> </FrameLayout>
<FrameLayout <FrameLayout
...@@ -113,6 +122,26 @@ ...@@ -113,6 +122,26 @@
android:layout_marginRight="0dp" android:layout_marginRight="0dp"
app:srcCompat="@drawable/asteroid4" app:srcCompat="@drawable/asteroid4"
android:layout_marginLeft="120dp" /> android:layout_marginLeft="120dp" />
<TextView
android:id="@+id/vie"
android:layout_width="103dp"
android:layout_height="36dp"
android:layout_gravity="right"
android:text="Vie"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:id="@+id/score"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="Score"
android:textSize="30dp"
android:textStyle="bold" />
</FrameLayout> </FrameLayout>
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" /> <background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground" /> <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon> </adaptive-icon>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" /> <background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground" /> <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon> </adaptive-icon>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment