/// <summary> /// /// </summary> /// <param name="e"></param> /// <param name="args">The position and velocity of the bullet + the health/damage</param> /// <returns></returns> public Entity BuildEntity(Entity e, params object[] args) { e.Group = "Enemies"; #region Sprite //Builds a sprite using "redshot3" (arbitrary). TODO: FIX DIS BITCH HELLA D string spriteKey = "redspikeball"; if (args.Length > 3) { spriteKey = (string)args[3]; } Sprite bulletSprite = e.AddComponent<Sprite>(new Sprite(_SS, spriteKey, 0.54f + (float)num / 1000000f)); #endregion Sprite #region Body //Creates a body based off of the position and velocity supplied in the args list. Body bitch = e.AddComponent<Body>(new Body(_World, e)); bitch.BodyType = BodyType.Dynamic; bitch.Position = (Vector2)args[0]; bitch.LinearVelocity = (Vector2)args[1]; FixtureFactory.AttachEllipse( ConvertUnits.ToSimUnits(bulletSprite.CurrentRectangle.Width / 2), ConvertUnits.ToSimUnits(bulletSprite.CurrentRectangle.Height / 2), 6, 1, bitch); bitch.CollisionCategories = Category.Cat4; bitch.CollidesWith = Category.Cat1 | Category.Cat3; #endregion Body #region Health //Creates health based off of the third parameter of the build entity. Health bulletHealth = e.AddComponent<Health>(new Health((int)args[2])); bulletHealth.OnDeath += ent => { _World.CreateEntityGroup("BigExplosion", "Explosions", bitch.Position, 10, e, e.GetComponent<IVelocity>().LinearVelocity); SoundManager.Play("Explosion1"); }; bitch.OnCollision += (f1, f2, c) => { bulletHealth.SetHealth(f2.UserData as Entity, 0.0); return true; }; #endregion Health return e; }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <param name="args">The position and velocity of the bullet + the health/damage</param> /// <returns></returns> public Entity BuildEntity(Entity e, params object[] args) { e.Group = "Fire"; #region Sprite Sprite fireSprite = e.AddComponent<Sprite>(new Sprite(_SS, "minifire", 0.55f + (float)num / 1000000f)); #endregion Sprite #region Body //Creates a body based off of the position and velocity supplied in the args list. Body bitch = e.AddComponent<Body>(new Body(_World, e)); bitch.BodyType = BodyType.Dynamic; bitch.Position = (Vector2)args[0]; bitch.LinearVelocity = (Vector2)args[1]; bitch.RotateTo(bitch.LinearVelocity); bitch.IsBullet = true; bitch.SleepingAllowed = false; FixtureFactory.AttachEllipse( ConvertUnits.ToSimUnits(fireSprite.CurrentRectangle.Width / 2), ConvertUnits.ToSimUnits(fireSprite.CurrentRectangle.Height / 2), 6, 1, bitch); bitch.CollisionCategories = Category.Cat4; bitch.CollidesWith = Category.Cat1 | Category.Cat3; bitch.OnCollision += (f1, f2, c) => { if (f2.Body.UserData != null && f2.Body.UserData is Entity) if ((f2.Body.UserData as Entity).Group != "Crystals") { try { (f2.Body.UserData as Entity).GetComponent<Health>().SetHealth(f1.Body.UserData as Entity, (f2.Body.UserData as Entity).GetComponent<Health>().CurrentHealth - 3); } catch { } //Lol nullreferenceexception bitch } return false; }; #endregion Body return e; }
public Entity BuildEntity(Entity e, params object[] args) { Entity ent = args[0] as Entity; Vector2 offset = (Vector2)args[1]; Vector2 velocity = -ent.GetComponent<Body>().LinearVelocity; string spriteKey = "bluespark"; Vector2 center = new Vector2(_SpriteSheet[spriteKey][0].Center.X, _SpriteSheet[spriteKey][0].Center.Y); Sprite s = e.AddComponent<Sprite>(new Sprite(_SpriteSheet, spriteKey, 1)); Animation a = e.AddComponent<Animation>(new Animation(AnimationType.Once, 5)); ITransform i = new Transform(ent.GetComponent<Body>().Position + offset, 0f); IVelocity v = new Velocity(velocity, 0f); e.AddComponent<Particle>(new Particle(e, i.Position, i.Rotation, v.LinearVelocity, v.AngularVelocity)); e.Group = "Explosions"; return e; }
public Entity BuildEntity(Entity e, params object[] args) { float magnitude = (float)args[0]; int power = (int)args[3]; string spriteKey = "splosion" + power.ToString(); Vector2 center = new Vector2(_SpriteSheet[spriteKey][0].Center.X, _SpriteSheet[spriteKey][0].Center.Y); Sprite s = e.AddComponent<Sprite>(new Sprite(_SpriteSheet, spriteKey, 0.97f)); Animation a = e.AddComponent<Animation>(new Animation(AnimationType.Once, 5)); //ITransform i = e.AddComponent<ITransform>(new Transform((Vector2)args[1], 0f)); if (power == 1) e.AddComponent<Origin>(new Origin(args[5] as Entity)); Particle p = e.AddComponent<Particle>(new Particle(e, (Vector2)args[1], 0f, (args.Length > 4) ? (Vector2)args[4] : Vector2.Zero, 0f)); e.Group = "Explosions"; Explode((Entity)args[2], 1, p.Position, 3, magnitude); return e; }
public Entity BuildEntity(Entity e, params object[] args) { e.Group = "Base"; e.Tag = "Base"; #region Body Body Body = e.AddComponent<Body>(new Body(world, e)); { FixtureFactory.AttachEllipse(//Add a basic bounding box (rectangle status) ConvertUnits.ToSimUnits(spriteSheet.Animations["base"][0].Width / 2f), ConvertUnits.ToSimUnits(spriteSheet.Animations["base"][0].Height / 2f), 15, 1, Body); Body.Position = ConvertUnits.ToSimUnits(new Vector2(0, 0)); Body.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Static; Body.CollisionCategories = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat6 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat16; Body.CollidesWith = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat2 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat4 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat5 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat16; Body.SleepingAllowed = false; } #endregion Body #region Sprite Sprite Sprite = e.AddComponent<Sprite>( new Sprite(spriteSheet, "base", Body, 1, Color.White, 0.1f)); #endregion Sprite e.AddComponent<Score>(new Score()); int health = 40; #if DEBUG health = 1000000; #endif Health h = new Health(health); h.OnDeath += LambdaComplex.BigEnemyDeath(e, world as SpaceWorld, 0); h.OnDamage += ent => { SoundManager.SetVibration(0.25f, 0.15f); e.RemoveComponent<Sprite>(Sprite); double healthFraction = (h.CurrentHealth / h.MaxHealth); if (healthFraction >= 0.33 && Sprite.FrameIndex == 2) { Sprite.FrameIndex = 1; } else if (healthFraction < 0.33 && Sprite.FrameIndex == 1) { Sprite.FrameIndex = 2; SoundManager.SetVibration(0.3f, 0.3f); } else if (healthFraction >= 0.66 && Sprite.FrameIndex == 1) { Sprite.FrameIndex = 0; } else if (healthFraction < 0.66 && Sprite.FrameIndex == 0) { Sprite.FrameIndex = 1; SoundManager.SetVibration(0.3f, 0.3f); } e.AddComponent<Sprite>(Sprite); }; e.AddComponent<Health>(h); e.AddComponent<HealthRender>(new HealthRender()); return e; }