feat: ajout du routage des pistes et affichages des tiles

This commit is contained in:
Nicolas Hordé 2015-07-08 13:58:18 +02:00
parent e6d4d0e650
commit dc4b82c189
2 changed files with 159 additions and 9 deletions

View File

@ -16,14 +16,139 @@ public class Grid implements Serializable{
this.Cells[x][y]=new Cell(); this.Cells[x][y]=new Cell();
} }
} }
} }
public Cell GetXY(int X,int Y) { public void tiling() {
if (X<0 || Y<0 || X>=this.sizeX || Y>=this.sizeY) { for (int x=0;x<this.sizeX;x++)
for (int y=0;y<this.sizeY;y++)
if (GetCopper(x,y))
{
int value=0;
if (GetCopper(x,y+1))
value++;
if (GetCopper(x-1,y))
value+=8;
if (GetCopper(x,y-1))
value+=4;
if (GetCopper(x+1,y))
value+=2;
GetXY(x,y).Copper_calc=value;
}
else
GetXY(x,y).Copper_calc=60;
for (int x=0;x<this.sizeX;x++)
for (int y=0;y<this.sizeY;y++)
{
int value=0;
if (GetCoppercalc(x,y)==15)
{
if (GetCopper(x-1,y-1))
value++;
if (GetCopper(x,y-1))
value++;
if (GetCopper(x+1,y-1))
value++;
if (GetCopper(x-1,y))
value++;
if (GetCopper(x+1,y))
value++;
if (GetCopper(x-1,y+1))
value++;
if (GetCopper(x,y+1))
value++;
if (GetCopper(x+1,y+1))
value++;
if (value>=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;x<this.sizeX;x++)
for (int y=0;y<this.sizeY;y++)
{
if (GetCoppercalc(x,y)==35)
{
int value=0;
if (!GetCopper(x+1,y+1))
value+=2;
if (!GetCopper(x-1,y-1))
value+=8;
if (!GetCopper(x+1,y-1))
value+=4;
if (!GetCopper(x-1,y+1))
value+=1;
GetXY(x,y).Copper_calc=GetXY(x,y).Copper_calc+value;
}
}
for (int x=0;x<this.sizeX;x++)
for (int y=0;y<this.sizeY;y++)
{
int oldvalue=GetXY(x,y).Copper_calc;
if (oldvalue==27||oldvalue==31||oldvalue==33||oldvalue==34)
{
int value=0;
if (GetCopper(x,y+1) && GetCoppercalc(x,y+1)<15)
value+=1;
if (GetCopper(x-1,y) && GetCoppercalc(x-1,y)<15)
value+=6;
if (GetCopper(x,y-1) && GetCoppercalc(x,y-1)<15)
value+=2;
if (GetCopper(x+1,y) && GetCoppercalc(x+1,y)<15)
value+=2;
if (value>0)
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 null;
} else
return this.Cells[X][Y]; 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;
} }

View File

@ -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;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell; import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer; 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.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Image;
@ -88,13 +89,13 @@ public class GameScreen implements Screen {
Barre[6].addListener(new ClickListener(){ Barre[6].addListener(new ClickListener(){
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
map.setZoom(map.getZoom()*0.7f); map.setZoom(1.1f);
} }
}); });
Barre[5].addListener(new ClickListener(){ Barre[5].addListener(new ClickListener(){
@Override @Override
public void clicked(InputEvent event, float x, float y) { 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"); 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); objectives.setPosition(890,AssetLoader.height-95);
buttonlevel=new ButtonLevel(level,true); buttonlevel=new ButtonLevel(level,true);
buttonlevel.setPosition(1760,AssetLoader.height-125); 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"); Gdx.app.debug(getClass().getSimpleName(),"Ajout des barres");
Barrehaut=new Image(AssetLoader.Atlas_level.findRegion("barrehaut")); Barrehaut=new Image(AssetLoader.Atlas_level.findRegion("barrehaut"));
Barrehaut.setBounds(0.0f, AssetLoader.height-200.0f,1920.0f,200.0f); 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=new Image(AssetLoader.Atlas_level.findRegion("barrebas"));
Barrebas.setBounds(0.0f, 0.0f,1920.0f,95.0f); Barrebas.setBounds(0.0f, 0.0f,1920.0f,95.0f);
Barrebas.setColor(0.25f, 0.25f, 0.25f, 0.9f); 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 @Override