public override void Update(float elapsedSeconds) { foreach (Entity e in this.actives.Values) { TransformComponent transform = e.GetComponent <TransformComponent>(); MotionComponent motion = e.GetComponent <MotionComponent>(); AccelerationComponent acceleration = e.GetComponent <AccelerationComponent>(); IntentComponent intent = e.GetComponent <IntentComponent>(); System.Diagnostics.Debug.Assert(transform != null, "PositionComponent not found"); System.Diagnostics.Debug.Assert(motion != null, "VelocityComponent not found"); System.Diagnostics.Debug.Assert(acceleration != null, "MotionComponent not found"); System.Diagnostics.Debug.Assert(intent != null, "IntentComponent not found"); if (intent.IntentManager.HasIntent(Intent.Accelerate)) { // add force to center of object; // TODO: add rocketengine/boostercomponent with offset from origin motion.AddAcceleration(VectorExtensions.AngleToVector2(transform.Rotation) * acceleration.AccelerationFactor); } if (intent.IntentManager.HasIntent(Intent.Decelerate)) { motion.Drag = 0.05f; } else { motion.Drag = 0.005f; //stop after a while } if (intent.IntentManager.HasIntent(Intent.RotateLeft)) { motion.AngularDrag = 0f; motion.AddAngularAcceleration(-acceleration.RotationAccelerationFactor); } if (intent.IntentManager.HasIntent(Intent.RotateRight)) { motion.AngularDrag = 0f; motion.AddAngularAcceleration(acceleration.RotationAccelerationFactor); } if (!(intent.IntentManager.HasIntent(Intent.RotateLeft) || intent.IntentManager.HasIntent(Intent.RotateRight))) { motion.AngularDrag = 0.75f; } } }
public override void Update(float elapsedSeconds) { foreach (Entity e in this.actives.Values) { TransformComponent transform = e.GetComponent <TransformComponent>(); ParticleSpawnComponent particles = e.GetComponent <ParticleSpawnComponent>(); IntentComponent intent = e.GetComponent <IntentComponent>(); System.Diagnostics.Debug.Assert(transform != null, "PositionComponent not found"); System.Diagnostics.Debug.Assert(particles != null, "ParticleSpawnComponent not found"); System.Diagnostics.Debug.Assert(intent != null, "IntentComponent not found"); if (intent.IntentManager.HasIntent(Intent.Accelerate)) { this.particleEngine.SpawnParticles(particles.Amount, transform.EntityToWorld(particles.Location) /* (transform.Position + VectorExtensions.RotateVector(particles.Location, transform.Rotation))*/, particles.Color, transform.Rotation + MathHelper.Pi, particles.AngularAperture); } } }
public override void Update(float elapsedSeconds) { foreach (Entity e in this.actives.Values) { TransformComponent transform = e.GetComponent <TransformComponent>(); GunComponent gun = e.GetComponent <GunComponent>(); IntentComponent intent = e.GetComponent <IntentComponent>(); System.Diagnostics.Debug.Assert(transform != null, "PositionComponent not found"); System.Diagnostics.Debug.Assert(gun != null, "GunComponent not found"); System.Diagnostics.Debug.Assert(intent != null, "IntentComponent not found"); if ((gun.TimeSinceShot > gun.Cooldown) && intent.IntentManager.HasIntent(Intent.Shoot)) { gun.TimeSinceShot = 0; Entity newEntity = this.EntityWorld.EntityManager.CreateEntity(); this.entityFactory.AddProjectile(newEntity, transform.EntityToWorld(gun.OffsetFromParent) /* transform.Position + VectorExtensions.RotateVector(gun.OffsetFromParent, transform.Rotation)*/, transform.Rotation); newEntity.GetComponent <ParentComponent>().ParentId = e.EntityId; } else if ((gun.TimeSinceShot > gun.Cooldown) && intent.IntentManager.HasIntent(Intent.ShootMissile)) { gun.TimeSinceShot = 0; Entity newEntity = this.EntityWorld.EntityManager.CreateEntity(); this.entityFactory.AddMissile(newEntity, transform.EntityToWorld(gun.OffsetFromParent), transform.Rotation); newEntity.GetComponent <ParentComponent>().ParentId = e.EntityId; foreach (Entity entity in EntityWorld.EntityManager.GetEntities()) { if (entity.GetComponent <TagComponent>().Tag.Equals(GameConfig.Asteroid.Tag)) { newEntity.GetComponent <TargetComponent>().TargetId = entity.EntityId; break; } } } else { gun.TimeSinceShot += elapsedSeconds; } } }