private int GetGmode(Vector2 g_direction) { if(g_direction.Equals(-Vector2.up)) return 0; if(g_direction.Equals(Vector2.right)) return 1; if(g_direction.Equals(Vector2.up)) return 2; if(g_direction.Equals(-Vector2.right)) return 3; return -1; }
/// <summary> /// Handles translation of the object /// </summary> /// <param name="mousePos">The position in World Coordinates of the touch or thing dragging the object</param> public void OnTouchDrag(Vector2 mousePos) { //If the drag just started if (reset) { //Save old location oldPosition = transform.position; //Raise the object up and make obstruction panels appear transform.Translate(0, 1.0f, 0); reset = false; child.appear(); } //Snap mousePos to the nearing tile mousePos.x -= mousePos.x % tileSize - 0.5f; mousePos.y -= mousePos.y % tileSize - 0.5f; //If the mousePos changed this time if (!mousePos.Equals(transform.position)) { transform.position = new Vector3(mousePos.x, transform.position.y, mousePos.y); //Update the obstruction panels and move to the new position child.recheck(); } }
public override void attack(WeaponController weaponController, float attackRate, bool isNewAttack, Vector2 aiInput) { if (!isAttacking && isReady) { Vector2 rockPos = new Vector2(weaponController.transform.position.x, weaponController.transform.position.y); if (aiInput.Equals(Vector2.zero)) { return; } Vector2 lookAtDir = aiInput.normalized; GameObject rockWall = MonoBehaviour.Instantiate(weaponController.associatedPrefab, rockPos + (aiInput.normalized * wallDist), new Quaternion(0, 0, 0, 0)) as GameObject; rockWall.transform.Rotate(Vector3.forward, (180.0f / Mathf.PI) * Mathf.Atan2(lookAtDir.y, lookAtDir.x)); MonoBehaviour.Destroy(rockWall, coolDownTime); // Start cooldown if (coolDownCorout != null) { weaponController.StopCoroutine(coolDownCorout); } coolDownCorout = weaponController.StartCoroutine(coolDown()); } }
public TreeNode search(Vector2 cmpLoc) { Vector2 locXY = item.getLocXY(); locXY.X += item.getDia() / 2; locXY.Y += item.getDia() / 2; //check done if (cmpLoc.Equals(locXY) || children == null) return this; //figure out which child to use else if (cmpLoc.X > locXY.X) { if (cmpLoc.Y > locXY.Y) { //search through the child, and its children return children[4].search(cmpLoc); } else return children[2].search(cmpLoc); } else { if (cmpLoc.Y > locXY.Y) { return children[3].search(cmpLoc); } else return children[1].search(cmpLoc); } }
public void Vector2_EqualsWithTolerence_Test() { var a = new Vector2(1f, 1f); var b = new Vector2(1.0000001f, 1.0000001f); Assert.IsFalse(a.Equals(b)); Assert.IsTrue(a.EqualsWithTolerance(b)); }
private void Arc(Vector2 direction, int numberOfEnemies) { if (!direction.Equals (Vector2.zero)) { Vector2 groupPosition = direction * Distance () + cameraPosition; Vector2 normal = Quaternion.AngleAxis (90, Vector3.forward) * direction; for (int i = 0; i < numberOfEnemies; i++) { Spawn (groupPosition + Random.insideUnitCircle * 2.0f + normal * Random.Range (-12, 12)); } } }
private void SetStartPosition(EasyGameComponent originatingComponent, Vector2 direction) { Vector2 positionOffset = Vector2.Zero; if (direction.Equals(ProjectileDirections.Up)) { positionOffset = originatingComponent.Height * .6f * direction; } else if (direction.Equals(ProjectileDirections.Down)) { positionOffset = originatingComponent.Height * .6f * direction; } else if (direction.Equals(ProjectileDirections.Left)) { positionOffset = originatingComponent.Width * .6f * direction; } else if (direction.Equals(ProjectileDirections.Right)) { positionOffset = originatingComponent.Width * .6f * direction; } DisplayPosition = originatingComponent.DisplayPosition + positionOffset; }
protected void UpdateLookDirection(Vector2 lookDirection) { if (lookDirection.Equals(Vector2.left)) { transform.localScale = new Vector3( -Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z); } else { transform.localScale = new Vector3( Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z); } }
public void CheckCenterCalculation() { // Create a platform at (100, 100) with a width of 100 and a height of 200. Vector2 position = new Vector2(100f, 100f); Vector2 size = new Vector2(100f, 200f); Platform plat = new Platform(null, position, size, false); // We know what the answers should be... Vector2 expected = new Vector2(150f, 200f); // ...so make sure that the center is calculated correctly. Console.WriteLine("Comparing " + plat.Center.X + " to " + expected.X); Console.WriteLine("Comparing " + plat.Center.Y + " to " + expected.Y); Assert.IsTrue(expected.Equals(plat.Center)); }
public Fireball(Texture2D texture, Vector2 position, Vector2 direction, float rotation) { Texture = texture; Position = position; Speed = 25; Direction = direction; Rotation = rotation; MaxDistance = 750; CollisionBoundaries = new Rectangle((int)(Position.X - Texture.Width / 2), (int)(Position.Y - Texture.Height / 2), Texture.Width, Texture.Height); if (direction.Equals(new Vector2(0, 0))) { Destroy(); } }
void Update() { if (m_victim) { // Get player's position and steer towards it m_target = m_victim.transform.position; m_position = this.transform.position; m_movement = m_target - m_position; // Normalized to get a Vector of magnitude 1 similar to player's input values Vector2 movement2D = new Vector2(m_movement.x,m_movement.y).normalized; // Call the move if (!(movement2D.Equals(Vector2.zero))) { m_moveScript.Move(movement2D); } } }
public void CheckMovePlatformNoBody() { // Create a platform at (100, 100) with a width of 100 and a height of 100. Vector2 position = new Vector2(100f, 100f); Vector2 size = new Vector2(100f, 100f); Platform plat = new Platform(null, position, size, false); // We know what the new position should be, so change the platform's position... Vector2 newPos = new Vector2(200f, 300f); plat.Origin = new Vector2(newPos.X, newPos.Y); // ...and check to see if it actually moved. Console.WriteLine("Comparing " + plat.Origin.X + " to " + newPos.X); Console.WriteLine("Comparing " + plat.Origin.Y + " to " + newPos.Y); Assert.IsTrue(newPos.Equals(plat.Origin)); // This is supposed to be the new center of the platform, now that it moved... Vector2 expectedCenter = new Vector2(250f, 350f); // .. so check if that's the case. Console.WriteLine("Comparing " + plat.Center.X + " to " + expectedCenter.X); Console.WriteLine("Comparing " + plat.Center.Y + " to " + expectedCenter.Y); Assert.IsTrue(expectedCenter.Equals(plat.Center)); }
public void Vector2EqualsTest() { Vector2 a = new Vector2(1.0f, 2.0f); Vector2 b = new Vector2(1.0f, 2.0f); // case 1: compare between same values object obj = b; bool expected = true; bool actual = a.Equals(obj); Assert.AreEqual(expected, actual, "Vector2.Equals did not return the expected value."); // case 2: compare between different values b.X = 10.0f; obj = b; expected = false; actual = a.Equals(obj); Assert.AreEqual(expected, actual, "Vector2.Equals did not return the expected value."); // case 3: compare between different types. obj = new Quaternion(); expected = false; actual = a.Equals(obj); Assert.AreEqual(expected, actual, "Vector2.Equals did not return the expected value."); // case 3: compare against null. obj = null; expected = false; actual = a.Equals(obj); Assert.AreEqual(expected, actual, "Vector2.Equals did not return the expected value."); }
// Update is called once per frame void Update() { // we do not want to update our proto-type (should it be active) if (name == "mover-prototype") { return; } if (rotating) { // we are rotating so increase rotating time rotationTime += Time.deltaTime; if (rotationTime >= rotationSpeed) { // we are rotating long enough so stop rotating rotating = false; // set mover to current waypoint SetPosition(wayPoint, false); } else { // rotate sprite towards waypoint sprite.rotation = fromRotation + rotationAngle * (rotationTime / rotationSpeed); } } else { // we are moving so determine the movement vector Vector2 towards = towardsPoint - sprite.position; // update mover sprite position sprite.position += towards.normalized * speed * Time.deltaTime; // determine new movement vector Vector2 result = towardsPoint - sprite.position; // if the normalized vectors do not match we have passed the next waypoint if (!Vector2.Equals(result.normalized, towards.normalized)) { // set our sprite on the next waypoint sprite.position = towardsPoint; // indicate that we will start rotating rotating = true; // increment our current waypoint and check if we have to go back to the first wayPoint++; if (wayPoint == wayPoints.Length) { wayPoint = 0; } // determine next wayoint if ((wayPoint + 1) < wayPoints.Length) { towardsPoint = wayPoints[wayPoint + 1]; } else { towardsPoint = wayPoints[0]; } // keep current rotation value fromRotation = sprite.rotation; // determine next rotation value by rotating towards next waypoint sprite.RotateTowards(towardsPoint); towardsRotation = sprite.rotation; // back to current rotation value, because we will be rotating from that angle sprite.rotation = fromRotation; // intialize rotation variables rotationTime = 0; // determine rotation delta angle rotationAngle = -90; if ((Mathf.Round(fromRotation) == 270 && Mathf.Round(towardsRotation) == 0) || (Mathf.Round(fromRotation) == 180 && Mathf.Round(towardsRotation) == 270)) { rotationAngle = 90; } } } }
/// <summary> /// モンスターハウスとなる部屋を設定するためのメソッド。 /// プレイヤと階段がある座標にはアイテム、トラップ、エネミーを配置しない。 /// </summary> /// <param name="playerpos"></param> /// <param name="stairspos"></param> /// <returns></returns> Room setMonsterHouse(Vector2 playerpos, Vector2 stairspos) { /* ・モンスターハウスが生成できるダンジョンか判定 ・生成できるならモンスターハウスを生成するか乱数で判定 ・生成する場合の部屋を選択 ・選択された部屋にオブジェクトを配置 ・通常のオブジェクト配置 */ Room room = CurrentDungeonInformation.CurrentFloor.selectRnadomRoom(); int itemcountlimit = (int)(DungeonInformation.MaxItemCount * 0.8f); int trapcountlimit = (int)(DungeonInformation.MaxTrapCount * 0.8f); int enemycountlimit = (int)(DungeonInformation.MaxEnemyCount * 0.8f); room = CurrentDungeonInformation.CurrentFloor.selectRnadomRoom(); //denyroom.Add(room); room.isMonsterHouse = true; float roomsize = room.RoomRect.width * room.RoomRect.height; /* 部屋面積の5~8割をアイテムとトラップで分け合うだたし設置上限の8割を超えないようにする モンスターは部屋面積の7~9割か配置上限の8割 */ int objectcountlimit = GameController.Rnd.Next((int)(roomsize * 0.5), (int)(roomsize * 0.8)); int putitemrate = GameController.Rnd.Next((int)(objectcountlimit * 0.65f), (int)(objectcountlimit * 0.85f)); itemcountlimit = (int)Mathf.Min(putitemrate, itemcountlimit); int puttraprate = objectcountlimit - putitemrate; puttraprate = Mathf.Max(0, puttraprate); trapcountlimit = (int)Mathf.Min(puttraprate, trapcountlimit); enemycountlimit = (int)Mathf.Min(GameController.Rnd.Next((int)(roomsize * 0.7), (int)(roomsize * 0.9)), enemycountlimit); List<ItemBasis> itemlist = CurrentDungeonParameter.DistributionTable.randomSelectItemFromCurrentFloor(CurrentDungeonInformation.CurrentFloorNumber, itemcountlimit); List<TrapBasis> traplist = CurrentDungeonParameter.DistributionTable.randomSelectTrapFromCurrentFloor(CurrentDungeonInformation.CurrentFloorNumber, trapcountlimit); List<CharacterParameterBasis> enemylist = CurrentDungeonParameter.DistributionTable.randomSelectEnemyFromCurrentFloor(CurrentDungeonInformation.CurrentFloorNumber, enemycountlimit); int xmin = (int)room.RoomRect.xMin; int xmax = (int)room.RoomRect.xMax; int ymin = (int)room.RoomRect.yMin; int ymax = (int)room.RoomRect.yMax; List<Vector2> poslist = new List<Vector2>(); for (int i = xmin; i < xmax; i++) { for (int j = ymin; j < ymax; j++) { Vector2 pos = new Vector2(i, j); Debug.Log("SamePlayerPos: " + pos.Equals(GameController.MainPlayer.transform.position)); if(!pos.Equals(playerpos) && !pos.Equals(stairspos)) poslist.Add(pos); } } List<Vector2> placed = new List<Vector2>(); // キャラクターの配置 foreach (CharacterParameterBasis enemy in enemylist) { Vector2 pos = poslist[GameController.Rnd.Next(poslist.Count)]; placed.Add(pos); poslist.Remove(pos); CharacterParameterBasis param = Activator.CreateInstance(enemy.GetType()) as CharacterParameterBasis; var entity = ObjectEntityFactory.enableCharacterEntity(param, pos); entity.InRoom = room; entity.registerBuff(new MHSleep(entity)); } // 設置済みリストのリセット poslist.AddRange(placed); placed.Clear(); // アイテムの設置 foreach (ItemBasis item in itemlist) { Vector2 pos = poslist[GameController.Rnd.Next(poslist.Count)]; placed.Add(pos); poslist.Remove(pos); item.init(); ObjectEntityFactory.enableItemEntity(item, pos).InRoom = room; } // アイテムとトラップは設置場所が排他的なので設置済みリストをリセットしない // トラップの設置 foreach (TrapBasis trap in traplist) { Debug.Log("PosCount: " + poslist.Count); Vector2 pos = poslist[GameController.Rnd.Next(poslist.Count)]; placed.Add(pos); poslist.Remove(pos); ObjectEntityFactory.enableTrapEntity(trap, pos).InRoom = room; } ///initialset = true; room.isMonsterHouse = true; return room; }
public override bool Equals(object obj) { Tile other = (Tile)obj; return(pos.Equals(other.pos)); }
public void OnEnterDarkCave(Collider collider) { if (darkCave) { Vector2 darkCaveDoor = new Vector2 (collider.transform.position.x, collider.transform.position.y); if (darkCaveDoor.Equals (curDarkCave.Door1) || darkCaveDoor.Equals (curDarkCave.Door2)) OnDarkCaveExit (collider); else darkCave = false; } if (!darkCave) { bool found = false; for (int i = 0; i < darkCavesList.Count; i ++) { Vector2 darkCaveDoor = new Vector2 (collider.transform.position.x, collider.transform.position.y); if (darkCaveDoor.Equals (darkCavesList [i].Door1) || darkCaveDoor.Equals (darkCavesList [i].Door2)) { found = darkCave = true; curDarkCave = darkCavesList [i]; break; } } if (!found) throw new UnityException ("DarkCaveEnter triggered on a DarkCave that doesn't exist!"); else { // Find centre of the Cave. float darkCaveCentreX = Mathf.Abs(curDarkCave.Door1.x - curDarkCave.Door2.x)/2f; if (curDarkCave.Door1.x > curDarkCave.Door2.x) darkCaveCentreX += curDarkCave.Door2.x; else darkCaveCentreX += curDarkCave.Door1.x; // Find spots at which the ambient should completely be black. // That is, when player reaches any of these points from outside the cave, // the ambient should have completely transitioned to darkness. // If instead, the player reaches these points from inside the cave, // the ambient slowly starts transitioning to original colour as he makes // his way out of the cave. darknessTriggerSpots [0] = Mathf.Abs(darkCaveCentreX - curDarkCave.Door1.x)/4f; darknessTriggerSpots [1] = Mathf.Abs(darkCaveCentreX - curDarkCave.Door2.x)/4f; if (curDarkCave.Door1.x > curDarkCave.Door2.x) { darknessTriggerSpots [1] += curDarkCave.Door2.x; darknessTriggerSpots [0] = curDarkCave.Door1.x - darknessTriggerSpots [0]; } else { darknessTriggerSpots [0] += curDarkCave.Door1.x; darknessTriggerSpots [1] = curDarkCave.Door2.x - darknessTriggerSpots [1]; } RenderSettings.skybox = null; } } }
public readonly bool Equals(TexturedVertex3D other) => Position.Equals(other.Position) && TexturePosition.Equals(other.TexturePosition) && Colour.Equals(other.Colour);
private SectorPolygon EarClip(List <Vector2> polygon) { SectorPolygon output = new SectorPolygon(); // Early out for convex polygons int conv = IsConvex(polygon); if (conv != 0) { if (conv == -1) { polygon.Reverse(); } output.points = polygon; for (int t = 0; t < polygon.Count - 2; t++) { output.triangles.Add(0); output.triangles.Add(t + 1); output.triangles.Add(t + 2); } return(output); } // Now we earclip List <int> clippedIndexes = new List <int>(); int polygonCount = polygon.Count; int i = 0; int i1, i2, i3; int safe = 5000; while (clippedIndexes.Count < polygonCount - 2 && safe >= 0) // be careful!!! { i1 = i % polygonCount; while (clippedIndexes.Contains(i1)) { i1 = (i1 + 1) % polygonCount; } i2 = (i1 + 1) % polygonCount; while (clippedIndexes.Contains(i2) || i2 == i1) { i2 = (i2 + 1) % polygonCount; } i3 = (i2 + 1) % polygonCount; while (clippedIndexes.Contains(i3) || i3 == i2) { i3 = (i3 + 1) % polygonCount; } bool clipped = false; bool intersects = false; bool straightLine = false; if (PointOnLine(polygon[i1], polygon[i2], polygon[i3])) { straightLine = true; } if (straightLine == false) { for (int j = 0; j < polygonCount; j++) { int j1 = (j + 1) % polygonCount; if (!Vector2.Equals(polygon[i1], polygon[j]) && !Vector2.Equals(polygon[i3], polygon[j])) { if (LinesIntersect(polygon, i1, i3, j, j1) && !Vector2.Equals(polygon[i1], polygon[j1]) && !Vector2.Equals(polygon[i3], polygon[j1])) { intersects = true; break; } List <Vector2> testPoly = new List <Vector2>() { polygon[i1], polygon[i2], polygon[i3] }; if (!Vector2.Equals(polygon[i2], polygon[j]) && PointInPolygon(polygon[j], testPoly)) { intersects = true; break; } } } } if (intersects == false && straightLine == false) { Vector2 midpoint = new Vector2((polygon[i3].x + polygon[i1].x) / 2f, (polygon[i3].y + polygon[i1].y) / 2f); if (PointInPolygon(midpoint, polygon)) { // Clippit!!! clippedIndexes.Add(i2); output.triangles.Add(i1); output.triangles.Add(i2); output.triangles.Add(i3); clipped = true; } } if (clipped == false) { i += 1; safe -= 1; } } if (!IsClockwise(polygon)) { output.triangles.Reverse(); } output.points = polygon; if (safe <= 0) { // OPTIMISATION: Every time this is hit, the polygon is triangulated but we didn't catch it had finished // If we can succeessfully detect when it is done it'll hit this less and triangulation will be faster // Edit: i think we don't hit this any more Debug.LogWarning("EarClip: while loop broke safety net. Clipped Indexes :" + clippedIndexes.Count + " polygonCount: " + polygonCount); System.IO.File.WriteAllText("outputtriangles.json", JsonUtility.ToJson(output, true)); } return(output); }
public virtual Vector2 GetToolLocation(bool ignoreClick = false) { if (!Game1.wasMouseVisibleThisFrame || Game1.isAnyGamePadButtonBeingHeld()) { ignoreClick = true; } if ((Game1.player.CurrentTool == null || !(Game1.player.CurrentTool is WateringCan)) && (int)(lastClick.X / 64f) == Game1.player.getTileX() && (int)(lastClick.Y / 64f) == Game1.player.getTileY()) { Microsoft.Xna.Framework.Rectangle bb = GetBoundingBox(); switch (FacingDirection) { case 0: return(new Vector2(bb.X + bb.Width / 2, bb.Y - 64)); case 1: return(new Vector2(bb.X + bb.Width + 64, bb.Y + bb.Height / 2)); case 2: return(new Vector2(bb.X + bb.Width / 2, bb.Y + bb.Height + 64)); case 3: return(new Vector2(bb.X - 64, bb.Y + bb.Height / 2)); } } if (!ignoreClick && !lastClick.Equals(Vector2.Zero) && Name.Equals(Game1.player.Name) && ((int)(lastClick.X / 64f) != Game1.player.getTileX() || (int)(lastClick.Y / 64f) != Game1.player.getTileY() || (Game1.player.CurrentTool != null && Game1.player.CurrentTool is WateringCan)) && Utility.distance(lastClick.X, Game1.player.getStandingX(), lastClick.Y, Game1.player.getStandingY()) <= 128f) { return(lastClick); } Microsoft.Xna.Framework.Rectangle boundingBox = GetBoundingBox(); if (Game1.player.CurrentTool != null && Game1.player.CurrentTool.Name.Equals("Fishing Rod")) { switch (FacingDirection) { case 0: return(new Vector2(boundingBox.X - 16, boundingBox.Y - 102)); case 1: return(new Vector2(boundingBox.X + boundingBox.Width + 64, boundingBox.Y)); case 2: return(new Vector2(boundingBox.X - 16, boundingBox.Y + boundingBox.Height + 64)); case 3: return(new Vector2(boundingBox.X - 112, boundingBox.Y)); } } else { switch (FacingDirection) { case 0: return(new Vector2(boundingBox.X + boundingBox.Width / 2, boundingBox.Y - 48)); case 1: return(new Vector2(boundingBox.X + boundingBox.Width + 48, boundingBox.Y + boundingBox.Height / 2)); case 2: return(new Vector2(boundingBox.X + boundingBox.Width / 2, boundingBox.Y + boundingBox.Height + 48)); case 3: return(new Vector2(boundingBox.X - 48, boundingBox.Y + boundingBox.Height / 2)); } } return(new Vector2(getStandingX(), getStandingY())); }
public static bool IsEmpty(this Vector2 vector) { return(vector.Equals(Vector2.Zero)); }
public static void CheckIfNormalized(MeshFilter temp) { //Path search Transform current = temp.transform; while (current.parent != null) { current = current.parent; } UnityEngine.Object prefabed = EditorUtility.GetPrefabParent(current); string path = AssetDatabase.GetAssetPath(prefabed); if (path.Length < 1) { path = "primitive.notAFile"; } if (temp.sharedMesh.uv2.Length == temp.sharedMesh.vertexCount) { Vector2[] uvs = temp.sharedMesh.uv2; bool normalized = true; for (int j = 0; j < uvs.Length && normalized; j++) { if (uvs[j].x > 1 || uvs[j].x < 0 || uvs[j].y < 0 || uvs[j].y > 1) { LightmappingTool.notNormalized2.Add(path); LightmappingTool.notNormalized2.Add(temp.transform); normalized = false; } } //Overlapping test if (SystemInfo.supportsRenderTextures) { Shader finded = Shader.Find("ExternalLightmappingTool/uvDebug"); if (finded == null) { Debug.LogError("Cannot find uvDebug shader within LightmappingTools folder!"); return; } int res = 128; RenderTexture rt = RenderTexture.GetTemporary(res, res, 0); RenderTexture.active = rt; if (Camera.current == null) { Camera.SetupCurrent(Camera.main); } RenderTexture oldRT = RenderTexture.active; rt = RenderTexture.GetTemporary(res, res, 0); RenderTexture.active = rt; GL.Clear(true, true, Color.black); Material mat = new Material(finded); Mesh mesh = temp.sharedMesh; mat.SetPass(0); GL.PushMatrix(); GL.LoadOrtho(); Graphics.DrawMeshNow(mesh, Matrix4x4.identity); GL.PopMatrix(); UnityEngine.Object.DestroyImmediate(mat); Texture2D texture = new Texture2D(res, res, TextureFormat.ARGB32, false); texture.ReadPixels(new Rect(0, 0, res, res), 0, 0); texture.Apply(); RenderTexture.active = oldRT; RenderTexture.ReleaseTemporary(rt); UnityEngine.Object.DestroyImmediate(rt); //byte[] bytes = texture.EncodeToPNG(); //File.WriteAllBytes(Application.dataPath + "/../test.png", bytes); Color[] tmp = texture.GetPixels(); int i = 0; int incorrect = 0; for (; i < tmp.Length; i++) { if (tmp[i].r > 0.6f) { incorrect++; texture.SetPixel(i % res, i / res, Color.red); } } if (incorrect * 300 > res * res) { texture.Apply(); LightmappingTool.overlapping2.Add(path); LightmappingTool.overlapping2.Add(texture); LightmappingTool.overlapping2.Add(temp.transform); } else { UnityEngine.Object.DestroyImmediate(texture); } } //UnityEngine.Object.DestroyImmediate(texture); } else if (temp.sharedMesh.uv.Length == temp.sharedMesh.vertexCount) { Vector2 tempek = Vector2.zero; for (int jj = 0; jj < temp.sharedMesh.uv.Length && tempek.Equals(Vector2.zero); jj++) { tempek = temp.sharedMesh.uv[jj]; } if (tempek.Equals(Vector2.zero)) { LightmappingTool.noUVs.Add(path); LightmappingTool.noUVs.Add(temp.transform); } LightmappingTool.usingFirstUV.Add(temp.transform); Vector2[] uvs = temp.sharedMesh.uv; bool normalized = true; for (int j = 0; j < uvs.Length && normalized; j++) { if (uvs[j].x > 1 || uvs[j].x < 0 || uvs[j].y < 0 || uvs[j].y > 1) { LightmappingTool.notNormalized.Add(path); LightmappingTool.notNormalized.Add(temp.transform); normalized = false; } } if (SystemInfo.supportsRenderTextures) { //Overlapping test Shader finded = Shader.Find("ExternalLightmappingTool/uvDebug"); if (finded == null) { Debug.LogError("Cannot find uvDebug shader within LightmappingTools folder!"); return; } int res = 128; RenderTexture rt = RenderTexture.GetTemporary(res, res, 0); RenderTexture.active = rt; if (Camera.current == null) { Camera.SetupCurrent(Camera.main); } RenderTexture oldRT = RenderTexture.active; rt = RenderTexture.GetTemporary(res, res, 0); RenderTexture.active = rt; GL.Clear(true, true, Color.black); Material mat = new Material(finded); Mesh mesh = temp.sharedMesh; mat.SetPass(0); GL.PushMatrix(); GL.LoadOrtho(); Graphics.DrawMeshNow(mesh, Matrix4x4.identity); GL.PopMatrix(); UnityEngine.Object.DestroyImmediate(mat); Texture2D texture = new Texture2D(res, res, TextureFormat.ARGB32, false); texture.ReadPixels(new Rect(0, 0, res, res), 0, 0); texture.Apply(); RenderTexture.active = oldRT; RenderTexture.ReleaseTemporary(rt); UnityEngine.Object.DestroyImmediate(rt); //byte[] bytes = texture.EncodeToPNG(); //File.WriteAllBytes(Application.dataPath + "/../test.png", bytes); Color[] tmp = texture.GetPixels(); int i = 0; int incorrect = 0; for (; i < tmp.Length; i++) { if (tmp[i].r > 0.6f) { incorrect++; texture.SetPixel(i % res, i / res, Color.red); } } if (incorrect * 300 > res * res) { texture.Apply(); LightmappingTool.overlapping.Add(path); LightmappingTool.overlapping.Add(texture); LightmappingTool.overlapping.Add(temp.transform); } else { UnityEngine.Object.DestroyImmediate(texture); } } //UnityEngine.Object.DestroyImmediate(texture); } else { LightmappingTool.noUVs.Add(path); LightmappingTool.noUVs.Add(temp.transform); } }
/// <summary> /// Obtains a list of vertexes that represent the polyline approximating the curve segments as necessary. /// </summary> /// <param name="bulgePrecision">Curve segments precision (a value of zero means that no approximation will be made).</param> /// <param name="weldThreshold">Tolerance to consider if two new generated vertexes are equal.</param> /// <param name="bulgeThreshold">Minimum distance from which approximate curved segments of the polyline.</param> /// <returns>A list of vertexes expressed in object coordinate system.</returns> public List <Vector2> PolygonalVertexes(int bulgePrecision, double weldThreshold, double bulgeThreshold) { List <Vector2> ocsVertexes = new List <Vector2>(); int index = 0; foreach (LwPolylineVertex vertex in this.Vertexes) { double bulge = vertex.Bulge; Vector2 p1; Vector2 p2; if (index == this.Vertexes.Count - 1) { p1 = new Vector2(vertex.Position.X, vertex.Position.Y); p2 = new Vector2(this.vertexes[0].Position.X, this.vertexes[0].Position.Y); // ignore bulge value of last vertex for open polylines if (!this.IsClosed) { bulge = 0; } } else { p1 = new Vector2(vertex.Position.X, vertex.Position.Y); p2 = new Vector2(this.vertexes[index + 1].Position.X, this.vertexes[index + 1].Position.Y); } if (!p1.Equals(p2, weldThreshold) || (index == this.Vertexes.Count - 1 && !this.IsClosed)) { if (MathHelper.IsZero(bulge) || bulgePrecision == 0) { ocsVertexes.Add(p1); } else { double c = Vector2.Distance(p1, p2); if (c >= bulgeThreshold) { double s = (c / 2) * Math.Abs(bulge); double r = ((c / 2) * (c / 2) + s * s) / (2 * s); double theta = 4 * Math.Atan(Math.Abs(bulge)); double gamma = (Math.PI - theta) / 2; double phi = Vector2.Angle(p1, p2) + Math.Sign(bulge) * gamma; Vector2 center = new Vector2(p1.X + r * Math.Cos(phi), p1.Y + r * Math.Sin(phi)); Vector2 a1 = p1 - center; double angle = Math.Sign(bulge) * theta / (bulgePrecision + 1); ocsVertexes.Add(p1); Vector2 prevCurvePoint = p1; for (int i = 1; i <= bulgePrecision; i++) { Vector2 curvePoint = new Vector2(); curvePoint.X = center.X + Math.Cos(i * angle) * a1.X - Math.Sin(i * angle) * a1.Y; curvePoint.Y = center.Y + Math.Sin(i * angle) * a1.X + Math.Cos(i * angle) * a1.Y; if (!curvePoint.Equals(prevCurvePoint, weldThreshold) && !curvePoint.Equals(p2, weldThreshold)) { ocsVertexes.Add(curvePoint); prevCurvePoint = curvePoint; } } } else { ocsVertexes.Add(p1); } } } index++; } return(ocsVertexes); }
void Start() { if (numberOfExits > sizeX || numberOfExits > sizeY || numberOfExits < 2) { numberOfExits = 2; } _floorSprite = floortile.GetComponent <SpriteRenderer>(); _incrementX = _floorSprite.bounds.size.x; _incrementY = _floorSprite.bounds.size.y; Debug.Log("x, y" + _incrementX + " , " + _incrementY); for (int x = 0; x < sizeX; x++) { for (int y = 0; y < sizeY; y++) { if (y == 0 || x == 0 || y == sizeY - 1 || x == sizeX - 1) { _possiblePositionsWall.Add((new Vector2(x * _incrementX + transform.position.x, y * _incrementY + transform.position.y))); } else { _possiblePositionsTile.Add(new Vector2(x * _incrementX + transform.position.x, y * _incrementY + transform.position.y)); } } } for (int i = 0; i < numberOfExits; i++) { Vector2 vec = _possiblePositionsWall[Random.Range(0, _possiblePositionsWall.Count - 1)]; _possiblePositionsWall.Remove(vec); _exits.Add(vec); } foreach (Vector2 vec in _exits) { if (vec.x == transform.position.x) { exitTile.GetComponent <ExitProperties>().direction = ExitProperties.Dir.LEFT; } if (vec.x == (sizeX - 1) * _incrementX + transform.position.x) { exitTile.GetComponent <ExitProperties>().direction = ExitProperties.Dir.RIGHT; } if (vec.y == transform.position.y) { exitTile.GetComponent <ExitProperties>().direction = ExitProperties.Dir.DOWN; } if (vec.y == (sizeY - 1) * _incrementY + transform.position.y) { exitTile.GetComponent <ExitProperties>().direction = ExitProperties.Dir.UP; } Instantiate(exitTile, vec, Quaternion.identity); } foreach (Vector2 vec in _possiblePositionsWall) { if (!vec.Equals(_entry)) { Instantiate(walltile, vec, Quaternion.identity); } } foreach (Vector2 vec in _possiblePositionsTile) { Instantiate(floortile, vec, Quaternion.identity); Instantiate(fogTile, new Vector3(vec.x, vec.y, -2), Quaternion.identity); } if (!_entry.Equals(new Vector2(0, 0))) { Instantiate(entryTile, new Vector3(_entry.x, _entry.y, -2), Quaternion.identity); } }
public bool Equals(VertexPositionNormalTexture other) { return(Position.Equals(other.Position) && Normal.Equals(other.Normal) && TextureCoordinate.Equals(other.TextureCoordinate)); }
public void Vector2EqualsNanTest() { Vector2 a = new Vector2(float.NaN, 0); Vector2 b = new Vector2(0, float.NaN); Assert.IsFalse(a == Vector2.Zero); Assert.IsFalse(b == Vector2.Zero); Assert.IsTrue(a != Vector2.Zero); Assert.IsTrue(b != Vector2.Zero); Assert.IsFalse(a.Equals(Vector2.Zero)); Assert.IsFalse(b.Equals(Vector2.Zero)); // Counterintuitive result - IEEE rules for NaN comparison are weird! Assert.IsFalse(a.Equals(a)); Assert.IsFalse(b.Equals(b)); }
/// <summary> /// Default Update for WorldObject and subclasses. Moves this object by its velocity. /// </summary> /// <param name="timeElapsed">Amount of game time in seconds. May be ignored.</param> public virtual void Update(int timeElapsed) { if (timeElapsed == lastUpdated) return; // Don't update if time isnt flowing lastUpdated = timeElapsed; if (!isBoundToAnotherPlatform) { Vector2 newVel = velocity; if (hasGravity) newVel.Y += gravity; if (newVel.Y > terminalVelocity) newVel.Y = terminalVelocity; velocity = newVel; if (velocity.Equals(Vector2.Zero)) return; int xoff = (int)newVel.X; int yoff = (int)newVel.Y; MoveFrame(xoff, yoff); foreach (WorldObject w in boundObjects) { w.MoveFrame(xoff, yoff); //w.AddBindVelocity(newVel); } } collisionRect = drawRect; if (patrol != null) { velocity = patrol.getCurrentVector(timeElapsed); } }
// Token: 0x06000C1E RID: 3102 RVA: 0x000EFACC File Offset: 0x000EDCCC public override void behaviorAtGameTick(GameTime time) { base.behaviorAtGameTick(time); this.isEmoting = false; Microsoft.Xna.Framework.Rectangle r = this.GetBoundingBox(); if (this.sprite.currentFrame < 4) { r.Inflate(Game1.tileSize * 2, Game1.tileSize * 2); if (!this.isInvisible || r.Contains(Game1.player.getStandingX(), Game1.player.getStandingY())) { if (this.isInvisible) { if (Game1.currentLocation.map.GetLayer("Back").Tiles[(int)Game1.player.getTileLocation().X, (int)Game1.player.getTileLocation().Y].Properties.ContainsKey("NPCBarrier") || (!Game1.currentLocation.map.GetLayer("Back").Tiles[(int)Game1.player.getTileLocation().X, (int)Game1.player.getTileLocation().Y].TileIndexProperties.ContainsKey("Diggable") && Game1.currentLocation.map.GetLayer("Back").Tiles[(int)Game1.player.getTileLocation().X, (int)Game1.player.getTileLocation().Y].TileIndex != 0)) { return; } this.position = new Vector2(Game1.player.position.X, Game1.player.position.Y + (float)Game1.player.sprite.spriteHeight - (float)this.sprite.spriteHeight); Game1.playSound("Duggy"); this.sprite.interval = 100f; this.position = Game1.player.getTileLocation() * (float)Game1.tileSize; } this.isInvisible = false; this.sprite.AnimateDown(time, 0, ""); } } if (this.sprite.currentFrame >= 4 && this.sprite.CurrentFrame < 8) { if (!this.hasDugForTreasure) { base.getTileLocation(); } r.Inflate(-Game1.tileSize * 2, -Game1.tileSize * 2); Game1.currentLocation.isCollidingPosition(r, Game1.viewport, false, 8, false, this); this.sprite.AnimateRight(time, 0, ""); this.sprite.interval = 220f; } if (this.sprite.currentFrame >= 8) { this.sprite.AnimateUp(time, 0, ""); } if (this.sprite.currentFrame >= 10) { this.isInvisible = true; this.sprite.currentFrame = 0; this.hasDugForTreasure = false; int attempts = 0; Vector2 tile = base.getTileLocation(); Game1.currentLocation.map.GetLayer("Back").Tiles[(int)tile.X, (int)tile.Y].TileIndex = 0; Game1.currentLocation.removeEverythingExceptCharactersFromThisTile((int)tile.X, (int)tile.Y); Vector2 attemptedPosition = new Vector2((float)(Game1.player.GetBoundingBox().Center.X / Game1.tileSize + Game1.random.Next(-12, 12)), (float)(Game1.player.GetBoundingBox().Center.Y / Game1.tileSize + Game1.random.Next(-12, 12))); while (attempts < 4 && (attemptedPosition.X <= 0f || attemptedPosition.X >= (float)Game1.currentLocation.map.Layers[0].LayerWidth || attemptedPosition.Y <= 0f || attemptedPosition.Y >= (float)Game1.currentLocation.map.Layers[0].LayerHeight || Game1.currentLocation.map.GetLayer("Back").Tiles[(int)attemptedPosition.X, (int)attemptedPosition.Y] == null || Game1.currentLocation.isTileOccupied(attemptedPosition, "") || !Game1.currentLocation.isTilePassable(new Location((int)attemptedPosition.X, (int)attemptedPosition.Y), Game1.viewport) || attemptedPosition.Equals(new Vector2((float)(Game1.player.getStandingX() / Game1.tileSize), (float)(Game1.player.getStandingY() / Game1.tileSize))) || Game1.currentLocation.map.GetLayer("Back").Tiles[(int)attemptedPosition.X, (int)attemptedPosition.Y].Properties.ContainsKey("NPCBarrier") || (!Game1.currentLocation.map.GetLayer("Back").Tiles[(int)attemptedPosition.X, (int)attemptedPosition.Y].TileIndexProperties.ContainsKey("Diggable") && Game1.currentLocation.map.GetLayer("Back").Tiles[(int)attemptedPosition.X, (int)attemptedPosition.Y].TileIndex != 0))) { attemptedPosition = new Vector2((float)(Game1.player.GetBoundingBox().Center.X / Game1.tileSize + Game1.random.Next(-2, 2)), (float)(Game1.player.GetBoundingBox().Center.Y / Game1.tileSize + Game1.random.Next(-2, 2))); attempts++; } } }
public static Vector2 GetPosition(Vector2 start, Vector2 toGoal, float radius, Entity source) { float range = toGoal.Length(); toGoal.Normalize(); if(range == 0) { return start; } #region Standard method Vector2 curGoal = start + toGoal * (range + radius); float standardRange = range; if (_level.IsPixelAccessible((curGoal))) { return curGoal - toGoal * radius; } else { if (source != null) { Entity ent = _level.GetEntityAt(curGoal); if (ent.Equals(source)) { return curGoal; } ent.OnCollide(source); if (!start.Equals(source.GetPosition())) { return source.GetPosition(); } if (ent.CanBePickedUp()) { return curGoal - toGoal * radius; } } } while (!_level.IsPixelAccessible((curGoal))) { if (standardRange > 1) { standardRange -= 1; } else { break; } curGoal = start + toGoal * (standardRange + radius); if (_level.IsPixelAccessible((curGoal))) { return curGoal - toGoal * radius; } else { if (source != null) { Entity ent = _level.GetEntityAt(curGoal); ent.OnCollide(source); if (!start.Equals(source.GetPosition())) { return source.GetPosition(); } if (ent.CanBePickedUp()) { return curGoal - toGoal * radius; } } } } #endregion #region "Slide" method if (Math.Abs(toGoal.X) > Math.Abs(toGoal.Y)) { toGoal = new Vector2(toGoal.X, 0); } else { toGoal = new Vector2(0, toGoal.Y); } curGoal = start + toGoal * (range + radius); while (!_level.IsPixelAccessible((curGoal))) { if (standardRange > 1) { standardRange -= 1; } else { return start; } curGoal = start + toGoal * (standardRange + radius); } #endregion return curGoal - toGoal * radius; }
private static bool IsRemovableData(Vector2 element) { return(element.Equals(Vector2.zero)); }
public void OnDarkCaveExit(Collider collider) { if (darkCave) { Vector2 darkCaveDoor = new Vector2 (collider.transform.position.x, collider.transform.position.y); if (darkCaveDoor.Equals (curDarkCave.Door1) || darkCaveDoor.Equals (curDarkCave.Door2)) ResetDarkCave (); else OnEnterDarkCave (collider); } else OnEnterDarkCave (collider); }
// Update is called once per frame void Update() { if (!Pause.isPaused) { if (Input.GetKeyDown(KeyCode.Space) && HasGravity() && (IsGrounded() || extra_jumps > 0)) { if (!IsGrounded()) { extra_jumps--; } // Audio if (direction == Vector2.down) { FindObjectOfType <AudioManager>().Play("Gravity"); } else { FindObjectOfType <AudioManager>().Play("Gravityd"); } rigidBody2d.velocity = new Vector2(rigidBody2d.velocity.x, 0f); rigidBody2d.gravityScale = -rigidBody2d.gravityScale; if (direction.Equals(Vector2.down)) { direction = Vector2.up; } else { direction = Vector2.down; } } else if (Input.GetKeyDown(KeyCode.Space) && (IsGrounded() || extra_jumps > 0)) { if (!IsGrounded()) { extra_jumps--; } // Audio FindObjectOfType <AudioManager>().Play("Jump" + jump_sound); if (jump_sound == 6) { jump_sound = 1; } else { jump_sound++; } isJumping = true; rigidBody2d.velocity = new Vector2(rigidBody2d.velocity.x, 0f); rigidBody2d.AddForce(Vector2.up * jumpVelocity * 60); } if (isJumping) { if (Input.GetKeyUp(KeyCode.Space)) { isJumping = false; if (rigidBody2d.velocity.y > minVelocity) { rigidBody2d.velocity = new Vector2(rigidBody2d.velocity.x, minVelocity); } } } if (IsGrounded()) { extra_jumps = SlimeBoosts(); } if (rigidBody2d.gravityScale < 0 && !HasGravity()) { rigidBody2d.gravityScale = -rigidBody2d.gravityScale; direction = Vector2.down; } if (Mathf.Abs(rigidBody2d.velocity.y) > maxVelocity) { rigidBody2d.velocity = new Vector2(rigidBody2d.velocity.x, maxVelocity * rigidBody2d.velocity.y / Mathf.Abs(rigidBody2d.velocity.y)); } } if (!bound.Contains(transform.position)) { Die(); } }
public static Vector2[] CheckLinevLine(Vector2 a1, Vector2 a2, Vector2 b1, Vector2 b2) { if (a1.Equals(a2) && b1.Equals(b2)) { if (a1.Equals(b1)) { return new Vector2[] { a1 }; } return new Vector2[0]; } else if (b1.Equals(b2)) { if (Collision.PointOnLine(b1, a1, a2)) { return new Vector2[] { b1 }; } return new Vector2[0]; } else if (a1.Equals(a2)) { if (Collision.PointOnLine(a1, b1, b2)) { return new Vector2[] { a1 }; } return new Vector2[0]; } else { float num = (b2.X - b1.X) * (a1.Y - b1.Y) - (b2.Y - b1.Y) * (a1.X - b1.X); float num2 = (a2.X - a1.X) * (a1.Y - b1.Y) - (a2.Y - a1.Y) * (a1.X - b1.X); float num3 = (b2.Y - b1.Y) * (a2.X - a1.X) - (b2.X - b1.X) * (a2.Y - a1.Y); if (-Collision.Epsilon >= num3 || num3 >= Collision.Epsilon) { float num4 = num / num3; float num5 = num2 / num3; if (0f <= num4 && num4 <= 1f && 0f <= num5 && num5 <= 1f) { return new Vector2[] { new Vector2(a1.X + num4 * (a2.X - a1.X), a1.Y + num4 * (a2.Y - a1.Y)) }; } return new Vector2[0]; } else { if ((-Collision.Epsilon >= num || num >= Collision.Epsilon) && (-Collision.Epsilon >= num2 || num2 >= Collision.Epsilon)) { return new Vector2[0]; } if (a1.Equals(a2)) { return Collision.OneDimensionalIntersection(b1, b2, a1, a2); } return Collision.OneDimensionalIntersection(a1, a2, b1, b2); } } }
public bool Equals(VertexPositionNormalTangentTexture other) => Position.Equals(other.Position) && Normal.Equals(other.Normal) && Tangent.Equals(other.Tangent) && TextureCoordinate.Equals(other.TextureCoordinate);
public bool IsDeadBuffer() { return(buffer.Equals(Vector2.zero)); }
void UpdateFacing(Vector2 delta) { if (delta.y > 0) { mFacing = FacingType.Up; } else if (delta.y < 0) { mFacing = FacingType.Down; } else if (delta.x > 0) { mFacing = FacingType.Right; } else if (delta.x < 0) { mFacing = FacingType.Left; } if (!delta.Equals(Vector2.zero)) mIsMoving = true; else mIsMoving = false; }
/// <summary> /// Updates the collision matrix with the new position /// </summary> /// <param name="obj">Object we want to update</param> /// <param name="oldPosition">Position where object was before</param> private void UpdateCollisionMatrix(GameObject obj, Vector2 oldPosition) { Vector2 newPosition = GridSpace.GetGridCoord(obj.mPosition); if (oldPosition.Equals(newPosition)) return; mCollisionMatrix[(int)oldPosition.Y][(int)oldPosition.X].Remove(obj); if(!mCollisionMatrix[(int)newPosition.Y][(int)newPosition.X].Contains(obj)) mCollisionMatrix[(int)newPosition.Y][(int)newPosition.X].Add(obj); }
private static bool HandlePlayerUpdate(GetDataHandlerArgs args) { byte plr = args.Data.ReadInt8(); BitsByte control = args.Data.ReadInt8(); BitsByte pulley = args.Data.ReadInt8(); byte item = args.Data.ReadInt8(); var pos = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); var vel = Vector2.Zero; if (pulley[2]) vel = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); if (OnPlayerUpdate(plr, control, item, pos, vel, pulley)) return true; if (pos.X < 0 || pos.Y < 0 || pos.X >= Main.maxTilesX * 16 - 16 || pos.Y >= Main.maxTilesY * 16 - 16) { return true; } if (item < 0 || item >= args.TPlayer.inventory.Length) { return true; } if (args.Player.LastNetPosition == Vector2.Zero) { return true; } if (!pos.Equals(args.Player.LastNetPosition)) { float distance = Vector2.Distance(new Vector2(pos.X/16f, pos.Y/16f), new Vector2(args.Player.LastNetPosition.X/16f, args.Player.LastNetPosition.Y/16f)); if (TShock.CheckIgnores(args.Player)) { if (distance > TShock.Config.MaxRangeForDisabled) { if (args.Player.IgnoreActionsForCheating != "none") { args.Player.SendErrorMessage("Disabled for cheating: " + args.Player.IgnoreActionsForCheating); } else if (args.Player.IgnoreActionsForDisabledArmor != "none") { args.Player.SendErrorMessage("Disabled for banned armor: " + args.Player.IgnoreActionsForDisabledArmor); } else if (args.Player.IgnoreActionsForInventory != "none") { args.Player.SendErrorMessage("Disabled for Server Side Inventory: " + args.Player.IgnoreActionsForInventory); } else if (TShock.Config.RequireLogin && !args.Player.IsLoggedIn) { args.Player.SendErrorMessage("Please /register or /login to play!"); } else if (args.Player.IgnoreActionsForClearingTrashCan) { args.Player.SendErrorMessage("You need to rejoin to ensure your trash can is cleared!"); } var lastTileX = args.Player.LastNetPosition.X; var lastTileY = args.Player.LastNetPosition.Y - 48; if (!args.Player.Teleport(lastTileX, lastTileY)) { args.Player.Spawn(); } return true; } return true; } if (args.Player.Dead) { return true; } if (!args.Player.Group.HasPermission(Permissions.ignorenoclipdetection) && TSCheckNoclip(pos, args.TPlayer.width, args.TPlayer.height) && !TShock.Config.IgnoreNoClip && !args.TPlayer.tongued) { var lastTileX = args.Player.LastNetPosition.X; var lastTileY = args.Player.LastNetPosition.Y; if (!args.Player.Teleport(lastTileX, lastTileY )) { args.Player.SendErrorMessage("You got stuck in a solid object, Sent to spawn point."); args.Player.Spawn(); } return true; } args.Player.LastNetPosition = pos; } if (control[5]) { string itemName = args.TPlayer.inventory[item].name; if (TShock.Itembans.ItemIsBanned(itemName, args.Player)) { control[5] = false; args.Player.Disable("using a banned item ({0})".SFormat(itemName), DisableFlags.WriteToLogAndConsole); args.Player.SendErrorMessage("You cannot use {0} on this server. Your actions are being ignored.", itemName); } if (args.TPlayer.inventory[item].name == "Mana Crystal" && args.Player.TPlayer.statManaMax <= 180) { args.Player.TPlayer.statMana += 20; args.Player.TPlayer.statManaMax += 20; args.Player.PlayerData.maxMana += 20; } else if (args.TPlayer.inventory[item].name == "Life Crystal" && args.Player.TPlayer.statLifeMax <= 380) { args.TPlayer.statLife += 20; args.TPlayer.statLifeMax += 20; args.Player.PlayerData.maxHealth += 20; } else if (args.TPlayer.inventory[item].name == "Life Fruit" && args.Player.TPlayer.statLifeMax >= 400 && args.Player.TPlayer.statLifeMax <= 495) { args.TPlayer.statLife += 5; args.TPlayer.statLifeMax += 5; args.Player.PlayerData.maxHealth += 5; } } args.TPlayer.selectedItem = item; args.TPlayer.position = pos; args.TPlayer.oldVelocity = args.TPlayer.velocity; args.TPlayer.velocity = vel; args.TPlayer.fallStart = (int) (pos.Y/16f); args.TPlayer.controlUp = false; args.TPlayer.controlDown = false; args.TPlayer.controlLeft = false; args.TPlayer.controlRight = false; args.TPlayer.controlJump = false; args.TPlayer.controlUseItem = false; args.TPlayer.pulley = pulley[0]; if (pulley[0]) args.TPlayer.pulleyDir = (byte)(pulley[1] ? 2 : 1); if (pulley[3]) args.TPlayer.vortexStealthActive = true; args.TPlayer.gravDir = pulley[4] ? 1f : -1f; args.TPlayer.direction = -1; if (control[0]) { args.TPlayer.controlUp = true; } if (control[1]) { args.TPlayer.controlDown = true; } if (control[2]) { args.TPlayer.controlLeft = true; } if (control[3]) { args.TPlayer.controlRight = true; } if (control[4]) { args.TPlayer.controlJump = true; } if (control[5]) { args.TPlayer.controlUseItem = true; } if (control[6]) { args.TPlayer.direction = 1; } else { args.TPlayer.direction = -1; } if (args.Player.Confused && Main.ServerSideCharacter && args.Player.IsLoggedIn) { if (args.TPlayer.controlUp) { args.TPlayer.controlDown = true; args.TPlayer.controlUp = false; } else if (args.TPlayer.controlDown) { args.TPlayer.controlDown = false; args.TPlayer.controlUp = true; } if (args.TPlayer.controlLeft) { args.TPlayer.controlRight = true; args.TPlayer.controlLeft = false; } else if (args.TPlayer.controlRight) { args.TPlayer.controlRight = false; args.TPlayer.controlLeft = true; } args.TPlayer.Update(args.TPlayer.whoAmI); NetMessage.SendData((int)PacketTypes.PlayerUpdate, -1, -1, "", args.Player.Index); return true; } NetMessage.SendData((int)PacketTypes.PlayerUpdate, -1, args.Player.Index, "", args.Player.Index); return true; }
// player input entries void Move(Vector2 dir, Vector2 touchPos) { Character character = GetMainActor (); if (character.splited && character.splitChild != null) { Log.i ("move splited child"); Character splitChild = GetValidScript(character.splitChild.transform); if(!touchPos.Equals(Vector2.zero)) { dir = touchPos - splitChild.ScreenPos(); } splitChild.Move(dir); if(!touchPos.Equals(Vector2.zero)) { dir = touchPos - character.ScreenPos(); } } if (!dir.Equals (Vector2.zero)) { dir = touchPos - character.ScreenPos (); } character.Move(dir); }
private void RefreshRangeItems(GameLocation location) { if (!Context.IsWorldReady || location == null) { return; } Vector2 mouseTile = new Vector2((Game1.getMouseX() + Game1.viewport.X) / Game1.tileSize, (Game1.getMouseY() + Game1.viewport.Y) / Game1.tileSize); this.displayManager.Clear(); //Objects in the world and objects being hovered over foreach (KeyValuePair <Vector2, SObject> item in location.Objects.Pairs) { foreach (IObjectRangeCreator creator in this.objectRangeCreators) { if (creator.CanHandle(item.Value)) { this.displayManager.AddTilesToDisplay(creator.HandledRangeItem, creator.GetRange(item.Value, item.Key, location), mouseTile.Equals(item.Key) && this.isModifierKeyDown); } } } //Buildings in the world and objects being hovered over foreach (IBuildingRangeCreator creator in this.buildingRangeCreators) { Vector2 mouseTileOrZero = this.isModifierKeyDown ? mouseTile : Vector2.Zero; this.displayManager.AddTilesToDisplay(creator.HandledRangeItem, creator.GetRange(mouseTileOrZero, location)); this.displayManager.AddTilesToDisplay(creator.HandledRangeItem, creator.GetForceRange(mouseTileOrZero, location), true); } //Held item if (this.activeObject != null && this.config.ShowRangeOfHeldItem) { foreach (IObjectRangeCreator creator in this.objectRangeCreators) { if (creator.CanHandle(this.activeObject)) { this.displayManager.AddTilesToDisplay(creator.HandledRangeItem, creator.GetRange(this.activeObject, mouseTile, Game1.currentLocation), true); } } } }
public void Vector2EqualsTest1() { Vector2 a = new Vector2(1.0f, 2.0f); Vector2 b = new Vector2(1.0f, 2.0f); // case 1: compare between same values bool expected = true; bool actual = a.Equals(b); Assert.AreEqual(expected, actual, "Vector2.Equals did not return the expected value."); // case 2: compare between different values b.X = 10.0f; expected = false; actual = a.Equals(b); Assert.AreEqual(expected, actual, "Vector2.Equals did not return the expected value."); }
static void MergeVertsFast(int[] piTriList_in_and_out, ref STmpVert[] pTmpVert, ref SMikkTSpaceContext context, int iL_in, int iR_in) { int c = 0, l = 0, channel = 0; float[] fvMin = new float[3], fvMax = new float[3]; float dx = 0, dy = 0, dz = 0, fSep = 0; for (c = 0; c < 3; c++) { fvMin[c] = pTmpVert[iL_in].vert[c]; fvMax[c] = fvMin[c]; } for (l = (iL_in + 1); l <= iR_in; l++) { for (c = 0; c < 3; c++) { if (fvMin[c] > pTmpVert[l].vert[c]) { fvMin[c] = pTmpVert[l].vert[c]; } else if (fvMax[c] < pTmpVert[l].vert[c]) { fvMax[c] = pTmpVert[l].vert[c]; } } } dx = fvMax[0] - fvMin[0]; dy = fvMax[1] - fvMin[1]; dz = fvMax[2] - fvMin[2]; channel = 0; if (dy > dx && dy > dz) { channel = 1; } else if (dz > dx) { channel = 2; } fSep = 0.5f * (fvMax[channel] + fvMin[channel]); if (fSep >= fvMax[channel] || fSep <= fvMin[channel]) { for (l = iL_in; l <= iR_in; l++) { int i = pTmpVert[l].index; int index = piTriList_in_and_out[i]; Vector3 vP = GetPosition(ref context, index); Vector3 vN = GetNormal(ref context, index); Vector2 vT = GetTexCoord(ref context, index); bool bNotFound = true; int l2 = iL_in, i2rec = -1; while (l2 < l && bNotFound) { int i2 = pTmpVert[l2].index; int index2 = piTriList_in_and_out[i2]; Vector3 vP2 = GetPosition(ref context, index2); Vector3 vN2 = GetNormal(ref context, index2); Vector2 vT2 = GetTexCoord(ref context, index2); i2rec = i2; if (vP.Equals(vP2) && vN.Equals(vN2) && vT.Equals(vT2)) { bNotFound = false; } else { l2++; } } if (!bNotFound) { piTriList_in_and_out[i] = piTriList_in_and_out[i2rec]; } } } else { int iL = iL_in, iR = iR = iR_in; while (iL < iR) { bool bReadyLeftSwap = false, bReadyRightSwap = false; while ((!bReadyLeftSwap) && iL < iR) { bReadyLeftSwap = !(pTmpVert[iL].vert[channel] < fSep); if (!bReadyLeftSwap) { ++iL; } } while ((!bReadyRightSwap) && iL < iR) { bReadyRightSwap = pTmpVert[iR].vert[channel] < fSep; if (!bReadyRightSwap) { --iR; } } if (bReadyLeftSwap && bReadyRightSwap) { STmpVert sTmp = pTmpVert[iL]; pTmpVert[iL] = pTmpVert[iR]; pTmpVert[iR] = sTmp; ++iL; --iR; } } if (iL == iR) { bool bReadyRightSwap = pTmpVert[iR].vert[channel] < fSep; if (bReadyRightSwap) { ++iL; } else { --iR; } } if (iL_in < iR) { MergeVertsFast(piTriList_in_and_out, ref pTmpVert, ref context, iL_in, iR); } if (iL < iR_in) { MergeVertsFast(piTriList_in_and_out, ref pTmpVert, ref context, iL, iR_in); } } }
private static bool HandlePlayerUpdate(GetDataHandlerArgs args) { var plr = args.Data.ReadInt8(); var control = args.Data.ReadInt8(); var item = args.Data.ReadInt8(); var pos = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); var vel = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); if (item < 0 || item >= args.TPlayer.inventory.Length) { return true; } if (!pos.Equals(args.Player.LastNetPosition)) { float distance = Vector2.Distance(new Vector2(pos.X / 16f, pos.Y / 16f), new Vector2(args.Player.LastNetPosition.X / 16f, args.Player.LastNetPosition.Y / 16f)); if (TShock.CheckIgnores(args.Player) && distance > TShock.Config.MaxRangeForDisabled) { if(args.Player.IgnoreActionsForCheating != "none") { args.Player.SendMessage("Disabled for cheating: " + args.Player.IgnoreActionsForCheating, Color.Red); } else if (args.Player.IgnoreActionsForDisabledArmor != "none") { args.Player.SendMessage("Disabled for banned armor: " + args.Player.IgnoreActionsForDisabledArmor, Color.Red); } else if (args.Player.IgnoreActionsForInventory != "none") { args.Player.SendMessage("Disabled for Server Side Inventory: " + args.Player.IgnoreActionsForInventory, Color.Red); } else if (TShock.Config.RequireLogin && !args.Player.IsLoggedIn) { args.Player.SendMessage("Please /register or /login to play!", Color.Red); } else if (args.Player.IgnoreActionsForClearingTrashCan) { args.Player.SendMessage("You need to rejoin to ensure your trash can is cleared!", Color.Red); } else if (args.Player.IgnoreActionsForPvP) { args.Player.SendMessage("PvP is forced! Enable PvP else you can't move or do anything!", Color.Red); } int lastTileX = (int)(args.Player.LastNetPosition.X / 16f); int lastTileY = (int)(args.Player.LastNetPosition.Y / 16f); if (!args.Player.Teleport(lastTileX, lastTileY + 3)) { args.Player.Spawn(); } return true; } if (args.Player.Dead) { return true; } if (!args.Player.Group.HasPermission(Permissions.ignorenoclipdetection) && Collision.SolidCollision(pos, args.TPlayer.width, args.TPlayer.height)) { int lastTileX = (int)(args.Player.LastNetPosition.X / 16f); int lastTileY = (int)(args.Player.LastNetPosition.Y / 16f); if (!args.Player.Teleport(lastTileX, lastTileY + 3)) { args.Player.SendMessage("You got stuck in a solid object, Sent to spawn point."); args.Player.Spawn(); } return true; } } args.Player.LastNetPosition = pos; if ((control & 32) == 32) { if (!args.Player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned(args.TPlayer.inventory[item].name, args.Player)) { control -= 32; args.Player.LastThreat = DateTime.UtcNow; args.Player.SendMessage(string.Format("You cannot use {0} on this server. Your actions are being ignored.", args.TPlayer.inventory[item].name), Color.Red); } } args.TPlayer.selectedItem = item; args.TPlayer.position = pos; args.TPlayer.velocity = vel; args.TPlayer.oldVelocity = args.TPlayer.velocity; args.TPlayer.fallStart = (int)(pos.Y / 16f); args.TPlayer.controlUp = false; args.TPlayer.controlDown = false; args.TPlayer.controlLeft = false; args.TPlayer.controlRight = false; args.TPlayer.controlJump = false; args.TPlayer.controlUseItem = false; args.TPlayer.direction = -1; if ((control & 1) == 1) { args.TPlayer.controlUp = true; } if ((control & 2) == 2) { args.TPlayer.controlDown = true; } if ((control & 4) == 4) { args.TPlayer.controlLeft = true; } if ((control & 8) == 8) { args.TPlayer.controlRight = true; } if ((control & 16) == 16) { args.TPlayer.controlJump = true; } if ((control & 32) == 32) { args.TPlayer.controlUseItem = true; } if ((control & 64) == 64) { args.TPlayer.direction = 1; } NetMessage.SendData((int)PacketTypes.PlayerUpdate, -1, args.Player.Index, "", args.Player.Index); return true; }
public bool Equals(Circle2 other) { return(center.Equals(other.center) && radius.Equals(other.radius)); }
List<Vector3> checkCollision() { freezeCollide = false; // Move the bounding circle to new position circleCol.Update(pos); boundingBox.Update(pos, direction); // legacy, need to update everything to use the new circle collider List<Vector3> normals = new List<Vector3>(); // Get current node co-ordinates nodePos = new Vector2((int)((pos.X / 30) + 0.5f), (int)((pos.Z / 30) + 0.5f)); // Make a list containing current node and all neighbor nodes List<MapNode> currentNodes = new List<MapNode>(); currentNodes.Add(game.map.map[(int)nodePos.X, (int)nodePos.Y]); for (int i = 0; i < 4; i++) { if (game.map.map[(int)nodePos.X, (int)nodePos.Y].neighbors[i] != null) { currentNodes.Add(game.map.map[(int)nodePos.X, (int)nodePos.Y].neighbors[i]); } } //Debugging for Spatial Hashing if (!(nodePos.Equals(lastNodePos))) { System.Diagnostics.Debug.WriteLine("The player has moved from one node to the next"); System.Diagnostics.Debug.WriteLine("Spatial hashing now includes the following nodes"); foreach(MapNode node in currentNodes) { System.Diagnostics.Debug.WriteLine(node.position); } lastNodePos = nodePos; } //For the current node check if your X component will make you collide with wall foreach (MapNode node in currentNodes) { // Check map collision boxes foreach (OOBB box in node.collisionBoxes) { Vector3 normal = circleCol.wallCollide(box); if(!(normal.Equals(Vector3.Zero))) { normals.Add(normal); } } foreach (JunkShip j in game.asteroidManager.junkShips) { if (node.position.X == j.nodePos.X && node.position.Y == j.nodePos.Y) { foreach (OOBB box in j.cols) { Vector3 normal = circleCol.wallCollide(box); if (!(normal.Equals(Vector3.Zero))) { normals.Add(normal); } } } } // Check enemies within spatial partitioning foreach (Enemy e in game.enemyManager.enemies) { if (node.position.X == e.nodePos.X && node.position.Y == e.nodePos.Y) { foreach (CircleCollider c in e.cols) { Vector3 normal = circleCol.circleCollide(c); if (!(normal.Equals(Vector3.Zero))) { freezeCollide = true; normals.Add(normal); //c.push(moveSpeed, pos, 4.0f); //game.modelManager.addEffect(new ImpactParticleModel(game, pos)); } } } } // Check asteroids within spatial partitioning foreach (Asteroid a in game.asteroidManager.asteroids) { if (node.position.X == a.nodePos.X && node.position.Y == a.nodePos.Y) { Vector3 normal = circleCol.circleCollide(a.col); if (!(normal.Equals(Vector3.Zero))) { if (!(((WeaponDrill)weapons.weapons.ElementAt(4)).active && moving)) { a.push(moveSpeed, direction, 2f); } else { a.stop(); freezeCollide = true; } normals.Add(normal); //game.modelManager.addEffect(new ImpactParticleModel(game, pos)); } } } // Check sentries within spatial partitioning foreach (Sentry s in game.enemyManager.sentries) { if (node.position.X == s.nodePos.X && node.position.Y == s.nodePos.Y) { Vector3 normal = circleCol.circleCollide(s.col); if (!(normal.Equals(Vector3.Zero))) { //c.push(moveSpeed, pos, 4.0f); //game.modelManager.addEffect(new ImpactParticleModel(game, pos)); normals.Add(normal); freezeCollide = true; } } } } // Check collision with core Vector3 coreNormal = circleCol.circleCollide(game.core.col); if (!(coreNormal.Equals(Vector3.Zero))) { normals.Add(coreNormal); } return normals; }
private bool JoystickStateNotEqual(Vector2 joystick) { return(!joystick.Equals(_dataStream.Joystick.Value)); }
public bool requestMove(int entityId, Vector2 curLoc, Vector2 requestedLocation){ curLoc = this.translate(curLoc, true); requestedLocation = this.translate(requestedLocation, true); if( curLoc.Equals(requestedLocation) || this.isPassable(requestedLocation, false)){ this.entityGrid[(int)curLoc.X, (int)curLoc.Y] = -1; this.entityGrid[(int)requestedLocation.X, (int)requestedLocation.Y] = entityId; this.occupancyGrid[(int)curLoc.X, (int)curLoc.Y] = State.Occupancy.UNOCCUPIED; this.occupancyGrid[(int)requestedLocation.X, (int)requestedLocation.Y] = State.Occupancy.OCCUPIED; return true; } return false; }
public bool Equals(VertexPositionColorTextureSwizzle other) { return(Position.Equals(other.Position) && ColorScale.Equals(other.ColorScale) && ColorAdd.Equals(other.ColorAdd) && TextureCoordinate.Equals(other.TextureCoordinate)); }
public static void DrawLine(Vector2 pointA, Vector2 pointB, Color color, float width) { if (pointA.Equals(pointB)) // points are the same. return; // Save the current GUI matrix, since we're going to make changes to it. var matrix = GUI.matrix; // Generate a single pixel texture if it doesn't exist if (!lineTex) lineTex = new Texture2D(1, 1); // Store current GUI color, so we can switch it back later, // and set the GUI color to the color parameter var savedColor = GUI.color; GUI.color = color; // Determine the angle of the line. var angle = Vector3.Angle(pointB - pointA, Vector2.right); // Vector3.Angle always returns a positive number. // If pointB is above pointA, then angle needs to be negative. if (pointA.y > pointB.y) angle = -angle; // Use ScaleAroundPivot to adjust the size of the line. // We could do this when we draw the texture, but by scaling it here we can use // non-integer values for the width and length (such as sub 1 pixel widths). // Note that the pivot point is at +.5 from pointA.y, this is so that the width of the line // is centered on the origin at pointA. GUIUtility.ScaleAroundPivot(new Vector2((pointB - pointA).magnitude, width), new Vector2(pointA.x, pointA.y + 0.5f)); // Set the rotation for the line. // The angle was calculated with pointA as the origin. GUIUtility.RotateAroundPivot(angle, pointA); // Finally, draw the actual line. // We're really only drawing a 1x1 texture from pointA. // The matrix operations done with ScaleAroundPivot and RotateAroundPivot will make this // render with the proper width, length, and angle. GUI.DrawTexture(new Rect(pointA.x, pointA.y, 1, 1), lineTex); // We're done. Restore the GUI matrix and GUI color to whatever they were before. GUI.matrix = matrix; GUI.color = savedColor; }
private void DrawCorridor(Vector2 start, Vector2 direction) { // napraviti stepenice Vector2 stairsPos = Vector2.zero; if (direction.Equals(Vector2.right) || direction.Equals(Vector2.left)) { int dir = 1; float stairsAngle = 0; if (direction.Equals(Vector2.right)) { stairsAngle = 0; dir = 1; } else if (direction.Equals(Vector2.left)) { stairsAngle = 180; dir = -1; } GameObject stairs = Instantiate(LevelGeneration.I.stairsPrefab, start, Quaternion.Euler(0, stairsAngle, 0), transform); stairs.GetComponentInChildren <Stairs>().right = (dir == 1); stairsPos = start; stairsPositions.Add(stairsPos); start.y -= 1; stairs = Instantiate(LevelGeneration.I.stairsPrefab, start, Quaternion.Euler(0, stairsAngle, 0), transform); stairs.GetComponentInChildren <Stairs>().right = (dir == 1); //stairsPos = start; stairsPositions.Add(start); //start.x += dir; start.y += 2; Vector3Int pos = obstacleTilemap.WorldToCell(start); obstacleTilemap.SetTile(pos, null); } else { Instantiate(LevelGeneration.I.stairsVertPrefab, start + new Vector2(0.5f, 0), Quaternion.identity, transform); Instantiate(LevelGeneration.I.stairsVertPrefab, start + new Vector2(-0.5f, 0), Quaternion.identity, transform); } Vector3Int tilePos = new Vector3Int(); int i = 0; while (Mathf.Abs(start.x - transform.position.x) <= LevelGeneration.I.roomWidth / 2 && Mathf.Abs(start.y - transform.position.y) <= LevelGeneration.I.roomHeight / 2) { tilePos = groundTilemap.WorldToCell(start); TileBase prefab = ((direction.Equals(Vector2.left) || direction.Equals(Vector2.right)) ? LevelGeneration.I.corridorHorizPrefab : LevelGeneration.I.corridorVertPrefab); corridorTilemap.SetTile(tilePos, prefab); if (direction.Equals(Vector2.left) || direction.Equals(Vector2.right)) // corridor left / right { corridorTilemap.SetTile(tilePos + new Vector3Int(0, 1, 0), prefab); corridorTilemap.SetTile(tilePos + new Vector3Int(0, -1, 0), prefab); corridorTilemap.SetTile(tilePos + new Vector3Int(0, -2, 0), prefab); if (!tilePos.Equals(stairsPos) && !context.IsTileWalkable(context.groundTilemap, tilePos + new Vector3Int(0, 1, 0))) { obstacleTilemap.SetTile(tilePos + new Vector3Int(0, 1, 0), LevelGeneration.I.acidPrefab); } if (!context.IsTileWalkable(context.groundTilemap, tilePos + new Vector3Int(0, -1, 0))) { obstacleTilemap.SetTile(tilePos + new Vector3Int(0, -1, 0), LevelGeneration.I.acidPrefab); } if (!context.IsTileWalkable(context.groundTilemap, tilePos + new Vector3Int(0, 2, 0))) { obstacleTilemap.SetTile(tilePos + new Vector3Int(0, -2, 0), LevelGeneration.I.acidPrefab); } // foreground if (i == 0) { //corridorTilemap.SetTile(tilePos, null); if (direction.Equals(Vector2.left)) { foregroundTilemap.SetTile(tilePos + new Vector3Int(0, -1, 0), LevelGeneration.I.corridorHorizForegroundLeftPrefab); } else { foregroundTilemap.SetTile(tilePos + new Vector3Int(0, -1, 0), LevelGeneration.I.corridorHorizForegroundRightPrefab); } } else if (i > 0) { foregroundTilemap.SetTile(tilePos + new Vector3Int(0, -1, 0), LevelGeneration.I.corridorHorizForegroundPrefab); } obstacleTilemap.SetTile(tilePos + new Vector3Int(0, -1, 0), null); } else { corridorTilemap.SetTile(tilePos + new Vector3Int(1, 0, 0), prefab); corridorTilemap.SetTile(tilePos + new Vector3Int(-1, 0, 0), prefab); corridorTilemap.SetTile(tilePos + new Vector3Int(-2, 0, 0), prefab); if (!context.IsTileWalkable(context.groundTilemap, tilePos + new Vector3Int(1, 0, 0))) { obstacleTilemap.SetTile(tilePos + new Vector3Int(1, 0, 0), LevelGeneration.I.acidPrefab); } if (!context.IsTileWalkable(context.groundTilemap, tilePos + new Vector3Int(-1, 0, 0))) { obstacleTilemap.SetTile(tilePos + new Vector3Int(-1, 0, 0), LevelGeneration.I.acidPrefab); } if (!context.IsTileWalkable(context.groundTilemap, tilePos + new Vector3Int(-2, 0, 0))) { obstacleTilemap.SetTile(tilePos + new Vector3Int(-2, 0, 0), LevelGeneration.I.acidPrefab); } } acidTilemap.SetTile(acidTilemap.WorldToCell(start), null); obstacleTilemap.SetTile(tilePos, null); obstacleTilemap.SetTile(tilePos + new Vector3Int(-1, 0, 0), null); start += direction; i++; } positionEndOfCorridor = tilePos; start -= direction; acidTilemap.SetTile(acidTilemap.WorldToCell(start), null); Vector3Int corridorPos = LevelGeneration.I.corridorTilemap.WorldToCell(start); if (direction.Equals(Vector2.up) || direction.Equals(Vector2.down)) { for (int j = -1; j <= 1; j++) { LevelGeneration.I.corridorTilemap.SetTile(corridorPos + new Vector3Int(0, j, 0), LevelGeneration.I.corridorBridgeVertPrefab); LevelGeneration.I.corridorTilemap.SetTile(corridorPos + new Vector3Int(1, j, 0), LevelGeneration.I.corridorBridgeVertPrefab); LevelGeneration.I.corridorTilemap.SetTile(corridorPos + new Vector3Int(-1, j, 0), LevelGeneration.I.corridorBridgeVertPrefab); LevelGeneration.I.corridorTilemap.SetTile(corridorPos + new Vector3Int(-2, j, 0), LevelGeneration.I.corridorBridgeVertPrefab); } } else { for (int j = -1; j <= 1; j++) { LevelGeneration.I.corridorTilemap.SetTile(corridorPos + new Vector3Int(j, 0, 0), LevelGeneration.I.corridorBridgeHorizPrefab); LevelGeneration.I.corridorTilemap.SetTile(corridorPos + new Vector3Int(j, 1, 0), LevelGeneration.I.corridorBridgeHorizPrefab); LevelGeneration.I.corridorTilemap.SetTile(corridorPos + new Vector3Int(j, -1, 0), LevelGeneration.I.corridorBridgeHorizPrefab); LevelGeneration.I.corridorTilemap.SetTile(corridorPos + new Vector3Int(j, -2, 0), LevelGeneration.I.corridorBridgeHorizPrefab); } } }
/// <summary> /// Determines whether a Vector2 represents an invalid position, i.e. if it is equal to <see cref="INVALID_POSITION"/>. /// </summary> /// <param name="position">Screen position.</param> /// <returns><c>true</c> if position is invalid; otherwise, <c>false</c>.</returns> public static bool IsInvalidPosition(Vector2 position) { return position.Equals(INVALID_POSITION); }
public override void UpdateWhenCurrentLocation(GameTime time) { base.UpdateWhenCurrentLocation(time); if (drivingOff && !leaving) { busMotion.X -= 0.075f; if (busPosition.X + 512f < 0f) { leaving = true; Game1.globalFadeToBlack(busLeftToValley, 0.01f); } } if (drivingBack && busMotion != Vector2.Zero) { Game1.player.Position = busDoor.position; Game1.player.freezePause = 100; if (busPosition.X - 1088f < 256f) { busMotion.X = Math.Min(-1f, busMotion.X * 0.98f); } if (Math.Abs(busPosition.X - 1088f) <= Math.Abs(busMotion.X * 1.5f)) { busPosition.X = 1088f; busMotion = Vector2.Zero; Game1.globalFadeToBlack(delegate { drivingBack = false; busDoor.Position = busPosition + new Vector2(16f, 26f) * 4f; busDoor.pingPong = true; busDoor.interval = 70f; busDoor.currentParentTileIndex = 5; busDoor.endFunction = doorOpenAfterReturn; localSound("trashcanlid"); Game1.globalFadeToClear(); }); } } if (!busMotion.Equals(Vector2.Zero)) { busPosition += busMotion; if (busDoor != null) { busDoor.Position += busMotion; } } if (busDoor != null) { busDoor.update(time); } if (isTravelingDeserteMerchantHere()) { chimneyTimer -= time.ElapsedGameTime.Milliseconds; if (chimneyTimer <= 0) { chimneyTimer = 500; Vector2 smokeSpot = new Vector2(670f, 308f) * 4f; temporarySprites.Add(new TemporaryAnimatedSprite("LooseSprites\\Cursors", new Microsoft.Xna.Framework.Rectangle(372, 1956, 10, 10), smokeSpot, flipped: false, 0.002f, new Color(255, 222, 198)) { alpha = 0.05f, alphaFade = -0.01f, alphaFadeFade = -8E-05f, motion = new Vector2(0f, -0.5f), acceleration = new Vector2(0.002f, 0f), interval = 99999f, layerDepth = 1f, scale = 3f, scaleChange = 0.01f, rotationChange = (float)Game1.random.Next(-5, 6) * (float)Math.PI / 256f }); } } }