Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider deb7b9b3 rédigé par Pierrick Lermite's avatar Pierrick Lermite
Parcourir les fichiers

modif

parent 157b699f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -9,17 +9,18 @@ import App.Block.Block;
public class GroundDisplay {
private Graphics g;
private Ground ground;
private int blocksize;
public GroundDisplay(Ground gr, Graphics gg){
this.g = gg;
this.ground = gr;
this.blocksize = 60;
}
public void draw(){
Graphics2D[][] l_g = new Graphics2D[ground.getnbX()][ground.getnbY()];
Block[][] grid = ground.getGrid();
int blocksize = 60;
for(int j = 0; j < ground.getnbY(); j++){
for (int i = 0; i < ground.getnbX(); i++){
......@@ -29,6 +30,10 @@ public class GroundDisplay {
l_g[i][j].setColor(Color.white);
l_g[i][j].fillRect(i * blocksize, j * blocksize, blocksize, blocksize);
}
if (grid[i][j].getLife() == 1){
l_g[i][j].setColor(Color.yellow);
l_g[i][j].fillRect(i * blocksize, j * blocksize, blocksize, blocksize);
}
}
}
}
......
......@@ -100,6 +100,9 @@ public class GamePanel extends JPanel implements Runnable{
if(keyH.leftPressed == true && !game.collisionTestBLock(player1,-player1.getSpeed() ,0 )){
player1.addX(-player1.getSpeed());
}
System.out.println(player1.getGridX() + " " + player1.getGridY());
}
public void paintComponent(Graphics g){
super.paintComponent(g);
......
......@@ -26,16 +26,23 @@ public class Ground {
grid[i][j] = new ImbreakableBlock();
}
else{
//Vide
grid[i][j] = new VoidBlock();
//Génération bloc cassable
if(((Math.random()*100) >= 33) &&
!((j == 1 && (i == 1 || i == 2) || (j == 2 && i ==1 ))) &&
!((j == nby - 2 && (i == nbx - 3 || i == nbx - 2 ) || (j == nby - 3 && i == nbx - 2 )))
){
grid[i][j] = new OneLifeBlock();
}
else{
//Vide
grid[i][j] = new VoidBlock();
}
}
}
}
}
}
// A FINIR
public boolean collisionTestBLock(Player p, int dx, int dy){
int boxsizeplayer = 34;
int pX = p.getX();
......
......@@ -8,7 +8,21 @@ public class Player {
public Player(int xx, int yy){
this.x = xx;
this.y = yy;
this.speed = 2;
this.speed = 4;
}
public int getGridX(){
int boxsizebloc = 60;
int boxsizeplayer = 34;
int centerplayer = boxsizeplayer /2;
return (this.x + centerplayer) / boxsizebloc;
}
public int getGridY(){
int boxsizebloc = 60;
int boxsizeplayer = 34;
int centerplayer = boxsizeplayer /2;
return (this.y + centerplayer) / boxsizebloc;
}
public int getX(){
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter