public MovementUpdate(Entity entity) { id = entity.Id; newPosition = entity.Get<PositionComponent>().Position; newRotation = entity.Get<PositionComponent>().Rotation; newVel = entity.Get<MovementComponent>().Velocity; }
private void DrawBullet(GraphicsContext graphicsContext, Entity entity, CBullet bullet) { TextureDefinition texture = this.GetTexture(bullet.Weapon.Type); if (bullet.Weapon.Type == WeaponType.RocketLauncher) { graphicsContext.SpriteBatch.DrawCentered(texture, entity.Transform.Position, Color.White, entity.Transform.Rotation, 2); } else if (bullet.Weapon.Type == WeaponType.Bouncer) { graphicsContext.SpriteBatch.DrawCentered(texture, entity.Transform.Position, new Color(160, 160, 160), entity.Transform.Rotation, 1); } else if (bullet.Weapon.Type == WeaponType.Flamethrower) { CLifeTime lifeTime = entity.Get<CLifeTime>(); Color color = Color.Lerp(Color.LightGoldenrodYellow, Color.OrangeRed, 1 - lifeTime.NormalizedTimeRemaining) * 0.75f; graphicsContext.SpriteBatch.DrawCentered(graphicsContext.BlankTexture, entity.Transform.Position, color * lifeTime.NormalizedTimeRemaining, 0, FlaiMath.Scale(lifeTime.NormalizedTimeRemaining, 1, 0, 8, 32)); } else if (bullet.Weapon.Type == WeaponType.Waterblaster) { CLifeTime lifeTime = entity.Get<CLifeTime>(); Color color = Color.Lerp(Color.AliceBlue, new Color(0, 69, 255), 1 - lifeTime.NormalizedTimeRemaining) * 0.75f; graphicsContext.SpriteBatch.DrawCentered(graphicsContext.BlankTexture, entity.Transform.Position, color * lifeTime.NormalizedTimeRemaining, 0, FlaiMath.Scale(lifeTime.NormalizedTimeRemaining, 1, 0, 8, 32)); } else { graphicsContext.SpriteBatch.DrawCentered(texture, entity.Transform.Position, new Color(255, 255, 128) * 0.625f, entity.Transform.Rotation, 4); } }
public void Update(Entity e, GameTime t) { // We burn through just enough time for emission to occur. We // update the state, then perform an emission. Then we pick up // where we left off (when the loop loops). uint dt = (uint) t.ElapsedGameTime.TotalMilliseconds; while (dt > 0) { uint emitTime = e.Get(EmitTime); uint timeToEmission = e.Get(TimeToEmission); if (timeToEmission == 0) { timeToEmission = emitTime; } uint burntTime = Math.Min(timeToEmission, dt); timeToEmission -= burntTime; dt -= burntTime; e.Set(TimeToEmission, timeToEmission); if (timeToEmission == 0 && e.Get(IsEmitting)) { this.onEmit(e); } } }
public override void OnEntityAdded(Entity entity) { if (Contains<Animation>(entity) && Contains<Position>(entity)) { _animations.Add(entity.Get<Animation>()); _positions.Add(entity.Get<Position>()); _entities.Add(entity); } if (Contains<Tilemap>(entity) && Contains<Tilesheet>(entity)) { if (entity.Get<Tilemap>().Layer <= 0) { _bgTilemaps.Add(entity); _bgTilemaps.Sort(); } else { _fgTilemaps.Add(entity); _fgTilemaps.Sort(); } } if (Contains<Viewport>(entity)) { _viewports.Add(entity); } }
public override void Process(Entity entity, GameTime gameTime) { foreach (InputEvent e in entity.Get<InputComponent>().InputEvents.Keys) { if(e is KeyboardInputEvent) { KeyboardInputEvent key = (KeyboardInputEvent)e; if (Keyboard.CheckInput(key.Key, key.InputType)) { //then we have a match, do something Message message = entity.Get<InputComponent>().InputEvents[e](); Messageboard.PostMessage(message); } } else if (e is GamepadButtonInputEvent || e is GamepadAnalogStickInputEvent) { if (Gamepad.CheckInput(e)) { if (e is GamepadButtonInputEvent) { Message message = entity.Get<InputComponent>().InputEvents[e](); Messageboard.PostMessage(message); } else { Vector2 stickInput = Gamepad.GetAnalogStick(((GamepadAnalogStickInputEvent)e).Stick); Vector3 movement = new Vector3(stickInput.X, 0, stickInput.Y) * 3f; Message message = entity.Get<InputComponent>().InputEvents[e](movement); Messageboard.PostMessage(message); } } } } }
public override void Bind(Entity result, Main main, bool creating = false) { this.SetMain(result, main); Transform transform = result.Get<Transform>(); Model model = result.Get<Model>("Model"); model.Add(new Binding<Matrix>(model.Transform, transform.Matrix)); }
public override void AttachEditorComponents(Entity result, Main main) { base.AttachEditorComponents(result, main); Model model = result.Get<Model>("EditorModel"); model.Add(new Binding<Vector3, string>(model.Color, x => string.IsNullOrEmpty(x) ? Vector3.One : new Vector3(1.0f, 0.0f, 0.0f), result.Get<Script>().Errors)); }
public override void Bind(Entity result, Main main, bool creating = false) { result.CannotSuspendByDistance = true; Transform transform = result.Get<Transform>(); DirectionalLight directionalLight = result.Get<DirectionalLight>(); this.SetMain(result, main); directionalLight.Add(new TwoWayBinding<Vector3, Matrix> ( directionalLight.Direction, delegate(Matrix x) { Vector3 y = Vector3.Normalize(-x.Forward); if (Vector3.Dot(y, directionalLight.Direction) > 0.0f) return y; return -y; }, transform.Orientation, delegate(Vector3 x) { Matrix matrix = Matrix.Identity; matrix.Forward = Vector3.Normalize(-x); matrix.Left = x.Equals(Vector3.Up) ? Vector3.Left : Vector3.Normalize(Vector3.Cross(x, Vector3.Up)); matrix.Up = Vector3.Normalize(Vector3.Cross(matrix.Left, matrix.Forward)); return matrix; } )); }
public override void Bind(Entity result, Main main, bool creating = false) { this.SetMain(result, main); result.CannotSuspendByDistance = true; Transform transform = result.Get<Transform>(); ModelAlpha model = new ModelAlpha(); model.Color.Value = new Vector3(1.2f, 1.0f, 0.8f); model.Editable = false; model.Serialize = false; model.Filename.Value = "Models\\electricity"; model.DrawOrder.Value = 11; result.Add("Model", model); result.GetOrMakeProperty<bool>("IsMapEdge", true, true); PhysicsBlock block = result.Get<PhysicsBlock>(); block.Box.BecomeKinematic(); this.boundaries.Add(result); result.Add(new CommandBinding(result.Delete, delegate() { this.boundaries.Remove(result); })); block.Add(new TwoWayBinding<Matrix>(transform.Matrix, block.Transform)); model.Add(new Binding<Matrix>(model.Transform, transform.Matrix)); model.Add(new Binding<Vector3>(model.Scale, x => new Vector3(x.X * 0.5f, x.Y * 0.5f, 1.0f), block.Size)); Property<Vector2> scaleParameter = model.GetVector2Parameter("Scale"); model.Add(new Binding<Vector2, Vector3>(scaleParameter, x => new Vector2(x.Y, x.X), model.Scale)); model.Add(new CommandBinding(main.ReloadedContent, delegate() { scaleParameter.Reset(); })); }
public override void Bind(Entity result, Main main, bool creating = false) { this.SetMain(result, main); Transform transform = result.Get<Transform>(); Sound sound = result.Get<Sound>("Sound"); sound.Add(new Binding<Vector3>(sound.Position, transform.Position)); result.CannotSuspendByDistance = !sound.Is3D; result.Add(new NotifyBinding(delegate() { result.CannotSuspendByDistance = !sound.Is3D; }, sound.Is3D)); Property<float> min = result.GetProperty<float>("MinimumInterval"); Property<float> max = result.GetProperty<float>("MaximumInterval"); Random random = new Random(); float interval = min + ((float)random.NextDouble() * (max - min)); result.Add(new Updater { delegate(float dt) { if (!sound.IsPlaying) interval -= dt; if (interval <= 0) { sound.Play.Execute(); interval = min + ((float)random.NextDouble() * (max - min)); } } }); }
public override void AttachEditorComponents(Entity result, Main main) { base.AttachEditorComponents(result, main); Model editorModel = result.Get<Model>("EditorModel"); Model model = result.Get<Model>("Model"); editorModel.Add(new Binding<bool>(editorModel.Enabled, x => !x, model.IsValid)); }
public override void Bind(Entity result, Main main, bool creating = false) { if (result.GetOrMakeProperty<bool>("Attach", true)) MapAttachable.MakeAttachable(result, main); this.SetMain(result, main); if (main.EditorEnabled) { result.Add("Spawn Here", new Command { Action = delegate() { ((GameMain)main).StartSpawnPoint.Value = result.ID; Editor editor = main.Get("Editor").First().Get<Editor>(); if (editor.NeedsSave) editor.Save.Execute(); main.EditorEnabled.Value = false; IO.MapLoader.Load(main, null, main.MapFile); }, ShowInEditor = true, }); } Transform transform = result.Get<Transform>(); PlayerSpawn spawn = result.Get<PlayerSpawn>(); spawn.Add(new TwoWayBinding<Vector3>(transform.Position, spawn.Position)); spawn.Add(new Binding<float, Vector3>(spawn.Rotation, x => ((float)Math.PI * -0.5f) - (float)Math.Atan2(x.Z, x.X), transform.Forward)); PlayerTrigger trigger = result.Get<PlayerTrigger>(); trigger.Enabled.Editable = true; trigger.Add(new TwoWayBinding<Vector3>(transform.Position, trigger.Position)); trigger.Add(new CommandBinding<Entity>(trigger.PlayerEntered, delegate(Entity player) { spawn.Activate.Execute(); })); }
public override void Bind(Entity result, Main main, bool creating = false) { this.SetMain(result, main); Transform transform = result.Get<Transform>(); ParticleEmitter emitter = result.Get<ParticleEmitter>(); emitter.Add(new Binding<Vector3>(emitter.Position, transform.Position)); }
private static Rectangle CalculateRectAfterMove(Entity entity) { var pointAfterVerticalMovement = new Vector2D( entity.Get<Rectangle>().TopLeft.X + entity.Get<Velocity2D>().velocity.X * Time.Delta, entity.Get<Rectangle>().TopLeft.Y + entity.Get<Velocity2D>().velocity.Y * Time.Delta); return new Rectangle(pointAfterVerticalMovement, entity.Get<Rectangle>().Size); }
public override void AttachEditorComponents(Entity entity, Main main) { base.AttachEditorComponents(entity, main); VoxelAttachable.AttachEditorComponents(entity, main, entity.Get<Model>().Color); EntityConnectable.AttachEditorComponents(entity, "Target", entity.Get<VoxelFill>().Target); }
public override void Bind(Entity result, Main main, bool creating = false) { this.SetMain(result, main); Transform transform = result.Get<Transform>(); PlayerTrigger trigger = result.Get<PlayerTrigger>(); trigger.Add(new TwoWayBinding<Vector3>(transform.Position, trigger.Position)); }
public override void AttachEditorComponents(Entity result, Main main) { base.AttachEditorComponents(result, main); Model model = result.Get<Model>("Model"); Model editorModel = result.Get<Model>("EditorModel"); Property<bool> editorSelected = result.GetOrMakeProperty<bool>("EditorSelected", false); editorSelected.Serialize = false; editorModel.Add(new Binding<bool>(editorModel.Enabled, () => !editorSelected || !model.IsValid, editorSelected, model.IsValid)); }
public override void Bind(Entity result, Main main, bool creating = false) { base.Bind(result, main, creating); result.CannotSuspendByDistance = true; Model skybox = result.Get<Model>("Skybox"); skybox.Add(new Binding<Matrix>(skybox.Transform, result.Get<Transform>().Matrix)); skybox.DrawOrder.Value = -10; }
public override void Bind(Entity result, Main main, bool creating = false) { result.CannotSuspendByDistance = true; Transform transform = result.Get<Transform>(); Water water = result.Get<Water>(); this.SetMain(result, main); water.Add(new TwoWayBinding<Vector3>(water.Position, transform.Position)); }
public override void Bind(Entity result, Main main, bool creating = false) { PointLight light = result.Get<PointLight>(); Transform transform = result.Get<Transform>(); Property<float> attachOffset = result.GetOrMakeProperty<float>("AttachmentOffset", true); light.Add(new TwoWayBinding<Vector3>(light.Position, transform.Position)); if (result.GetOrMakeProperty<bool>("Attach", true)) MapAttachable.MakeAttachable(result, main); this.SetMain(result, main); }
public override void AttachEditorComponents(Entity result, Main main) { Model model = new Model(); model.Filename.Value = "Models\\light"; model.Add(new Binding<Vector3>(model.Color, result.Get<DirectionalLight>().Color)); model.Editable = false; model.Serialize = false; result.Add("EditorModel", model); model.Add(new Binding<Matrix>(model.Transform, result.Get<Transform>().Matrix)); }
protected override void UpdateEntity(float dt, Entity entity) { var direction = entity.Get<Direction>(); var body = entity.Get<Body>(); var position = entity.Get<Position>(); for (int i = 0; i < entity.Count(); ++i) { direction.X[i] = direction.X[i] + dt * body.Friction[i] * (0 - direction.X[i]); direction.Y[i] += (float)Math.Pow(body.Weight[i], dt); } }
public void Add(Entity e) { if (e.Has<ImageComponent>()) { var i = e.Get<ImageComponent>(); this.images.Add(i); } else if (e.Has<SpriteSheetComponent>()) { var i = e.Get<SpriteSheetComponent>(); this.images.Add(i); } }
public override void Process(Entity entity, GameTime gameTime) { CameraComponent camera = entity.Get<CameraComponent>(); //if we need to update either if (camera.NeedsFOVUpdate) { CalculateFOVMatrix(camera, entity.Get<Transform3DComponent>().Position); camera.NeedsViewUpdate = true; } if (camera.NeedsViewUpdate) CalculateViewMatrix(camera, entity.Get<Transform3DComponent>().Position, entity.Get<Transform3DComponent>().RotationMatrix); }
public override void Bind(Entity result, Main main, bool creating = false) { Transform transform = result.Get<Transform>(); SpotLight spotLight = result.Get<SpotLight>(); if (result.GetOrMakeProperty<bool>("Attach", true)) MapAttachable.MakeAttachable(result, main); this.SetMain(result, main); spotLight.Add(new TwoWayBinding<Vector3>(spotLight.Position, transform.Position)); spotLight.Add(new TwoWayBinding<Quaternion>(spotLight.Orientation, transform.Quaternion)); }
public override void AttachEditorComponents(Entity result, Main main) { Model model = new Model(); model.Filename.Value = "Models\\sphere"; model.IsInstanced.Value = false; model.Add(new Binding<Vector3>(model.Color, result.Get<AmbientLight>().Color)); model.Scale.Value = new Vector3(0.5f); model.Editable = false; model.Serialize = false; result.Add("EditorModel", model); model.Add(new Binding<Matrix>(model.Transform, result.Get<Transform>().Matrix)); }
public override void Bind(Entity result, Main main, bool creating = false) { this.SetMain(result, main); Transform transform = result.Get<Transform>(); AnimatedModel model = result.Get<AnimatedModel>("Model"); model.Add(new Binding<Matrix>(model.Transform, transform.Matrix)); Property<string> animation = result.GetProperty<string>("Animation"); Property<bool> loop = result.GetProperty<bool>("Loop"); model.Add(new NotifyBinding(delegate() { model.Stop(); if (animation != null) model.StartClip(animation, 0, loop); }, animation, loop)); }
public override void Bind(Entity result, Main main, bool creating = false) { this.SetMain(result, main); Transform transform = result.Get<Transform>(); Sound sound = result.Get<Sound>("Sound"); result.CannotSuspendByDistance = !sound.Is3D; result.Add(new NotifyBinding(delegate() { result.CannotSuspendByDistance = !sound.Is3D; }, sound.Is3D)); sound.Add(new Binding<Vector3>(sound.Position, transform.Position)); }
public static float Damage(Entity e, float damageAmount, Entity damager = null) { float originalHealth = e.Get(Health); float finalHealth = Math.Max(0, originalHealth - damageAmount); e.Set(Health, finalHealth); float damageDealt = originalHealth - finalHealth; if (damager != null) { damager.ForEach<IDamager>((c) => { c.Damaged(damager, e, damageDealt); }); } if (finalHealth == 0) { e.ForEach<IKillable>((c) => { c.Kill(e, damager); }); if (damager != null) { damager.ForEach<IKiller>((c) => { c.Killed(damager, e); }); } } return damageDealt; }
public static void AttachEditorComponents(Entity result, ListProperty<Entity.Handle> target) { Transform transform = result.Get<Transform>(); Property<bool> selected = result.GetOrMakeProperty<bool>("EditorSelected"); Command<Entity> toggleEntityConnected = new Command<Entity> { Action = delegate(Entity entity) { if (target.Contains(entity)) target.Remove(entity); else if (entity != result) target.Add(entity); } }; result.Add("ToggleEntityConnected", toggleEntityConnected); LineDrawer connectionLines = new LineDrawer { Serialize = false }; connectionLines.Add(new Binding<bool>(connectionLines.Enabled, selected)); Color connectionLineColor = new Color(1.0f, 1.0f, 1.0f, 0.5f); ListBinding<LineDrawer.Line, Entity.Handle> connectionBinding = new ListBinding<LineDrawer.Line, Entity.Handle>(connectionLines.Lines, target, delegate(Entity.Handle entity) { return new LineDrawer.Line { A = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(transform.Position, connectionLineColor), B = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(entity.Target.Get<Transform>().Position, connectionLineColor) }; }, x => x.Target != null && x.Target.Active); result.Add(new NotifyBinding(delegate() { connectionBinding.OnChanged(null); }, selected)); result.Add(new NotifyBinding(delegate() { connectionBinding.OnChanged(null); }, () => selected, transform.Position)); connectionLines.Add(connectionBinding); result.Add(connectionLines); }