From e6d4d0e6502d2250dc31048f4a1f5cf047d5bd41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Tue, 30 Jun 2015 23:44:27 +0200 Subject: [PATCH] feat: ajout de l'objet touchmaptiles qui permet d'afficher le plateau de jeu chargement de tiles --- core/src/fr/evolving/assets/AssetLoader.java | 14 +++++++ core/src/fr/evolving/assets/SaveObject.java | 4 +- core/src/fr/evolving/automata/Cell.java | 1 + core/src/fr/evolving/automata/Grid.java | 2 +- core/src/fr/evolving/screens/GameScreen.java | 40 ++++++++++++++++++- core/src/fr/evolving/worlds/GameRenderer.java | 21 +++------- core/src/fr/evolving/worlds/GameWorld.java | 2 +- 7 files changed, 62 insertions(+), 22 deletions(-) diff --git a/core/src/fr/evolving/assets/AssetLoader.java b/core/src/fr/evolving/assets/AssetLoader.java index 55fb82c..dedd451 100644 --- a/core/src/fr/evolving/assets/AssetLoader.java +++ b/core/src/fr/evolving/assets/AssetLoader.java @@ -21,6 +21,9 @@ import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.Texture.TextureWrap; import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.maps.tiled.TiledMap; +import com.badlogic.gdx.maps.tiled.TiledMapTileSet; +import com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.ScalingViewport; @@ -48,6 +51,7 @@ public class AssetLoader { public static NinePatch empty; public static NinePatch full; public static AssetManager manager; + public static TiledMapTileSet tileSet; public static void addstyle(TextureAtlas Atlas_level,String Name) { AtlasRegion AnAtlasRegion = Atlas_level.findRegion(Name); @@ -109,6 +113,16 @@ public class AssetLoader { Typecolors=new Color[]{new Color(0,0,1f,1),new Color(0,0.6f,0,1),new Color(0.196f,0.803f,0.196f,1),new Color(0.5f,0.5f,0.5f,1),new Color(0.8f,0.8f,0.8f,1),new Color(0.6f,0,0,1),new Color(1f,0,0,1),new Color(0,0,0.6f,1),new Color(0,0,0.6f,1),new Color(0,0,0.6f,1),new Color(0,0,0.6f,1),new Color(0.294f,0.466f,0.615f,1),new Color(0.478f,0.192f,0.098f,1)}; Typenames=new String[13]; Typenames=new String[]{"E-","e-","Ph","e0","E0","e+","E+","K","L","M","N","n","p"}; + Gdx.app.debug("AssetLoader","Création des tiles..."); + tileSet = new TiledMapTileSet(); + tileSet.setName("copper"); + for (int i = 0; i < 70; i++) { + TextureRegion tileText = Atlas_level.findRegion("sprite"+i); + if (tileText != null) { + tileSet.putTile(i, new StaticTiledMapTile(tileText)); + Gdx.app.debug("AssetLoader","Tiles N°:"+String.valueOf(i)); + } + } } public static int setpref() { diff --git a/core/src/fr/evolving/assets/SaveObject.java b/core/src/fr/evolving/assets/SaveObject.java index 98116de..487b8cf 100644 --- a/core/src/fr/evolving/assets/SaveObject.java +++ b/core/src/fr/evolving/assets/SaveObject.java @@ -162,7 +162,7 @@ public class SaveObject { 460f, -1, 15, - new Grid(20,20), + new Grid(10,3), 0, 0, 0, @@ -188,7 +188,7 @@ public class SaveObject { 550f, 0, 16, - new Grid(20,20), + new Grid(30,20), 0, 0, 0, diff --git a/core/src/fr/evolving/automata/Cell.java b/core/src/fr/evolving/automata/Cell.java index ab1a31b..b2b74c7 100644 --- a/core/src/fr/evolving/automata/Cell.java +++ b/core/src/fr/evolving/automata/Cell.java @@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.Sprite; public class Cell implements Serializable{ public int Fiber; public boolean Copper; + public transient int Copper_calc; public transient int Fiber_old; public transient Sprite Sprite ; public Transmuter Transmuter; diff --git a/core/src/fr/evolving/automata/Grid.java b/core/src/fr/evolving/automata/Grid.java index 142a569..4c91a50 100644 --- a/core/src/fr/evolving/automata/Grid.java +++ b/core/src/fr/evolving/automata/Grid.java @@ -5,7 +5,7 @@ import com.badlogic.gdx.Gdx; public class Grid implements Serializable{ public Cell[][] Cells; - private Integer sizeX,sizeY; + public Integer sizeX,sizeY; public Grid(Integer X,Integer Y) { this.sizeX=X; diff --git a/core/src/fr/evolving/screens/GameScreen.java b/core/src/fr/evolving/screens/GameScreen.java index 0aa6bd4..0058249 100644 --- a/core/src/fr/evolving/screens/GameScreen.java +++ b/core/src/fr/evolving/screens/GameScreen.java @@ -6,8 +6,16 @@ import java.util.TimerTask; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.maps.MapLayers; +import com.badlogic.gdx.maps.tiled.TiledMap; +import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; +import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell; +import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; import com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton; import com.badlogic.gdx.scenes.scene2d.ui.Table; @@ -18,6 +26,7 @@ import fr.evolving.worlds.GameWorld; import fr.evolving.worlds.LevelRenderer; import fr.evolving.UI.ButtonLevel; import fr.evolving.UI.Objectives; +import fr.evolving.UI.TouchMaptiles; import fr.evolving.assets.AssetLoader; import fr.evolving.automata.Level; import fr.evolving.inputs.InputHandler; @@ -36,7 +45,8 @@ public class GameScreen implements Screen { String[] tocreate={"run","stop","speed","separator","move","zoomp","zoomm","separator","raz","save","levels","tree","exits","separator","screen","sound","tuto","settings","separator","stat"}; private ButtonLevel buttonlevel; private Objectives objectives; - + private TouchMaptiles map; + private Image Barrehaut,Barrebas; // This is the constructor, not the class declaration public GameScreen(Level alevel) { @@ -74,7 +84,19 @@ public class GameScreen implements Screen { public void clicked(InputEvent event, float x, float y) { Gdx.app.exit(); } - }); + }); + Barre[6].addListener(new ClickListener(){ + @Override + public void clicked(InputEvent event, float x, float y) { + map.setZoom(map.getZoom()*0.7f); + } + }); + Barre[5].addListener(new ClickListener(){ + @Override + public void clicked(InputEvent event, float x, float y) { + map.setZoom(map.getZoom()*1.3f); + } + }); Gdx.app.debug(getClass().getSimpleName(),"Création de la barre de gestion du haut"); cycle=new ImageTextButton(String.valueOf(level.Cycle),AssetLoader.Skin_level,"cycle2"); cycle.setPosition(10,AssetLoader.height-74); @@ -93,10 +115,21 @@ public class GameScreen implements Screen { objectives.setPosition(890,AssetLoader.height-95); buttonlevel=new ButtonLevel(level,true); buttonlevel.setPosition(1760,AssetLoader.height-125); + Gdx.app.debug(getClass().getSimpleName(),"Création d'une tilemap"); + map=new TouchMaptiles(level,128,128); + Gdx.app.debug(getClass().getSimpleName(),"Ajout des barres"); + Barrehaut=new Image(AssetLoader.Atlas_level.findRegion("barrehaut")); + Barrehaut.setBounds(0.0f, AssetLoader.height-200.0f,1920.0f,200.0f); + Barrehaut.setColor(0.25f, 0.25f, 0.25f, 0.9f); + Barrebas=new Image(AssetLoader.Atlas_level.findRegion("barrebas")); + Barrebas.setBounds(0.0f, 0.0f,1920.0f,95.0f); + Barrebas.setColor(0.25f, 0.25f, 0.25f, 0.9f); } @Override public void render(float delta) { + Gdx.gl.glClearColor(0, 0, 0, 1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); runTime += delta; world.update(delta); Renderer.render(delta, runTime); @@ -114,6 +147,9 @@ public class GameScreen implements Screen { table.bottom().left().padBottom(10f); for (int i=0;i