Пример #1
0
 // --------------------------------------------------------------------------
 // CONSTRUCTOR
 // --------------------------------------------------------------------------
 public Cursor(CircuitRenderer cRend, Texture2D pixel)
 {
     cCase               = new NXTCase(Case.STRAIGHT);
     this.tStraight      = cRend.Texture_Straight;
     this.tTurn          = cRend.Texture_Turn;
     this.tIntersec      = cRend.Texture_Intersection;
     this.tPixel         = pixel;
     this.cursorLocation = new Vector2(0);
 }
Пример #2
0
        // --------------------------------------------------------------------------
        // METHODS
        // --------------------------------------------------------------------------
        public void Render(SpriteBatch sb)
        {
            for (int x = 0; x < circuit.Width; x++)
            {
                for (int y = 0; y < circuit.Height; y++)
                {
                    NXTCase   c = circuit.getCase(x, y);
                    Texture2D t;
                    Color     col = c.CaseColor;

                    // On trouve la texture (et couleur) adaptée
                    switch (c.TypeCase)
                    {
                    case (Case.EMPTY):
                        t   = tStraight;
                        col = Color.Black;
                        break;

                    case (Case.STRAIGHT):
                        t = tStraight;
                        break;

                    case (Case.VIRAGE):
                        t = tTurn;
                        break;

                    case (Case.INTERSECTION):
                        t = tIntersec;
                        break;

                    default:
                        t   = tStraight;
                        col = Color.Black;
                        break;
                    }

                    //sb.Draw(t, new Vector2(x * 32, y * 32), col);
                    sb.Draw(t, new Vector2(x * 32 + 16, y * 32 + 16), new Rectangle(0, 0, t.Width, t.Height), col, (((float)c.CaseOrientation) / 2) * (float)Math.PI, new Vector2(t.Width / 2, t.Height / 2), 1.0f, SpriteEffects.None, 1f); // Deprecated but OK
                }
            }
        }
Пример #3
0
        public void AddToIABuffer(List <Point> path)
        {
            NXTAction action;
            Point     oldPos    = vehicule.Position;
            Point     direction = vehicule.Direction;

            NXTCase currentCase = circuit.getCase(oldPos);

            if (path.Count > 0)
            {
                if (!((currentCase.goThrough(new NXTAction(NXTMovement.STRAIGHT), direction) + oldPos).Equals(path[0]) ||
                      (currentCase.goThrough(new NXTAction(NXTMovement.INTER_LEFT), direction) + oldPos).Equals(path[0]) ||
                      (currentCase.goThrough(new NXTAction(NXTMovement.INTER_RIGHT), direction) + oldPos).Equals(path[0])))
                {
                    this.buffer.Add(new NXTAction(NXTMovement.UTURN), false);
                    direction = Rotate90Clockwise(Rotate90Clockwise(direction));
                }
            }

            foreach (Point p in path)
            {
                action = MovementToAction(circuit.getCase(oldPos), oldPos, direction, p, out direction);

                if (circuit.hasPatient(p) && vehicule.Patients < vehicule.MAX_PATIENTS)
                {
                    action.Action = NXTAction.TAKE;
                }
                else if (circuit.hasHopital(p) && vehicule.Patients > 0)
                {
                    action.Action = NXTAction.DROP;
                }

                this.buffer.Add(action, false);
                oldPos = p;
            }
        }
Пример #4
0
        protected NXTAction MovementToAction(NXTCase currentCase, Point currentPosition, Point currentDirection, Point destination, out Point newDirection)
        {
            NXTAction outInstance = null;

            newDirection = currentDirection;
            Point deplacement   = destination - currentPosition;
            Point caseDirection = OrientationToDirection(currentCase.CaseOrientation);

            //Si le robot doit marquer une pause
            if (destination.Equals(currentPosition))
            {
                outInstance = new NXTAction(NXTMovement.PAUSE);
            }

            // Si destination derriere direction actuelle, demi tour
            if (destination.Equals(currentPosition - currentDirection))
            {
                outInstance = new NXTAction(NXTMovement.UTURN);
            }
            // Sinon si virage ou tout droit envoyer straight
            else if (currentCase.TypeCase == Case.STRAIGHT || currentCase.TypeCase == Case.VIRAGE)
            {
                outInstance = new NXTAction(NXTMovement.STRAIGHT);

                if (currentCase.TypeCase == Case.VIRAGE)
                {
                    newDirection = currentCase.goThrough(new NXTAction(NXTMovement.STRAIGHT), currentDirection);
                }
            }
            // sinon (intersection)
            else
            {
                //Console.WriteLine("[INTERSECTION] Deplacement= " + deplacement);
                // Si la case est dans la meme direction que le vehicule
                if (caseDirection.Equals(currentDirection))
                {
                    if (deplacement.Equals(Rotate90Clockwise(currentDirection)))
                    {
                        outInstance  = new NXTAction(NXTMovement.INTER_RIGHT);
                        newDirection = Rotate90Clockwise(currentDirection);
                    }
                    else
                    {
                        outInstance  = new NXTAction(NXTMovement.INTER_LEFT);
                        newDirection = Rotate90AntiClockwise(currentDirection);
                    }
                }
                else if (caseDirection.Equals(Rotate90Clockwise(currentDirection))) // r = tout droit
                {
                    if (deplacement.Equals(Rotate90AntiClockwise(currentDirection)))
                    {
                        outInstance  = new NXTAction(NXTMovement.INTER_LEFT);
                        newDirection = Rotate90AntiClockwise(currentDirection);
                    }
                    else
                    {
                        outInstance = new NXTAction(NXTMovement.INTER_RIGHT);
                    }
                }
                else if (caseDirection.Equals(Rotate90AntiClockwise(currentDirection))) // l = tout droit
                {
                    if (deplacement.Equals(Rotate90Clockwise(currentDirection)))
                    {
                        outInstance  = new NXTAction(NXTMovement.INTER_RIGHT);
                        newDirection = Rotate90Clockwise(currentDirection);
                    }
                    else
                    {
                        outInstance = new NXTAction(NXTMovement.INTER_LEFT);
                    }
                }
            }

            //Console.WriteLine(currentCase + " @ " + currentPosition + " -> " + destination + " _ " + DirectionToOrientation(newDirection) + "\nResult= " + outInstance);

            return(outInstance);
        }