/// <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; }
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(); }
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); } } }
public void saveBrick(Brick bks) { BrickSave bSv = bricks[bks.id]; bSv.drilledAmount = bks.drilledAmount; bSv.mineralType = bks.mineralType; bSv.neighbourCode = bks.neighbourCode; }
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; } } } }
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); }
Brick NewBrick () { GameObject go = GameObject.Instantiate (CloneDynamicBrick) as GameObject; go.transform.parent = this.transform; go.SetActive (false); Brick b = new Brick (go); return b; }
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); }
/// <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)); }
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)); }
/// <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)); }
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); }
public void BrickCollision(Vector3 pos, Brick brick) { brickHitEmitter.transform.position = pos; brickHitEmitter.Emit(brick.score); if (brick.Hits > 0) { brick.Hits--; } totalScore += brick.score; }
/// <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)); }
private void AddBrick(float x, float y) { Brick brick = new Brick(); brick.x = x; brick.y = y; bricks.Add(brick); fContainerMain.AddChild(brick); }
/// <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)); }
/// <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); }
/// <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)); }
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"); } }
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); }
// 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(); }
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; }
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; } } }
private void OnBrickDestruction(Brick obj) { UpdateRemainingBricksText(); UpdateScoreText(10); }
protected AbstractAction(Brick brick, NotifyMethodAsync notify) { Brick = brick; Notify = notify; }
static async void ConnectToBrick() { brick = new Brick(new UsbCommunication()); await brick.ConnectAsync(); }
internal Brick Edit(Brick update) { throw new NotImplementedException(); }
/// <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"); }
public static void addBrick(float x, float y) { int actualSector = Building.getBuilding().getIndexActualSector(); Brick brick = new Brick((int)x, (int)y, actualSector); }
/// <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) { }
/// <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) { }
/// <summary> /// Initialize a NXT Sound Sensor /// </summary> /// <param name="port">Sensor Port</param> public NXTSoundSensor(Brick brick, BrickPortSensor port) : this(brick, port, 1000) { }
/// <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) { }
/// <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) { }
/// <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) { }
/// <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; }
/// <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}"); }
/// <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) { }
public MotorCollection(Brick brick) { this.brick = brick; motors = new Motor[4]; }
/// <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) { }
/// <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) { }
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); } }
private void Button4_Click(object sender, EventArgs e) { m_Brick = m_Factory.CreatBrick(); pictureBox1.Refresh(); }
protected override bool TestEquals(Brick other) { return base.TestEquals(other) && TestEquals((NxtMotorBrick) other); }
/// <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) { }
public NxtBrick(string comPort) { this.brick = new Brick<Sensor, Sensor, Sensor, Sensor>(comPort); this.brick.Connection.Disconnected += ConnectionOnDisconnected; }
internal void Create(Brick newData) { throw new NotImplementedException(); }
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; }
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); }
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(); */ }
/// <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) { }
/// <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)); }
protected override bool TestEquals(Brick other) { return base.TestEquals(other) && TestEquals((ChangeNxtMotorAngleBrick) other); }
private void BrickDestroyed(Brick obj) { UpdateTargetsText(); UpdateScoreText(1); }
protected override bool TestEquals(Brick other) { return base.TestEquals(other) && TestEquals((PlayNxtToneBrick) other); }
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(); } }
//產生將來用作生成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); } } } } }
protected override void UpdateCore() { SetBrick(Point.Empty, Brick.From(ColorConsole.CharMap['♣'], ConsoleColor.Green)); }