From 4530136a9906c10231c522184ecc5e9279d83bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Thu, 25 Aug 2016 00:48:56 +0200 Subject: [PATCH] feat: avancement des photons (nouveau code) --- core/src/fr/evolving/automata/Particle.java | 201 ++++++-------------- 1 file changed, 62 insertions(+), 139 deletions(-) diff --git a/core/src/fr/evolving/automata/Particle.java b/core/src/fr/evolving/automata/Particle.java index 77146a5..6f77b16 100644 --- a/core/src/fr/evolving/automata/Particle.java +++ b/core/src/fr/evolving/automata/Particle.java @@ -1,6 +1,7 @@ package fr.evolving.automata; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.math.Vector2; public class Particle { public enum Type { @@ -16,6 +17,7 @@ public class Particle { Positif, Negatif, Neutre }; + private Orientation oldorientation; private Orientation orientation; private Size size; private Charge charge; @@ -129,159 +131,80 @@ public class Particle { this.charge=Charge.Negatif; } + private Vector2 testorientation(Orientation orientation) { + int movex=0,movey=0; + if (orientation.toString().contains("N")) movey=+1; + if (orientation.toString().contains("S")) movey=-1; + if (orientation.toString().contains("E")) movex=+1; + if (orientation.toString().contains("O")) movex=-1; + if (this.grid.GetXY(this.coordX+movex, this.coordY+movey)!=null && this.grid.GetXY(this.coordX+movex, this.coordY+movey).Fiber) + return new Vector2(movex,movey); + else + return null; + } + + private Orientation[] get_orientations(Orientation orientation) { + if (orientation==Orientation.E) + return new Orientation[]{Orientation.E,Orientation.NE,Orientation.SE}; + if (orientation==Orientation.NE) + return new Orientation[]{Orientation.NE,Orientation.N,Orientation.E}; + if (orientation==Orientation.N) + return new Orientation[]{Orientation.N,Orientation.NE,Orientation.NO}; + if (orientation==Orientation.NO) + return new Orientation[]{Orientation.NO,Orientation.N,Orientation.O}; + if (orientation==Orientation.O) + return new Orientation[]{Orientation.O,Orientation.NO,Orientation.SO}; + if (orientation==Orientation.SO) + return new Orientation[]{Orientation.SO,Orientation.S,Orientation.O}; + if (orientation==Orientation.S) + return new Orientation[]{Orientation.S,Orientation.SE,Orientation.SO}; + if (orientation==Orientation.SE) + return new Orientation[]{Orientation.SE,Orientation.E,Orientation.S}; + return new Orientation[]{Orientation.SE,Orientation.E,Orientation.S}; + } + public void Next() { this.life++; - int movex = 0,movey = 0; + Vector2 move=null; Orientation neworientation=this.orientation; if (type==Type.Photon) { if (life>=30) this.kill(); - if (this.orientation==Orientation.E) - { - if (this.grid.GetXY(this.coordX+1, this.coordY)!=null && this.grid.GetXY(this.coordX+1, this.coordY).Fiber) { - movex=+1; - neworientation=Orientation.E; - } - else if (this.grid.GetXY(this.coordX+1, this.coordY+1)!=null && this.grid.GetXY(this.coordX+1, this.coordY+1).Fiber) { - movex=+1; - movey=+1; - neworientation=Orientation.NE; - } - else if (this.grid.GetXY(this.coordX+1, this.coordY-1)!=null && this.grid.GetXY(this.coordX+1, this.coordY-1).Fiber) { - movex=+1; - movey=-1; - neworientation=Orientation.SE; - } + Orientation[] orientations=get_orientations(this.orientation); + Vector2 soluce0=testorientation(orientations[0]); + Vector2 soluce1=testorientation(orientations[1]); + Vector2 soluce2=testorientation(orientations[2]); + if (soluce0!=null) { + neworientation=orientations[0]; + move=soluce0; } - else if (this.orientation==Orientation.NE) - { - if (this.grid.GetXY(this.coordX+1, this.coordY+1)!=null && this.grid.GetXY(this.coordX+1, this.coordY+1).Fiber) { - movex=+1; - movey=+1; - neworientation=Orientation.NE; - } - else if (this.grid.GetXY(this.coordX, this.coordY+1)!=null && this.grid.GetXY(this.coordX, this.coordY+1).Fiber) { - movey=+1; - neworientation=Orientation.N; - } - else if (this.grid.GetXY(this.coordX+1, this.coordY)!=null && this.grid.GetXY(this.coordX+1, this.coordY).Fiber) { - movex=+1; - neworientation=Orientation.E; - } + else if (soluce1!=null && soluce2!=null) { + neworientation=orientations[1]; + move=soluce1; } - else if (this.orientation==Orientation.N) - { - if (this.grid.GetXY(this.coordX, this.coordY+1)!=null && this.grid.GetXY(this.coordX, this.coordY+1).Fiber) { - movey=+1; - neworientation=Orientation.N; - } - else if (this.grid.GetXY(this.coordX-1, this.coordY+1)!=null && this.grid.GetXY(this.coordX-1, this.coordY+1).Fiber) { - movey=+1; - movex=-1; - neworientation=Orientation.NO; - } - else if (this.grid.GetXY(this.coordX+1, this.coordY+1)!=null && this.grid.GetXY(this.coordX+1, this.coordY+1).Fiber) { - movex=+1; - movey=+1; - neworientation=Orientation.NE; - } + else if (soluce1!=null) { + neworientation=orientations[1]; + move=soluce1; } - else if (this.orientation==Orientation.NO) - { - if (this.grid.GetXY(this.coordX-1, this.coordY+1)!=null && this.grid.GetXY(this.coordX-1, this.coordY+1).Fiber) { - movey=+1; - movex=-1; - neworientation=Orientation.NO; - } - else if (this.grid.GetXY(this.coordX-1, this.coordY+1)!=null && this.grid.GetXY(this.coordX-1, this.coordY+1).Fiber) { - movey=+1; - movex=-1; - neworientation=Orientation.N; - } - else if (this.grid.GetXY(this.coordX+1, this.coordY+1)!=null && this.grid.GetXY(this.coordX+1, this.coordY+1).Fiber) { - movex=+1; - movey=+1; - neworientation=Orientation.O; - } + else if (soluce2!=null) { + neworientation=orientations[2]; + move=soluce2; } - else if (this.orientation==Orientation.O) - { - if (this.grid.GetXY(this.coordX, this.coordY+1)!=null && this.grid.GetXY(this.coordX, this.coordY+1).Fiber) { - movey=+1; - neworientation=Orientation.N; - } - else if (this.grid.GetXY(this.coordX-1, this.coordY+1)!=null && this.grid.GetXY(this.coordX-1, this.coordY+1).Fiber) { - movey=+1; - movex=-1; - neworientation=Orientation.NO; - } - else if (this.grid.GetXY(this.coordX+1, this.coordY+1)!=null && this.grid.GetXY(this.coordX+1, this.coordY+1).Fiber) { - movex=+1; - movey=+1; - neworientation=Orientation.NE; - } - } - else if (this.orientation==Orientation.SO) - { - if (this.grid.GetXY(this.coordX, this.coordY+1)!=null && this.grid.GetXY(this.coordX, this.coordY+1).Fiber) { - movey=+1; - neworientation=Orientation.N; - } - else if (this.grid.GetXY(this.coordX-1, this.coordY+1)!=null && this.grid.GetXY(this.coordX-1, this.coordY+1).Fiber) { - movey=+1; - movex=-1; - neworientation=Orientation.NO; - } - else if (this.grid.GetXY(this.coordX+1, this.coordY+1)!=null && this.grid.GetXY(this.coordX+1, this.coordY+1).Fiber) { - movex=+1; - movey=+1; - neworientation=Orientation.NE; - } - } - else if (this.orientation==Orientation.S) - { - if (this.grid.GetXY(this.coordX, this.coordY+1)!=null && this.grid.GetXY(this.coordX, this.coordY+1).Fiber) { - movey=+1; - neworientation=Orientation.N; - } - else if (this.grid.GetXY(this.coordX-1, this.coordY+1)!=null && this.grid.GetXY(this.coordX-1, this.coordY+1).Fiber) { - movey=+1; - movex=-1; - neworientation=Orientation.NO; - } - else if (this.grid.GetXY(this.coordX+1, this.coordY+1)!=null && this.grid.GetXY(this.coordX+1, this.coordY+1).Fiber) { - movex=+1; - movey=+1; - neworientation=Orientation.NE; - } - } - else if (this.orientation==Orientation.SE) - { - if (this.grid.GetXY(this.coordX, this.coordY+1)!=null && this.grid.GetXY(this.coordX, this.coordY+1).Fiber) { - movey=+1; - neworientation=Orientation.N; - } - else if (this.grid.GetXY(this.coordX-1, this.coordY+1)!=null && this.grid.GetXY(this.coordX-1, this.coordY+1).Fiber) { - movey=+1; - movex=-1; - neworientation=Orientation.NO; - } - else if (this.grid.GetXY(this.coordX+1, this.coordY+1)!=null && this.grid.GetXY(this.coordX+1, this.coordY+1).Fiber) { - movex=+1; - movey=+1; - neworientation=Orientation.NE; - } - } - if (movex==0 && movey==0) + if (move==null) { Gdx.app.debug("wirechem-Particle", "coords:"+this.coordX+","+this.coordY+" killed no place to go"); this.kill(); } - else { - Gdx.app.debug("wirechem-Particle", "coords:"+this.coordX+","+this.coordY+" move to "+orientation+":"+movex+","+movey+" life:"+this.life); + else + { + Gdx.app.debug("wirechem-Particle", "coords:"+this.coordX+","+this.coordY+" move to "+orientation+":"+move.x+","+move.y+" life:"+this.life); + if (orientation!=neworientation) + oldorientation=orientation; orientation=neworientation; - this.coordX+=movex; - this.coordY+=movey; + this.coordX+=move.x; + this.coordY+=move.y; } } } -} + + +} \ No newline at end of file