public Weapon(SPRWorld sprWorld, Bot bot, Vector2 relativePosition, float relativeRotation, String textureName, Vector2 scale, WeaponType weaponType, float health, float power) { m_SPRWorld = sprWorld; m_Time = 0; this.m_owner = bot; this.m_firing = false; this.m_reloadTime = weaponType == WeaponType.melee ? 0 : .2f; this.m_reloading = 0; this.weaponType = weaponType; this.m_power = power; m_Position = relativePosition; m_Rotation = relativeRotation; m_Texture = TextureStatic.Get(textureName); m_Scale = scale; this.m_health = health; Vertices v = SPRWorld.computedSpritePolygons[textureName]; // Simplify the object until it has few enough verticies. while (v.Count > Physics.Settings.MaxPolygonVertices) // Infinite loop potential? { v = SimplifyTools.DouglasPeuckerSimplify(v, 2); // Where 2 is a completely arbitrary number? } v.Scale(ref scale); //v.Translate(ref relativePosition); v.Rotate(relativeRotation); Fixture f = FixtureFactory.CreatePolygon(v, 1f, bot.Body, relativePosition); m_Fixture = f; f.Friction = 0.5f; f.Restitution = 0f; f.UserData = this; if (this.weaponType == WeaponType.melee) { Body tempBody = BodyFactory.CreateBody(m_SPRWorld.World); tempBody.BodyType = BodyType.Dynamic; Vertices v2 = SPRWorld.computedSpritePolygons["Axe"]; // Simplify the object until it has few enough verticies. while (v2.Count > Physics.Settings.MaxPolygonVertices) // Infinite loop potential? { v2 = SimplifyTools.DouglasPeuckerSimplify(v2, 2); // Where 2 is a completely arbitrary number? } Fixture f2 = FixtureFactory.CreatePolygon(SPRWorld.computedSpritePolygons[textureName], 0.1f, tempBody); f2.Friction = 0.5f; f2.Restitution = 0f; tempBody.SetTransform(this.GetAbsPosition(), this.GetAbsRotation()); Projectile justFired = new Projectile(m_SPRWorld, tempBody, TextureStatic.Get("Axe"), new Vector2(0, 0), this.GetRelRotation(), 5, Settings.MetersPerPixel * 80, 80 * Settings.MetersPerPixel, m_power, m_health); f2.UserData = justFired; f2.OnCollision += Projectile.OnMeleeHit; RevoluteJoint joint = JointFactory.CreateRevoluteJoint(m_SPRWorld.World, this.m_owner.Body, tempBody, Vector2.Zero); joint.MaxMotorTorque = 160; joint.LimitEnabled = true; joint.MotorEnabled = true; joint.LowerLimit = - (float)Math.PI / 4f; joint.UpperLimit = (float)Math.PI / 4f; m_AxeJoint = joint; m_SPRWorld.AddEntity(justFired); } }
public SPRAI(SPRWorld world) { m_World = world; m_Weapons = new bool[4]; m_Move = Vector2.Zero; m_Fire = Vector2.Zero; m_Spin = 0f; }
public Bot(SPRWorld sprWord, Body body, Bot.Player player, Bot.Type type, SPRAI control, Texture2D texture, float width, float height, float health) : base(sprWord, body, texture, width, height, health) { this.m_player = player; this.m_type = type; this.m_Control = control; this.m_Weapons = new Weapon[4]; }
public Projectile(SPRWorld sprWorld, Body body, Texture2D texture, Vector2 velocity, float rotation, float life, float width, float height, float power) : base(sprWorld, body, texture, width, height, (float)1.0) { this.m_rotation = rotation; this.m_velocity = velocity; this.m_Life = life; this.m_power = power; m_toRemove = new List<Body>(); }
public Projectile(SPRWorld sprWorld, Body body, Texture2D texture, Vector2 velocity, float rotation, float life, float width, float height, float power, float health) : base(sprWorld, body, texture, width, height, health) { this.m_rotation = rotation; this.m_velocity = velocity; this.m_Life = life; this.m_power = power; m_toRemove = new List <Body>(); }
public ModeAI(SPRWorld world) : base(world) { foreach(Entity e in world.GetEntities()) { if(e is Bot && ((Bot)e).IsPlayer()) m_Player = (Bot)e; } m_ModeTimeout = 0; }
public Entity(SPRWorld sprWorld, Body body, Texture2D texture, float width, float height, float maxHealth) { this.m_SPRWorld = sprWorld; this.m_Body = body; m_ID = s_ID++; m_Dead = false; m_Texture = texture; m_Width = width; m_Height = height; this.m_maxHealth = maxHealth; this.m_health = maxHealth; }
public ModeAI(SPRWorld world) : base(world) { foreach (Entity e in world.GetEntities()) { if (e is Bot && ((Bot)e).IsPlayer()) { m_Player = (Bot)e; } } m_ModeTimeout = 0; }
public override void Update(float dTime, Bot self) { m_ModeTimeout -= dTime; m_Self = self; this.chooseMode(); Vector2 move = this.chooseMove(); int side = chooseSide(); float relRot = side * (float)Math.PI / 2f; float ownRot = self.GetRotation(); Vector2 facing = new Vector2((float)Math.Cos(ownRot + relRot), (float)Math.Sin(ownRot + relRot)); Vector2 desired = m_Player.GetPosition() - self.GetPosition(); this.Spin = Math.Min(Math.Max(SPRWorld.SignedAngle(facing, desired) * 4, -1), 1) * .5f; this.Move = move; this.Weapons = chooseFire(); }
public BrickAI(SPRWorld world) : base(world) { }
private Vector2 chooseMove() { if (m_Mode == Mode.DEFENSE) { Vector2 toP = m_Player.GetPosition() - m_Self.GetPosition(); Vector2[] corners = { new Vector2(300, 300) * Settings.MetersPerPixel, new Vector2(1620, 300) * Settings.MetersPerPixel, new Vector2(1620, 780) * Settings.MetersPerPixel, new Vector2(300, 780) * Settings.MetersPerPixel }; List <Vector2> cornList = new List <Vector2>(corners); int bad = 0; for (int i = 0; i < cornList.Count; i++) { Vector2 pToCorn = cornList.ElementAt(i) - m_Player.GetPosition(); Vector2 badCorn = cornList.ElementAt(bad) - m_Player.GetPosition(); if (pToCorn.Length() < badCorn.Length()) { bad = i; } } cornList.RemoveAt(bad); Vector2[] toCorners = new Vector2[cornList.Count]; int best = 0; for (int i = 0; i < toCorners.Length; i++) { toCorners[i] = cornList[i] - m_Self.GetPosition(); if (Vector2.Dot(toCorners[i], toP) < Vector2.Dot(toCorners[best], toP)) { best = i; } } Vector2 move = toCorners[best]; move.Normalize(); return(move); /* * Vector2 toMid = new Vector2(960 * Settings.MetersPerPixel, 540 * Settings.MetersPerPixel) - m_Self.GetPosition(); * Vector2 pMid = new Vector2(960 * Settings.MetersPerPixel, 540 * Settings.MetersPerPixel) - m_Player.GetPosition(); * * if (move.Length() > 300 * Settings.MetersPerPixel || Vector2.Dot(-move, toMid) <= 0) * { * move.Normalize(); * return move; * } * else if (pMid.Length() < 200 * Settings.MetersPerPixel) * { * toMid.Normalize(); * return -toMid; * } else * { * move.Normalize(); * Vector2 sideStep = new Vector2(-move.Y, move.X); * return sideStep * Math.Sign(SPRWorld.SignedAngle(move, toMid)); * }*/ } else if (m_Mode == Mode.RANGED) { Vector2 toP = m_Player.GetPosition() - m_Self.GetPosition(); if (toP.Length() < 300 * Settings.MetersPerPixel) { toP.Normalize(); return(-toP); } else if (toP.Length() > 400 * Settings.MetersPerPixel) { toP.Normalize(); return(toP); } else { return(Vector2.Zero); } } else if (m_Mode == Mode.MELEE) { Vector2 toP = m_Player.GetPosition() - m_Self.GetPosition(); float[] angles = new float[4]; int closest = 0; for (int i = 0; i < 4; i++) { float rota = m_Player.GetRotation() + i * (float)Math.PI / 2; float rotb = m_Player.GetRotation() + closest * (float)Math.PI / 2; float a = Vector2.Dot(new Vector2((float)Math.Cos(rota), (float)Math.Sin(rota)), -toP); float b = Vector2.Dot(new Vector2((float)Math.Cos(rotb), (float)Math.Sin(rotb)), -toP); if (a > b) { closest = i; } } float best = m_Player.GetRotation() + closest * (float)Math.PI / 2; Vector2 rot = new Vector2((float)Math.Cos(best), (float)Math.Sin(best)); float angle = SPRWorld.SignedAngle(rot, -toP); float rotation = 0; if (angle < 0) { rotation = ((float)Math.PI + angle) / 2; } else { rotation = (-(float)Math.PI + angle) / 2; } float angleToPlayer = (float)Math.Atan2(toP.Y, toP.X); toP.Normalize(); Vector2 walk = toP + 2 * new Vector2((float)Math.Cos(angleToPlayer + rotation), (float)Math.Sin(angleToPlayer + rotation)); walk.Normalize(); return(walk); } else { return(Vector2.Zero); } }
public Weapon(SPRWorld sprWorld, Bot bot, Vector2 relativePosition, float relativeRotation, String textureName, Vector2 scale, WeaponType weaponType, float health, float power) { m_SPRWorld = sprWorld; m_Time = 0; this.m_owner = bot; this.m_firing = false; this.m_reloadTime = weaponType == WeaponType.melee ? 0 : .2f; this.m_reloading = 0; this.weaponType = weaponType; this.m_power = power; m_Position = relativePosition; m_Rotation = relativeRotation; m_Texture = TextureStatic.Get(textureName); m_Scale = scale; this.m_health = health; Vertices v = SPRWorld.computedSpritePolygons[textureName]; // Simplify the object until it has few enough verticies. while (v.Count > Physics.Settings.MaxPolygonVertices) // Infinite loop potential? { v = SimplifyTools.DouglasPeuckerSimplify(v, 2); // Where 2 is a completely arbitrary number? } v.Scale(ref scale); //v.Translate(ref relativePosition); v.Rotate(relativeRotation); Fixture f = FixtureFactory.CreatePolygon(v, 1f, bot.Body, relativePosition); m_Fixture = f; f.Friction = 0.5f; f.Restitution = 0f; f.UserData = this; if (this.weaponType == WeaponType.melee) { Body tempBody = BodyFactory.CreateBody(m_SPRWorld.World); tempBody.BodyType = BodyType.Dynamic; Vertices v2 = SPRWorld.computedSpritePolygons["Axe"]; // Simplify the object until it has few enough verticies. while (v2.Count > Physics.Settings.MaxPolygonVertices) // Infinite loop potential? { v2 = SimplifyTools.DouglasPeuckerSimplify(v2, 2); // Where 2 is a completely arbitrary number? } Fixture f2 = FixtureFactory.CreatePolygon(SPRWorld.computedSpritePolygons[textureName], 0.1f, tempBody); f2.Friction = 0.5f; f2.Restitution = 0f; tempBody.SetTransform(this.GetAbsPosition(), this.GetAbsRotation()); Projectile justFired = new Projectile(m_SPRWorld, tempBody, TextureStatic.Get("Axe"), new Vector2(0, 0), this.GetRelRotation(), 5, Settings.MetersPerPixel * 80, 80 * Settings.MetersPerPixel, m_power, m_health); f2.UserData = justFired; f2.OnCollision += Projectile.OnMeleeHit; RevoluteJoint joint = JointFactory.CreateRevoluteJoint(m_SPRWorld.World, this.m_owner.Body, tempBody, Vector2.Zero); joint.MaxMotorTorque = 160; joint.LimitEnabled = true; joint.MotorEnabled = true; joint.LowerLimit = -(float)Math.PI / 4f; joint.UpperLimit = (float)Math.PI / 4f; m_AxeJoint = joint; m_SPRWorld.AddEntity(justFired); } }
public HumanAI(SPRWorld world) : base(world) { }