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; } } }
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 Draw(float elapsedSeconds, SpriteBatch spriteBatch) { //Parallel.ForEach(this.actives.Values, (e) => //{ //}); foreach (Entity e in this.actives.Values) { TransformComponent transform = e.GetComponent<TransformComponent>(); SpriteAnimationComponent animation = e.GetComponent<SpriteAnimationComponent>(); System.Diagnostics.Debug.Assert(transform != null, "TransformComponent not found"); System.Diagnostics.Debug.Assert(animation != null, "SpriteAnimationComponent not found"); if (animation.Visible) { spriteBatch.Draw(animation.Animation.Texture, transform.EntityToWorld(animation.Offset) * WindowSettings.UnitScale, animation.Animation.GetCurrentFrame(), Color.White, transform.Rotation, animation.Animation.Origin, animation.Scale * WindowSettings.UnitScale, SpriteEffects.None, 0.8f); } } }
public void Draw(float elapsedSeconds, SpriteBatch spriteBatch) { if (this.isDebug) { if (this.UseSpatialHashing) { //note: test only Kadro.Physics.PhysicsVisualizer.DrawSpatialGridCells(spriteBatch, this.spatialGrid.GetCells()); //todo: move this to another class (maybe even spatialgrid) //for (int i = 0; i < GameConfig.NumCells.X; i++) //{ // spriteBatch.DrawLineSegment(new Vector2(i * GameConfig.CellSize.X, 0), new Vector2(i * GameConfig.CellSize.X, GameConfig.WorldSize.Y), Color.Blue, 1); //} //for (int i = 0; i < GameConfig.NumCells.Y; i++) //{ // spriteBatch.DrawLineSegment(new Vector2(0, i * GameConfig.CellSize.Y), new Vector2(GameConfig.WorldSize.X, i * GameConfig.CellSize.Y), Color.Blue, 1); //} } for (int i = 0; i < this.targets.Count; i++) { CollidableComponent collidable = this.targets[i].GetComponent <CollidableComponent>(); TransformComponent transform = this.targets[i].GetComponent <TransformComponent>(); System.Diagnostics.Debug.Assert(collidable != null, "CollidableComponent not found"); System.Diagnostics.Debug.Assert(transform != null, "TransformComponent not found"); collidable.Collider.ApplyTransform(transform.Position, transform.Rotation, transform.Scale); collidable.DebugDraw(spriteBatch, 1); spriteBatch.DrawLineSegment(transform.Position, transform.EntityToWorld(VectorExtensions.AngleToVector2(0f) * 20), Color.Green, 1); spriteBatch.DrawLineSegment(transform.Position, transform.Position + Vector2.One, Color.Brown, 1); //collidable.Collider.GetBounds().Draw(spriteBatch, Color.Violet, 1); } } }