Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mygdx.game;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.Input.Keys;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.OrthographicCamera;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.badlogic.gdx.graphics.g2d.TextureRegion;
- import com.badlogic.gdx.maps.MapLayers;
- import com.badlogic.gdx.maps.tiled.TiledMap;
- import com.badlogic.gdx.maps.tiled.TiledMapTile;
- import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
- import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell;
- import com.badlogic.gdx.maps.tiled.renderers.HexagonalTiledMapRenderer;
- import com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile;
- import com.badlogic.gdx.scenes.scene2d.InputEvent;
- import com.badlogic.gdx.scenes.scene2d.Stage;
- import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
- import com.badlogic.gdx.scenes.scene2d.ui.Skin;
- import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
- import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
- public class GameState extends State {
- private Stage stage;
- private TiledMap map;
- private OrthographicCamera camera;
- private HexagonalTiledMapRenderer renderer;
- private Texture background;
- private ButtonHud buttonhud;
- private SpriteBatch batch;
- private SpriteBatch batch2;
- private Texture tuiletest;
- private Texture hexture;
- private Hud hud;
- private Skin skin;
- private Texture tresor1j1;
- private Joueur j1;
- private Joueur j2;
- private Joueur j3;
- private Joueur j4;
- private Joueur actif;
- public GameState(GameStateManager gsm) {
- super(gsm);
- float w = 128;
- float h = 128;
- tresor1j1 = new Texture(Gdx.files.internal("Tresor1.png"));
- TextureRegion tresor1j1R = new TextureRegion(tresor1j1,0,0,125,110);
- skin = new Skin(Gdx.files.internal("ui/defaultskin.json"));
- background = new Texture(Gdx.files.internal("backgroundJeux1.png"));
- j1 = new Joueur("Joueur 1");
- j2 = new Joueur("Joueur 2");
- j3 = new Joueur("Joueur 3");
- j4 = new Joueur("Joueur 4");
- Tresor t1 = new Tresor("Tresor");
- j1.ajouterTresor(t1);
- actif = j4;
- camera = new OrthographicCamera();
- camera.setToOrtho(false, (w / h) * 1100, 825);// 780,640 1170,960
- camera.update();
- stage = new Stage();
- Gdx.input.setInputProcessor(stage);
- hexture = new Texture("test.png");
- hud = new Hud(gsm);
- batch = new SpriteBatch();
- batch2 = new SpriteBatch();
- tuiletest = new Texture(Gdx.files.internal("testtuile.png"));
- TextureRegion tuiletests;
- tuiletests = new TextureRegion(tuiletest,0,0,125,110);
- // Création de la carte
- TextureRegion[][] hexes = TextureRegion.split(hexture, 125, 110);
- map = new TiledMap();
- MapLayers layers = map.getLayers();
- TiledMapTile[] tiles = new TiledMapTile[3];
- tiles[0] = new StaticTiledMapTile(new TextureRegion(hexes[0][0]));
- for (int l = 0; l < 5; l++) {
- TiledMapTileLayer layer = new TiledMapTileLayer(8, 5, 125, 110);// 8,5,125,110
- for (int y = 0; y < 5; y++) {
- for (int x = 0; x < 8; x++) {
- int id = 0;
- Cell cell = new Cell();
- cell.setTile(tiles[id]);
- layer.setCell(x, y, cell);
- System.out.println("x :" + x + " " + "y : " + y + " " + "cell :" + cell);
- }
- }
- layers.add(layer);
- }
- renderer = new HexagonalTiledMapRenderer(map);
- j1.setActif();
- tourSuivant();// Initialisation du tour avec le Joueur1
- // Tous les boutons de l'interface
- TextButton buttonPion = new TextButton("Placer un pion", skin);
- buttonPion.setBounds(705, 475, 200, 45);
- stage.addActor(buttonPion);
- buttonPion.addListener(new ClickListener() {
- @Override
- public void clicked(InputEvent event, float x, float y) {
- System.out.println("Place un pion");
- if (actif.placerPionPoint() == false) {
- notEnoughPoint();
- }
- hud.updateTour(actif);
- }
- });
- TextButton buttonPionMouv = new TextButton("Deplacer un pion", skin);
- buttonPionMouv.setBounds(705, 427, 200, 45);
- stage.addActor(buttonPionMouv);
- buttonPionMouv.addListener(new ClickListener() {
- @Override
- public void clicked(InputEvent event, float x, float y) {
- System.out.println("Delace un pion");
- if (actif.deplacerPionPoint() == false) {
- notEnoughPoint();
- }
- }
- });
- TextButton buttonComapement = new TextButton("Placer un campement", skin);
- buttonComapement.setBounds(705, 379, 200, 45);
- stage.addActor(buttonComapement);
- buttonComapement.addListener(new ClickListener() {
- @Override
- public void clicked(InputEvent event, float x, float y) {
- System.out.println("Place un campement");
- if (actif.placerCampementPoint() == false) {
- notEnoughPoint();
- }
- hud.updateTour(actif);
- }
- });
- TextButton buttonDeterrerTresor = new TextButton("Deterrer un tresor", skin);
- buttonDeterrerTresor.setBounds(705, 331, 200, 45);
- stage.addActor(buttonDeterrerTresor);
- buttonDeterrerTresor.addListener(new ClickListener() {
- @Override
- public void clicked(InputEvent event, float x, float y) {
- System.out.println("Deterrer un tresor");
- if (actif.deterrerTresorPoint() == false) {
- notEnoughPoint();
- }
- hud.updateTour(actif);
- }
- });
- TextButton buttonEchangerTresor = new TextButton("Echanger un tresor", skin);
- buttonEchangerTresor.setBounds(705, 283, 200, 45);
- stage.addActor(buttonEchangerTresor);
- buttonEchangerTresor.addListener(new ClickListener() {
- @Override
- public void clicked(InputEvent event, float x, float y) {
- System.out.println("Echanger un tresor");
- actif.Afficher();
- //selectTresorEchange();
- }
- });
- TextButton buttonAmeliorerTemple = new TextButton("Ameliorer un temple", skin);
- buttonAmeliorerTemple.setBounds(705, 235, 200, 45);
- stage.addActor(buttonAmeliorerTemple);
- buttonAmeliorerTemple.addListener(new ClickListener() {
- @Override
- public void clicked(InputEvent event, float x, float y) {
- System.out.println("Ameliorer un temple");
- if (actif.AmeliorerTemplePoint() == false) {
- notEnoughPoint();
- }
- hud.updateTour(actif);
- }
- });
- TextButton buttonGardien = new TextButton("Placer un gardien", skin);
- buttonGardien.setBounds(705, 187, 200, 45);
- stage.addActor(buttonGardien);
- buttonGardien.addListener(new ClickListener() {
- @Override
- public void clicked(InputEvent event, float x, float y) {
- System.out.println("Place un gardien");
- if (actif.PlacerGardienPoint()) {
- notEnoughPoint();
- }
- hud.updateTour(actif);
- }
- });
- TextButton buttonTerminerTour = new TextButton("Terminer le tour", skin);
- buttonTerminerTour.setBounds(705, 60, 200, 50);
- stage.addActor(buttonTerminerTour);
- buttonTerminerTour.addListener(new ClickListener() {
- @Override
- public void clicked(InputEvent event, float x, float y) {
- actif.setPa(10);
- tourSuivant();
- }
- });
- TextButton buttonQuitter = new TextButton("Quitter la partie", skin);
- buttonQuitter.setBounds(705, 5, 200, 50);
- stage.addActor(buttonQuitter);
- buttonQuitter.addListener(new ClickListener() {
- @Override
- public void clicked(InputEvent event, float x, float y) {
- System.out.println("Quitter");
- Gdx.app.exit();
- }
- });
- }
- @Override
- public void render(SpriteBatch sb) {
- Gdx.gl.glClearColor(0, 0, 0, 0);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- //Affichage background + image des tresor dans letableau des scores
- batch2.begin();
- batch2.draw(background,0,0);
- for(Tresor t: actif.getTresors()){
- int x = 560;
- int y = 613;
- batch2.draw(tresor1j1,x, y,62, 70, 125, 110, 1, 1, 60, 62, 55, 682, 605, false, false);
- x++;
- }
- batch2.end();
- //Affichage boutton + tableau des scores + plateau de jeu
- sb.begin();
- camera.update();
- renderer.setView(camera);
- renderer.render();
- hud.stage.draw();
- hud.stage.draw();
- sb.end();
- stage.draw();
- //image sur la carte
- batch.setProjectionMatrix(camera.combined);
- batch.begin();
- batch.draw(tuiletest, 0, 55, 125, 110); //A5
- batch.draw(tuiletest, 0, 165, 125, 110); //A4
- batch.draw(tuiletest, 0, 275, 125, 110); //A3
- batch.draw(tuiletest, 0, 385, 125, 110); //A2
- batch.draw(tuiletest, 0, 495, 125, 110); //A1
- batch.draw(tuiletest, 95, 0, 125, 110); //B5
- batch.draw(tuiletest, 95, 110, 125, 110); //B4
- batch.draw(tuiletest, 95, 220, 125, 110); //B3
- batch.draw(tuiletest, 95, 330, 125, 110); //B2
- batch.draw(tuiletest, 95, 440, 125, 110); //B1
- batch.draw(tuiletest, 190, 55, 125, 110); //C5
- batch.draw(tuiletest, 190, 165, 125, 110); //C4
- batch.draw(tuiletest, 190, 275, 125, 110); //C3
- batch.draw(tuiletest, 190, 385, 125, 110); //C2
- batch.draw(tuiletest, 190, 495, 125, 110); //C1
- batch.draw(tuiletest, 285, 0, 125, 110); //D5
- batch.draw(tuiletest, 285, 110, 125, 110); //D4
- batch.draw(tuiletest, 285, 220, 125, 110); //D3
- batch.draw(tuiletest, 285, 330, 125, 110); //D2
- batch.draw(tuiletest, 285, 440, 125, 110); //D1
- batch.draw(tuiletest, 380, 55, 125, 110); //E5
- batch.draw(tuiletest, 380, 165, 125, 110); //E4
- batch.draw(tuiletest, 380, 275, 125, 110); //E3
- batch.draw(tuiletest, 380, 385, 125, 110); //E2
- batch.draw(tuiletest, 380, 495, 125, 110); //E1
- batch.draw(tuiletest, 475, 0, 125, 110); //F5
- batch.draw(tuiletest, 475, 110, 125, 110); //F4
- batch.draw(tuiletest, 475, 220, 125, 110); //F3
- batch.draw(tuiletest, 475, 330, 125, 110); //F2
- batch.draw(tuiletest, 475, 440, 125, 110); //F1
- batch.draw(tuiletest, 570, 55, 125, 110); //G5
- batch.draw(tuiletest, 570, 165, 125, 110); //G4
- batch.draw(tuiletest, 570, 275, 125, 110); //G3
- batch.draw(tuiletest, 570, 385, 125, 110); //G2
- batch.draw(tuiletest, 570, 495, 125, 110); //G1
- batch.draw(tuiletest, 665, 0, 125, 110); //H5
- batch.draw(tuiletest, 665, 110, 125, 110); //H4
- batch.draw(tuiletest, 665, 220, 125, 110); //H3
- batch.draw(tuiletest, 665, 330, 125, 110); //H2
- batch.draw(tuiletest, 665, 440, 125, 110); //H1
- //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);
- batch.end();
- }
- @Override
- public void dispose() {
- background.dispose();
- renderer.dispose();
- hexture.dispose();
- map.dispose();
- stage.dispose();
- hud.dispose();
- }
- public void push() {
- // TODO Auto-generated method stub
- System.out.println("Envoyé");
- }
- @Override
- public void update(float dt) {
- // TODO Auto-generated method stub
- }
- // Changer le joueur actif
- public void tourSuivant() {
- if (actif == j1) {
- actif = j2;
- } else if (actif == j2) {
- actif = j3;
- } else if (actif == j3) {
- actif = j4;
- } else if (actif == j4) {
- actif = j1;
- }
- hud.updateTour(actif);
- }
- // Affichage de la popup vous n'avez pas assez de PA pour jouer
- public void notEnoughPoint() {
- Dialog dialog = new Dialog("Erreur PA", skin, "dialog") {
- public void result(Object obj) {
- System.out.println("result " + obj);
- remove();
- }
- };
- dialog.text("Vous n'avez pas assez de point d'action !");
- dialog.button("Ok", true); // sends "true" as the result
- dialog.show(stage);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement