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 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 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) { this.Move = new Vector2(GameWorld.controller.ContainsFloat(ActionType.MoveHorizontal), -GameWorld.controller.ContainsFloat(ActionType.MoveVertical)); this.Fire = new Vector2(GameWorld.controller.ContainsFloat(ActionType.LookHorizontal), -GameWorld.controller.ContainsFloat(ActionType.LookVertical)); this.Spin = GameWorld.controller.ContainsFloat(ActionType.RightTrigger) - GameWorld.controller.ContainsFloat(ActionType.LeftTrigger); this.Weapons[0] = GameWorld.controller.ContainsBool(ActionType.BButton); this.Weapons[1] = GameWorld.controller.ContainsBool(ActionType.AButton); this.Weapons[2] = GameWorld.controller.ContainsBool(ActionType.XButton); this.Weapons[3] = GameWorld.controller.ContainsBool(ActionType.YButton); }
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(); }
/// <summary> /// Updates the AI. /// </summary> /// <param name="dTime">Time elapsed.</param> public abstract void Update(float dTime, Bot self);
public void CreateBots(XmlNodeList nodes, Vector2[] edges) { Console.WriteLine(nodes.Count); foreach (XmlNode botNode in nodes) { if (botNode.Name == "Award") { this.winReward = int.Parse(botNode.InnerText); continue; } XmlNodeList innerNodes = botNode.ChildNodes; Bot.Player AIType; Console.WriteLine(innerNodes[0].InnerText); SPRAI control; switch (innerNodes[0].InnerText) { case "HumanAI": AIType = Bot.Player.Human; control = new HumanAI(sprWorld); break; case "BrickAI": AIType = Bot.Player.Computer; control = new BrickAI(sprWorld); break; case "ModeAI": AIType = Bot.Player.Computer; control = new ModeAI(sprWorld); break; default: AIType = Bot.Player.Human; control = new HumanAI(sprWorld); break; } float health = float.Parse(innerNodes[1].InnerText); Texture2D texture = TextureStatic.Get(innerNodes[2].InnerText); Vector2 position = new Vector2(int.Parse(innerNodes[3].InnerText), int.Parse(innerNodes[4].InnerText)); Body tempBody = BodyFactory.CreateBody(world); tempBody.BodyType = BodyType.Dynamic; Fixture f = FixtureFactory.CreatePolygon(new Vertices(edges), 10f, tempBody); f.OnCollision += MyOnCollision; f.Friction = .5f; f.Restitution = 0f; tempBody.SetTransform(position * Settings.MetersPerPixel, 0); Bot newBot = new Bot(sprWorld, tempBody, AIType, Bot.Type.FourSided, control, texture, 2 * botHalfWidth * Settings.MetersPerPixel, 2 * botHalfWidth * Settings.MetersPerPixel, health); f.UserData = newBot; for (int weaponNumber = 0; weaponNumber < 4; weaponNumber++) { XmlNodeList weaponChilds = innerNodes[weaponNumber + 5].ChildNodes; int side = weaponNumber; WeaponType weaponType; switch (weaponChilds[0].InnerText) { case "gun": weaponType = WeaponType.gun; break; case "shield": weaponType = WeaponType.shield; break; case "melee": weaponType = WeaponType.melee; break; default: weaponType = WeaponType.gun; break; } String weaponTexture = weaponChilds[1].InnerText; float weaponHealth = float.Parse(weaponChilds[2].InnerText); float weaponPower = float.Parse(weaponChilds[3].InnerText); newBot.AddWeapon(weaponNumber, weaponTexture, weaponType, weaponHealth, weaponPower); } sprWorld.AddEntity(newBot); } }
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); } }