Commit 27a3b70f authored by Benjamin LEROUX's avatar Benjamin LEROUX

init ben

parent 288fded0
......@@ -4,9 +4,9 @@
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:icon="@drawable/asteroid1"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@drawable/asteroid1"
android:supportsRtl="true"
android:theme="@style/Theme.StarWarsGame">
<activity android:name=".MainActivity">
......
......@@ -3,6 +3,7 @@ package com.imtm1.starwarsgame;
import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
......@@ -29,10 +30,10 @@ class JoyStickView {
ViewGroup mainLayout ;
Context context;
Boolean joystickIsPressed=false;
View tie;
ImageView tie;
public JoyStickView (ViewGroup mainLayout, Context context, View tie)
public JoyStickView (ViewGroup mainLayout, Context context, ImageView tie)
{
this.mainLayout = mainLayout;
this.context = context;
......
......@@ -5,10 +5,12 @@ import androidx.appcompat.app.AppCompatActivity;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Path;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
......@@ -23,6 +25,8 @@ import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
ImageView padExte;
......@@ -51,10 +55,27 @@ public class MainActivity extends AppCompatActivity {
ObjectAnimator animator = ObjectAnimator.ofFloat(asteroid1, View.X, View.Y, path);
animator.setDuration(2000);
animator.setRepeatCount(Animation.INFINITE);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
if(sontEnCollision(asteroid1,tie)){
Log.i("collision", "true");
}
}
});
animator.start();
ObjectAnimator animator2 = ObjectAnimator.ofFloat(asteroid2, View.X, View.Y, path);
animator2.setDuration(5000);
animator2.setRepeatCount(Animation.INFINITE);
animator2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
if(sontEnCollision(asteroid2,tie)){
Log.i("collision2", "true");
}
}
});
animator2.start();
......@@ -66,6 +87,7 @@ public class MainActivity extends AppCompatActivity {
public void run() {
// tie.setTranslationX(joyStickView.xDelta);
// tie.setTranslationY(joyStickView.yDelta);
Log.i( "TAG","Bool:"+ joyStickView.joystickIsPressed);
if (joyStickView.joystickIsPressed) {
Toast.makeText(MainActivity.this, "joysitck is pressed", Toast.LENGTH_SHORT).show();
......@@ -83,4 +105,19 @@ public class MainActivity extends AppCompatActivity {
padCenter.setOnTouchListener(joyStickView.touchListener);
}
boolean sontEnCollision(ImageView firstView, ImageView secondView) {
int [] firstPosition = new int[2];
int [] secondPosition = new int[2];
firstView .getLocationOnScreen(firstPosition);
secondView.getLocationOnScreen(secondPosition);
Rect rectFirstView = new Rect(firstPosition [0], firstPosition [1],
firstPosition [0] + firstView .getMeasuredWidth(), firstPosition [1] + firstView .getMeasuredHeight());
Rect rectSecondView = new Rect(secondPosition[0], secondPosition[1],
secondPosition[0] + secondView.getMeasuredWidth(), secondPosition[1] + secondView.getMeasuredHeight());
return(rectFirstView. intersect (rectSecondView));
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="JoystickView">
<attr name="joystickIsPressed" format="boolean"/>
</declare-styleable>
</resources>
\ 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