public override Entity Create(Main main) { Entity result = new Entity(main, "DirectionalLight"); Transform transform = new Transform(); result.Add("Transform", transform); DirectionalLight directionalLight = new DirectionalLight(); result.Add("DirectionalLight", directionalLight); return result; }
public override Entity Create(Main main) { Entity result = new Entity(main, "SpotLight"); Transform transform = new Transform(); result.Add("Transform", transform); SpotLight spotLight = new SpotLight(); result.Add("SpotLight", spotLight); return result; }
public override Entity Create(Main main) { Entity result = new Entity(main, "Fog"); Transform transform = new Transform(); result.Add("Transform", transform); Fog fog = new Fog(); result.Add("Fog", fog); return result; }
public override Entity Create(Main main) { Entity result = new Entity(main, "Water"); Transform transform = new Transform(); result.Add("Transform", transform); Water water = new Water(); result.Add("Water", water); return result; }
public override Entity Create(Main main) { Entity result = new Entity(main, "PlayerSpawn"); result.Add("PlayerSpawn", new PlayerSpawn()); Transform transform = new Transform(); result.Add("Transform", transform); result.Add("Trigger", new PlayerTrigger()); return result; }
public override Entity Create(Main main) { Entity result = new Entity(main, "Skybox"); Transform transform = new Transform(); result.Add("Transform", transform); Model skybox = new Model(); skybox.Filename.Value = "Models\\skybox"; skybox.CullBoundingBox.Value = false; result.Add("Skybox", skybox); return result; }
public override Entity Create(Main main) { Entity result = new Entity(main, "PlayerTrigger"); Transform position = new Transform(); PlayerTrigger trigger = new PlayerTrigger(); trigger.Radius.Value = 10.0f; result.Add("PlayerTrigger", trigger); result.Add("Position", position); return result; }
public override Entity Create(Main main) { Entity result = new Entity(main, "Cloud"); Transform transform = new Transform(); result.Add("Transform", transform); ModelAlpha clouds = new ModelAlpha(); clouds.Filename.Value = "Models\\clouds"; clouds.CullBoundingBox.Value = false; clouds.DisableCulling.Value = true; clouds.DrawOrder.Value = -9; result.Add("Clouds", clouds); return result; }
public override Entity Create(Main main) { Entity result = new Entity(main, "Block"); Transform transform = new Transform(); result.Add("Transform", transform); PhysicsBlock physics = new PhysicsBlock(); result.Add("Physics", physics); Property<string> cue = new Property<string> { Value = "ConcreteRubble" }; result.Add("CollisionSoundCue", cue); ModelInstance model = new ModelInstance(); result.Add("Model", model); model.Scale.Value = new Vector3(0.5f); return result; }
public override Entity Create(Main main) { Entity result = new Entity(main, "EffectBlock"); Transform transform = new Transform(); result.Add("Transform", transform); ModelInstance model = new ModelInstance(); result.Add("Model", model); result.Add("Offset", new Property<Vector3> { Editable = false }); result.Add("Lifetime", new Property<float> { Editable = false }); result.Add("TotalLifetime", new Property<float> { Editable = true }); result.Add("StartPosition", new Property<Vector3> { Editable = true }); result.Add("StartOrientation", new Property<Matrix> { Editable = false }); result.Add("TargetMap", new Property<Entity.Handle> { Editable = true }); result.Add("TargetCoord", new Property<Map.Coordinate> { Editable = false }); result.Add("TargetCellStateID", new Property<int> { Editable = true }); result.Add("Scale", new Property<bool> { Editable = true, Value = true }); return result; }
public override Entity Create(Main main) { Entity result = new Entity(main, "FallingTower"); Transform transform = new Transform(); result.Add("Transform", transform); result.Add("Trigger", new PlayerCylinderTrigger()); result.Add("DynamicMaps", new ListProperty<Entity.Handle> { Editable = false }); result.Add("TimeUntilRebuild", new Property<float> { Editable = false }); result.Add("TimeUntilRebuildComplete", new Property<float> { Editable = false }); result.Add("RebuildDelay", new Property<float> { Editable = true, Value = 4.0f }); result.Add("RebuildTime", new Property<float> { Editable = true, Value = 1.0f }); return result; }
public override Entity Create(Main main) { Entity result = new Entity(main, "MapExit"); Transform position = new Transform(); PlayerTrigger trigger = new PlayerTrigger(); trigger.Radius.Value = 10.0f; result.Add("PlayerTrigger", trigger); result.Add("Transform", position); result.Add("NextMap", new Property<string> { Editable = true }); result.Add("SpawnPoint", new Property<string> { Editable = true }); return result; }
private void raycast(Main main, Vector3 ray, out Entity closestEntity, out Transform closestTransform) { closestEntity = null; float closestEntityDistance = main.Camera.FarPlaneDistance; closestTransform = null; Vector3 rayStart = main.Camera.Position; foreach (Entity entity in main.Entities) { foreach (Transform transform in entity.GetAll<Transform>()) { Vector3 entityPos = transform.Position; float distance = (entityPos - rayStart).Length(); Vector3 closestToEntity = rayStart + ray * distance; if ((distance < closestEntityDistance) && (closestToEntity - entityPos).Length() < 0.5f) { closestEntityDistance = distance; closestEntity = entity; closestTransform = transform; } } } Map.GlobalRaycastResult hit = Map.GlobalRaycast(rayStart, ray, closestEntityDistance, true); if (hit.Coordinate != null) { closestEntity = hit.Map.Entity; closestTransform = null; } }
public override Entity Create(Main main) { Entity result = new Entity(main, "Snake"); Transform transform = new Transform(); result.Add("Transform", transform); result.Add("Coordinate", new Property<Map.Coordinate> { Editable = false }); result.Add("OperationalRadius", new Property<float> { Editable = true, Value = 100.0f }); return result; }
private Transform addCornerModel(Entity entity, Property<bool> selected) { Transform transform = new Transform { Serialize = false, Editable = false }; entity.AddWithoutOverwriting(transform); Model cornerModel1 = new Model(); cornerModel1.Filename.Value = "Models\\sphere"; cornerModel1.Color.Value = this.Color; cornerModel1.IsInstanced.Value = false; cornerModel1.Scale.Value = new Vector3(0.5f); cornerModel1.Editable = false; cornerModel1.Serialize = false; entity.Add(cornerModel1); cornerModel1.Add(new Binding<Matrix, Vector3>(cornerModel1.Transform, x => Matrix.CreateTranslation(x), transform.Position)); cornerModel1.Add(new Binding<bool>(cornerModel1.Enabled, selected)); return transform; }
public override Entity Create(Main main) { Entity result = new Entity(main, "Blast"); Transform transform = new Transform(); result.Add("Transform", transform); PhysicsBlock physics = new PhysicsBlock(); result.Add("Physics", physics); Model model = new Model(); result.Add("Model", model); model.Filename.Value = "Models\\blast"; model.Color.Value = new Vector3(0.75f, 2.0f, 0.75f); PointLight light = new PointLight(); light.Shadowed.Value = true; light.Color.Value = new Vector3(model.Color.Value.X, model.Color.Value.Y, model.Color.Value.Z); light.Attenuation.Value = 10.0f; result.Add("Light", light); if (ParticleSystem.Get(main, "Sparks") == null) { ParticleSystem.Add(main, "Sparks", new ParticleSystem.ParticleSettings { TextureName = "Particles\\spark", MaxParticles = 1000, Duration = TimeSpan.FromSeconds(1.0f), MinHorizontalVelocity = 0.0f, MaxHorizontalVelocity = 0.0f, MinVerticalVelocity = 0.0f, MaxVerticalVelocity = 0.0f, Gravity = new Vector3(0.0f, 0.0f, 0.0f), EndVelocity = 0.0f, MinRotateSpeed = -20.0f, MaxRotateSpeed = 20.0f, MinStartSize = 0.5f, MaxStartSize = 0.4f, MinEndSize = 0.2f, MaxEndSize = 0.1f, BlendState = Microsoft.Xna.Framework.Graphics.BlendState.Additive, MinColor = new Vector4(0.75f, 2.0f, 0.75f, 1.0f), MaxColor = new Vector4(0.75f, 2.0f, 0.75f, 1.0f), }); } ParticleEmitter emitter = new ParticleEmitter(); emitter.ParticleType.Value = "Sparks"; emitter.ParticlesPerSecond.Value = 200; emitter.Jitter.Value = new Vector3(0.25f); result.Add("Particles", emitter); Sound loopSound = new Sound(); result.Add("LoopSound", loopSound); loopSound.Cue.Value = "Blast Loop"; return result; }
public void InternalBind(Entity result, Main main, bool creating = false, Transform transform = null) { if (transform == null) transform = result.GetOrCreate<Transform>("Transform"); result.CannotSuspend = false; Map map = result.Get<Map>(); // Apply the position and orientation components to the map map.Add(new TwoWayBinding<Matrix>(transform.Matrix, map.Transform)); map.Add(new CommandBinding(map.CompletelyEmptied, delegate() { if (!main.EditorEnabled) result.Delete.Execute(); })); Entity world = main.Get("World").FirstOrDefault(); map.Chunks.ItemAdded += delegate(int index, Map.Chunk chunk) { Dictionary<int, bool> models = new Dictionary<int, bool>(); Action<Map.CellState> createModel = delegate(Map.CellState state) { if (state.ID == 0) return; // 0 = empty DynamicModel<Map.MapVertex> model = new DynamicModel<Map.MapVertex>(Map.MapVertex.VertexDeclaration); model.EffectFile.Value = "Effects\\Environment"; model.Lock = map.Lock; state.ApplyTo(model); /* ModelAlpha debug = new ModelAlpha { Serialize = false }; debug.Alpha.Value = 0.01f; debug.DrawOrder.Value = 11; // In front of water debug.Color.Value = new Vector3(1.0f, 0.8f, 0.6f); debug.Filename.Value = "Models\\alpha-box"; debug.CullBoundingBox.Value = false; debug.DisableCulling.Value = true; debug.Add(new Binding<Matrix>(debug.Transform, delegate() { BoundingBox box = model.BoundingBox; return Matrix.CreateScale(box.Max - box.Min) * Matrix.CreateTranslation((box.Max + box.Min) * 0.5f) * transform.Matrix; }, transform.Matrix, model.BoundingBox)); result.Add(debug); */ model.Add(new Binding<Matrix>(model.Transform, transform.Matrix)); Vector3 min = new Vector3(chunk.X, chunk.Y, chunk.Z); Vector3 max = min + new Vector3(map.ChunkSize); model.Add(new Binding<Vector3>(model.GetVector3Parameter("Offset"), map.Offset)); Map.CellState s = state; if (!s.ShadowCast) model.UnsupportedTechniques.Add(new[] { Technique.Shadow, Technique.PointLightShadow }); model.Add(new ListBinding<Map.MapVertex, Map.Box> ( model.Vertices, chunk.Boxes, delegate(Map.Box box) { Map.MapVertex[] vertices = new Map.MapVertex[box.Surfaces.Where(x => x.HasArea).Count() * 4]; int i = 0; foreach (Map.Surface surface in box.Surfaces) { if (surface.HasArea) { Array.Copy(surface.Vertices, 0, vertices, i, 4); i += 4; } } return vertices; }, x => x.Type == s )); result.Add(model); // We have to create this binding after adding the model to the entity // Because when the model loads, it automatically calculates a bounding box for it. model.Add(new Binding<BoundingBox, Vector3>(model.BoundingBox, x => new BoundingBox(min - x, max - x), map.Offset)); models[state.ID] = true; }; chunk.Boxes.ItemAdded += delegate(int i, Map.Box box) { if ((!box.Type.Invisible || main.EditorEnabled) && !models.ContainsKey(box.Type.ID)) createModel(box.Type); }; chunk.Boxes.ItemChanged += delegate(int i, Map.Box oldBox, Map.Box newBox) { if ((!newBox.Type.Invisible || main.EditorEnabled) && !models.ContainsKey(newBox.Type.ID)) createModel(newBox.Type); }; }; this.SetMain(result, main); map.Offset.Changed(); }