Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. package mygame;
  2.  
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Image;
  6. import javax.swing.ImageIcon;
  7. import javax.swing.JPanel;
  8.  
  9. import GameState.MenuState;
  10.  
  11. // moteur Graphique et physique
  12.  
  13.  
  14. @SuppressWarnings("serial")
  15. public class Scene extends JPanel {
  16. public MenuPause menu;
  17.  
  18. private ImageIcon icoFond;
  19. private Image imgFond1;
  20.  
  21. private ImageIcon icoPlayer;
  22. private Image imgPlayer;
  23. private ImageIcon icoPorte;
  24. private Image imgPorte;
  25.  
  26.  
  27. private int xFond1;
  28.  
  29.  
  30. private int dx;
  31. private int pause;
  32. private int xPos;
  33.  
  34.  
  35. //CONSTRUCTEUR
  36. public Scene(){
  37.  
  38. super();
  39.  
  40. this.xFond1 = 50;
  41. this.pause = 0;
  42. this.dx = 0;
  43. this.xPos = -1 ;
  44.  
  45.  
  46. icoFond = new ImageIcon(getClass().getResource("/Images/FondEcranFinal1.jpg"));
  47. this.imgFond1 = this.icoFond.getImage();
  48. icoPlayer = new ImageIcon(getClass().getResource("/Images/PlayerStandDroitFinal.png"));
  49. this.imgPlayer = this.icoPlayer.getImage();
  50. icoPorte = new ImageIcon(getClass().getResource("/Images/Porte.png"));
  51. this.imgPorte = this.icoPorte.getImage();
  52.  
  53. this.setFocusable(true);
  54. this.requestFocusInWindow();
  55. this.addKeyListener(new InputGame());
  56.  
  57. Thread ChronoEcran = new Thread(new Chrono());
  58. ChronoEcran.start();
  59. }
  60.  
  61. //GETTERS
  62. public int getDx() {return dx;}
  63. public int getxPos() {return xPos;}
  64.  
  65.  
  66.  
  67. //SETTERS
  68. public void setDx(int dx) {this.dx = dx;}
  69. public void setxPos(int xPos) {this.xPos = xPos;}
  70. public void setxFond1(int xFond1) {this.xFond1 = xFond1;}
  71.  
  72.  
  73. //METHODS
  74. public void deplacementFond(){
  75.  
  76. if(this.xPos >=0 ){
  77. this.xPos = this.xPos +this.dx;
  78. this.xFond1 = this.xFond1 - this.dx;;
  79. }
  80. if(this.xFond1 == -1485){this.xFond1 = 1485;}
  81. else if (this.xFond1 == 1485){this.xFond1 = -1485;}
  82. }
  83.  
  84.  
  85.  
  86. public void paintComponent(Graphics g){
  87.  
  88. super.paintComponent(g);
  89. Graphics g2 =(Graphics2D)g;
  90.  
  91. this.deplacementFond();
  92.  
  93. g2.drawImage(this.imgFond1, this.xFond1, 0, null);
  94. g2.drawImage(imgPlayer,300, 485, null);
  95. g2.drawImage(imgPorte,600 - this.xPos, 298, null);
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement