Commit 40ef8205 authored by Rominho15's avatar Rominho15
Browse files

Version 9.2 : Tir disponible (au début du jeu seulement)

parent 834255f5
......@@ -12,6 +12,7 @@ import com.example.rleger.cassebrique.Model.Bat;
import com.example.rleger.cassebrique.Model.Brick;
import com.example.rleger.cassebrique.Model.BrickGroup;
import com.example.rleger.cassebrique.Model.GameModel;
import com.example.rleger.cassebrique.Model.Shoot;
import com.example.rleger.cassebrique.R;
import com.example.rleger.cassebrique.Screen.BetweenLevelActivity;
import com.example.rleger.cassebrique.Screen.EndActivity;
......@@ -115,7 +116,7 @@ public class GameController {
}
/**
* Met à jour le jeu (déplacement de la balle)
* Met à jour le jeu (déplacement de la balle et du tir)
*/
public void update() {
......@@ -182,9 +183,26 @@ public class GameController {
this.endGame(true);
}
}
if(gameModel.getShoot() != null) {
if(collides(gameModel.getShoot(), b)){
mp = MediaPlayer.create(context, R.raw.brickdelete);
mp.start();
gameModel.destroyShoot();
brickGroup.destroyBrick(b);
gameModel.getEvents().addScore();
if(gameModel.getNbBricks() == 0) {
this.endGame(true);
}
}
}
}
}
if(gameModel.getShoot() != null) {
gameModel.getShoot().setY(gameModel.getShoot().getY() - 2);
}
// calcule le nouveau centre de la balle
cx+=vx;
cy+=vy;
......@@ -367,11 +385,27 @@ public class GameController {
}
public boolean collides(Shoot s, Brick br) {
int[] rect1 = {s.getX(),s.getX()+s.getWidth(),s.getY(),s.getY()+s.getHeight()};
int[] rect2 = {br.getX(),br.getX()+br.getWidth(),br.getY(),br.getY()+br.getHeight()};
return collidesRect(rect1,rect2);
}
public boolean collidesRect(int[] rect1, int[] rect2) {
return (rect1[0] < rect2[1] && rect1[1] > rect2[0] && rect1[2] < rect2[3] && rect1[3] > rect2[2]);
}
/**
* 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());
}
}
/**
......
......@@ -6,6 +6,7 @@ package com.example.rleger.cassebrique.Model;
public class Evenements {
private int score = 0;
private int bonus = 0;
private boolean canShoot = false;
public int getScore() {
return score;
......@@ -30,4 +31,12 @@ public class Evenements {
public void addBonus() {
this.bonus++;
}
public boolean isCanShoot() {
return canShoot;
}
public void setCanShoot(boolean canShoot) {
this.canShoot = canShoot;
}
}
......@@ -14,6 +14,7 @@ public class GameModel{
private Ground ground;
private ArrayList<BrickGroup> brickGroups;
private Evenements events;
private Shoot shoot;
public GameModel(int p) {
bat = new Bat(50,50);
......@@ -24,6 +25,7 @@ public class GameModel{
ball = new Ball(15,15);
events = new Evenements();
brickGroups = new ArrayList<>();
events.setCanShoot(true);
}
public Ground getGround() {
......@@ -82,6 +84,22 @@ public class GameModel{
return brickGroups.size();
}
public Shoot getShoot() {
return shoot;
}
public void setShoot(Shoot shoot) {
this.shoot = shoot;
}
public void createShoot(int x, int y) {
this.shoot = new Shoot(x,y);
}
public void destroyShoot() {
this.shoot = null;
}
public int getNbBricks() {
int size = 0;
for (BrickGroup gb : brickGroups) {
......
package com.example.rleger.cassebrique.Model;
/**
* Created by Utilisateur on 17/01/2016.
*/
public class Shoot {
private int x = 0;
private int y = 0;
private int width = 5;
private int height = 20;
public Shoot(int xi, int yi) {
x = xi;
y = yi;
}
public Shoot() {}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
}
......@@ -34,9 +34,6 @@ public class EndActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_end);
mp = MediaPlayer.create(this, R.raw.lp);
mp.start();
// Récupération des paramètres
Bundle extras = getIntent().getExtras();
score = extras.getInt("val_score");
......@@ -45,6 +42,11 @@ public class EndActivity extends AppCompatActivity {
if(!extras.getBoolean("win")) {
TextView TVwin = (TextView) findViewById(R.id.messageWin);
TVwin.setText(R.string.Failed);
mp = MediaPlayer.create(this, R.raw.lp);
mp.start();
} else {
mp = MediaPlayer.create(this, R.raw.win);
mp.start();
}
// Affichage score
......
......@@ -26,6 +26,8 @@ public class GameView extends View {
Paint paintBrick;
Paint paintBat;
Paint paintBat2;
Paint paintShoot;
Paint paintCursor;
GameController gameControlleur;
int methode;
Button left;
......@@ -55,6 +57,12 @@ public class GameView extends View {
paintBat2=new Paint();
paintBat2.setARGB(255, 0, 255, 0);
paintShoot=new Paint();
paintShoot.setARGB(255, 255, 0, 255);
paintCursor=new Paint();
paintCursor.setARGB(200, 200, 200, 200);
}
/**
......@@ -146,7 +154,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();
}
return false;
}
......@@ -181,6 +189,12 @@ public class GameView extends View {
paintBat2=new Paint();
paintBat2.setARGB(255, 0, 255, 0);
paintShoot=new Paint();
paintShoot.setARGB(255, 255, 0, 255);
paintCursor=new Paint();
paintCursor.setARGB(200, 200, 200, 200);
}
/**
......@@ -204,8 +218,13 @@ 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())
paintCursor.setARGB(200, 255, 0, 255);
else
paintCursor.setARGB(200, 200, 200, 200);
// Curseur de la bat 1
canvas.drawCircle(xBat + wBat / 2, yBat + hBat + 20, 7, paintBall);
canvas.drawCircle(xBat + wBat / 2, yBat + hBat + 20, 7, paintCursor);
// Si multijoueur
if(gameControlleur.getGameModel().getBat2() != null) {
......@@ -218,7 +237,7 @@ public class GameView extends View {
canvas.drawRoundRect(xBat2, yBat2, xBat2 + wBat2, yBat2 + hBat2, 7, 7, paintBat2);
// Curseur de la bat 2
canvas.drawCircle(xBat2 + wBat2 / 2, yBat2 - 20, 7, paintBall);
canvas.drawCircle(xBat2 + wBat2 / 2, yBat2 - 20, 7, paintCursor);
}
// Affichage des briques
......@@ -240,6 +259,14 @@ public class GameView extends View {
}
}
}
if(gameControlleur.getGameModel().getShoot() != null) {
int xShoot = gameControlleur.getGameModel().getShoot().getX();
int yShoot = gameControlleur.getGameModel().getShoot().getY();
int wShoot = gameControlleur.getGameModel().getShoot().getWidth();
int hShoot = gameControlleur.getGameModel().getShoot().getHeight();
canvas.drawRoundRect(xShoot, yShoot, xShoot + wShoot, yShoot + hShoot, 7, 7, paintShoot);
}
}
/**
......
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