Skip to content
Snippets Groups Projects
Commit ed10ca7c authored by Azurlors's avatar Azurlors
Browse files

De rien pour la Cam

parent 42204f31
Branches
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ import java.awt.Graphics; ...@@ -9,6 +9,7 @@ import java.awt.Graphics;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import javax.swing.JPanel; import javax.swing.JPanel;
import static jeu.Jeu.getGameCharacter;
public class DrawingPanel extends JPanel { public class DrawingPanel extends JPanel {
...@@ -89,8 +90,16 @@ public class DrawingPanel extends JPanel { ...@@ -89,8 +90,16 @@ public class DrawingPanel extends JPanel {
*/ */
public void paint(Graphics g) { public void paint(Graphics g) {
super.paint(g); super.paint(g);
g.drawImage(this.currentImage, 0, 0, getWidth(), getHeight(), 0, 0, if (getGameCharacter().getCoord() != null){
getWidth(), getHeight(), null); int x = (int) getGameCharacter().getCoord().getX();
int z = (int) getGameCharacter().getCoord().getZ();
g.drawImage(this.currentImage, 0,0, getWidth(), getHeight(),0, 0, getWidth(), getHeight(), null);
}
else {
g.drawImage(this.currentImage, 0,0, getWidth(), getHeight()+100, 0, 0,
getWidth(), getHeight(), null);
System.out.println("test");
}
} }
} }
...@@ -27,14 +27,11 @@ public class Character extends Entity{ ...@@ -27,14 +27,11 @@ public class Character extends Entity{
private Map<String,Double> tableCommande; //table des commandes du perso private Map<String,Double> tableCommande; //table des commandes du perso
//private BufferedImage sprite; //private BufferedImage sprite;
public Character(Coordonnees c, double vitesseMax, double m, double impSaut){ public Character(Coordonnees c, double vitesseMax, double m, double impSaut){
super(c,vitesseMax,30,60,1); // comme tous les entities ont une hitbox, j'ai factorise super(c,vitesseMax,30,60,1); // comme tous les entities ont une hitbox, j'ai factorise
this.masse = m; this.masse = m;
this.impulsionSaut = impSaut; this.impulsionSaut = impSaut;
this.tableCommande = new HashMap<>(); this.tableCommande = new HashMap<>();
tableCommande.put("CommandX",(double)0); tableCommande.put("CommandX",(double)0);
tableCommande.put("CommandZ",(double)0); tableCommande.put("CommandZ",(double)0);
......
...@@ -23,6 +23,11 @@ public class Jeu implements Game{ ...@@ -23,6 +23,11 @@ public class Jeu implements Game{
//coordonnees du sol //coordonnees du sol
//private static Coordonnees coordSol = new Coordonnees(200,700); //coordonnees du sol (en realite juste Z nous interesse) //private static Coordonnees coordSol = new Coordonnees(200,700); //coordonnees du sol (en realite juste Z nous interesse)
//Coordonees de debut du personnage
static final double zdebut = 300;
static final double xdebut = 300;
//perso //perso
static Character gameCharacter; static Character gameCharacter;
...@@ -107,7 +112,7 @@ public class Jeu implements Game{ ...@@ -107,7 +112,7 @@ public class Jeu implements Game{
//on charge le perso (a la fin du constructeur, cest important par rapport a obstacleTable, sinon y'a des pbs de "causalite") //on charge le perso (a la fin du constructeur, cest important par rapport a obstacleTable, sinon y'a des pbs de "causalite")
gameCharacterLoader = new CharacterLoader(characterSkinPath,new Character(new Coordonnees(300, 300), 2000, 1,600000)); gameCharacterLoader = new CharacterLoader(characterSkinPath,new Character(new Coordonnees(300, 300), 2000, 1,600000));
gameCharacter = new Character(new Coordonnees(300, 300), 2000, 1,600000); gameCharacter = new Character(new Coordonnees(xdebut, zdebut), 2000, 1,600000);
//on remplit la map des frames //on remplit la map des frames
Map<String,Integer> tempMap = gameCharacterLoader.getPathTable(); Map<String,Integer> tempMap = gameCharacterLoader.getPathTable();
...@@ -174,11 +179,11 @@ public class Jeu implements Game{ ...@@ -174,11 +179,11 @@ public class Jeu implements Game{
//si on a change de mouvement, le jeu doit redemarrer a la premiere frame correspondante //si on a change de mouvement, le jeu doit redemarrer a la premiere frame correspondante
//System.out.println(numberOfMovement); //System.out.println(numberOfMovement);
if (previousMovement != movement){numberOfMovement = 1;nbBeforeFramechgt = nbIterationPerFrame;} if ( !previousMovement.equals(movement)){numberOfMovement = 1;nbBeforeFramechgt = nbIterationPerFrame;}
if (numberOfMovement == gameCharacterLoader.getPathTable().get(movement)){ if (numberOfMovement == gameCharacterLoader.getPathTable().get(movement)){
//System.out.println(movement); //System.out.println(movement);
//characterNotMoving = true; //characterNotMoving = true;
if (movement == "character_attack"){ if (movement.equals("character_attack")){
characterAttacking = false; characterAttacking = false;
} }
} }
......
...@@ -25,31 +25,36 @@ public class Painter implements GamePainter{ ...@@ -25,31 +25,36 @@ public class Painter implements GamePainter{
public static Obstacle test = new Obstacle(new HitBox(new Coordonnees(300,550),32,128)); public static Obstacle test = new Obstacle(new HitBox(new Coordonnees(300,550),32,128));
private static Coordonnees coordonneesCam;
private int xCam;
private int zCam;
public Painter() { public Painter() {
} }
@Override @Override
public void draw(BufferedImage im) { public void draw(BufferedImage im) {
coordonneesCam = gameCharacter.getCoord();
xCam = -WIDTH/2 + (int) coordonneesCam.getX();
zCam = -HEIGHT/2 +(int) coordonneesCam.getZ();
Graphics2D crayon = (Graphics2D) im.getGraphics(); Graphics2D crayon = (Graphics2D) im.getGraphics();
crayon.setColor(Color.blue); crayon.setColor(Color.blue);
drawCharacter(crayon,gameCharacterLoader.getImageCharacter()); drawCharacter(crayon,gameCharacterLoader.getImageCharacter());
//drawQuadrillage(crayon);*/
drawMap(crayon); drawMap(crayon);
drawSol(crayon); drawSol(crayon);
drawObstacleBis(crayon,test,"plateforme.png"); drawObstacleBis(crayon,test,"plateforme.png"); // A changer
drawLifePoints(crayon); drawLifePoints(crayon);
drawMonsters(crayon); drawMonsters(crayon);
} }
private void drawCharacter(Graphics2D crayon,Image imageCharac){ private void drawCharacter(Graphics2D crayon,Image imageCharac){
int x = (int) gameCharacter.getCoord().getX(); crayon.fillRect(WIDTH/2-(int) gameCharacter.getEntityWIDTH()/2,WIDTH/2-(int) gameCharacter.getEntityHEIGHT()/2, (int) gameCharacter.getEntityWIDTH(),(int) gameCharacter.getEntityHEIGHT());
int y = (int) gameCharacter.getCoord().getZ(); crayon.drawRect(WIDTH/2-500,WIDTH/2-500, 1000,1000);
crayon.fillRect(x-(int) gameCharacter.getEntityWIDTH()/2,y-(int) gameCharacter.getEntityHEIGHT()/2, (int) gameCharacter.getEntityWIDTH(),(int) gameCharacter.getEntityHEIGHT()); crayon.drawImage(imageCharac, WIDTH/2- (int) gameCharacter.getEntityWIDTH()/2-10, HEIGHT/2 - (int) gameCharacter.getEntityHEIGHT()/2-3, null, null);
crayon.drawRect(x-500,y-500, 1000,1000);
crayon.drawImage(imageCharac, x-(int) gameCharacter.getEntityWIDTH()/2-10, y- (int) gameCharacter.getEntityHEIGHT()/2-3, null, null);
} }
...@@ -78,10 +83,10 @@ public class Painter implements GamePainter{ ...@@ -78,10 +83,10 @@ public class Painter implements GamePainter{
Coordonnees hg = extremites.get("HautGauche"); Coordonnees hg = extremites.get("HautGauche");
Coordonnees bg = extremites.get("BasGauche"); Coordonnees bg = extremites.get("BasGauche");
if (HitBox.collision(gameCharacter.getVoisinage(), obstacle.getHitbox()))crayon.setColor(Color.green); if (HitBox.collision(gameCharacter.getVoisinage(), obstacle.getHitbox()))crayon.setColor(Color.green);
crayon.drawLine((int)hd.getX(),(int)hd.getZ(),(int)bd.getX(),(int)bd.getZ()); crayon.drawLine((int)hd.getX() - xCam,(int)hd.getZ() - zCam,(int)bd.getX() - xCam,(int)bd.getZ() - zCam);
crayon.drawLine((int)bd.getX(),(int)bd.getZ(),(int)bg.getX(),(int)bg.getZ()); crayon.drawLine((int)bd.getX() - xCam,(int)bd.getZ() - zCam,(int)bg.getX() - xCam,(int)bg.getZ() - zCam);
crayon.drawLine((int)bg.getX(),(int)bg.getZ(),(int)hg.getX(),(int)hg.getZ()); crayon.drawLine((int)bg.getX() - xCam,(int)bg.getZ() - zCam,(int)hg.getX() - xCam,(int)hg.getZ() - zCam);
crayon.drawLine((int)hg.getX(),(int)hg.getZ(),(int)hd.getX(),(int)hd.getZ()); crayon.drawLine((int)hg.getX() - xCam,(int)hg.getZ() - zCam,(int)hd.getX() - xCam,(int)hd.getZ() - zCam);
} }
/*private void drawCoffre(Graphics2D crayon, Coffre coffre){ /*private void drawCoffre(Graphics2D crayon, Coffre coffre){
...@@ -102,7 +107,7 @@ public class Painter implements GamePainter{ ...@@ -102,7 +107,7 @@ public class Painter implements GamePainter{
HitBox hitBox = loader.getObstacle().getHitbox(); HitBox hitBox = loader.getObstacle().getHitbox();
int z = (int) hitBox.getCentre().getZ(); int z = (int) hitBox.getCentre().getZ();
for (int x = 0;x<3000;x+=128) { for (int x = 0;x<3000;x+=128) {
crayon.drawImage(loader.getImageObstacle(),x,z ,null,null); crayon.drawImage(loader.getImageObstacle(),x -xCam ,z - zCam,null,null);
} }
} }
...@@ -132,7 +137,7 @@ public class Painter implements GamePainter{ ...@@ -132,7 +137,7 @@ public class Painter implements GamePainter{
HitBox hitBox = loader.getObstacle().getHitbox(); HitBox hitBox = loader.getObstacle().getHitbox();
int z = (int) hitBox.getCentre().getZ(); int z = (int) hitBox.getCentre().getZ();
int x = (int) hitBox.getCentre().getX(); int x = (int) hitBox.getCentre().getX();
crayon.drawImage(loader.getImageObstacle(), x - (int) hitBox.getWidth()/2,z - (int) hitBox.getHeight()/2,null,null); crayon.drawImage(loader.getImageObstacle(), x - (int) hitBox.getWidth()/2 -xCam,z - (int) hitBox.getHeight()/2 -zCam,null,null);
} }
/*private void drawCoffreBis(Graphics2D crayon, Coffre coffre, String nom){ /*private void drawCoffreBis(Graphics2D crayon, Coffre coffre, String nom){
...@@ -152,9 +157,9 @@ public class Painter implements GamePainter{ ...@@ -152,9 +157,9 @@ public class Painter implements GamePainter{
x = (int)monster.getCoord().getX(); x = (int)monster.getCoord().getX();
z = (int)monster.getCoord().getZ(); z = (int)monster.getCoord().getZ();
crayon.drawRect(x-300, z-300, 600, 600); crayon.drawRect(x-300 - xCam, z-300 - zCam, 600, 600);
if (HitBox.collision(gameCharacter.getHitBox(),monster.getHitBox()))crayon.setColor(Color.red); if (HitBox.collision(gameCharacter.getHitBox(),monster.getHitBox()))crayon.setColor(Color.red);
crayon.fillRect(x-(int)monster.getEntityWIDTH()/2, z-(int)monster.getEntityHEIGHT()/2, (int)monster.getEntityWIDTH(), (int)monster.getEntityHEIGHT()); crayon.fillRect(x-(int)monster.getEntityWIDTH()/2 - xCam, z-(int)monster.getEntityHEIGHT()/2 - zCam, (int)monster.getEntityWIDTH(), (int)monster.getEntityHEIGHT());
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment