feat: avancement des photons (nouveau code)
This commit is contained in:
parent
692860cfb4
commit
4530136a99
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue