// Update is called once per frame void Update() { /* * // (Debug) * if (Input.GetKeyDown(KeyCode.Z)) { * Attack(); * } * * if (Input.GetKeyUp(KeyCode.Z)) { * TurtleAni.SetBool("Attack", false); * } * * if (Input.GetKeyDown(KeyCode.X)) * { * FuryAttack(); * } * * if (Input.GetKeyUp(KeyCode.X)) * { * TurtleAni.SetBool("Fury", false); * } */ if (Input.GetKeyDown(KeyCode.Space)) { HP -= 5; TurtleAni.SetInteger("HP", HP); if (HP == 0) { state = TurtleState.Dead; StartCoroutine("DelayDying"); } StartCoroutine("DelayStunning"); } }
public TurtleState(TurtleState t) { pos = new Vector3(t.pos.x, t.pos.y, t.pos.z); stepSize = t.stepSize; width = t.width; rot = Quaternion.Euler(t.rot.eulerAngles); }
private void FuryAttack() { state = TurtleState.Attack; TurtleAni.SetBool("Fury", true); StartCoroutine(DelayAttack(3.0f)); }
public void CheckForRespawn(float TimeElapsed) { if (prevstate == TurtleState.stand && state == TurtleState.stand && collisionYbot) { timeToRespawn += TimeElapsed; if (timeToRespawn > 2 && timeToRespawn <= 4) { BeginRespawn = true; } else if (timeToRespawn > 4) { state = TurtleState.walk; if (rectangle.height == 32) { this.rectangle = new Rectangle(rectangle.X, rectangle.Y - 32, 32, 64); } timeToRespawn = 0; BeginRespawn = false; } } else { timeToRespawn = 0; BeginRespawn = false; } }
static Turtle SetupTurtle() { var table = new Table(); var turtleState = new TurtleState(); return(new Turtle(turtleState, table)); }
public void Operate( ref TurtleState state, int indexInString, SymbolString <float> sourceString) { var paramIndex = sourceString.parameters[indexInString]; if (paramIndex.length == 0) { state.transformation *= Matrix4x4.Scale(defaultScaleFactor * nonUniformScale); } else if (paramIndex.length == 1) { state.transformation *= Matrix4x4.Scale(sourceString.parameters[paramIndex, 0] * nonUniformScale); } else if (paramIndex.length == 3) { state.transformation *= Matrix4x4.Scale( new Vector3( sourceString.parameters[paramIndex, 0], sourceString.parameters[paramIndex, 1], sourceString.parameters[paramIndex, 2] )); } else { Debug.LogError($"Invalid scale parameter length: {paramIndex.length}"); } }
public void SequenceOfCommands_All_Valid() { var table = new Table(); var turtleState = new TurtleState(); var turtle = new Turtle(turtleState, table); string reportMessage = ""; Action <string> report = (msg) => reportMessage = msg; Action clearCommandLine = () => { }; Func <string, bool> isValidPlaceCommand = (cmd) => { return(true); }; var commandSequence = new List <string>() { "PLACE 0,0,NORTH", "MOVE", "MOVE", "MOVE", "RIGHT", "MOVE", "LEFT", "MOVE", "LEFT", "REPORT" }; foreach (var command in commandSequence) { turtle.ProcessCommand(command, report, clearCommandLine, isValidPlaceCommand); } reportMessage.Should().Be("1 4 WEST"); }
public void SequenceOfCommands_Valid_Place_Coordinates_MoveOutSideTable_SOUTH() { var table = new Table(); var turtleState = new TurtleState(); var turtle = new Turtle(turtleState, table); string reportMessage = ""; Action <string> report = (msg) => reportMessage = msg; Action clearCommandLine = () => { }; Func <string, bool> isValidPlaceCommand = (cmd) => { return(true); }; var commandSequence = new List <string>() { "PLACE 0,0,SOUTH", "MOVE", "MOVE", "MOVE", "MOVE", "MOVE", "MOVE", "REPORT" }; foreach (var command in commandSequence) { turtle.ProcessCommand(command, report, clearCommandLine, isValidPlaceCommand); } reportMessage.Should().Be("0 0 SOUTH"); }
private void GoForward() { float newX = state.Point.X + trailLen * (float)Math.Cos(state.Angle); float newY = state.Point.Y + trailLen * (float)Math.Sin(state.Angle); state = new TurtleState(new PointF(newX, newY), state.Angle); }
public Turtle() { pen = new Pen(PEN_COLOR, MIN_PEN_WIDTH); trailLen = MIN_TRAIL_LEN; state = new TurtleState(new PointF(START_X, START_Y), NORTH); states = new Stack <TurtleState>(); }
IEnumerator DelayStunning() { state = TurtleState.Idle; yield return(new WaitForSeconds(1.5f)); state = TurtleState.Wander; }
public void Operate( ref TurtleState state, int indexInString, SymbolString <float> sourceString) { var paramIndex = sourceString.parameters[indexInString]; float bendFactor = defaultBendFactor; if (paramIndex.length == 1) { bendFactor = sourceString.parameters[paramIndex, 0]; } var localBendDirection = state.transformation.inverse.MultiplyVector(defaultBendDirection); var adjustment = (bendFactor) * (Vector3.Cross(localBendDirection, Vector3.right)); state.transformation *= Matrix4x4.Rotate( Quaternion.Slerp( Quaternion.identity, Quaternion.FromToRotation( Vector3.right, localBendDirection), adjustment.magnitude ) ); }
public void Operate( ref TurtleState state, int indexInString, SymbolString <float> sourceString, TurtleVolumetricHandles volumetricHandles) { var paramIndex = sourceString.parameters[indexInString]; if (paramIndex.length != 1) { return; } var pointInLocalSpace = state.transformation.MultiplyPoint(Vector3.zero); var voxelIndex = volumetricHandles.universalWriter.GetVoxelIndexFromLocalSpace(pointInLocalSpace); if (!voxelIndex.IsValid) { return; } var amountInSymbol = sourceString.parameters[paramIndex, 0]; if (diffusionDirection == OrganDiffusionDirection.PUMP_OUT) { volumetricHandles.universalWriter.AppendAmountChangeToOtherLayer(voxelIndex, amountInSymbol, resourceLayerId); return; } var amountInVoxel = volumetricHandles.volumetricData[voxelIndex, resourceLayerId]; var diffusionToLSystem = (amountInVoxel - amountInSymbol) * diffusionConstant; switch (diffusionDirection) { case OrganDiffusionDirection.DIFFUSE_IN_ONLY: diffusionToLSystem = math.max(diffusionToLSystem, 0); break; case OrganDiffusionDirection.DIFFUSE_OUT_ONLY: diffusionToLSystem = math.min(diffusionToLSystem, 0); break; default: break; } if (diffusionCap > 0) { var maxAllowableDiffuseIn = math.max(diffusionCap - amountInSymbol, 0); diffusionToLSystem = math.min(diffusionToLSystem, maxAllowableDiffuseIn); var maxAllowableDiffuseOut = math.max(diffusionCap - amountInVoxel, 0); diffusionToLSystem = -math.min(-diffusionToLSystem, maxAllowableDiffuseOut); } if (diffusionToLSystem == 0) { return; } sourceString.parameters[paramIndex, 0] = amountInSymbol + diffusionToLSystem; volumetricHandles.universalWriter.AppendAmountChangeToOtherLayer(voxelIndex, -diffusionToLSystem, resourceLayerId); }
internal Turtle(Point startPosition, Direction startDirection) { this.StartPosition = startPosition; this.CurrentPosition = startPosition; this.StartDirection = startDirection; this.CurrentDirection = startDirection; this.Status = TurtleState.IsInDanger; }
private void Attack() { state = TurtleState.Attack; TurtleAni.SetBool("Attack", true); print(TurtleAni.GetCurrentAnimatorStateInfo(0).normalizedTime); StartCoroutine(DelayAttack(1.5f)); }
private bool Place(TurtleState currentState) { if (IsInsideRange(currentState.XPos, currentState.YPos)) { this.State = currentState; return(true); } return(false); }
public void TurtleIsInDanger_EvaluateMultipleCommands_ReturnsCorrectState( Board board, IEnumerable <ITurtleCommand> commands, TurtleState expectedState) { var sut = MakeBoardEvaluator(board); var actual = sut.Evaluate(commands); Assert.Equal(expectedState, actual); }
private void Awake() { if (Instance == null) { Instance = this; } else { throw new Exception("There can only be one TurtleStats in a scene!"); } turtleTransition = GetComponent <TurtleTransition>(); }
//create the physical representation void axiomInterpreter(string axi) { Stopwatch timer = new Stopwatch(); timer.Start(); Vector3 curLoc = new Vector3(0, 0, 0); for (int i = 0; i < axi.Length; i++) { if (axi.ToCharArray()[i].ToString().Equals("-")) { int rand = Random.Range(-this.stochasticAngle, this.stochasticAngle); this.curAngle -= this.angle + rand; } else if (axi.ToCharArray()[i].ToString().Equals("+")) { int rand = Random.Range(-this.stochasticAngle, this.stochasticAngle); this.curAngle += this.angle + rand; } else if (axi.ToCharArray()[i].ToString().Equals("(")) { this.turtleStack.Push(new TurtleState(this.curAngle, curLoc)); } else if (axi.ToCharArray()[i].ToString().Equals(")")) { TurtleState temp = this.turtleStack.Pop(); this.curAngle = temp.getAngle(); curLoc = temp.getPosition(); } else if (axi.ToCharArray()[i].ToString().Equals("X")) { } else { for (int j = 0; j < 5; j++) { GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.localScale = new Vector3(1f, 1f, 1f); sphere.transform.Rotate(0, this.curAngle, 0); sphere.transform.position = curLoc; Color matColor = colorGen(curLoc.x, curLoc.y, this.curAngle); sphere.renderer.material.color = matColor; Transform temp = sphere.transform; temp.Translate(0, 0, 1); curLoc = temp.position; //TODO: don't reallocate memory every time } } timer.Stop(); UnityEngine.Debug.Log(timer.ElapsedTicks + ": time taken :" + timer.ElapsedMilliseconds); } }
// Use this for initialization void Start() { state = TurtleState.Wander; TurtleAni = this.GetComponent <Animator>(); sprd = this.GetComponent <SpriteRenderer>(); TimeInterval = Random.Range(3.0f, 5.0f); AttackInterval = 5.0f; catchTime = Time.time; getTime = Time.time; fury = (int)Random.Range(3, 5); TurtleAni.SetInteger("HP", HP); audio = gameObject.GetComponent <AudioSource>(); }
public void Operate( ref TurtleState state, int indexInString, SymbolString <float> sourceString) { var paramIndex = sourceString.parameters[indexInString]; float theta = defaultTheta; if (paramIndex.length >= 1) { theta = sourceString.parameters[paramIndex, 0]; } state.transformation *= Matrix4x4.Rotate(Quaternion.Euler(theta * unitEulerRotation)); }
public void Valid_First_Command_Return_True() { var table = new Table(); var turtleState = new TurtleState(); var turtle = new Turtle(turtleState, table); string input = "PLACE 0,0,NORTH"; Action <string> message = (msg) => { }; Action clearCommandLine = () => { }; Func <string, bool> isValidPlaceCommand = (cmd) => { return(true); }; var result = turtle.ProcessCommand(input, message, clearCommandLine, isValidPlaceCommand); result.Should().Be(true); }
public void addLeafVert(TurtleState turtleState) { Vector3 center = turtleState.baseCenter; Vector3 rotation = turtleState.angle; float xAngle = rotation.x; float yAngle = rotation.y; Vector3 newCenter = new Vector3( center.x + length * Mathf.Cos(xAngle) * Mathf.Cos(yAngle), center.y + length * Mathf.Sin(xAngle), center.z + length * Mathf.Cos(xAngle) * Mathf.Sin(yAngle)); newLeafVs.Add(newCenter); turtleState.baseCenter = newCenter; }
public void Operate( ref TurtleState state, int indexInString, SymbolString <float> sourceString, EntityCommandBuffer spawningCommandBuffer, Matrix4x4 localToWorldTransform) { var paramIndex = sourceString.parameters[indexInString]; var spawned = spawningCommandBuffer.Instantiate(instantiableEntity); var newbuffer = spawningCommandBuffer.SetBuffer <TurtleSpawnedParameters>(spawned); var parameterSlice = sourceString.parameters.data.Slice(paramIndex.index, paramIndex.length); newbuffer.CopyFrom(parameterSlice.SliceConvert <TurtleSpawnedParameters>()); var totalLocalToWorld = localToWorldTransform * state.transformation * prefabTransform; var rot = totalLocalToWorld.rotation; Vector3 pos = totalLocalToWorld.GetColumn(3); // Extract new local scale Vector3 scale = new Vector3( totalLocalToWorld.GetColumn(0).magnitude, totalLocalToWorld.GetColumn(1).magnitude, totalLocalToWorld.GetColumn(2).magnitude ); spawningCommandBuffer.SetComponent(spawned, new Rotation { Value = rot }); spawningCommandBuffer.SetComponent(spawned, new Translation { Value = pos }); // scale is done a bit differently for everything. if scale changes are needed, read from the TurtleSpawnedParameters //spawningCommandBuffer.SetComponent(instantiableEntity, new NonUniformScale //{ // Value = scale //}); //spawningCommandBuffer.SetComponent(instantiableEntity, new LocalToWorld //{ // Value = localToWorldTransform * state.transformation //}); }
public static string GetTurtleString(TurtleState turtleState) { switch (turtleState) { case TurtleState.good: return("good"); case TurtleState.bad: return("bad"); case TurtleState.worse: return("worse"); default: return("neutral"); } }
/// <summary> /// Execute REPORT command /// </summary> /// <param name="turtle">turtle instance</param> /// <param name="arguments">NOT REQUIRED</param> /// <param name="message">message after command execution result</param> /// <returns>command execution result</returns> public bool DoExecution(ITurtle turtle, string[] arguments, out string message) { bool isSuccess; if (turtle != null && turtle.Report() != null) { TurtleState currentState = turtle.Report(); isSuccess = true; message = string.Format("{0}, {1}, {2}", currentState.X, currentState.Y, currentState.FacingDirection.ToString().ToUpper()); } else { isSuccess = false; message = MessageConstants.InvalidStateMsg; } return(isSuccess); }
/* Update States */ /* Turtle */ private void UpdateTimedData(object sender, ElapsedEventArgs e) { TimeSpan timeElapsed = e.SignalTime - timeKeeper.StartTime; TurtleState newTurtleState = turtle.CurrentTurtleState; if (turtle.TurtleName != turtleNameLabel.Text) { turtleNameLabel.Text = turtle.TurtleName.ToString(); } if (timeElapsed.TotalSeconds < 20) { newTurtleState = TurtleState.good; } else if (timeElapsed.TotalSeconds < 40) { newTurtleState = TurtleState.bad; } else if (timeElapsed.TotalSeconds >= 120) { newTurtleState = TurtleState.worse; } /* Display bag and jellyfish */ if (timeElapsed.TotalSeconds >= 10) { Device.BeginInvokeOnMainThread(() => { bag.FadeTo(1, 500, Easing.Linear); jellyfish.FadeTo(1, 500, Easing.Linear); }); } /* Update state */ if (newTurtleState != turtle.CurrentTurtleState) { turtle.CurrentTurtleState = newTurtleState; updateUI(); } }
IEnumerator DelayAttack(float force) { yield return(new WaitForSeconds(0.5f)); if (PhotonNetwork.isMasterClient) { PhotonNetwork.InstantiateSceneObject("Roll", this.transform.position + Vector3.left * ((flip == false)? 1:-1) * force, this.transform.rotation, 0, null); } state = TurtleState.Wander; if (force == 3.0f) { TurtleAni.SetBool("Fury", false); } else { TurtleAni.SetBool("Attack", false); } }
private static string DescriptionForState(TurtleState state) { switch (state) { case TurtleState.InDanger: return("Still in danger!"); case TurtleState.HitMine: return("Mine hit!"); case TurtleState.FoundExit: return("Success!"); case TurtleState.OutOfBounds: return("Out of bounds!"); } return("Unknown state"); }
public void Operate( ref TurtleState state, int indexInString, SymbolString <float> sourceString) { var paramIndex = sourceString.parameters[indexInString]; if (paramIndex.length == 0) { state.thickness *= defaultThicknessScale; } else if (paramIndex.length == 1) { state.thickness *= sourceString.parameters[paramIndex, 0]; } else { Debug.LogError($"Invalid scale parameter length: {paramIndex.length}"); } }
public TurtleState(TurtleState ts) : this(new Point2D(ts.pos), new Point2D(ts.dir), new Rotation(ts.rot)) { }
public Turtle(float w) { turtleState = new TurtleState(w, Matrix4x4.identity); tss = new Stack<TurtleState>(); }
// Restore a previous state public void Pop() { if (tss.Count==0){ Debug.LogError("Invalid pop. Stack is empty (more pop than push)"); } turtleState = tss.Pop(); }
public Skeleton(String Filename, StreamWriter logSW) { //Read in Skeleton StreamReader input = new StreamReader(Filename); TurtleState current = new TurtleState(new Point2D(0, 0), new Point2D(1, 0), new Rotation()); List<TurtleState> turtleStack = new List<TurtleState>(); Dictionary<String, Rotation> sphereTable = new Dictionary<string,Rotation>(); while (!input.EndOfStream) { String LineIn = input.ReadLine(); char[] charSeparators = { ' ', ',', '=', '\t' }; String[] tokens = LineIn.Split( charSeparators, StringSplitOptions.RemoveEmptyEntries ); if( tokens.Length == 0 || tokens[0].StartsWith("#") ) { continue; } /* if */ //FIRST TOKEN = command String command = (tokens[0]).ToLower(); //SECOND TOKEN = distance (or label) double fDistance = 0.0; if (tokens.Length >= 2) { try { fDistance = double.Parse(tokens[1]) * DMS.HALFTAU; } catch (System.FormatException) { // if second token not a number, it could be a label. if (command == "s" || command == "save") { // save the label and move on. sphereTable[tokens[1]] = current.rot; continue; } else if (sphereTable.ContainsKey(tokens[1])) { Rotation newRot = sphereTable[tokens[1]]; Point3D A = current.rot.Rotate(-Point3D.XAxis); Point3D B = current.rot.Rotate(Point3D.ZAxis); Point3D C = newRot.Rotate(Point3D.ZAxis); // add a rotation from AB to BC double turn = Math.PI - Point3D.DihedralAngle(A, B, C); if (Point3D.Dot(B, Point3D.Cross(A - B, B - C)) < 0) { turn *= -1.0; } current.dir.Theta += turn; current.rot *= new Rotation(Math.Cos(turn / 2.0), 0, 0, Math.Sin(turn / 2.0)); if (command == "r" || command == "rotate") { continue; } else if (command == "l" || command == "line" || command == "lineto" || command == "m" || command == "move" || command == "moveto") { // move or line from B to C fDistance = Point3D.Angle(B, Point3D.Origin, C) - 0.01; } } } } //THIRD TOKEN = strength double fStrength = 1.0; if (tokens.Length >= 3) { try { fStrength = 1.0 / double.Parse(tokens[2]); } catch (System.FormatException) { continue; } } if( command == "l" || command == "line" || command == "lineto" ) { if (fDistance == 0.0) m_Segments.Add(new Segment(current.rot, current.pos, current.pos + current.dir, fStrength, true)); else if (fDistance > 0.0) m_Segments.Add(new Segment(current.rot, current.pos, current.pos + current.dir * fDistance, fStrength)); else m_Segments.Add(new Segment(current.rot * new Rotation(0, 0, 0, 1), current.pos, current.pos + current.dir * fDistance, fStrength)); current.pos += current.dir * fDistance; current.rot *= new Rotation(Math.Cos(fDistance / 2.0), 0, Math.Sin(fDistance / 2.0), 0); } else if( command == "m" || command == "move" || command == "moveto" ) { //move current.pos += current.dir * fDistance; current.rot *= new Rotation(Math.Cos(fDistance / 2.0), 0, Math.Sin(fDistance / 2.0), 0); } else if( command == "o" || command == "moveinplane" ) { //move in plane *O*nly current.pos += current.dir * fDistance; } else if( command == "r" || command == "rotate" ) { //rotate (clockwise) current.dir.Theta += fDistance; current.rot *= new Rotation( Math.Cos(fDistance / 2.0), 0, 0, Math.Sin(fDistance / 2.0) ); } else if( command == "p" && fDistance > 0 || command == "push" || command == "{") { turtleStack.Add(new TurtleState(current)); } else if (command == "p" || command == "pop" || command == "}") { current = turtleStack.Last<TurtleState>(); turtleStack.Remove(current); } else if (command == "b" || command == "bleedout") { m_bleedout = fDistance; } } /* while */ input.Close(); }