From dc4b82c1896a698b3e34a3c74d914eb004fc79f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Wed, 8 Jul 2015 13:58:18 +0200 Subject: [PATCH] feat: ajout du routage des pistes et affichages des tiles --- core/src/fr/evolving/automata/Grid.java | 135 ++++++++++++++++++- core/src/fr/evolving/screens/GameScreen.java | 33 ++++- 2 files changed, 159 insertions(+), 9 deletions(-) diff --git a/core/src/fr/evolving/automata/Grid.java b/core/src/fr/evolving/automata/Grid.java index 4c91a50..f06fdbc 100644 --- a/core/src/fr/evolving/automata/Grid.java +++ b/core/src/fr/evolving/automata/Grid.java @@ -16,14 +16,139 @@ public class Grid implements Serializable{ this.Cells[x][y]=new Cell(); } } - } - public Cell GetXY(int X,int Y) { - if (X<0 || Y<0 || X>=this.sizeX || Y>=this.sizeY) { + public void tiling() { + for (int x=0;x=5) + GetXY(x,y).Copper_calc=GetXY(x,y).Copper_calc+20; + } + else + { + if (GetCoppercalc(x,y)!=60) + { + int oldvalue=GetXY(x,y).Copper_calc; + if (GetCoppercalc(x-1,y-1)==15 || GetCoppercalc(x-1,y-1)==35) + value++; + if (GetCoppercalc(x,y-1)==15 || GetCoppercalc(x,y-1)==35) + value++; + if (GetCoppercalc(x+1,y-1)==15 || GetCoppercalc(x+1,y-1)==35) + value++; + if (GetCoppercalc(x-1,y)==15 || GetCoppercalc(x-1,y)==35) + value++; + if (GetCoppercalc(x+1,y)==15 || GetCoppercalc(x+1,y)==35) + value++; + if (GetCoppercalc(x-1,y+1)==15 || GetCoppercalc(x-1,y+1)==35) + value++; + if (GetCoppercalc(x,y+1)==15 || GetCoppercalc(x,y+1)==35) + value++; + if (GetCoppercalc(x+1,y+1)==15 || GetCoppercalc(x+1,y+1)==35) + value++; + if (value>=1 && oldvalue!=1 && oldvalue!=2 && oldvalue!=4 && oldvalue!=8 && oldvalue!=10 && oldvalue!=5) + GetXY(x,y).Copper_calc=oldvalue+20; + } + } + } + for (int x=0;x0) + GetXY(x,y).Copper_calc=oldvalue+22+value; + } + + } + return; + } + + + public Cell GetXY(float X,float Y) { + if (X<0 || Y<0 || X>=this.sizeX || Y>=this.sizeY) return null; - } - return this.Cells[X][Y]; + else + return this.Cells[(int)X][(int)Y]; + } + + public boolean GetCopper(float X,float Y) { + Cell cell=GetXY(X,Y); + if (cell==null) + return false; + else + return cell.Copper; + } + + public int GetCoppercalc(float X,float Y) { + Cell cell=GetXY(X,Y); + if (cell==null) + return 0; + else + return cell.Copper_calc; } diff --git a/core/src/fr/evolving/screens/GameScreen.java b/core/src/fr/evolving/screens/GameScreen.java index 0058249..97ae82f 100644 --- a/core/src/fr/evolving/screens/GameScreen.java +++ b/core/src/fr/evolving/screens/GameScreen.java @@ -13,6 +13,7 @@ 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.math.Vector3; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Image; @@ -88,13 +89,13 @@ public class GameScreen implements Screen { Barre[6].addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y) { - map.setZoom(map.getZoom()*0.7f); + map.setZoom(1.1f); } }); Barre[5].addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y) { - map.setZoom(map.getZoom()*1.3f); + map.setZoom(0.9f); } }); Gdx.app.debug(getClass().getSimpleName(),"Création de la barre de gestion du haut"); @@ -115,8 +116,6 @@ 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); @@ -124,6 +123,32 @@ public class GameScreen implements Screen { 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); + Gdx.app.debug(getClass().getSimpleName(),"Création d'une tilemap"); + map=new TouchMaptiles(level,128,128); + map.setBounds(0, 0, AssetLoader.width, AssetLoader.height); + map.addListener(new ClickListener(){ + @Override + public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { + + //Vector3 temp_coord = new Vector3(x,y,0); + //Vector3 coords = map.camera.unproject(temp_coord); + //x =(int) coords.x; + //y =(int) coords.y; + x=(int)((x/AssetLoader.width*map.camera.viewportWidth)+map.decx); + y=(int)((y/AssetLoader.height*map.camera.viewportHeight)+map.decy); + if (level.Grid.GetXY(x,y)!=null) + { + System.out.println("Screen coordinates translated to world coordinates: "+ "X: " + x + " Y: " + y+" zoom:"+map.getZoom()); + if (level.Grid.GetCopper(x,y)==false) + level.Grid.GetXY(x,y).Copper=true; + else + level.Grid.GetXY(x,y).Copper=false; + level.Grid.tiling(); + map.redraw(); + } + return false; + } + }); } @Override