feat: ajout de l'objet touchmaptiles qui permet d'afficher le plateau de jeu chargement de tiles

This commit is contained in:
Nicolas Hordé 2015-06-30 23:44:27 +02:00
parent 50ccccaac1
commit e6d4d0e650
7 changed files with 62 additions and 22 deletions

View File

@ -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() {

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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,6 +84,18 @@ 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");
@ -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<tocreate.length;i++)
table.add(Barre[i]).padLeft(10f);
stage.addActor(map);
stage.addActor(Barrehaut);
stage.addActor(Barrebas);
stage.addActor(objectives);
stage.addActor(buttonlevel);
stage.addActor(rayon);

View File

@ -18,7 +18,7 @@ import fr.evolving.screens.GameScreen;
public class GameRenderer {
private GameWorld myWorld;
//private ShapeRenderer shapeRenderer;
private ShapeRenderer shapeRenderer;
private SpriteBatch batcher;
private GameScreen GameScreen;
@ -30,25 +30,14 @@ public class GameRenderer {
this.GameScreen=GameScreen;
batcher = new SpriteBatch();
batcher.setProjectionMatrix(AssetLoader.Camera.combined);
//shapeRenderer = new ShapeRenderer();
//shapeRenderer.setProjectionMatrix(AssetLoader.Camera.combined);
shapeRenderer = new ShapeRenderer();
shapeRenderer.setProjectionMatrix(AssetLoader.Camera.combined);
}
public void render(float delta, float runTime) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
//shapeRenderer.begin(ShapeType.Filled);
//shapeRenderer.setColor(0.15f, 0.15f, 0.15f, 0.5f);
//shapeRenderer.rect(5, 5, AssetLoader.width-10, 74);
//shapeRenderer.rect(5, AssetLoader.height-81, 810, 74);
//shapeRenderer.rect(825, AssetLoader.height-107, 500, 100);
//shapeRenderer.rect(1335, AssetLoader.height-107, 200, 100);
//shapeRenderer.circle(1850, AssetLoader.height, 300, 60);
//shapeRenderer.end();
shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.end();
batcher.begin();
batcher.setColor(0.25f, 0.25f, 0.25f, 0.5f);
batcher.draw(AssetLoader.Atlas_level.findRegion("barrehaut"), 0.0f, AssetLoader.height-200.0f,1920.0f,200.0f);
batcher.draw(AssetLoader.Atlas_level.findRegion("barrebas"), 0.0f, 0.0f,1920.0f,95.0f);
batcher.end();
}

View File

@ -22,7 +22,7 @@ public class GameWorld {
}
public GameWorld(Level level) {
Gdx.app.log(this.getClass().getSimpleName(),"Initialisation du niveau...");
Gdx.app.debug(this.getClass().getSimpleName(),"Initialisation du niveau...");
currentState = GameState.MENU;
//myGrid= new Grid(20,20);
//MySaveObject= new SaveObject("com.mysql.jdbc.Driver","jdbc:mysql://dahut.fr:3306/popfr_games","popfr_games","ef^J,khGMIL~");