public Obstacle(int angles, float minSize, float maxSize, Vector2 pos) { //Obsolete!!! Vector2[] v = new Vector2[angles]; for (int i = 0; i < v.Length; ++i) { v[i] = TankGame.random.OnScaledCircle(minSize, maxSize); } Vector2 c = ExtensionMethods.GetPolyCenter(v); for (int i = 0; i < v.Length; ++i) { v[i] -= c; } v = ExtensionMethods.SortPolyClockwise(v, c); Mesh ObstacleMesh = new Mesh(v, this, Color.Gray, PrimitiveType.LineLoop); meshes.Add(ObstacleMesh); position = pos; collider = new Collider(this, meshes[0], PhysicsLayer.Default); Initialize(); }
public static void ShrinkMesh(Mesh m, float multiplier) { Vector2 center = ExtensionMethods.GetPolyCenter(m.vertices); for (int i = 0; i < m.vertices.Length; i++) { m.vertices[i] = ExtensionMethods.Lerp(m.vertices[i], center, multiplier); } }
public override void Update() { base.Update(); for (int i = 0; i < meshes.Count; i++) { while (i > spinDir.Count - 1) { spinDir.Add(ExtensionMethods.Range(TankGame.random, 0f, 2f) < 1 ? -1 : 1); } meshes[i].RotateVertices(0.01f * spinDir[i], ExtensionMethods.GetPolyCenter(meshes[i].vertices)); } }
public Obstacle(Vector2[] v, bool destroyable) { Vector2 c = ExtensionMethods.GetPolyCenter(v); Mesh m = new Mesh(v, this, destroyable ? Color.Beige : Color.Gray, PrimitiveType.LineLoop); m.offset = -c; meshes.Add(m); position = c; collider = new Collider(this, meshes[0], destroyable ? PhysicsLayer.Destroyable : PhysicsLayer.Default); Initialize(); }
public override void Update() { lifeTime -= Time.deltatime; if (lifeTime <= 0) { Destroy(); } position += moveDir; meshes[0].RotateVertices(spin, ExtensionMethods.GetPolyCenter(meshes[0].vertices)); meshes[0].Scale(0.03f); //Move current color towards 0 colorCurrent = ExtensionMethods.MoveTowards(colorCurrent, Vector3.Zero, Time.deltatime * (1f / lifeTime)); //Convert vector3 back to color meshes[0].color = colorCurrent.ToColor(); }
public List <Mesh> SplitMesh(Mesh m) { List <Mesh> list = new List <Mesh>(); List <Vector2> midPoints = new List <Vector2>(); Vector2 center = ExtensionMethods.GetPolyCenter(m.verticesWorldSpace); for (int i = 0; i < m.verticesWorldSpace.Length; i++) { midPoints.Add((m.verticesWorldSpace[i + 1 == m.verticesWorldSpace.Length ? 0 : i + 1] + m.verticesWorldSpace[i]) / 2); } for (int i = 0; i < midPoints.Count; i++) { list.Add(new Mesh(new Vector2[] { m.verticesWorldSpace[i], midPoints[i], center, midPoints[i - 1 < 0 ? midPoints.Count - 1 : i - 1], m.verticesWorldSpace[i] }, m.parent, m.color)); } return(list); }
public override void Update() { for (int i = 0; i < dots.Count; ++i) { if (!dots[i].alive) { dots.Remove(dots[i]); } } while (prevLength > dots.Count) { TankGame.RemoveMeshFromRenderStack(meshes[meshes.Count - 1]); meshes.Remove(meshes[meshes.Count - 1]); prevLength--; } if (prevLength == 0) { Destroy(); return; } for (int i = 0; i < dots.Count; ++i) { dots[i].Update(Time.deltatime); meshes[i].offset = dots[i].position; meshes[i].RotateVertices(i % 2 == 0 ? -dots[i].velocity.Length * 0.01f : dots[i].velocity.Length * 0.01f, ExtensionMethods.GetPolyCenter(meshes[i].vertices)); //Move current color towards 0 meshes[i].color = ExtensionMethods.Lerp(Vector3.Zero, startColor, (dots[i].killTime - Time.time) / dots[i].lifeTime).ToColor(); meshes[i].Scale(2 * Time.deltatime); } }