Advertisement
Mirelawiel

coordonnees

Feb 5th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.42 KB | None | 0 0
  1. package com.mygdx.game;
  2.  
  3. import com.badlogic.gdx.Gdx;
  4. import com.badlogic.gdx.Input.Keys;
  5. import com.badlogic.gdx.graphics.GL20;
  6. import com.badlogic.gdx.graphics.OrthographicCamera;
  7. import com.badlogic.gdx.graphics.Texture;
  8. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  9. import com.badlogic.gdx.graphics.g2d.TextureRegion;
  10. import com.badlogic.gdx.maps.MapLayers;
  11. import com.badlogic.gdx.maps.tiled.TiledMap;
  12. import com.badlogic.gdx.maps.tiled.TiledMapTile;
  13. import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
  14. import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell;
  15. import com.badlogic.gdx.maps.tiled.renderers.HexagonalTiledMapRenderer;
  16. import com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile;
  17. import com.badlogic.gdx.scenes.scene2d.InputEvent;
  18. import com.badlogic.gdx.scenes.scene2d.Stage;
  19. import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
  20. import com.badlogic.gdx.scenes.scene2d.ui.Skin;
  21. import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
  22. import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
  23.  
  24. public class GameState extends State {
  25.  
  26.     private Stage stage;
  27.     private TiledMap map;
  28.     private OrthographicCamera camera;
  29.     private HexagonalTiledMapRenderer renderer;
  30.     private Texture background;
  31.     private ButtonHud buttonhud;
  32.    
  33.     private SpriteBatch batch;
  34.     private SpriteBatch batch2;
  35.     private Texture tuiletest;
  36.  
  37.     private Texture hexture;
  38.     private Hud hud;
  39.     private Skin skin;
  40.  
  41.     private Texture tresor1j1;
  42.    
  43.     private Joueur j1;
  44.     private Joueur j2;
  45.     private Joueur j3;
  46.     private Joueur j4;
  47.     private Joueur actif;
  48.  
  49.  
  50.     public GameState(GameStateManager gsm) {
  51.         super(gsm);
  52.         float w = 128;
  53.         float h = 128;
  54.         tresor1j1 = new Texture(Gdx.files.internal("Tresor1.png"));
  55.         TextureRegion tresor1j1R = new TextureRegion(tresor1j1,0,0,125,110);
  56.         skin = new Skin(Gdx.files.internal("ui/defaultskin.json"));
  57.        
  58.  
  59.         background = new Texture(Gdx.files.internal("backgroundJeux1.png"));
  60.  
  61.         j1 = new Joueur("Joueur 1");
  62.         j2 = new Joueur("Joueur 2");
  63.         j3 = new Joueur("Joueur 3");
  64.         j4 = new Joueur("Joueur 4");
  65.        
  66.         Tresor t1 = new Tresor("Tresor");
  67.         j1.ajouterTresor(t1);
  68.         actif = j4;
  69.  
  70.         camera = new OrthographicCamera();
  71.         camera.setToOrtho(false, (w / h) * 1100, 825);// 780,640 1170,960
  72.         camera.update();
  73.  
  74.         stage = new Stage();
  75.         Gdx.input.setInputProcessor(stage);
  76.         hexture = new Texture("test.png");
  77.         hud = new Hud(gsm);
  78.        
  79.         batch = new SpriteBatch();
  80.         batch2 = new SpriteBatch();
  81.         tuiletest = new Texture(Gdx.files.internal("testtuile.png"));
  82.         TextureRegion tuiletests;
  83.         tuiletests = new TextureRegion(tuiletest,0,0,125,110);
  84.  
  85.         // Création de la carte
  86.         TextureRegion[][] hexes = TextureRegion.split(hexture, 125, 110);
  87.         map = new TiledMap();
  88.         MapLayers layers = map.getLayers();
  89.         TiledMapTile[] tiles = new TiledMapTile[3];
  90.         tiles[0] = new StaticTiledMapTile(new TextureRegion(hexes[0][0]));
  91.  
  92.         for (int l = 0; l < 5; l++) {
  93.             TiledMapTileLayer layer = new TiledMapTileLayer(8, 5, 125, 110);// 8,5,125,110
  94.             for (int y = 0; y < 5; y++) {
  95.                 for (int x = 0; x < 8; x++) {
  96.                     int id = 0;
  97.                     Cell cell = new Cell();
  98.                     cell.setTile(tiles[id]);
  99.                     layer.setCell(x, y, cell);
  100.                     System.out.println("x :" + x + " " + "y : " + y + " " + "cell :" + cell);
  101.                 }
  102.             }
  103.             layers.add(layer);
  104.         }
  105.         renderer = new HexagonalTiledMapRenderer(map);
  106.         j1.setActif();
  107.         tourSuivant();// Initialisation du tour avec le Joueur1
  108.    
  109.        
  110.    
  111.     // Tous les boutons de l'interface
  112.     TextButton buttonPion = new TextButton("Placer un pion", skin);
  113.     buttonPion.setBounds(705, 475, 200, 45);
  114.     stage.addActor(buttonPion);
  115.     buttonPion.addListener(new ClickListener() {
  116.         @Override
  117.         public void clicked(InputEvent event, float x, float y) {
  118.             System.out.println("Place un pion");
  119.             if (actif.placerPionPoint() == false) {
  120.                 notEnoughPoint();
  121.             }
  122.             hud.updateTour(actif);
  123.         }
  124.     });
  125.  
  126.     TextButton buttonPionMouv = new TextButton("Deplacer un pion", skin);
  127.     buttonPionMouv.setBounds(705, 427, 200, 45);
  128.     stage.addActor(buttonPionMouv);
  129.     buttonPionMouv.addListener(new ClickListener() {
  130.         @Override
  131.         public void clicked(InputEvent event, float x, float y) {
  132.             System.out.println("Delace un pion");
  133.             if (actif.deplacerPionPoint() == false) {
  134.                 notEnoughPoint();
  135.             }
  136.         }
  137.     });
  138.  
  139.     TextButton buttonComapement = new TextButton("Placer un campement", skin);
  140.     buttonComapement.setBounds(705, 379, 200, 45);
  141.     stage.addActor(buttonComapement);
  142.     buttonComapement.addListener(new ClickListener() {
  143.         @Override
  144.         public void clicked(InputEvent event, float x, float y) {
  145.             System.out.println("Place un campement");
  146.             if (actif.placerCampementPoint() == false) {
  147.                 notEnoughPoint();
  148.             }
  149.             hud.updateTour(actif);
  150.         }
  151.     });
  152.  
  153.     TextButton buttonDeterrerTresor = new TextButton("Deterrer un tresor", skin);
  154.     buttonDeterrerTresor.setBounds(705, 331, 200, 45);
  155.     stage.addActor(buttonDeterrerTresor);
  156.     buttonDeterrerTresor.addListener(new ClickListener() {
  157.         @Override
  158.         public void clicked(InputEvent event, float x, float y) {
  159.             System.out.println("Deterrer un tresor");
  160.             if (actif.deterrerTresorPoint() == false) {
  161.                 notEnoughPoint();
  162.             }
  163.             hud.updateTour(actif);
  164.         }
  165.     });
  166.  
  167.     TextButton buttonEchangerTresor = new TextButton("Echanger un tresor", skin);
  168.     buttonEchangerTresor.setBounds(705, 283, 200, 45);
  169.     stage.addActor(buttonEchangerTresor);
  170.     buttonEchangerTresor.addListener(new ClickListener() {
  171.         @Override
  172.         public void clicked(InputEvent event, float x, float y) {
  173.             System.out.println("Echanger un tresor");
  174.             actif.Afficher();
  175.             //selectTresorEchange();
  176.         }
  177.     });
  178.  
  179.     TextButton buttonAmeliorerTemple = new TextButton("Ameliorer un temple", skin);
  180.     buttonAmeliorerTemple.setBounds(705, 235, 200, 45);
  181.     stage.addActor(buttonAmeliorerTemple);
  182.     buttonAmeliorerTemple.addListener(new ClickListener() {
  183.         @Override
  184.         public void clicked(InputEvent event, float x, float y) {
  185.             System.out.println("Ameliorer un temple");
  186.             if (actif.AmeliorerTemplePoint() == false) {
  187.                 notEnoughPoint();
  188.             }
  189.             hud.updateTour(actif);
  190.         }
  191.     });
  192.  
  193.     TextButton buttonGardien = new TextButton("Placer un gardien", skin);
  194.     buttonGardien.setBounds(705, 187, 200, 45);
  195.     stage.addActor(buttonGardien);
  196.     buttonGardien.addListener(new ClickListener() {
  197.         @Override
  198.         public void clicked(InputEvent event, float x, float y) {
  199.             System.out.println("Place un gardien");
  200.             if (actif.PlacerGardienPoint()) {
  201.                 notEnoughPoint();
  202.             }
  203.             hud.updateTour(actif);
  204.         }
  205.     });
  206.  
  207.     TextButton buttonTerminerTour = new TextButton("Terminer le tour", skin);
  208.     buttonTerminerTour.setBounds(705, 60, 200, 50);
  209.     stage.addActor(buttonTerminerTour);
  210.     buttonTerminerTour.addListener(new ClickListener() {
  211.         @Override
  212.         public void clicked(InputEvent event, float x, float y) {
  213.             actif.setPa(10);
  214.             tourSuivant();
  215.         }
  216.     });
  217.  
  218.     TextButton buttonQuitter = new TextButton("Quitter la partie", skin);
  219.     buttonQuitter.setBounds(705, 5, 200, 50);
  220.     stage.addActor(buttonQuitter);
  221.     buttonQuitter.addListener(new ClickListener() {
  222.         @Override
  223.         public void clicked(InputEvent event, float x, float y) {
  224.             System.out.println("Quitter");
  225.             Gdx.app.exit();
  226.         }
  227.     });
  228. }
  229.  
  230.     @Override
  231.     public void render(SpriteBatch sb) {
  232.         Gdx.gl.glClearColor(0, 0, 0, 0);
  233.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  234.        
  235.         //Affichage background + image des tresor dans letableau des scores
  236.         batch2.begin();
  237.         batch2.draw(background,0,0);
  238.         for(Tresor t: actif.getTresors()){
  239.             int x = 560;
  240.             int y = 613;
  241.             batch2.draw(tresor1j1,x, y,62, 70, 125, 110, 1, 1, 60, 62, 55, 682, 605, false, false);
  242.             x++;
  243.         }
  244.         batch2.end();
  245.  
  246.         //Affichage boutton + tableau des scores + plateau de jeu
  247.         sb.begin();
  248.         camera.update();
  249.         renderer.setView(camera);
  250.         renderer.render();
  251.         hud.stage.draw();
  252.         hud.stage.draw();
  253.         sb.end();
  254.         stage.draw();
  255.        
  256.         //image sur la carte
  257.         batch.setProjectionMatrix(camera.combined);
  258.         batch.begin();
  259.         batch.draw(tuiletest, 0, 55, 125, 110); //A5
  260.         batch.draw(tuiletest, 0, 165, 125, 110); //A4
  261.         batch.draw(tuiletest, 0, 275, 125, 110); //A3
  262.         batch.draw(tuiletest, 0, 385, 125, 110); //A2
  263.         batch.draw(tuiletest, 0, 495, 125, 110); //A1
  264.        
  265.         batch.draw(tuiletest, 95, 0, 125, 110); //B5
  266.         batch.draw(tuiletest, 95, 110, 125, 110); //B4
  267.         batch.draw(tuiletest, 95, 220, 125, 110); //B3
  268.         batch.draw(tuiletest, 95, 330, 125, 110); //B2
  269.         batch.draw(tuiletest, 95, 440, 125, 110); //B1
  270.        
  271.         batch.draw(tuiletest, 190, 55, 125, 110); //C5
  272.         batch.draw(tuiletest, 190, 165, 125, 110); //C4
  273.         batch.draw(tuiletest, 190, 275, 125, 110); //C3
  274.         batch.draw(tuiletest, 190, 385, 125, 110); //C2
  275.         batch.draw(tuiletest, 190, 495, 125, 110); //C1
  276.        
  277.         batch.draw(tuiletest, 285, 0, 125, 110); //D5
  278.         batch.draw(tuiletest, 285, 110, 125, 110); //D4
  279.         batch.draw(tuiletest, 285, 220, 125, 110); //D3
  280.         batch.draw(tuiletest, 285, 330, 125, 110); //D2
  281.         batch.draw(tuiletest, 285, 440, 125, 110); //D1
  282.        
  283.         batch.draw(tuiletest, 380, 55, 125, 110); //E5
  284.         batch.draw(tuiletest, 380, 165, 125, 110); //E4
  285.         batch.draw(tuiletest, 380, 275, 125, 110); //E3
  286.         batch.draw(tuiletest, 380, 385, 125, 110); //E2
  287.         batch.draw(tuiletest, 380, 495, 125, 110); //E1
  288.        
  289.         batch.draw(tuiletest, 475, 0, 125, 110); //F5
  290.         batch.draw(tuiletest, 475, 110, 125, 110); //F4
  291.         batch.draw(tuiletest, 475, 220, 125, 110); //F3
  292.         batch.draw(tuiletest, 475, 330, 125, 110); //F2
  293.         batch.draw(tuiletest, 475, 440, 125, 110); //F1
  294.        
  295.         batch.draw(tuiletest, 570, 55, 125, 110); //G5
  296.         batch.draw(tuiletest, 570, 165, 125, 110); //G4
  297.         batch.draw(tuiletest, 570, 275, 125, 110); //G3
  298.         batch.draw(tuiletest, 570, 385, 125, 110); //G2
  299.         batch.draw(tuiletest, 570, 495, 125, 110); //G1
  300.        
  301.         batch.draw(tuiletest, 665, 0, 125, 110); //H5
  302.         batch.draw(tuiletest, 665, 110, 125, 110); //H4
  303.         batch.draw(tuiletest, 665, 220, 125, 110); //H3
  304.         batch.draw(tuiletest, 665, 330, 125, 110); //H2
  305.         batch.draw(tuiletest, 665, 440, 125, 110); //H1
  306.        
  307.         //batch.draw(tuiletest, /*x*/ 0,/*y*/ 55, /*alignement case */62, 70, 125, 110, 1, 1,/* degre inclinaison*/ 60, /*angle rotation*/62, 55, 682, 605, false, false);
  308.         batch.end();
  309.     }
  310.  
  311.     @Override
  312.     public void dispose() {
  313.         background.dispose();
  314.         renderer.dispose();
  315.         hexture.dispose();
  316.         map.dispose();
  317.         stage.dispose();
  318.         hud.dispose();
  319.     }
  320.  
  321.     public void push() {
  322.         // TODO Auto-generated method stub
  323.         System.out.println("Envoyé");
  324.     }
  325.  
  326.     @Override
  327.     public void update(float dt) {
  328.         // TODO Auto-generated method stub
  329.  
  330.     }
  331.  
  332.     // Changer le joueur actif
  333.     public void tourSuivant() {
  334.         if (actif == j1) {
  335.             actif = j2;
  336.         } else if (actif == j2) {
  337.             actif = j3;
  338.         } else if (actif == j3) {
  339.             actif = j4;
  340.         } else if (actif == j4) {
  341.             actif = j1;
  342.         }
  343.         hud.updateTour(actif);
  344.     }
  345.  
  346.     // Affichage de la popup vous n'avez pas assez de PA pour jouer
  347.     public void notEnoughPoint() {
  348.         Dialog dialog = new Dialog("Erreur PA", skin, "dialog") {
  349.             public void result(Object obj) {
  350.                 System.out.println("result " + obj);
  351.                 remove();
  352.             }
  353.         };
  354.         dialog.text("Vous n'avez pas assez de point d'action !");
  355.         dialog.button("Ok", true); // sends "true" as the result
  356.         dialog.show(stage);
  357.     }
  358.  
  359. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement