feat: ajout du chargements des tiles depuis l'atlas "level" avec une gestion des animations lors de l'ajout des transmuteurs, il est possible de voir si le postitionnement correspond aux exigeance de celuici l'objet transmuter est clonable

This commit is contained in:
Nicolas Hordé 2015-12-27 20:21:22 +01:00
parent 6283a40a10
commit b83d7c759d
5 changed files with 162 additions and 28 deletions

View File

@ -1,6 +1,7 @@
package fr.evolving.UI;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.maps.MapLayers;
@ -14,6 +15,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
import fr.evolving.assets.AssetLoader;
import fr.evolving.automata.Level;
import fr.evolving.automata.Transmuter;
import fr.evolving.automata.Transmuter.Angular;
public class TouchMaptiles extends Actor{
@ -32,7 +34,7 @@ public TouchMaptiles(Level level,int sizex,int sizey) {
map=new TiledMap();
map.getTileSets().addTileSet(AssetLoader.tileSet);
MapLayers layers = map.getLayers();
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 5; i++) {
TiledMapTileLayer layer = new TiledMapTileLayer(level.Grid.sizeX, level.Grid.sizeY, sizex, sizey);
for (int x = 0; x < layer.getWidth();x++) {
for (int y = 0; y < layer.getHeight(); y++) {
@ -44,6 +46,7 @@ public TouchMaptiles(Level level,int sizex,int sizey) {
}
layers.add(layer);
}
layers.get(3).setOpacity(0.9f);
MapRenderer = new OrthogonalTiledMapRenderer(map,1/128.0f);
camera = new OrthographicCamera();
initzoom();
@ -61,6 +64,26 @@ public Vector2 screentoworldsize(float x, float y) {
return new Vector2(x,y);
}
public void tempdraw(float x,float y, int tile, int rotation, int surtile)
{
Cell cell=((TiledMapTileLayer)map.getLayers().get(3)).getCell((int)x, (int)y);
if (cell!=null)
{
((TiledMapTileLayer)map.getLayers().get(4)).getCell((int)x, (int)y).setTile(AssetLoader.tileSet.getTile(tile));
((TiledMapTileLayer)map.getLayers().get(4)).getCell((int)x, (int)y).setRotation(rotation);
((TiledMapTileLayer)map.getLayers().get(3)).getCell((int)x, (int)y).setTile(AssetLoader.tileSet.getTile(surtile));
}
}
public void tempclear()
{
for (int x=0;x<level.Grid.sizeX;x++)
for (int y=0;y<level.Grid.sizeY;y++) {
((TiledMapTileLayer)map.getLayers().get(3)).getCell((int)x, (int)y).setTile(null);
((TiledMapTileLayer)map.getLayers().get(4)).getCell((int)x, (int)y).setTile(null);
}
}
public void redraw(int tile) {
for (int x=0;x<level.Grid.sizeX;x++)
for (int y=0;y<level.Grid.sizeY;y++) {
@ -80,6 +103,9 @@ public void redraw(int tile) {
((TiledMapTileLayer)map.getLayers().get(2)).getCell((int)x, (int)y).setRotation(level.Grid.getTransmuterrot(x, y));
}
}
((TiledMapTileLayer)map.getLayers().get(0)).getCell((int)0, (int)0).setTile(AssetLoader.tileSet.getTile(1010));
((TiledMapTileLayer)map.getLayers().get(0)).getCell((int)1, (int)0).setTile(AssetLoader.tileSet.getTile(1010));
((TiledMapTileLayer)map.getLayers().get(0)).getCell((int)2, (int)0).setTile(AssetLoader.tileSet.getTile(1010));
}
public void initzoom() {

View File

@ -23,9 +23,11 @@ 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.AnimatedTiledMapTile;
import com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.ScalingViewport;
import com.badlogic.gdx.utils.viewport.StretchViewport;
@ -122,33 +124,43 @@ public class AssetLoader {
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 < 99; i++) {
TextureRegion tileText = Atlas_level.findRegion("sprite"+i);
if (tileText != null) {
StaticTiledMapTile atile= new StaticTiledMapTile(tileText);
atile.setId(i);
tileSet.putTile(i, atile);
Gdx.app.debug("AssetLoader","Tiles N°:"+String.valueOf(i));
Array<TextureAtlas.AtlasRegion> allregions=Atlas_level.getRegions();
for (int i=0;i<allregions.size;i++) {
if (allregions.get(i).name.startsWith("sprite")) {
if (allregions.get(i).name.contains("#"))
{
String[] name=allregions.get(i).name.split("_");
if (name[0].contains("sprite"))
{
int id=Integer.parseInt(name[1].split("#")[0]);
if (tileSet.getTile(1000+id)==null) {
Gdx.app.debug("AssetLoader","Animated Tiles N°:"+String.valueOf(id+1000));
int maxid=0;
for(int j=1;Atlas_level.findRegion("sprite_"+id+"#"+j)!=null;j++)
maxid=j;
Array<StaticTiledMapTile> frameTiles=new Array<StaticTiledMapTile>(maxid);
for(int j=1;j<=maxid;j++)
frameTiles.add(new StaticTiledMapTile((Atlas_level.findRegion("sprite_"+id+"#"+j))));
AnimatedTiledMapTile atile=new AnimatedTiledMapTile(0.15f,frameTiles);
Gdx.app.debug("AssetLoader","Taille:"+String.valueOf(frameTiles.size));
atile.setId(1000+id);
tileSet.putTile(1000+id, atile);
}
}
}
else
{
StaticTiledMapTile atile= new StaticTiledMapTile(allregions.get(i));
atile.setId(allregions.get(i).index);
tileSet.putTile(allregions.get(i).index, atile);
Gdx.app.debug("AssetLoader","Tiles N°:"+String.valueOf(allregions.get(i).index));
}
}
}
allTransmuter=new Transmuter[3];
allTransmuter[0]=new Positiver_I(null);
allTransmuter[1]=new Positiver_II(null);
allTransmuter[2]=new Positiver_III(null);
for(int i=0;i<allTransmuter.length;i++) {
int[] result;
result=allTransmuter[i].getallTiles();
for (int j=0;j<result.length;j++) {
TextureRegion tileText = Atlas_level.findRegion("sprite"+result[j]);
if (tileText != null) {
StaticTiledMapTile atile= new StaticTiledMapTile(tileText);
atile.setId(result[j]);
tileSet.putTile(result[j], atile);
Gdx.app.debug("AssetLoader","Tiles N°:"+String.valueOf(result[j]));
}
}
}
}
public static Transmuter getTransmuter(int Id) {

View File

@ -6,7 +6,7 @@ import java.util.Iterator;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
public abstract class Transmuter {
public abstract class Transmuter implements Cloneable {
public enum CaseType{Rien,Cuivre,Fibre,Tout,Nimporte};
public enum Class{Structure,Charge,Direction,Filtrage,Synthèse,Détection,Divers,Scénario};
public enum Angular{A00,A90,A180,A270};
@ -242,4 +242,14 @@ public abstract class Transmuter {
public void setRotation(Angular rotation) {
this.Rotation=rotation;
}
public Object clone() {
Object o = null;
try {
o = super.clone();
} catch(CloneNotSupportedException cnse) {
cnse.printStackTrace(System.err);
}
return o;
}
}

View File

@ -1,5 +1,6 @@
package fr.evolving.screens;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Timer;
import java.util.TimerTask;
@ -21,6 +22,7 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
@ -49,6 +51,7 @@ import fr.evolving.automata.Positiver_II;
import fr.evolving.automata.Positiver_III;
import fr.evolving.automata.Transmuter;
import fr.evolving.automata.Transmuter.Angular;
import fr.evolving.automata.Transmuter.CaseType;
import fr.evolving.inputs.InputHandler;
public class GameScreen implements Screen {
@ -368,7 +371,36 @@ public class GameScreen implements Screen {
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(){
map.addListener(new InputListener(){
@Override
public boolean mouseMoved(InputEvent event,float x,float y) {
if (selected==null)
;
else if (selected.getName()=="transmuter")
{
Vector2 coords=map.screentoworld(x, y);
if (level.Grid.GetXY(coords.x,coords.y)!=null)
{
Gdx.app.debug(event.getListenerActor().toString(),"Screen coordinates translated to world coordinates: "+ "X: " + coords.x + " Y: " + coords.y);
map.tempclear();
HashMap<Vector2,CaseType> tiles=selected_transmuter.getTiles();
Iterator<Vector2> keySetIterator = selected_transmuter.getTiles().keySet().iterator();
int MainTile=selected_transmuter.getMainTile();
int color=64;
if (level.Grid.getCopper(coords.x,coords.y) && level.Grid.getTransmutercalc(coords.x,coords.y)==0)
color=63;
map.tempdraw(coords.x, coords.y, MainTile, selected_transmuter.getRotation().ordinal(),color);
while(keySetIterator.hasNext()){
Vector2 key = keySetIterator.next();
color=64;
if (((!level.Grid.GetFiber(coords.x+key.x, coords.y+key.y) && !level.Grid.getCopper(coords.x+key.x, coords.y+key.y) && tiles.get(key)==CaseType.Rien) || (level.Grid.GetFiber(coords.x+key.x, coords.y+key.y) && level.Grid.getCopper(coords.x+key.x, coords.y+key.y) && tiles.get(key)==CaseType.Tout) || (level.Grid.GetFiber(coords.x+key.x, coords.y+key.y) && !level.Grid.getCopper(coords.x+key.x, coords.y+key.y) && tiles.get(key)==CaseType.Fibre) || (level.Grid.getCopper(coords.x+key.x, coords.y+key.y) && !level.Grid.GetFiber(coords.x+key.x, coords.y+key.y) && tiles.get(key)==CaseType.Cuivre)) && (level.Grid.getTransmutercalc(coords.x+key.x, coords.y+key.y)==0))
color=63;
map.tempdraw(coords.x+key.x, coords.y+key.y, ++MainTile, selected_transmuter.getRotation().ordinal(),color);
}
}
}
return true;
}
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
oldx=0;
@ -465,16 +497,70 @@ public class GameScreen implements Screen {
}
}
else if (selected.getName()=="transmuter")
{
if (button==1)
{
Vector2 coords=map.screentoworld(x, y);
if (level.Grid.GetXY(coords.x,coords.y)!=null)
{
Gdx.app.debug(event.getListenerActor().toString(),"Screen coordinates translated to world coordinates: "+ "X: " + coords.x + " Y: " + coords.y);
level.Grid.GetXY(coords.x,coords.y).Transmuter=selected_transmuter;
Angular angle=selected_transmuter.getRotation();
if (angle==Angular.A00)
selected_transmuter.setRotation(Angular.A90);
else if (angle==Angular.A90)
selected_transmuter.setRotation(Angular.A180);
else if (angle==Angular.A180)
selected_transmuter.setRotation(Angular.A270);
else if (angle==Angular.A270)
selected_transmuter.setRotation(Angular.A00);
map.tempclear();
HashMap<Vector2,CaseType> tiles=selected_transmuter.getTiles();
Iterator<Vector2> keySetIterator = selected_transmuter.getTiles().keySet().iterator();
int MainTile=selected_transmuter.getMainTile();
int color=64;
if (level.Grid.getCopper(coords.x,coords.y) && level.Grid.getTransmutercalc(coords.x,coords.y)==0)
color=63;
map.tempdraw(coords.x, coords.y, MainTile, selected_transmuter.getRotation().ordinal(),color);
while(keySetIterator.hasNext()){
Vector2 key = keySetIterator.next();
color=64;
if (((!level.Grid.GetFiber(coords.x+key.x, coords.y+key.y) && !level.Grid.getCopper(coords.x+key.x, coords.y+key.y) && tiles.get(key)==CaseType.Rien) || (level.Grid.GetFiber(coords.x+key.x, coords.y+key.y) && level.Grid.getCopper(coords.x+key.x, coords.y+key.y) && tiles.get(key)==CaseType.Tout) || (level.Grid.GetFiber(coords.x+key.x, coords.y+key.y) && !level.Grid.getCopper(coords.x+key.x, coords.y+key.y) && tiles.get(key)==CaseType.Fibre) || (level.Grid.getCopper(coords.x+key.x, coords.y+key.y) && !level.Grid.GetFiber(coords.x+key.x, coords.y+key.y) && tiles.get(key)==CaseType.Cuivre)) && (level.Grid.getTransmutercalc(coords.x+key.x, coords.y+key.y)==0))
color=63;
map.tempdraw(coords.x+key.x, coords.y+key.y, ++MainTile, selected_transmuter.getRotation().ordinal(),color);
}
}
return true;
}
Vector2 coords=map.screentoworld(x, y);
if (level.Grid.GetXY(coords.x,coords.y)!=null)
{
Gdx.app.debug(event.getListenerActor().toString(),"Screen coordinates translated to world coordinates: "+ "X: " + coords.x + " Y: " + coords.y);
level.Grid.GetXY(coords.x,coords.y).Transmuter=(Transmuter) selected_transmuter.clone();
level.Grid.tiling_transmuter();
map.redraw(60);
}
}
else if (selected.getName()=="copper-brush")
{
Vector2 coords=map.screentoworld(x, y);
if (level.Grid.GetXY(coords.x,coords.y)!=null)
{
Gdx.app.debug(event.getListenerActor().toString(),"Screen coordinates translated to world coordinates: "+ "X: " + coords.x + " Y: " + coords.y);
level.Grid.GetXY(coords.x,coords.y).Copper=true;
level.Grid.tiling_copper();
map.redraw(60);
}
}
else if (selected.getName()=="fiber-brush")
{
Vector2 coords=map.screentoworld(x, y);
if (level.Grid.GetXY(coords.x,coords.y)!=null)
{
Gdx.app.debug(event.getListenerActor().toString(),"Screen coordinates translated to world coordinates: "+ "X: " + coords.x + " Y: " + coords.y);
level.Grid.GetXY(coords.x,coords.y).Fiber=1;
map.redraw(60);
}
}
return true;
}
});
@ -631,7 +717,7 @@ public class GameScreen implements Screen {
coords2=menu.worldtoscreen((int)(coords.x+gotomain.x),(int)(coords.y+gotomain.y));
menuactor.setPosition(coords2.x, coords2.y);
selected.setName("transmuter");
selected_transmuter=transmuter;
selected_transmuter=(Transmuter) transmuter.clone();
Gdx.app.debug(event.getListenerActor().toString(),"transmuter deplacement vers origine:"+String.valueOf(gotomain.x)+","+String.valueOf(gotomain.y)+" coords:"+coords2.x+"x"+coords2.y);
}
}

View File

@ -47,8 +47,8 @@ public class GameRenderer {
batcher.begin();
batcher.setColor(0.25f, 0.25f, 0.25f, 1f);
batcher.draw(AssetLoader.Atlas_level.findRegion("barrehaut"),0.0f,AssetLoader.height-198.0f,1920.0f,200.0f);
batcher.draw(AssetLoader.Atlas_level.findRegion("barrebas"),0.0f,0.0f,1920.0f,170.0f);
batcher.draw(AssetLoader.Atlas_level.findRegion("barrecentre"),1480f,AssetLoader.height-785.0f,590f,530.0f);
batcher.draw(AssetLoader.Atlas_level.findRegion("barrebas"),0.0f,0.0f,1920.0f,170.0f);
if (GameScreen.unroll)
batcher.draw(AssetLoader.Atlas_level.findRegion("barrecentre2"),1180f,AssetLoader.height-1000.0f,880f,386.0f);
batcher.end();