Ejemplo n.º 1
0
 /// <summary>
 /// Create a vehicule with 2 motors, one left and one right
 /// </summary>
 /// <param name="left">Motor port for left motor</param>
 /// <param name="right">Motor port for right motor</param>
 public Vehicule(BrickPortMotor left, BrickPortMotor right)
 {
     brick = new Brick();
     //brick.Start();
     portleft = left;
     portright = right;
 }
Ejemplo n.º 2
0
    void Start()
    {
        FutileParams fParams = new FutileParams(true, true, true, true);
        fParams.AddResolutionLevel(1366, 1, 1, "");
        fParams.origin = new Vector2(0.5f, 0.5f);

        Futile.instance.Init(fParams);
        Futile.atlasManager.LoadAtlas("Atlases/Breakout");

        BreakoutBackground bg = new BreakoutBackground(1.4f, 1);
        _player = new Paddle();

        bricks = new List<Brick>();
        Brick b1 = new Brick();
        b1.x = -Futile.screen.halfWidth/2;
        b1.y = -Futile.screen.halfHeight/2;
        Brick b2 = new Brick();
        b2.x = Futile.screen.halfWidth/2;
        b2.y = -Futile.screen.halfHeight/2;
        Brick b3 = new Brick();
        b3.x = -Futile.screen.halfWidth / 2;
        b3.y = Futile.screen.halfHeight / 2;
        Brick b4 = new Brick();
        b4.x = Futile.screen.halfWidth / 2;
        b4.y = Futile.screen.halfHeight / 2;
        bricks.Add(b1);
        bricks.Add(b2);
        bricks.Add(b3);
        bricks.Add(b4);

        _ball = new Ball();
    }
Ejemplo n.º 3
0
 public BrickWall(Project2Game game, LevelPiece levelPiece, Vector3 offset, int height, int width, bool interleaved) :
     base(game, levelPiece, offset)
 {
     for (int i = 0; i < width; i++)
     {
         for (int j = 0; j < height; j++)
         {
             float sizeScaler = 4f;
             Vector3 brickPosition = this.originPosition + offset + new Vector3(2f * i, 1f * j, 0f) * (sizeScaler);
             brickPosition.Y += sizeScaler/2f; //push all bricks off the ground
             if (interleaved) {
                 if (j % 2 == 1) {
                     brickPosition.X += sizeScaler;
                 }
             }
             Brick newBrick = new Brick(
                 game,
                 game.models["box"],
                 brickPosition,
                 new Vector3(2f, 1f, 1f) * sizeScaler,
                 false
             );
             this.AddChild(newBrick);
         }
     }
 }
Ejemplo n.º 4
0
 public void saveBrick(Brick bks)
 {
     BrickSave bSv = bricks[bks.id];
     bSv.drilledAmount = bks.drilledAmount;
     bSv.mineralType = bks.mineralType;
     bSv.neighbourCode = bks.neighbourCode;
 }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            double tFood = 0;
            wormBrick = new Brick<Sensor, Sensor, Sensor, Sensor> ("usb");
            wormBrick.Connection.Open ();
            wormBrick.Sensor1 = new Sonar ();

            wormBrick.Vehicle.LeftPort = MotorPort.OutA;
            wormBrick.Vehicle.RightPort = MotorPort.OutB;
            wormBrick.Vehicle.ReverseLeft = false;
            wormBrick.Vehicle.ReverseRight = false;

            CreatePostSynaptic(neurons);

            for (; ;)
            {
                //var dist = ((Sonar)wormBrick.Sensor1).ReadDistance();
                var dist = 0;
                if (dist > 0 && dist < 30)
                {
                    Console.WriteLine("OBSTACLE (Nose Touch) " + dist);
                    DendriteAccumulate("FLPR");
                    DendriteAccumulate("FLPL");
                    DendriteAccumulate("ASHL");
                    DendriteAccumulate("ASHR");
                    DendriteAccumulate("IL1VL");
                    DendriteAccumulate("IL1VR");
                    DendriteAccumulate("OLQDL");
                    DendriteAccumulate("OLQDR");
                    DendriteAccumulate("OLQVR");
                    DendriteAccumulate("OLQVL");

                    RunConnectome();
                }
                else
                {
                    if (tFood < 2)
                    {
                        DendriteAccumulate("ADFL");
                        DendriteAccumulate("ADFR");
                        DendriteAccumulate("ASGR");
                        DendriteAccumulate("ASGL");
                        DendriteAccumulate("ASIL");
                        DendriteAccumulate("ASIR");
                        DendriteAccumulate("ASJR");
                        DendriteAccumulate("ASJL");

                        Thread.Sleep(500);
                        RunConnectome();
                    }

                    tFood += 0.5;
                    if (tFood > 20)
                    {
                        tFood = 0;
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public void Position()
 {
     var brick = new Brick(null, new Point(0.1f, 0.2f))
     {
         TopLeft = new Point(0.4f, 0.8f)
     };
     Assert.AreEqual(new Point(0.5f, 1.0f), brick.Position);
 }
Ejemplo n.º 7
0
	Brick NewBrick ()
	{
		GameObject go = GameObject.Instantiate (CloneDynamicBrick) as GameObject;
		go.transform.parent = this.transform;
		go.SetActive (false);
		Brick b = new Brick (go);
		return b;
	}
Ejemplo n.º 8
0
		public void Position()
		{
			var brick = new Brick(material, new Vector2D(0.1f, 0.2f), displayMode)
			{
				TopLeftGridCoord = new Vector2D(0.4f, 0.8f)
			};
			Assert.AreEqual(new Vector2D(0.5f, 1.0f), brick.Position);
		}
Ejemplo n.º 9
0
 /// <summary>
 /// Initialize a new NXT Touch sensor
 /// </summary>
 /// <param name="port">Sensor port</param>
 /// <param name="timeout">Period in millisecond to check sensor value changes</param>
 public NXTTouchSensor(BrickPortSensor port, int timeout)
 {
     brick = new Brick();
     Port = port;
     brick.BrickPi.Sensor[(int)Port].Type = BrickSensorType.TOUCH;
     periodRefresh = timeout;
     timer = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
Ejemplo n.º 10
0
 public Motor(BrickPortMotor port, int timeout)
 {
     brick = new Brick();
     Port = port;
     //brick.Start();
     periodRefresh = timeout;
     timer = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initialize a NXT Sound Sensor
 /// </summary>
 /// <param name="port">Sensor port</param>
 /// <param name="timeout">Period in millisecond to check sensor value changes</param>
 public NXTSoundSensor(BrickPortSensor port, int timeout)
 {
     brick = new Brick();
     Port = port;
     brick.BrickPi.Sensor[(int)Port].Type = (byte)BrickSensorType.SENSOR_RAW;
     periodRefresh = timeout;
     timer = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
Ejemplo n.º 12
0
	private void AddBrickToLose(Brick brick)
	{
		float y = 200 - brick.transform.localPosition.y;
		if (!BricksToLose.ContainsKey(y))
		{
			BricksToLose.Add(y, new List<global::Brick>());
		}
		BricksToLose[y].Add(brick);
	}
Ejemplo n.º 13
0
 public void BrickCollision(Vector3 pos, Brick brick)
 {
     brickHitEmitter.transform.position = pos;
     brickHitEmitter.Emit(brick.score);
     if (brick.Hits > 0) {
         brick.Hits--;
     }
     totalScore += brick.score;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Initialize an EV3 Gyro Sensor
 /// </summary>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">Gyro mode</param>
 /// <param name="timeout">Period in millisecond to check sensor value changes</param>
 public EV3GyroSensor(BrickPortSensor port, GyroMode mode, int timeout)
 {
     brick = new Brick();
     Port = port;
     gmode = mode;
     brick.BrickPi.Sensor[(int)Port].Type = (BrickSensorType)mode;
     periodRefresh = timeout;
     timer = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
Ejemplo n.º 15
0
Archivo: LD24.cs Proyecto: MrPhil/LD24
    private void AddBrick(float x, float y)
    {
        Brick brick = new Brick();
        brick.x = x;
        brick.y = y;

        bricks.Add(brick);
        fContainerMain.AddChild(brick);
    }
Ejemplo n.º 16
0
 /// <summary>
 /// Initilaize an EV3 Color Sensor
 /// </summary>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">Color mode</param>
 /// <param name="timeout">Period in millisecond to check sensor value changes</param>
 public EV3ColorSensor(BrickPortSensor port, ColorSensorMode mode, int timeout)
 {
     brick = new Brick();
     Port = port;
     colorMode = mode;
     //set the correct mode
     brick.BrickPi.Sensor[(int)Port].Type = GetEV3Mode(mode);
     periodRefresh = timeout;
     timer = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="model">the model to use for the copy</param>
 public Brick(Brick model)
     : base(model)
 {
     this.mActiveConnectionPointIndex = model.mActiveConnectionPointIndex;
     this.mAltitude = model.mAltitude;
     // we don't clone the attached rulers
     // call the init after setting the orientation (in the base copy copy constructor)
     // to compute the image in the right orientation
     // the init method will initialize mMipmapImages, mOriginalImageReference, mOriginalImageReference and mConnectionPoints
     init(model.mPartNumber);
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Initialize an EV3 Ultrasonic Sensor
 /// </summary>
 /// <param name="port">Sensor port</param>
 /// <param name="usmode">Ultrasonic mode</param>
 /// <param name="timeout">Period in millisecond to check sensor value changes</param>
 public EV3UltraSonicSensor(BrickPortSensor port, UltraSonicMode usmode, int timeout)
 {
     brick = new Brick();
     Port = port;
     if (UltraSonicMode.Listen == mode)
         mode = UltraSonicMode.Centimeter;
     mode = usmode;
     brick.BrickPi.Sensor[(int)Port].Type = (BrickSensorType)BrickSensorType.EV3_US_M0;
     periodRefresh = timeout;
     timer = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
Ejemplo n.º 19
0
    void FixedUpdate()
    {
        hitBottom = Physics2D.Raycast(transform.position, -Vector2.up, 0.3f, groundMask);
        if(hitBottom)
            brick = hitBottom.transform.gameObject.GetComponent<Brick>();

        // ground hit
        if (hitBottom && !shootFired) {
            shootFired = true;
            StartCoroutine("ProcessDestroy");
        }
    }
Ejemplo n.º 20
0
Archivo: LD24.cs Proyecto: MrPhil/LD24
    private void BrickDeath(Brick brick)
    {
        brick.BeingKilled = true;

        fContainerDeath.AddChild(brick);

        TweenConfig tweenConfig = new TweenConfig()
            .floatProp("scale", 1.6f)
            .floatProp("alpha", 0.5f)
            .colorProp("color", new Color(1, 1, 1, 1))
            .onComplete(BrickDead);
        brick.Tween = Go.to(brick, timeToKillMatch, tweenConfig);
    }
Ejemplo n.º 21
0
 // Todo : Running this coroutine several times quickly will cause client to request several time the same mesh or texture. Solve it.
 public IEnumerator RequestBrickOn(Chunck chunck)
 {
     List<string> bricksToLoad = new List<string>();
     List<string> texturesToLoad = new List<string>();
     foreach (string textureName in chunck.texturedBlocks.Keys)
     {
         if (!textures.ContainsKey(textureName))
         {
             if (!texturesToLoad.Contains(textureName))
             {
                 texturesToLoad.Add(textureName);
             }
         }
         foreach (Block b in chunck.texturedBlocks[textureName])
         {
             if (!bricks.ContainsKey(b.reference))
             {
                 if (!bricksToLoad.Contains(b.reference))
                 {
                     bricksToLoad.Add(b.reference);
                 }
             }
         }
     }
     foreach (string reference in bricksToLoad)
     {
         WWW request = new WWW("http://localhost:8080/bricks/" + reference);
         yield return request;
         if (!bricks.ContainsKey(reference))
         {
             BrickData bData = JsonUtility.FromJson<BrickData>(request.text);
             Brick b = new Brick();
             b.SetData(bData);
             Add(b);
         }
     }
     foreach (string texture in texturesToLoad)
     {
         Texture2D newTexture = new Texture2D(16, 16);
         WWW request = new WWW("http://localhost:8080/textures/" + texture + ".png");
         yield return request;
         request.LoadImageIntoTexture(newTexture);
         if (!textures.ContainsKey(texture))
         {
             Add(texture, newTexture);
         }
     }
     StartCoroutine(chunck.BuildBlocksAsync());
 }
    public static List<Brick> GetAllValidMoves(Brick[,] board, Othello.PlayerColor currentPlayer)
    {
        var validMoves = new List<Brick>();
        List<Direction> validDirections;
        foreach (Brick brick in board)
        {
            if (brick.brickColor == BrickColor.Empty || brick.brickColor == BrickColor.Hint)
            {

                validDirections = GetValidDirections(board, brick, currentPlayer);
                if (validDirections.Count > 0)
                {
                    validMoves.Add(brick);
                }
            }
        }
        return validMoves;
    }
  static void Main(string[] args)
  {
	      var ev3 = new Brick<Sensor,Sensor,Sensor,Sensor>("usb");
	      ev3.Connection.Open();
	      Stopwatch swouter = new Stopwatch();
		Stopwatch swinner = new Stopwatch();
		int steptime = 100;
		swouter.Start();
				//ev3.MotorA.On(40);
				//ev3.MotorA.On(10);
				ev3.MotorA.SetPower(80);
				
				System.Threading.Thread.Sleep(5000);
				ev3.MotorA.SetPower(0);
		
		//ev3.MotorA.Off(); 
		      ev3.Connection.Close();
	}
Ejemplo n.º 24
0
	private Brick SpawnBrick(Vector3 localPos, Color color)
	{
		if (Application.isPlaying)
			brick = Brick.Spawn(false).GetComponent<Brick>();
		else
		{
#if UNITY_EDITOR
			brick = (PrefabUtility.InstantiatePrefab(Brick) as GameObject).GetComponent<Brick>();
#endif
		}
		brick.transform.SetParent(BrickParent);
		brick.transform.localPosition = localPos;
		brick.SetColor(color);

		Bricks.Add(brick);
		AddBrickToLose(brick);
		BrickSprites.Add(brick.sprite);

		return brick;
	}
Ejemplo n.º 25
0
        public override void Draw()
        {
            base.Draw();
            int id = 0;

            w.Bricks = new List<Brick>();
            for (int i = 0; i < w.NumberOfLines; i++)
            {
                for (int j = 0; j < w.BricksOnALine; j++)
                {

                    float _x = w.Location.X + i * Brick.Width;
                    float _y = w.Location.Y + j * Brick.Height;

                    if (w.IsBrickDrawn(id))
                    {

                        Brick b = new Brick(_x, _y, Brick.Width, Brick.Height, id);
                        b.Draw();
                        //b.Draw(g, p);

                        //Test Lines
                        //PointF pBall = new PointF(Ball.Location.X + Ball.Radius / 2, Ball.Location.Y + Ball.Radius / 2);
                        //PointF pBrick = new PointF(b.Location.X + Brick.Width / 2, b.Location.Y + Brick.Width / 2);
                        //g.DrawLine(pLine, pBall, pBrick);
                        w.Bricks.Add(b);

                    }
                    else
                    {
                        Brick b = new Brick(_x, _y, Brick.Width, Brick.Height, id);
                        b.Drawer = new BrickDrawerDashed(b);
                        b.Draw();
                        //b.DrawDashed(g);

                    }
                    id += 1;
                }
            }
        }
Ejemplo n.º 26
0
 private void OnBrickDestruction(Brick obj)
 {
     UpdateRemainingBricksText();
     UpdateScoreText(10);
 }
Ejemplo n.º 27
0
 protected AbstractAction(Brick brick, NotifyMethodAsync notify)
 {
     Brick  = brick;
     Notify = notify;
 }
Ejemplo n.º 28
0
 static async void ConnectToBrick()
 {
     brick = new Brick(new UsbCommunication());
     await brick.ConnectAsync();
 }
Ejemplo n.º 29
0
 internal Brick Edit(Brick update)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Color light matrix.
 /// </summary>
 /// <param name="brick">The brick.</param>
 /// <param name="port">The port.</param>
 protected internal ColorLightMatrix(Brick brick, SensorPort port)
     : base(brick, port, SensorType.SpikeEssential3x3ColorLightMatrix)
 {
     Brick.SendRawCommand($"port {(byte)Port} ; plimit 1 ; set -1\r");
 }
Ejemplo n.º 31
0
 public static void addBrick(float x, float y)
 {
     int   actualSector = Building.getBuilding().getIndexActualSector();
     Brick brick        = new Brick((int)x, (int)y, actualSector);
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Initialize a new NXT Touch sensor
 /// </summary>
 /// <param name="brick">Interface to main Brick component</param>
 /// <param name="port">Sensor port</param>
 public NXTTouchSensor(Brick brick, SensorPort port)
     : this(brick, port, 1000)
 {
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Initialize a NXT Color Sensor
 /// </summary>
 /// <param name="brick">Interface to main Brick component</param>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">Color mode</param>
 public NXTColorSensor(Brick brick, SensorPort port, ColorSensorMode mode)
     : this(brick, port, mode, 1000)
 {
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Initialize a NXT Sound Sensor
 /// </summary>
 /// <param name="port">Sensor Port</param>
 public NXTSoundSensor(Brick brick, BrickPortSensor port) : this(brick, port, 1000)
 {
 }
Ejemplo n.º 35
0
 /// <summary>
 /// Initializes an EV3 IS Sensor
 /// </summary>
 /// <param name="brick">Interface to main Brick component</param>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">IR mode</param>
 public EV3InfraredSensor(Brick brick, SensorPort port, IRMode mode)
     : this(brick, port, mode, 1000)
 {
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Initialize an EV3 IR Sensor
 /// </summary>
 /// <param name="port">Sensor port</param>
 public EV3IRSensor(Brick brick, BrickPortSensor port) : this(brick, port, IRMode.Proximity, 1000)
 {
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Initializes an EV3 IS Sensor
 /// </summary>
 /// <param name="mode">IR mode</param>
 public EV3IRSensor(Brick brick, BrickPortSensor port, IRMode mode) : this(brick, port, mode, 1000)
 {
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Create a vehicule with 2 motors, one left and one right
 /// </summary>
 /// <param name="brick">The main brick controlling the motor</param>
 /// <param name="left">Motor port for left motor</param>
 /// <param name="right">Motor port for right motor</param>
 public Vehicle(Brick brick, BrickPortMotor left, BrickPortMotor right)
 {
     _brick    = brick;
     PortLeft  = left;
     PortRight = right;
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Displays the 9 leds with the same color.
 /// </summary>
 /// <param name="color">The color to use.</param>
 public void DisplayColor(LedColor color)
 {
     Brick.SendRawCommand($"port {(byte)Port} ;  select 1 ; write1 c1 {(byte)color:X}");
 }
Ejemplo n.º 40
0
 /// <summary>
 /// Initialize an EV3 Ulrasonic sensor
 /// </summary>
 /// <param name="brick">Interface to main Brick component</param>
 /// <param name="port">Sensor port</param>
 public EV3UltraSonicSensor(Brick brick, SensorPort port)
     : this(brick, port, UltraSonicMode.Centimeter, 1000)
 {
 }
Ejemplo n.º 41
0
 public MotorCollection(Brick brick)
 {
     this.brick = brick;
     motors     = new Motor[4];
 }
Ejemplo n.º 42
0
 /// <summary>
 /// Initialize a NXT Color Sensor
 /// </summary>
 /// <param name="brick">Interface to main Brick component</param>
 /// <param name="port">Sensor port</param>
 public NXTColorSensor(Brick brick, SensorPort port)
     : this(brick, port, ColorSensorMode.Color, 1000)
 {
 }
Ejemplo n.º 43
0
 /// <summary>
 /// Create a motor
 /// </summary>
 /// <param name="brick">The brick controlling the motor</param>
 /// <param name="port">Motor port</param>
 public Motor(Brick brick, BrickPortMotor port)
     : this(brick, port, 1000)
 {
 }
Ejemplo n.º 44
0
        private void CheckPowerUp()
        {
            while (active)
            {
                if (lastKnownBrick != Brick)
                {
                    if (Brick == Brick.None)
                    {
                        OnPowerUpUsed(this, new PowerUpUsedEventArgs(lastKnownBrick, lastKnownWhiteBricks));
                    }
                    else
                    {
                        OnPickedUpBrick(this, new PickedUpBrickEventArgs(Brick));
                    }
                }

                if (WhiteBricks > lastKnownWhiteBricks)
                {
                    OnPickedUpBrick(this, new PickedUpBrickEventArgs(Brick.White));
                }

                lastKnownBrick = Brick;
                lastKnownWhiteBricks = WhiteBricks;

                Thread.Sleep((int)Settings.RefreshRate);
            }
        }
Ejemplo n.º 45
0
 private void Button4_Click(object sender, EventArgs e)
 {
     m_Brick = m_Factory.CreatBrick();
     pictureBox1.Refresh();
 }
Ejemplo n.º 46
0
 protected override bool TestEquals(Brick other)
 {
     return base.TestEquals(other) && TestEquals((NxtMotorBrick) other);
 }
Ejemplo n.º 47
0
 /// <summary>
 /// Initialize a NXT Ultrasonic sensor
 /// </summary>
 /// <param name="brick"></param>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">Ultrasonic mode</param>
 public NXTUltraSonicSensor(Brick brick, SensorPort port, UltraSonicMode mode) : this(brick, port, mode, 1000)
 {
 }
Ejemplo n.º 48
0
 public NxtBrick(string comPort)
 {
     this.brick = new Brick<Sensor, Sensor, Sensor, Sensor>(comPort);
     this.brick.Connection.Disconnected += ConnectionOnDisconnected;
 }
Ejemplo n.º 49
0
 internal void Create(Brick newData)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 50
0
    public void HandleBrick(int _relativeBrickHeight, int _distanceInFront, int _distanceToSide, int _leadLeg, int _gripRotation, Brick _brickToMove, bool _pickupMode, bool _backWeight)
    {
        jointTargetList.Clear();
        int brickTypeToBeCarriedAfterHandle = 0;

        if (_pickupMode == true)
        {
            brickTypeToBeCarriedAfterHandle = _brickToMove.brickType;
        }

        brickBeingCarried = _brickToMove;

        bool straightSequence = false;

        if (_distanceToSide == 0 && _backWeight)
        {
            straightSequence = true;
        }
        bool  preTurnIsNeeded  = false;
        float preTurnAngle     = 0;
        bool  postTurnIsNeeded = false;
        float postTurnAngle    = 0;

        // account for foot A heel in or out
        float currentLegABase = 0;

        if (_distanceToSide <= 0 && !footAHeelIn)
        {
            currentLegABase = 180;
        }

        else if (_distanceToSide > 0 && !footAHeelIn)
        {
            preTurnIsNeeded  = true;
            preTurnAngle     = 0;
            postTurnIsNeeded = true;
            postTurnAngle    = 1800;
            currentLegABase  = 0;
        }

        else if (_distanceToSide < 0 && footAHeelIn)
        {
            preTurnIsNeeded  = true;
            preTurnAngle     = 1800;
            postTurnIsNeeded = true;
            postTurnAngle    = 0;
            currentLegABase  = 180;
        }

        else if (_distanceToSide >= 0 && footAHeelIn)
        {
            currentLegABase = 0;
        }

        float legARotation = RadianToDegree(Mathf.Atan((float)_distanceToSide / _distanceInFront));

        float gripRotation = 0;

        if (legARotation >= 0)
        {
            gripRotation = _gripRotation + legARotation;
        }
        else if (legARotation < 0)
        {
            gripRotation = 180 - _gripRotation + legARotation;
        }

        float legCPlacementDistance = Mathf.Sqrt(Mathf.Pow(_distanceInFront, 2) + Mathf.Pow(_distanceToSide, 2));


        //set leg types
        int leadingLeg;
        int trailingLeg;

        if (_leadLeg == legA)
        {
            leadingLeg  = legA;
            trailingLeg = legB;
        }
        else
        {
            leadingLeg   = legB;
            trailingLeg  = legA;
            legARotation = 0;
        }

        float[] jointTargetListValues0 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
        float[] jointTargetListValues1 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
        float[] jointTargetListValues2 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
        float[] jointTargetListValues3 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
        float[] jointTargetListValues4 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };

        if (preTurnIsNeeded)
        {
            jointTargetListValues0 = SetForCounterbalance(legB, currentStance, brickTypeCurrentlyCarried);
            jointTargetListValues1 = LiftLeg(legA, 1);
            jointTargetListValues2 = RotateLegA(preTurnAngle);
            jointTargetListValues3 = PlaceLeg(legA, 1);
            jointTargetListValues4 = ReturnToStance(currentStance);
        }

        float[] jointTargetListValues5 = SetForCounterbalance(leadingLeg, currentStance, brickTypeCurrentlyCarried);
        float[] jointTargetListValues6 = LiftLeg(trailingLeg, 1);

        float[] jointTargetListValues7 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };

        if (straightSequence)
        {
            jointTargetListValues7 = SetForCounterbalance(leadingLeg, 8, brickTypeCurrentlyCarried);
        }
        else
        {
            jointTargetListValues7 = SetForCounterbalance(leadingLeg, 4, brickTypeCurrentlyCarried);
        }

        float[] jointTargetListValues8 = RotateLegA((currentLegABase + legARotation) * 10); // non straight only

        float[] jointTargetListValues9 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };

        if (straightSequence)
        {
            jointTargetListValues9 = PlaceLeg(trailingLeg, 1);
        }

        float[] jointTargetListValues10 = PrepareLegsForGrip(leadingLeg, legCPlacementDistance, straightSequence, brickTypeCurrentlyCarried);
        float[] jointTargetListValues11 = RotateGrip((gripRotation * 10));
        float[] jointTargetListValues12 = LowerBothLegsForBrick(leadingLeg, _relativeBrickHeight, straightSequence);

        float[] jointTargetListValues13 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };

        if (_pickupMode)
        {
            jointTargetListValues13 = CloseGrip();
        }
        else
        {
            jointTargetListValues13 = OpenGrip();
        }

        float[] jointTargetListValues14 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };

        if (!straightSequence)
        {
            jointTargetListValues14 = PrepareLegsForGrip(leadingLeg, legCPlacementDistance, straightSequence, brickTypeToBeCarriedAfterHandle);
        }

        float[] jointTargetListValues15 = LiftBothLegsForBrick(leadingLeg, _relativeBrickHeight, straightSequence);
        float[] jointTargetListValues16 = RotateGrip(0);
        float[] jointTargetListValues17 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
        float[] jointTargetListValues18 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };

        if (straightSequence)
        {
            jointTargetListValues17 = SetForCounterbalance(leadingLeg, 8, brickTypeToBeCarriedAfterHandle);
            jointTargetListValues18 = LiftLeg(trailingLeg, 1);
        }


        float[] jointTargetListValues19 = SetForCounterbalance(leadingLeg, currentStance, brickTypeToBeCarriedAfterHandle);
        float[] jointTargetListValues20 = RotateLegA(currentLegABase * 10);
        float[] jointTargetListValues21 = PlaceLeg(trailingLeg, 1);
        float[] jointTargetListValues22 = ReturnToStance(currentStance);

        float[] jointTargetListValues23 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
        float[] jointTargetListValues24 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
        float[] jointTargetListValues25 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
        float[] jointTargetListValues26 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
        float[] jointTargetListValues27 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };

        if (postTurnIsNeeded)
        {
            jointTargetListValues23 = SetForCounterbalance(legB, currentStance, brickTypeToBeCarriedAfterHandle);
            jointTargetListValues24 = LiftLeg(legA, 1);
            jointTargetListValues25 = RotateLegA(postTurnAngle);
            jointTargetListValues26 = PlaceLeg(legA, 1);
            jointTargetListValues27 = ReturnToStance(currentStance);
        }

        jointTargetList.Add(jointTargetListValues0);
        jointTargetList.Add(jointTargetListValues1);
        jointTargetList.Add(jointTargetListValues2);
        jointTargetList.Add(jointTargetListValues3);
        jointTargetList.Add(jointTargetListValues4);
        jointTargetList.Add(jointTargetListValues5);
        jointTargetList.Add(jointTargetListValues6);
        jointTargetList.Add(jointTargetListValues7);
        jointTargetList.Add(jointTargetListValues8);
        jointTargetList.Add(jointTargetListValues9);
        jointTargetList.Add(jointTargetListValues10);
        jointTargetList.Add(jointTargetListValues11);
        jointTargetList.Add(jointTargetListValues12);
        jointTargetList.Add(jointTargetListValues13);
        jointTargetList.Add(jointTargetListValues14);
        jointTargetList.Add(jointTargetListValues15);
        jointTargetList.Add(jointTargetListValues16);
        jointTargetList.Add(jointTargetListValues17);
        jointTargetList.Add(jointTargetListValues18);
        jointTargetList.Add(jointTargetListValues19);
        jointTargetList.Add(jointTargetListValues20);
        jointTargetList.Add(jointTargetListValues21);
        jointTargetList.Add(jointTargetListValues22);
        jointTargetList.Add(jointTargetListValues23);
        jointTargetList.Add(jointTargetListValues24);
        jointTargetList.Add(jointTargetListValues25);
        jointTargetList.Add(jointTargetListValues26);
        jointTargetList.Add(jointTargetListValues27);


        if (_pickupMode)
        {
            pickupInProgress = true;
        }
        else
        {
            placementInProgress = true;
        }

        stepInProgress = true;
        moveCounter    = 0;
    }
Ejemplo n.º 51
0
    List <Brick.Direction[]> GenRow(int y)
    {
        var res = new List <Brick.Direction[]>();

        if (y == 0)
        {
            for (var j = 0; j < width; j++)
            {
                if (j == 0)
                {
                    res.Add(new Brick.Direction[2] {
                        Brick.Direction.top, Brick.Direction.bot
                    });
                    continue;
                }
                //res.Add(Brick.RandomAvailableDirs());
                res.Add(new Brick.Direction[2] {
                    Brick.Direction.none, Brick.Direction.none
                });
            }
        }
        else if (y < 3)
        {
            for (var j = 0; j < width; j++)
            {
                res.Add(new Brick.Direction[2] {
                    Brick.Direction.none, Brick.Direction.none
                });
            }
        }
        else
        {
            List <int> arr = new List <int>();
            for (var i = 0; i < width; i++)
            {
                if (At(i, y - 1)[0] != Brick.Direction.none)
                {
                    continue;
                }
                arr.Add(i);
            }
            // choose 1 - 2 from arr
            for (var i = 0; i < arr.Count; i++)
            {
                var r = Random.Range(0, arr.Count);
                var t = arr[i];
                arr[i] = arr[r];
                arr[r] = t;
            }
            for (var i = 0; i < width; i++)
            {
                if (i == arr[0])
                {
                    res.Add(Brick.RandomAvailableDirs());
                }
                else
                {
                    //res.Add(Brick.RandomAvailableDirs());
                    res.Add(new Brick.Direction[2] {
                        Brick.Direction.none, Brick.Direction.none
                    });
                }
            }
        }
        return(res);
    }
Ejemplo n.º 52
0
        static void Main(string[] args)
        {
            /*Position control
             * ev3 = new Brick<Sensor, Sensor, Sensor, Sensor>("COM40");
             * try
             * {
             *  ev3.Connection.Open();
             *  ev3.MotorA.ResetTacho();
             *  ev3.MotorA.On(50, 6 * 360, true);
             *  WaitForMotorToStop();
             *  Console.WriteLine("Position: " + ev3.MotorA.GetTachoCount());
             *  ev3.MotorA.On(-50, 9 * 360, true);
             *  WaitForMotorToStop();
             *  Console.WriteLine("Position: " + ev3.MotorA.GetTachoCount());
             *  ev3.MotorA.MoveTo(50, 0, true);
             *  WaitForMotorToStop();
             *  ev3.MotorA.Off();
             *  Console.WriteLine("Position: " + ev3.MotorA.GetTachoCount());
             * }
             * catch (Exception e)
             * {
             *  Console.WriteLine(e.StackTrace);
             *  Console.WriteLine("Error: " + e.Message);
             *  Console.WriteLine("Press any key to end...");
             *  Console.ReadKey();
             * }
             * finally
             * {
             *  ev3.Connection.Close();
             * }
             * }
             *
             * static void WaitForMotorToStop()
             * {
             * Thread.Sleep(500);
             * while (ev3.MotorA.IsRunning()) { Thread.Sleep(50); }
             * }*/
            /*ramp profile
             * var ev3 = new Brick<Sensor, Sensor, Sensor, Sensor>("COM40");
             * ev3.Connection.Open();
             * ev3.MotorA.SpeedProfileStep(50, 300, 600, 300, true);
             * ev3.Connection.Close();*/

            /*Synchronising motors
             * var ev3 = new Brick<Sensor, Sensor, Sensor, Sensor>("COM40");
             * ev3.Connection.Open();
             * ev3.MotorSync.BitField = OutputBitfield.OutA | OutputBitfield.OutD;
             * ev3.MotorSync.On(50, 0);
             * System.Threading.Thread.Sleep(3000);
             * ev3.MotorSync.On(50, 50);//Motor A runs twice as fast as motor D
             * System.Threading.Thread.Sleep(3000);
             * ev3.MotorSync.Brake();
             * System.Threading.Thread.Sleep(1000);
             * ev3.MotorSync.StepSync(-50, 0, 6 * 360, false);//Move to a position
             * ev3.Connection.Close();  */

            //Controling a vehicle
            var ev3 = new Brick <Sensor, Sensor, Sensor, Sensor>("COM40");

            try
            {
                ev3.Connection.Open();
                ev3.Vehicle.LeftPort     = MotorPort.OutA;
                ev3.Vehicle.RightPort    = MotorPort.OutD;
                ev3.Vehicle.ReverseLeft  = false;
                ev3.Vehicle.ReverseRight = false;
                sbyte          speed = 50;
                ConsoleKeyInfo cki;
                Console.WriteLine("Press T to quit");
                do
                {
                    cki = Console.ReadKey(true); //press a key
                    switch (cki.Key)
                    {
                    case ConsoleKey.W:
                        ev3.Vehicle.Forward(speed);
                        break;

                    case ConsoleKey.S:
                        ev3.Vehicle.Backward(speed);
                        break;

                    case ConsoleKey.D:
                        ev3.Vehicle.SpinRight(speed);
                        break;

                    case ConsoleKey.A:
                        ev3.Vehicle.SpinLeft(speed);
                        break;

                    case ConsoleKey.Q:
                        ev3.Vehicle.TurnLeftForward(speed, 50);
                        break;

                    case ConsoleKey.E:
                        ev3.Vehicle.TurnRightForward(speed, 50);
                        break;

                    case ConsoleKey.C:
                        ev3.Vehicle.TurnRightReverse(speed, 50);
                        break;

                    case ConsoleKey.Z:
                        ev3.Vehicle.TurnLeftReverse(speed, 50);
                        break;

                    case ConsoleKey.Spacebar:
                        ev3.Vehicle.Off();
                        break;
                    }
                } while (cki.Key != ConsoleKey.T);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                Console.WriteLine("Error: " + e.Message);
                Console.WriteLine("Press any key to end...");
                Console.ReadKey();
            }
            finally
            {
                ev3.Connection.Close();
            }

            /*Reading sensors
             * var ev3 = new Brick<Sensor, Sensor, Sensor, Sensor>("COM40");
             * ev3.Connection.Open();
             * ev3.Sensor1 = new IRSensor(IRMode.Proximity);
             * ev3.Sensor2 = new TouchSensor();
             * ev3.Sensor3 = new ColorSensor(ColorMode.Color);
             * ev3.Sensor4 = new GyroSensor(GyroMode.Angle);
             * ConsoleKeyInfo cki;
             * Console.WriteLine("Press Q to quit");
             * do
             * {
             *  cki = Console.ReadKey(true); //press a key
             *  switch (cki.Key)
             *  {
             *      case ConsoleKey.D1://1 is pressed
             *          Console.WriteLine("S1: " + ev3.Sensor1.ReadAsString());
             *          break;
             *      case ConsoleKey.D2://2 is pressed
             *          Console.WriteLine("S2: " + ev3.Sensor2.ReadAsString());
             *          break;
             *      case ConsoleKey.D3://3 is pressed
             *          Console.WriteLine("S3: " + ev3.Sensor3.ReadAsString());
             *          break;
             *      case ConsoleKey.D4://4 is pressed
             *          Console.WriteLine("S4: " + ev3.Sensor4.ReadAsString());
             *          break;
             *  }
             * } while (cki.Key != ConsoleKey.Q);
             * ev3.Connection.Close();  */
        }
Ejemplo n.º 53
0
 /// <summary>
 /// Initialize an EV3 IR Sensor
 /// </summary>
 /// <param name="brick">Interface to main Brick component</param>
 /// <param name="port">Sensor port</param>
 public EV3InfraredSensor(Brick brick, SensorPort port)
     : this(brick, port, IRMode.Proximity, 1000)
 {
 }
Ejemplo n.º 54
0
        /// <summary>
        /// Instanciate new brick by at scene editor in the middle of camera view.
        /// </summary>
        /// <returns>The instansiate.</returns>
        /// <param name="brick">Brick.</param>
        /// <returns>Brick</returns>
        public static Brick Instansiate(Brick brick)
        {
            var toolsManager = ToolsManager.instance;

            return(Instansiate(brick, toolsManager.colorButton.selectedColor, toolsManager.scaleSelector.scale));
        }
Ejemplo n.º 55
0
 protected override bool TestEquals(Brick other)
 {
     return base.TestEquals(other) && TestEquals((ChangeNxtMotorAngleBrick) other);
 }
Ejemplo n.º 56
0
 private void BrickDestroyed(Brick obj)
 {
     UpdateTargetsText();
     UpdateScoreText(1);
 }
Ejemplo n.º 57
0
 protected override bool TestEquals(Brick other)
 {
     return base.TestEquals(other) && TestEquals((PlayNxtToneBrick) other);
 }
Ejemplo n.º 58
0
    void Update()
    {
        // Handle Touch / Mouse input
        if (Input.touchCount > 0)
        {
            // Examine all current touches
            for (int i = 0; i < Input.touchCount; i++)
            {
                myTouch t = new myTouch();
                t.set(Input.GetTouch(i));
                CheckTouch(t);
            }
        }
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER || UNITY_WEBGL
        else
        {
            if (Input.GetMouseButtonDown(0))
            {
                CheckTouch(UITouchMaker.createTouchFromInput(UIMouseState.DownThisFrame, ref lastMousePosition));
            }
            if (Input.GetMouseButton(0))
            {
                CheckTouch(UITouchMaker.createTouchFromInput(UIMouseState.HeldDown, ref lastMousePosition));
            }
            if (Input.GetMouseButtonUp(0))
            {
                CheckTouch(UITouchMaker.createTouchFromInput(UIMouseState.UpThisFrame, ref lastMousePosition));
            }
        }
#endif

        // If game is playing
        if (gameState == GameState.Play)
        {
            // Count game time.
            gameTime     += Time.deltaTime;
            respawnTimer -= Time.deltaTime;

            // Remove destroyed bricks from brick array.
            //for (int i = 0; i < bricks.Count; i++)
            //    if (bricks[i] == null) bricks.Remove(bricks[i]);

            // Fade out the buff info text.
            if (textBuffRenderer.material.color.a > 0.01f)
            {
                Color temp = textBuffRenderer.material.color;
                temp.a -= Time.deltaTime / 3;
                textBuffRenderer.material.color = temp;
            }
            else
            {
                textBuffRenderer.enabled = false;
            }

            // Magnet Button Cooldown timer.
            if (cooldownMagnetCurrent < gameDifficulty.magnetCooldown)
            {
                guiMagnetButton.GetComponent <Renderer>().material.SetFloat("_Cutoff", cooldownMagnetCurrent / gameDifficulty.magnetCooldown);
                cooldownMagnetCurrent += Time.deltaTime;
            }
            else
            {
                guiMagnetButton.usable = true;
            }

            // Buff Spawn Cooldown timer.
            if (cooldownBuffCurrent > 0)
            {
                cooldownBuffCurrent -= Time.deltaTime;
            }


            if (gameMode == GameMode.FreePlay)   // [FreePlay] only logic.
            // Respawn Brick - minimum brick limit.
            {
                if (bricksActive.Count <= 15 && brickSpawns.Count > 0)
                {
                    int   bPos = brickSpawns[Random.Range(0, brickSpawns.Count)];
                    Brick b    = brickLevel.bricks[bPos];
                    //b.life = Random.Range(1, 6);
                    BrickSpawn(b, bPos);
                }
                // Respawn Brick - random time respawn.
                if (respawnTimer <= 0 && brickSpawns.Count > 0)
                {
                    respawnTimer = Random.Range(8, 15);
                    int   bPos = brickSpawns[Random.Range(0, brickSpawns.Count)];
                    Brick b    = brickLevel.bricks[bPos];
                    //b.life = Random.Range(1, 6);
                    BrickSpawn(b, bPos);
                }
            }
            else     // [Campaign] and [KidMode] logic.
            // Woo we won the game!
            {
                if (bricksActive.Count <= 0)
                {
                    WinGame();
                    gameState = GameState.Win;
                }
            }
        }

        // Update Game Info text on screen.
        floatingScore   = Mathf.Lerp(floatingScore, points, Time.deltaTime * 5);
        textScore.text  = floatingScore.ToString("F0");
        textTime.text   = gameTime.ToString("f1");
        textBlocks.text = bricksActive.Count + " Blocks Remaining";
        textLives.text  = gameOverBar.life.ToString();
        textCombo.text  = "+" + combo;

        // Escape is the back button on Android.
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            TogglePause();
        }

        // M can pull the ball towards the paddle.
        if (Input.GetKeyDown(KeyCode.M))
        {
            MagnetBall();
        }

        // B explodes and damages all bricks in a radius
        if (Input.GetKeyDown(KeyCode.B))
        {
            BombBall();
        }
    }
Ejemplo n.º 59
0
    //產生將來用作生成Graph的資料
    void buildGraph()
    {
        Debug.Log("buildGraph()");

        bool success = graphMap.resetMap(width, height);

        if (!success)
        {
            return;
        }

        //綁定Brick得tileData
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                GameObject obj = tileCreator.getObj(x, y);
                if (obj != null)
                {
                    Brick brick = obj.GetComponentInChildren <Brick>();
                    if (brick != null)
                    {
                        brick.tileData = tileData;
                        brick.x        = x;
                        brick.y        = y;
                    }
                }
            }
        }

        //建立node
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                byte arrow = arrowMap[remap(x, y)];
                if (arrow != (byte)Arrow.None)
                {
                    string description = "";
                    if (arrow == (byte)Arrow.JumpPoint)
                    {
                        description = "JumpPoint";
                    }
                    else if (isLadder(x, y))
                    {
                        description = "Ladder";
                    }
                    else if (isRope(x, y))
                    {
                        description = "Rope";
                    }
                    graphMap.addGraphNode(x, y, description);
                }
            }
        }

        //建立connection
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                int  from  = remap(x, y);
                byte arrow = arrowMap[from];
                if (arrow != (byte)Arrow.None && arrow != (byte)Arrow.Dot)
                {
                    if (arrow == (byte)Arrow.JumpPoint)
                    {
                        int   to   = jumpToMap[from];
                        float cost = (from - to);
                        graphMap.addConnection(from, to, cost);
                        continue;
                    }

                    if (hasArrow(arrow, Arrow.Up))
                    {
                        int to = tileData.remap(x, y + 1);
                        graphMap.addConnection(from, to, 1);
                    }
                    if (hasArrow(arrow, Arrow.Down))
                    {
                        int to = tileData.remap(x, y - 1);
                        graphMap.addConnection(from, to, 1);
                    }
                    if (hasArrow(arrow, Arrow.Left))
                    {
                        //讓JumpPointCost大一點
                        int  to        = tileData.remap(x - 1, y);
                        byte nextArrow = arrowMap[to];

                        float cost = 1;
                        if (nextArrow == (byte)Arrow.JumpPoint)//如果next是JumpPoint,cost稍大,這樣會優先走樓梯
                        {
                            cost += 1;
                        }

                        graphMap.addConnection(from, to, cost);
                    }
                    if (hasArrow(arrow, Arrow.Right))
                    {
                        int to = tileData.remap(x + 1, y);

                        byte nextArrow = arrowMap[to];

                        float cost = 1;
                        if (nextArrow == (byte)Arrow.JumpPoint)//如果next是JumpPoint,cost稍大,這樣會優先走樓梯
                        {
                            cost += 1;
                        }
                        graphMap.addConnection(from, to, cost);
                    }
                }
            }
        }
    }
Ejemplo n.º 60
0
 protected override void UpdateCore()
 {
     SetBrick(Point.Empty, Brick.From(ColorConsole.CharMap['♣'], ConsoleColor.Green));
 }