/// <summary> /// Returns true if the other entity is in the field of view of the given entity. /// </summary> /// <param name="entity"></param> /// <param name="other"></param> /// <returns></returns> public static bool IsEntityInSight(Entity entity, Entity other) { Rectangle rect = new Rectangle(entity.GetCollRectangle().Center.X, entity.GetCollRectangle().Center.Y, 1, 1); List <Rectangle> rects = new List <Rectangle>(); double xVector = (double)(other.GetCollRectangle().Center.X - rect.Center.X); double yVector = (double)(other.GetCollRectangle().Center.Y - rect.Center.Y); Vector2 maxVelocity = new Vector2(30, 30); double magnitude = Math.Sqrt((Math.Pow(xVector, 2.0)) + (Math.Pow(yVector, 2.0))); Vector2 newVelocity = new Vector2(maxVelocity.X * (float)(xVector / magnitude), maxVelocity.Y * (float)(yVector / magnitude)); for (int i = 0; i < 10; i++) { rects.Add(rect); int index = (int)(rect.Y / TMBAW_Game.Tilesize * GameWorld.WorldData.LevelWidth) + (int)(rect.X / TMBAW_Game.Tilesize); if (rect.Intersects(other.GetCollRectangle())) { return(true); } if (index > GameWorld.TileArray.Length - 1 || index < 0) { return(false); } if (GameWorld.TileArray[index].IsSolid) { return(false); } rect.X += (int)newVelocity.X; rect.Y += (int)newVelocity.Y; } return(false); }
public override void Update(Entity entity) { attackTimer.Increment(); if (attackTimer.TimeElapsedInMilliSeconds > TimeBetweenAttacks) { attackTimer.Reset(); entity.AddAnimationToQueue("attack"); entity.ComplexAnimation.AnimationEnded += ComplexAnimation_AnimationEnded; float velocityY = TMBAW_Game.Random.Next(-200, -180) / 10f; float velocityX = (GameWorld.GetPlayers()[0].CollRectangle.X - entity.GetCollRectangle().X) / 30f; //ProjectileSystem projectile = new ProjectileSystem(ProjectileSystem.Type.SnakeVenom, entity.Position + new Vector2(16, 13) * 2, new Vector2(velocityX, velocityY), entity); //GameWorld.EnemyProjectiles.Add(projectile); } base.Update(entity); }
private void Entity_CollidedWithTileBelow(Entity entity, Tile tile) { if (isFalling) { for (int i = 0; i < 20; i++) { ParticleSystem.Add(ParticleType.Smoke, CalcHelper.GetRandXAndY(new Rectangle(entity.GetCollRectangle().X, entity.GetCollRectangle().Bottom, entity.GetCollRectangle().Width, 1)), CalcHelper.GetRandXAndY(new Rectangle(-40, -5, 80, 10)) / 10f, Color.White); } } isFalling = false; }
/// <summary> /// Generates specified number of gems in gameworld. /// </summary> /// <param name="count"></param> /// <param name="entity"></param> public static void Generate(int count, Entity entity) { for (int i = 0; i < count; i++) { Gem gem = new Gem(entity.GetCollRectangle().Center.X, entity.GetCollRectangle().Center.Y); GameWorld.Instance.Entities.Add(gem); } }
public TrailParticle(Entity source, Color color) { Texture = GameWorld.ParticleSpriteSheet; CollRectangle = new Rectangle(source.GetCollRectangle().Center.X, source.GetCollRectangle().Center.Y, 8, 8); SourceRectangle = new Rectangle(8, 0, 8, 8); int buffer = 1; Velocity.X = GameWorld.RandGen.Next((int)-source.GetVelocity().X - buffer, (int)-source.GetVelocity().X + buffer + 1) * (float)GameWorld.RandGen.NextDouble(); Velocity.Y = GameWorld.RandGen.Next((int)-source.GetVelocity().Y - buffer, (int)-source.GetVelocity().Y + buffer + 1); Position = new Vector2(CollRectangle.X, CollRectangle.Y); Opacity = .5f; light = new Lights.DynamicPointLight(this, .5f, false, color, 1); GameWorld.Instance.LightEngine.AddDynamicLight(light); }
public static void Generate(int count, Entity entity) { for (int i = 0; i < count; i++) { int x = GameWorld.RandGen.Next(entity.GetCollRectangle().X, entity.GetCollRectangle().X+ entity.GetCollRectangle().Width - 4); int y = GameWorld.RandGen.Next(entity.GetCollRectangle().Y, entity.GetCollRectangle().Y + entity.GetCollRectangle().Height - 4); TestSmokeParticle par = new TestSmokeParticle(x, y); GameWorld.Instance.Particles.Add(par); } }
public StompSmokeParticle(Entity entity) { Texture = ContentHelper.LoadTexture("Effects/smoke"); CollRectangle = new Rectangle(entity.GetCollRectangle().Center.X - 4, entity.GetCollRectangle().Bottom - 4, 8, 8); SourceRectangle = new Rectangle(8 * GameWorld.RandGen.Next(0, 4), 0, 8, 8); Position = new Vector2(CollRectangle.X, CollRectangle.Y); Velocity.X = (float)GameWorld.RandGen.NextDouble() * GameWorld.RandGen.Next(-3, 3); Velocity.Y = (float)GameWorld.RandGen.NextDouble() * -1f; Opacity = 1f; }
public SparkParticle(Entity source, Color color) { SourceRectangle = new Rectangle(272, 96, 8, 8); Texture = GameWorld.SpriteSheet; CollRectangle = new Rectangle(source.GetCollRectangle().X - 4, source.GetCollRectangle().Y + 4, 8, 8); Velocity.X = GameWorld.RandGen.Next(-6, 7); Position = new Vector2(CollRectangle.X, CollRectangle.Y); Opacity = .7f; light = new DynamicPointLight(this, .05f, false, color, .5f); GameWorld.Instance.LightEngine.AddDynamicLight(light); }
public EntityFlameParticle(Entity source, Color color) { SourceRectangle = new Rectangle(32 * 8, 12 * 8, 8, 8); Texture = GameWorld.SpriteSheet; int randX = (int)(GameWorld.RandGen.Next(0, source.GetCollRectangle().Width) * GameWorld.RandGen.NextDouble()); int randY = (int)(GameWorld.RandGen.Next(0, source.GetCollRectangle().Height) * GameWorld.RandGen.NextDouble()); CollRectangle = new Rectangle(source.GetCollRectangle().X + randX - 4, source.GetCollRectangle().Y + randY - 4, 8, 8); Position = new Vector2(CollRectangle.X, CollRectangle.Y); Opacity = .5f; Velocity.X = (float)(GameWorld.RandGen.Next(-1, 2) * GameWorld.RandGen.NextDouble()); Velocity.Y = -3f; light = new DynamicPointLight(this, .5f, false, color, .5f); GameWorld.Instance.LightEngine.AddDynamicLight(light); }
public void CreateTookDamage(Entity entity) { CurrentParticle = ParticleType.TookDamage; Texture = ContentHelper.LoadTexture("Sparkles"); CollRectangle = new Rectangle(GameWorld.RandGen.Next(entity.GetCollRectangle().X, entity.GetCollRectangle().Right - 8), GameWorld.RandGen.Next(entity.GetCollRectangle().Y, entity.GetCollRectangle().Bottom - 8), 8, 8); SourceRectangle = new Rectangle(0, 0, 8, 8); Velocity.X = (float)(GameWorld.RandGen.NextDouble() * GameWorld.RandGen.Next(-4, 5)); Velocity.Y = (float)(GameWorld.RandGen.NextDouble() * GameWorld.RandGen.Next(-1, 2)); Position = new Vector2(CollRectangle.X, CollRectangle.Y); Opacity = 1; color = Color.Red; }
public void CreateDeathSmoke(Entity entity) { CurrentParticle = ParticleType.DeathSmoke; Texture = ContentHelper.LoadTexture("Effects/smoke"); CollRectangle = new Rectangle(GameWorld.RandGen.Next(entity.GetCollRectangle().X, entity.GetCollRectangle().Right - 16), GameWorld.RandGen.Next(entity.GetCollRectangle().Y, entity.GetCollRectangle().Bottom - 16), 16, 16); SourceRectangle = new Rectangle(GameWorld.RandGen.Next(0, 4) * 16, 0, 16, 16); Velocity.X = (float)(GameWorld.RandGen.NextDouble() * GameWorld.RandGen.Next(-2, 3)); Velocity.Y = -.5f; Position = new Vector2(CollRectangle.X, CollRectangle.Y); Opacity = 2; }
public MachineGunParticle(Entity source, int xCoor) { SourceRectangle = new Rectangle(264, 96, 8, 8); Texture = GameWorld.SpriteSheet; CollRectangle = new Rectangle(source.GetCollRectangle().X + xCoor - 4, source.GetCollRectangle().Y + 4, 8, 8); Position = new Vector2(CollRectangle.X, CollRectangle.Y); Opacity = 1f; Velocity.Y = -8f; _hitSound = new SoundFx("Sounds/Machine Gun/bulletHit",this); light = new DynamicPointLight(this, .05f, false, Color.White, .5f); GameWorld.Instance.LightEngine.AddDynamicLight(light); }
public void UpdatePositionOnly(Entity entity) { _drawRectangle = new Rectangle(entity.GetCollRectangle().X - _currentAnimationData.DeltaRectangle.X, entity.GetCollRectangle().Y - _currentAnimationData.DeltaRectangle.Y, _currentAnimationData.Width * Scale, _currentAnimationData.Height * Scale); this.entity = entity; }