Commit e9e9865e authored by Rominho15's avatar Rominho15
Browse files

Version 9.4 : Tir et bonus disponible solo ou multi (1 chance sur 25). Multi :...

Version 9.4 : Tir et bonus disponible solo ou multi (1 chance sur 25). Multi : Orienté vers le joueur le plus proche. Chacun son tir
parent c1df13e3
......@@ -171,7 +171,17 @@ public class GameController {
// Modification de la vitesse de la bale si collision
if (colBonus == 1) {
gameModel.destroyBonus();
gameModel.getEvents().setCanShoot(true);
gameModel.getBat().setCanShoot(true);
}
}
// Si le bonus est encore présent, et que la bat2 existe
if(gameModel.getBonus() != null && gameModel.getBat2() != null) {
int colBonus = collides(gameModel.getBonus(), gameModel.getBat2());
// Modification de la vitesse de la bale si collision
if (colBonus == 1) {
gameModel.destroyBonus();
gameModel.getBat2().setCanShoot(true);
}
}
......@@ -183,7 +193,7 @@ public class GameController {
Brick b = brickGroup.getBrick(i);
int colB = collides(gameModel.getBall(), b);
// Modification de la vitesse de la bale si collision
// Modification de la vitesse de la balle si collision
if(colB != 0) {
mp = MediaPlayer.create(context, R.raw.brickdelete);
mp.start();
......@@ -215,11 +225,11 @@ public class GameController {
}
if(gameModel.getShoot() != null) {
gameModel.getShoot().setY(gameModel.getShoot().getY() - 2);
gameModel.getShoot().setY(gameModel.getShoot().getY() - gameModel.getShoot().getSpeed());
}
if(gameModel.getBonus() != null) {
gameModel.getBonus().setY(gameModel.getBonus().getY() + 2);
gameModel.getBonus().setY(gameModel.getBonus().getY() + gameModel.getBonus().getSpeed());
}
// calcule le nouveau centre de la balle
......@@ -312,7 +322,15 @@ public class GameController {
int i = r.nextInt(26);
Log.d("Random", "" + i);
if(i == 0) {
gameModel.createBonus(x,y);
int s = 2;
if(gameModel.getBat2() != null && y < gameModel.getGround().getHeight()/2)
s = -2;
Log.d("height",""+gameModel.getGround().getHeight());
Log.d("y",""+y);
Log.d("s",""+s);
gameModel.createBonus(x,y,s);
}
}
......@@ -437,10 +455,18 @@ public class GameController {
/**
* Tir dans le jeu, pour détruire une brique
*/
public void tirer() {
if(gameModel.getEvents().isCanShoot()) {
gameModel.getEvents().setCanShoot(false);
gameModel.createShoot(gameModel.getBat().getX() + gameModel.getBat().getWidth()/2, gameModel.getBat().getY());
public void tirer(int j) {
Bat currentBat = null;
int vitesse = 2;
if(j == 1) {
currentBat = gameModel.getBat();
} else {
vitesse = -vitesse;
currentBat = gameModel.getBat2();
}
if(currentBat.isCanShoot()) {
currentBat.setCanShoot(false);
gameModel.createShoot(currentBat.getX() + currentBat.getWidth() / 2, currentBat.getY(),vitesse);
}
}
......
......@@ -9,6 +9,7 @@ public class Bat {
private int y;
private int width = 60;
private int height = 20;
private boolean canShoot = false;
public Bat(int xi, int yi) {
x = xi;
......@@ -46,4 +47,12 @@ public class Bat {
public void setHeight(int height) {
this.height = height;
}
public boolean isCanShoot() {
return canShoot;
}
public void setCanShoot(boolean canShoot) {
this.canShoot = canShoot;
}
}
......@@ -7,10 +7,12 @@ public class Bonus {
private float x;
private float y;
private int rayon = 5;
private int speed = 2;
public Bonus(int xi, int yi) {
public Bonus(int xi, int yi, int s) {
x = xi;
y = yi;
speed = s;
}
public float getX() {
......@@ -36,4 +38,12 @@ public class Bonus {
public void setY(float y) {
this.y = y;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
}
......@@ -5,7 +5,6 @@ package com.example.rleger.cassebrique.Model;
*/
public class Evenements {
private int score = 0;
private boolean canShoot = false;
public int getScore() {
return score;
......@@ -18,12 +17,4 @@ public class Evenements {
public void addScore() {
this.score += 10;
}
public boolean isCanShoot() {
return canShoot;
}
public void setCanShoot(boolean canShoot) {
this.canShoot = canShoot;
}
}
......@@ -26,7 +26,6 @@ public class GameModel{
ball = new Ball(15,15);
events = new Evenements();
brickGroups = new ArrayList<>();
events.setCanShoot(true);
}
public Ground getGround() {
......@@ -93,8 +92,8 @@ public class GameModel{
this.shoot = shoot;
}
public void createShoot(int x, int y) {
this.shoot = new Shoot(x,y);
public void createShoot(int x, int y, int s) {
this.shoot = new Shoot(x,y,s);
}
public void destroyShoot() {
......@@ -109,8 +108,8 @@ public class GameModel{
this.bonus = bonus;
}
public void createBonus(int x, int y) {
this.bonus = new Bonus(x,y);
public void createBonus(int x, int y, int s) {
this.bonus = new Bonus(x,y,s);
}
public void destroyBonus() {
......
......@@ -8,10 +8,12 @@ public class Shoot {
private int y = 0;
private int width = 5;
private int height = 20;
private int speed = 2;
public Shoot(int xi, int yi) {
public Shoot(int xi, int yi, int s) {
x = xi;
y = yi;
speed = s;
}
public Shoot() {}
......@@ -47,4 +49,12 @@ public class Shoot {
public void setHeight(int height) {
this.height = height;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
}
......@@ -158,7 +158,7 @@ public class GameView extends View {
shoot.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
gameControlleur.tirer();
gameControlleur.tirer(1);
}
return false;
}
......@@ -225,7 +225,7 @@ public class GameView extends View {
int hBat = gameControlleur.getGameModel().getBat().getHeight();
canvas.drawRoundRect(xBat, yBat, xBat + wBat, yBat + hBat, 7, 7, paintBat);
if(gameControlleur.getGameModel().getEvents().isCanShoot())
if(gameControlleur.getGameModel().getBat().isCanShoot())
paintCursor.setARGB(200, 255, 0, 255);
else
paintCursor.setARGB(200, 200, 200, 200);
......@@ -243,6 +243,11 @@ public class GameView extends View {
canvas.drawRoundRect(xBat2, yBat2, xBat2 + wBat2, yBat2 + hBat2, 7, 7, paintBat2);
if(gameControlleur.getGameModel().getBat2().isCanShoot())
paintCursor.setARGB(200, 255, 0, 255);
else
paintCursor.setARGB(200, 200, 200, 200);
// Curseur de la bat 2
canvas.drawCircle(xBat2 + wBat2 / 2, yBat2 - 20, 7, paintCursor);
}
......@@ -292,6 +297,7 @@ public class GameView extends View {
public boolean onTouchEvent(MotionEvent event) {
int yMax;
int yMin = 0;
int yMid = 0;
//Log.d("View : ", "onTouchEvent");
switch (event.getAction()) {
case (MotionEvent.ACTION_MOVE):
......@@ -299,21 +305,25 @@ public class GameView extends View {
int x = (int) event.getX();
int y = (int) event.getY();
if(gameControlleur.getGameModel().getBat2() != null)
if(gameControlleur.getGameModel().getBat2() != null) {
yMin = gameControlleur.getGameModel().getBat2().getY() - gameControlleur.getGameModel().getBat().getHeight();
yMid = gameControlleur.getGameModel().getGround().getHeight()/2;
}
yMax = gameControlleur.getGameModel().getBat().getY() + gameControlleur.getGameModel().getBat().getHeight();
// Action à effectuer
if(methode == 2) {
gameControlleur.tirer();
gameControlleur.tirer(1);
} else if (methode == 0){
if (y > yMax) {
gameControlleur.moveBat(x);
} else if (y < yMin){
gameControlleur.moveBat2(x);
} else if (y < yMid && yMid != 0){
gameControlleur.tirer(2);
} else {
gameControlleur.tirer();
gameControlleur.tirer(1);
}
}
break;
......@@ -322,21 +332,25 @@ public class GameView extends View {
x = (int) event.getX();
y = (int) event.getY();
if(gameControlleur.getGameModel().getBat2() != null)
if(gameControlleur.getGameModel().getBat2() != null) {
yMin = gameControlleur.getGameModel().getBat2().getY() - gameControlleur.getGameModel().getBat().getHeight();
yMid = gameControlleur.getGameModel().getGround().getHeight()/2;
}
yMax = gameControlleur.getGameModel().getBat().getY() + gameControlleur.getGameModel().getBat().getHeight();
// Action à effectuer
if(methode == 2) {
gameControlleur.tirer();
gameControlleur.tirer(1);
} else if (methode == 0){
if (y > yMax) {
gameControlleur.moveBat(x);
} else if (y < yMin){
gameControlleur.moveBat2(x);
} else if (y < yMid && yMid != 0){
gameControlleur.tirer(2);
} else {
gameControlleur.tirer();
gameControlleur.tirer(1);
}
}
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