From ea59612ae58ea55d291b94ecb676251c15d92839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Thu, 25 Aug 2016 14:21:41 +0200 Subject: [PATCH] feat: debut de gestion de l'activation --- core/src/fr/evolving/UI/TouchMaptiles.java | 5 ++- core/src/fr/evolving/automata/Grid.java | 42 ++++++++++++++++++++- core/src/fr/evolving/automata/Particle.java | 23 +++++++++-- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/core/src/fr/evolving/UI/TouchMaptiles.java b/core/src/fr/evolving/UI/TouchMaptiles.java index bc59f05..a351ba3 100644 --- a/core/src/fr/evolving/UI/TouchMaptiles.java +++ b/core/src/fr/evolving/UI/TouchMaptiles.java @@ -180,14 +180,15 @@ public class TouchMaptiles extends Actor implements GestureListener,InputProcess if (level.Grid.GetXY(x,y).Fiber_state==0) ((TiledMapTileLayer) map.getLayers().get(0)).getCell((int) x,(int) y).setTile(AssetLoader.tileSet.getTile(61)); else { - ((TiledMapTileLayer) map.getLayers().get(0)).getCell((int) x,(int) y).setTile(AssetLoader.tileSet.getTile(90+level.Grid.GetXY(x,y).Fiber_state)); + ((TiledMapTileLayer) map.getLayers().get(0)).getCell((int) x,(int) y).setTile(AssetLoader.tileSet.getTile(89 + +level.Grid.GetXY(x,y).Fiber_state)); } } else { if (worlds.isDebug()) { if (level.Grid.GetXY(x,y).Locked) - ((TiledMapTileLayer) map.getLayers().get(5)).getCell((int) x,(int) y).setTile(AssetLoader.tileSet.getTile(90)); + ((TiledMapTileLayer) map.getLayers().get(5)).getCell((int) x,(int) y).setTile(AssetLoader.tileSet.getTile(64)); else ((TiledMapTileLayer) map.getLayers().get(5)).getCell((int) x,(int) y).setTile(null); if (level.Grid.GetXY(x,y).Free) diff --git a/core/src/fr/evolving/automata/Grid.java b/core/src/fr/evolving/automata/Grid.java index ed836e8..fa18025 100644 --- a/core/src/fr/evolving/automata/Grid.java +++ b/core/src/fr/evolving/automata/Grid.java @@ -4,18 +4,25 @@ import java.io.Serializable; import java.util.Iterator; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.OrderedMap; +import com.badlogic.gdx.utils.ObjectMap.Entries; import com.badlogic.gdx.utils.ObjectMap.Entry; +import fr.evolving.assets.AssetLoader; import fr.evolving.automata.Particle.Orientation; import fr.evolving.automata.Particle.Type; +import fr.evolving.automata.Transmuter.CaseType; public class Grid implements Serializable,Cloneable { protected Cell[][] Cells; public Integer sizeX, sizeY; - public transient Array particles; + private transient Array particles; + private transient Array transmuters; + private transient Array transmuterscoords; public Grid(Integer X, Integer Y) { Reinit(); @@ -32,6 +39,10 @@ public class Grid implements Serializable,Cloneable { public void Reinit() { if (particles==null) particles=new Array(); + if (transmuters==null) + transmuters=new Array(); + if (transmuterscoords==null) + transmuterscoords=new Array(); } //Réalise un cycle de simulation dans la grille @@ -40,6 +51,20 @@ public class Grid implements Serializable,Cloneable { Gdx.app.debug("wirechem-Grid", "Grid Cycle -> Particle "+particle.getType()+"/"+particle.getSize()+ " coords:"+particle.getCoordx()+","+particle.getCoordy()+"/"+particle.getOrientation()+" charge:"+particle.getCharge()); if (particle.getType()==Type.Photon) { particle.Next(); + for(int i=0;i tiles = transmuters.get(i).getTilesidrotated(); + Entries iterator = tiles.iterator(); + while (iterator.hasNext()) { + Entry all = iterator.next(); + CaseType thecase=transmuters.get(i).getTilestype(tiles.keys().toArray().indexOf(all.key, false)); + Vector2 position=transmuterscoords.get(i); + if (GetXY(position.x+ all.key.x, position.y+ all.key.y).Fiber && position.x==particle.getCoordx() && position.y==particle.getCoordy()) + if (thecase==CaseType.Fibre||thecase==CaseType.Tout||thecase==CaseType.Fibre_seul) + Gdx.app.debug("wirechem-Grid", "Grid Cycle -> Activation Photon state :"+GetXY(particle.getCoordx(), particle.getCoordy()).Fiber_state+":"+particle.getCoordx()+","+particle.getCoordy()+"Transmuter:"+transmuters.get(i).getName()+"/"+transmuters.get(i).getActivationLevel()); + particle.subLife(transmuters.get(i).getMaxActivationLevel()-transmuters.get(i).getActivationLevel()); + transmuters.get(i).Activate(); + } + } if (!particle.isAlive()) { Gdx.app.debug("wirechem-Particle", "coords:"+particle.getCoordx()+","+particle.getCoordy()+" killed & removed"); particles.removeValue(particle, true); @@ -56,7 +81,7 @@ public class Grid implements Serializable,Cloneable { GetXY(x, y).Fiber_state = 0; for(Particle particle: particles) { if (particle.getType()==Type.Photon) { - GetXY(particle.getCoordx(), particle.getCoordy()).Fiber_state=Math.floorDiv(29-particle.getLife(),3); + GetXY(particle.getCoordx(), particle.getCoordy()).Fiber_state=1+Math.floorDiv(Particle.PHOTONLIFE-particle.getLife(),Math.floorDiv(Particle.PHOTONLIFE,10)); Gdx.app.debug("wirechem-Grid", "Grid Tiling -> Photon state :"+GetXY(particle.getCoordx(), particle.getCoordy()).Fiber_state+":"+particle.getCoordx()+","+particle.getCoordy()); } } @@ -71,6 +96,19 @@ public class Grid implements Serializable,Cloneable { particles.get(0).setCoordx(6); particles.get(0).setCoordy(3); particles.get(0).setOrientation(Orientation.E); + particles.add(new Particle(this)); + particles.get(1).setType(Type.Electron); + particles.get(1).setCoordx(7); + particles.get(1).setCoordy(13); + particles.get(1).setOrientation(Orientation.O); + transmuters.clear(); + transmuterscoords.clear(); + for (int x = 0; x < this.sizeX; x++) + for (int y = 0; y < this.sizeY; y++) + if (GetXY(x, y).Transmuter!=null) { + transmuters.add(GetXY(x, y).Transmuter); + transmuterscoords.add(new Vector2(x,y)); + } } //Genère des tiles qui correspondent aux transmuteurs sur la grille diff --git a/core/src/fr/evolving/automata/Particle.java b/core/src/fr/evolving/automata/Particle.java index 6f77b16..911a602 100644 --- a/core/src/fr/evolving/automata/Particle.java +++ b/core/src/fr/evolving/automata/Particle.java @@ -17,6 +17,8 @@ public class Particle { Positif, Negatif, Neutre }; + public final static int PHOTONLIFE=200; + private Orientation oldorientation; private Orientation orientation; private Size size; @@ -55,6 +57,14 @@ public class Particle { public void setLife(int life) { this.life=life; } + + public void subLife(int sub) { + this.life=life-sub; + if (this.life<=0) { + this.life=0; + this.kill(); + } + } public int getCoordx() { return this.coordX; @@ -168,7 +178,7 @@ public class Particle { Vector2 move=null; Orientation neworientation=this.orientation; if (type==Type.Photon) { - if (life>=30) this.kill(); + if (life>=PHOTONLIFE) this.kill(); Orientation[] orientations=get_orientations(this.orientation); Vector2 soluce0=testorientation(orientations[0]); Vector2 soluce1=testorientation(orientations[1]); @@ -178,8 +188,15 @@ public class Particle { move=soluce0; } else if (soluce1!=null && soluce2!=null) { - neworientation=orientations[1]; - move=soluce1; + if (orientations[1]==oldorientation) { + neworientation=orientations[1]; + move=soluce1; + } + else + { + neworientation=orientations[2]; + move=soluce2; + } } else if (soluce1!=null) { neworientation=orientations[1];