Commit 0fa1f506 authored by Rominho15's avatar Rominho15
Browse files

Version 5 :

- Gestion des 3 méthodes d'intéraction
- Gestion des objets selon la taille du device (tablette/smartphone)
parent efb9edad
Pipeline #1185 skipped
......@@ -47,6 +47,7 @@ public class GameController {
// place la balle au centre du terrain
gameModel.getBall().setX(gameModel.getGround().getCenter().x);
gameModel.getBall().setY(gameModel.getGround().getCenter().y);
gameModel.getBall().setRayon((int) (size.x / 72));
// place la batte en dessous de la balle
int batX = gameModel.getGround().getCenter().x;
......@@ -55,6 +56,8 @@ public class GameController {
// met à jour la position de la batte dans le modèle
gameModel.getBat().setX(batX);
gameModel.getBat().setY(batY);
gameModel.getBat().setWidth((int) (size.x / 10));
gameModel.getBat().setHeight((int) (size.y / 60));
if(niveau == 1) {
gameModel.initBricks1();
......@@ -147,6 +150,10 @@ public class GameController {
gameModel.getBat().setX(x);
}
public void moveBatAdd(int x) {
moveBatAccelerometer(-x);
}
public void moveBatAccelerometer(float x) {
int addX = (int)-x;
int oldX = gameModel.getBat().getX() + gameModel.getBat().getWidth()/2;
......
......@@ -9,7 +9,7 @@ public class Ball {
private int y;
private int vx;
private int vy;
private final int rayon = 10;
private int rayon = 10;
public Ball(int xi, int yi) {
x = xi;
......@@ -53,4 +53,8 @@ public class Ball {
public int getRayon() {
return rayon;
}
public void setRayon(int rayon) {
this.rayon = rayon;
}
}
......@@ -7,8 +7,8 @@ public class Bat {
private int x;
private int y;
private final int width = 60;
private final int height = 20;
private int width = 60;
private int height = 20;
public Bat(int xi, int yi) {
x = xi;
......@@ -38,4 +38,12 @@ public class Bat {
public int getHeight() {
return height;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
}
......@@ -14,9 +14,13 @@ import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;
import com.example.rleger.cassebrique.Controller.GameController;
import com.example.rleger.cassebrique.Model.BrickGroup;
import com.example.rleger.cassebrique.R;
import java.util.ArrayList;
......@@ -29,6 +33,9 @@ public class GameView extends View {
Paint paintBat;
GameController gameControlleur;
int methode;
Button left;
Button right;
Button shoot;
private SensorManager sensorManager;
private Sensor accelerometer;
......@@ -70,6 +77,67 @@ public class GameView extends View {
sensorManager = (SensorManager) gameControlleur.getContext().getSystemService(Service.SENSOR_SERVICE);
accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sensorManager.registerListener(eventListener, accelerometer, SensorManager.SENSOR_DELAY_GAME);
} else if (methode == 1) {
// Existing Layout
RelativeLayout rl = (RelativeLayout)this.getParent();
// New Layout
RelativeLayout newRL = new RelativeLayout(rl.getContext());
// parameters Left
RelativeLayout.LayoutParams lpLeft = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lpLeft.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
// Left Button
left = new Button(newRL.getContext());
left.setText("L");
rl.addView(left, lpLeft);
// parameters Right
RelativeLayout.LayoutParams lpRight = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lpRight.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lpRight.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
// Right Button
right = new Button(newRL.getContext());
right.setText("R");
rl.addView(right, lpRight);
// Shoot button
RelativeLayout.LayoutParams lpShoot = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lpShoot.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lpShoot.addRule(RelativeLayout.CENTER_HORIZONTAL);
shoot = new Button(newRL.getContext());
shoot.setText("S");
rl.addView(shoot, lpShoot);
left.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
int decalage = (int) (gameControlleur.getGameModel().getBat().getWidth() / 4);
gameControlleur.moveBatAdd(-decalage);
}
return false;
}
});
right.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
int decalage = (int)(gameControlleur.getGameModel().getBat().getWidth()/4);
gameControlleur.moveBatAdd(decalage);
}
return false;
}
});
shoot.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
}
return false;
}
});
}
}
......@@ -138,10 +206,14 @@ public class GameView extends View {
yMax = gameControlleur.getGameModel().getBat().getY() + gameControlleur.getGameModel().getBat().getHeight();
if (y > yMax) {
gameControlleur.moveBat(x);
} else {
if(methode == 2) {
gameControlleur.tirer();
} else if (methode == 0){
if (y > yMax) {
gameControlleur.moveBat(x);
} else {
gameControlleur.tirer();
}
}
break;
case (MotionEvent.ACTION_DOWN):
......@@ -151,10 +223,14 @@ public class GameView extends View {
yMax = gameControlleur.getGameModel().getBat().getY() + gameControlleur.getGameModel().getBat().getHeight();
if (y > yMax) {
gameControlleur.moveBat(x);
} else {
if(methode == 2) {
gameControlleur.tirer();
} else if (methode == 0){
if (y > yMax) {
gameControlleur.moveBat(x);
} else {
gameControlleur.tirer();
}
}
break;
}
......
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