/// <summary> /// Create and return a random shape object. /// </summary> private GameObject CreateRandomShape() { // tilemap actual size float tilemapActualSize = tilemapSize * tileSize; // collision shape and type ICollisionShape collisionShape = null; ShapeMeshes shapeType = ShapeMeshes.Cylinder; // random collision shape and type int randType = rand.Next(0, 2); switch (randType) { case 0: shapeType = ShapeMeshes.SphereSmooth; collisionShape = new CollisionSphere(); break; case 1: shapeType = ShapeMeshes.Cube; collisionShape = new CollisionBox(2f, 2f, 2f); break; } // create shape float sizeFactor = 1.0f + (float)rand.NextDouble() * 1.25f; GameObject shape = new GameObject(); var shapeRenderer = shape.AddComponent(new ShapeRenderer(shapeType)) as ShapeRenderer; shapeRenderer.MaterialOverride.DiffuseColor = new Color((rand.Next(0, 255)), (rand.Next(0, 255)), (rand.Next(0, 255))); var body = shape.AddComponent(new RigidBody(collisionShape, sizeFactor, 1f, 1f)) as RigidBody; body.Scale = Vector3.One * tileSize * 0.25f * sizeFactor; body.Restitution = 0.5f; body.Position = new Vector3( (float)rand.NextDouble() * tilemapActualSize, 10f + (float)rand.NextDouble() * 45f, (float)rand.NextDouble() * tilemapActualSize); return(shape); }
/// <summary> /// Create the model renderer component. /// </summary> /// <param name="shape">Shape to draw.</param> public ShapeRenderer(ShapeMeshes shape) : base(ShapeModelsRoot + shape.ToString()) { }