/// <summary> /// Attaches the bodies with revolute joints. /// </summary> /// <param name="world">The world.</param> /// <param name="bodies">The bodies.</param> /// <param name="localAnchorA">The local anchor A.</param> /// <param name="localAnchorB">The local anchor B.</param> /// <param name="connectFirstAndLast">if set to <c>true</c> [connect first and last].</param> /// <param name="collideConnected">if set to <c>true</c> [collide connected].</param> public static List<RevoluteJoint> AttachBodiesWithRevoluteJoint(World world, List<Body> bodies, Vector2 localAnchorA, Vector2 localAnchorB, bool connectFirstAndLast, bool collideConnected) { List<RevoluteJoint> joints = new List<RevoluteJoint>(bodies.Count + 1); for (int i = 1; i < bodies.Count; i++) { RevoluteJoint joint = new RevoluteJoint(bodies[i], bodies[i - 1], localAnchorA, localAnchorB); joint.CollideConnected = collideConnected; world.AddJoint(joint); joints.Add(joint); } if (connectFirstAndLast) { RevoluteJoint lastjoint = new RevoluteJoint(bodies[0], bodies[bodies.Count - 1], localAnchorA, localAnchorB); lastjoint.CollideConnected = collideConnected; world.AddJoint(lastjoint); joints.Add(lastjoint); } return joints; }
/// <summary> /// Creates a fixed angle joint. /// </summary> /// <param name="world">The world.</param> /// <param name="body">The body.</param> /// <returns></returns> public static FixedAngleJoint CreateFixedAngleJoint(World world, Body body) { FixedAngleJoint angleJoint = new FixedAngleJoint(body); world.AddJoint(angleJoint); return angleJoint; }
public static FixedDistanceJoint CreateFixedDistanceJoint(World world, Body body, Vector2 localAnchor, Vector2 worldAnchor) { FixedDistanceJoint distanceJoint = new FixedDistanceJoint(body, localAnchor, worldAnchor); world.AddJoint(distanceJoint); return distanceJoint; }
/// <summary> /// Creates an angle joint. /// </summary> /// <param name="world">The world.</param> /// <param name="bodyA">The first body.</param> /// <param name="bodyB">The second body.</param> /// <returns></returns> public static AngleJoint CreateAngleJoint(World world, Body bodyA, Body bodyB) { AngleJoint angleJoint = new AngleJoint(bodyA, bodyB); world.AddJoint(angleJoint); return angleJoint; }
public static DistanceJoint CreateDistanceJoint(World world, Body bodyA, Body bodyB, Vector2 anchorA, Vector2 anchorB) { DistanceJoint distanceJoint = new DistanceJoint(bodyA, bodyB, anchorA, anchorB); world.AddJoint(distanceJoint); return distanceJoint; }
public MasslessItem(Texture2D t, PhysicsShape shape, Vector2 position, World w) : base(position, w, t.Width, t.Height) { texture = t; body.BodyType = BodyType.Static; body.Position = position; switch (shape) { case PhysicsShape.Rectangle: fixture = FixtureFactory.CreateRectangle( texture.Width, texture.Height, 0.0f, Vector2.Zero, body); break; } //fixture.CollisionFilter.IgnoreCollisionWith(); fixture.OnCollision += new OnCollisionEventHandler(this.OnCollision); w.AddBody(body); //drawOrigin = new Vector2(texture.Width / 2, texture.Height / 2); //drawRectangle = new Rectangle(0, 0, texture.Width, texture.Height); }
public Battle(SPRWorld sprWorld, int botHalfWidth, World world, int currentLevel) { this.sprWorld = sprWorld; this.botHalfWidth = botHalfWidth; this.world = world; xmlDoc = new XmlDocument(); if (nextAllies == "") { xmlDoc.Load("Games/SuperPowerRobots/Storage/Allies.xml"); } else { xmlDoc.LoadXml(nextAllies); } //xmlDoc. XmlNodeList nodes = xmlDoc.GetElementsByTagName("Bot"); Vector2[] edges = { new Vector2(-botHalfWidth, -botHalfWidth) * Settings.MetersPerPixel, new Vector2(botHalfWidth, -botHalfWidth) * Settings.MetersPerPixel, new Vector2(botHalfWidth, botHalfWidth) * Settings.MetersPerPixel, new Vector2(-botHalfWidth, botHalfWidth) * Settings.MetersPerPixel }; CreateBots(nodes, edges); xmlDoc.Load("Games/SuperPowerRobots/Storage/Battles.xml"); nodes = xmlDoc.GetElementsByTagName("Level"); nodes = nodes[currentLevel].ChildNodes; CreateBots(nodes, edges); }
/// <summary> /// Creates a breakable body. You would want to remove collinear points before using this. /// </summary> /// <param name="world">The world.</param> /// <param name="vertices">The vertices.</param> /// <param name="density">The density.</param> /// <param name="position">The position.</param> /// <returns></returns> public static BreakableBody CreateBreakableBody(World world, Vertices vertices, float density, Vector2 position, Object userData) { List<Vertices> triangles = EarclipDecomposer.ConvexPartition(vertices); BreakableBody breakableBody = new BreakableBody(triangles, world, density, userData); breakableBody.MainBody.Position = position; world.AddBreakableBody(breakableBody); return breakableBody; }
public Bomb(Vector2 position, World world, Vector2 velocity) : base(position, world, TextureStatic.Get("bomb").Width, TextureStatic.Get("bomb").Height) { body.BodyType = BodyType.Dynamic; texture = TextureStatic.Get("bomb"); fixture = FixtureFactory.CreateCircle(TextureStatic.Get("bomb").Width / 2, 1, body); laidTime = GameClock.Now; world.AddBody(body); body.LinearVelocity = velocity; }
public Explosion(Vector2 position, World world, float radius, int power) : base(position, world, TextureStatic.Get("solitudeExplosion").Width, TextureStatic.Get("solitudeExplosion").Height) { body.BodyType = BodyType.Kinematic; body.Position = position; this.radius = 1f; maxRadius = radius; this.power = power; fixture = FixtureFactory.CreateCircle(this.maxRadius, 0f, body); fixture.CollisionFilter.CollidesWith = Category.None; texture = TextureStatic.Get("solitudeExplosion"); }
public SolitudeObject(Vector2 position, World world, Shape shape, float width, float height) { body = BodyFactory.CreateBody(world, position); //currently in wall class: fixture = new Fixture(body, shape); fixture.OnCollision += new OnCollisionEventHandler(OnCollision); //################### drawOrigin = new Vector2(width, height); drawRectangle = new Rectangle(0, 0, (int)width, (int)height); }
public Mauler(Vector2 position, World w) : base(position, w, TextureStatic.Get("solitudeMauler").Width, TextureStatic.Get("solitudeMauler").Height) { health = Settings.maulerHealth; world = w; body.BodyType = BodyType.Dynamic; body.Position = position; texture = TextureStatic.Get("solitudeMauler"); fixture = FixtureFactory.CreateCircle(texture.Width/2, 0.25f, body, Vector2.Zero); fixture.OnCollision += new OnCollisionEventHandler(OnCollision); world.AddBody(body); targetPoint = body.Position; }
public BreakableBody(IEnumerable<Vertices> vertices, World world, float density, Object userData) { _world = world; _world.ContactManager.PostSolve += PostSolve; MainBody = new Body(_world); MainBody.BodyType = BodyType.Dynamic; foreach (Vertices part in vertices) { PolygonShape polygonShape = new PolygonShape(part, density); Fixture fixture = MainBody.CreateFixture(polygonShape, userData); Parts.Add(fixture); } }
public Fighter(Vector2 position, World w) : base(position, w, TextureStatic.Get("fighter").Width, TextureStatic.Get("fighter").Height) { this.health = Settings.fighterHealth; world = w; lastShot = GameClock.Now; world = w; body.BodyType = BodyType.Dynamic; body.Position = position; texture = TextureStatic.Get("fighter"); fixture = FixtureFactory.CreateRectangle(texture.Width, texture.Height, 0.25f, Vector2.Zero, body); world.AddBody(body); targetPoint = body.Position; }
public TyTaylor(World w, Vector2 position) : base(position, w, TextureStatic.Get("ty").Width, TextureStatic.Get("ty").Height) { health = Settings.TyHealth; world = w; lastShot = GameClock.Now; body.BodyType = BodyType.Dynamic; body.Position = position; texture = TextureStatic.Get("ty"); fixture = FixtureFactory.CreateRectangle(texture.Width, texture.Height, 0.25f, Vector2.Zero, body); world.AddBody(body); targetPoint = body.Position; fixture.OnCollision += new OnCollisionEventHandler(this.OnCollision); }
// </DEBUG!!> /// <summary> /// Initializes a new instance of the <see cref="StupidGameScreen"/> class. /// </summary> /// <param name="scoreboardIndex">The game-specific index into the scoreboard.</param> public SPRGameScreen(int scoreboardIndex) : base(scoreboardIndex) { this.m_scoreboardIndex = scoreboardIndex; currentLevel = 0; scoreKeeper = new ScoreKeeper(true); previousGameTime = GameClock.Now; fantastica = new World(Vector2.Zero); Physics.Settings.MaxPolygonVertices = 30; // Defaults to 8? What are we, running on a TI-83 or something? Physics.Settings.EnableDiagnostics = false; this.sprWorld = new SPRWorld(fantastica, currentLevel); // Always call reset at the end of the constructor! this.Reset(); }
/// <summary> /// Creates a capsule. /// Note: Automatically decomposes the capsule if it contains too many vertices (controlled by Settings.MaxPolygonVertices) /// </summary> /// <param name="world">The world.</param> /// <param name="height">The height.</param> /// <param name="topRadius">The top radius.</param> /// <param name="topEdges">The top edges.</param> /// <param name="bottomRadius">The bottom radius.</param> /// <param name="bottomEdges">The bottom edges.</param> /// <param name="density">The density.</param> /// <param name="position">The position.</param> /// <returns></returns> public static List<Fixture> CreateCapsule(World world, float height, float topRadius, int topEdges, float bottomRadius, int bottomEdges, float density, Vector2 position, Object userData) { Vertices verts = PolygonTools.CreateCapsule(height, topRadius, topEdges, bottomRadius, bottomEdges); //There are too many vertices in the capsule. We decompose it. if (verts.Count >= Settings.MaxPolygonVertices) { List<Vertices> vertList = EarclipDecomposer.ConvexPartition(verts); List<Fixture> fixtureList = CreateCompoundPolygon(world, vertList, density, userData); fixtureList[0].Body.Position = position; return fixtureList; } return new List<Fixture> {CreatePolygon(world, verts, density, userData)}; }
public Door(Vector2 position, World world, float width, float height, float density, WallType type, Direction d) : base(position, world, width, height, density, type, d) { this.type = type; textureString = "solitudeWallDoor"; if (type == WallType.Grip) { textureString = "solitudeGripDoor"; } direction = d; switch (d) { case Direction.Up: body.Rotation = (float)(3 * Math.PI / 2); break; case Direction.Down: body.Rotation = (float)(Math.PI / 2); break; case Direction.Left: body.Rotation = (float)Math.PI; break; case Direction.Right: body.Rotation = 0; break; } //body.Rotation = (float)((int)d * (Math.PI / 2)); }
// Anything that is a fixture must have an object type for collision logic purposes /*public enum ObjectTypes { Bot = 1, Weapon = 2, // Since weapons will be fixtures, they too need an object type. Bullet = 3, Wall = 4 }*/ public SPRWorld(World world, int currentLevel) { int botHalfWidth = 31; // Half the bot's width (e.g. the distance from the centroid to the edge) m_World = world; this.m_Entities = new SortedDictionary<ulong,Entity>(); // Make polygons out of weapons and anything that needs collision. // NOTE: Stores the convex hull for each item, since collision detection // relies upon these verticies being convex polygons. String[] toPreload = new String[] { "Gun", "Axe", "Shield" }; foreach (String texture in toPreload) { Texture2D a = TextureStatic.Get(texture); uint[] data = new uint[a.Width * a.Height]; a.GetData<uint>(data); Vertices v = Melkman.GetConvexHull(PolygonTools.CreatePolygon(data, a.Width, a.Height)); Vector2 scale = new Vector2(Settings.MetersPerPixel, Settings.MetersPerPixel); v.Scale(ref scale); if (!computedSpritePolygons.ContainsKey(texture)) { computedSpritePolygons.Add(texture, v); } } //walls Vector2[] outer = { new Vector2(0, 0) * Settings.MetersPerPixel, new Vector2(0, 1920) * Settings.MetersPerPixel, new Vector2(1080, 1920) * Settings.MetersPerPixel, new Vector2(1080, 0) * Settings.MetersPerPixel }; Vector2[] inner = { new Vector2(200, 200) * Settings.MetersPerPixel, new Vector2(200, 1720) * Settings.MetersPerPixel, new Vector2(880, 1720) * Settings.MetersPerPixel, new Vector2(880, 200) * Settings.MetersPerPixel }; FixtureFactory.CreateRectangle(world, 1920 * Settings.MetersPerPixel, 200 * Settings.MetersPerPixel, 1f, new Vector2(960, 100) * Settings.MetersPerPixel, "Wall").Body.BodyType = BodyType.Static; FixtureFactory.CreateRectangle(world, 200 * Settings.MetersPerPixel, 1080 * Settings.MetersPerPixel, 1f, new Vector2(100, 540) * Settings.MetersPerPixel, "Wall").Body.BodyType = BodyType.Static; FixtureFactory.CreateRectangle(world, 1920 * Settings.MetersPerPixel, 200 * Settings.MetersPerPixel, 1f, new Vector2(960, 980) * Settings.MetersPerPixel, "Wall").Body.BodyType = BodyType.Static; FixtureFactory.CreateRectangle(world, 200 * Settings.MetersPerPixel, 1080 * Settings.MetersPerPixel, 1f, new Vector2(1820, 540) * Settings.MetersPerPixel, "Wall").Body.BodyType = BodyType.Static; Vector2[] edges = { new Vector2(-botHalfWidth, -botHalfWidth) * Settings.MetersPerPixel, new Vector2(botHalfWidth, -botHalfWidth) * Settings.MetersPerPixel, new Vector2(botHalfWidth, botHalfWidth) * Settings.MetersPerPixel, new Vector2(-botHalfWidth, botHalfWidth) * Settings.MetersPerPixel }; this.battle = new Battle(this, botHalfWidth, world, currentLevel); GameWorld.audio.SongPlay("sprbattle"); }
public Bullet(Vector2 velocity, Vector2 position, World w, Color color, Fixture sender) : base(position, w, 15f, 15f) { senderFixture = sender; world = w; BulletColor = color; body.BodyType = BodyType.Dynamic; body.IsBullet = true; body.LinearVelocity = velocity; body.Position = position; texture = TextureStatic.Get("bullet"); fixture = FixtureFactory.CreateCircle(7f, 1, body); body.Mass = 0; fixture.Body.UserData = "bullet"; body.Inertia = 0; body.Torque = 0; fixture.CollisionFilter.IgnoreCollisionWith(senderFixture); fixture.BeforeCollision += new BeforeCollisionEventHandler(BeforeCollision); fixture.OnCollision += new OnCollisionEventHandler(OnCollision); w.AddBody(body); }
/// <summary> /// Creates a chain. /// </summary> /// <param name="world">The world.</param> /// <param name="start">The start.</param> /// <param name="end">The end.</param> /// <param name="linkWidth">The width.</param> /// <param name="linkHeight">The height.</param> /// <param name="fixStart">if set to <c>true</c> [fix start].</param> /// <param name="fixEnd">if set to <c>true</c> [fix end].</param> /// <param name="numberOfLinks">The number of links.</param> /// <param name="linkDensity">The link density.</param> /// <returns></returns> public static Path CreateChain(World world, Vector2 start, Vector2 end, float linkWidth, float linkHeight, bool fixStart, bool fixEnd, int numberOfLinks, float linkDensity) { //Chain start / end Path path = new Path(); path.Add(start); path.Add(end); //A single chainlink PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(linkWidth, linkHeight), linkDensity); //Use PathManager to create all the chainlinks based on the chainlink created before. List<Body> chainLinks = PathManager.EvenlyDistributeShapesAlongPath(world, path, shape, BodyType.Dynamic, numberOfLinks); if (fixStart) { //Fix the first chainlink to the world JointFactory.CreateFixedRevoluteJoint(world, chainLinks[0], new Vector2(0, -(linkHeight/2)), chainLinks[0].Position); } if (fixEnd) { //Fix the last chainlink to the world JointFactory.CreateFixedRevoluteJoint(world, chainLinks[chainLinks.Count - 1], new Vector2(0, (linkHeight/2)), chainLinks[chainLinks.Count - 1].Position); } //Attach all the chainlinks together with a revolute joint PathManager.AttachBodiesWithRevoluteJoint(world, chainLinks, new Vector2(0, -linkHeight), new Vector2(0, linkHeight), false, false); return (path); }
public Wall(Vector2 position, World world, float width, float height, float density, WallType t, Direction d) : base(position, world, width, height) { body.Rotation = 0; if (d == Direction.Up || d == Direction.Down) // Up or down { body.Rotation = (float)Math.PI / 2; } body.BodyType = BodyType.Static; //world.AddBody(body); fixture = FixtureFactory.CreateRectangle(width, height, density, Vector2.Zero, body, null); fixture.OnCollision += new OnCollisionEventHandler(OnCollision); type = t; this.width = width; this.height = height; drawRectangle = new Rectangle(0, 0, (int)width, (int)height); switch (type){ case WallType.Smooth: textureString = /*TextureStatic.Get(*/"solitudeWallSmooth"; break; case WallType.HandHold: textureString = /*TextureStatic.Get(*/"solitudeWallHandHold"; break; case WallType.Grip: textureString = /*TextureStatic.Get(*/"solitudeWallGrip"; break; case WallType.Metal: textureString = /*TextureStatic.Get(*/"solitudeWallMetal"; break; case WallType.Hot: textureString = /*TextureStatic.Get(*/"solitudeWallHot"; break; case WallType.Cold: textureString = /*TextureStatic.Get(*/"solitudeWallCold"; break; case WallType.Spike: textureString = /*TextureStatic.Get(*/"solitudeWallSpike"; break; } }
public Terminal(Vector2 position, World w, string t) : base(TextureStatic.Get("terminal"), PhysicsShape.Rectangle, position, w) { fixture.OnCollision += new OnCollisionEventHandler(OnCollision); fixture.OnSeparation += new OnSeparationEventHandler(OnSeparation); text = t; }
public Enemy(Vector2 position, World world, float width, float height) : base(position, world, width, height) { }
public SolitudeObject(Vector2 position, World world, float width, float height) { body = BodyFactory.CreateBody(world, position); drawOrigin = new Vector2(width / 2f, height / 2f); drawRectangle = new Rectangle(0, 0, (int)width, (int)height); }
/// <summary> /// Resets this instance. This will be called when a new game is played. Reset all of /// your objects here so that you do not need to reallocate the memory for them. /// </summary> internal override void Reset() { base.Reset(); currentLevel = 0; scoreKeeper = new ScoreKeeper(true); previousGameTime = GameClock.Now; fantastica = new World(Vector2.Zero); Physics.Settings.MaxPolygonVertices = 30; // Defaults to 8? What are we, running on a TI-83 or something? Physics.Settings.EnableDiagnostics = false; Battle.nextAllies = ""; this.sprWorld = new SPRWorld(fantastica, currentLevel); this.gameOverTime = GameClock.Now + 10000000 * 10; // 10 Seconds. }
public void NextLevel() { currentLevel += 1; fantastica = new World(Vector2.Zero); Physics.Settings.MaxPolygonVertices = 30; // Defaults to 8? What are we, running on a TI-83 or something? Physics.Settings.EnableDiagnostics = false; addedEndScreen = false; this.sprWorld = new SPRWorld(fantastica, currentLevel); }
public Sentinel(Vector2 position, Vector2 velocity, World w, int rate) : base(position, w, TextureStatic.Get("sentinel").Width, TextureStatic.Get("sentinel").Height) { health = Settings.sentinelHealth; patrolRate = rate; lastShot = GameClock.Now; lastTurn = lastShot; world = w; body.BodyType = BodyType.Dynamic; speed = velocity; body.LinearVelocity = velocity; //body.Position = position; texture = TextureStatic.Get("sentinel"); fixture = FixtureFactory.CreateRectangle(texture.Width, texture.Height, 0.25f, Vector2.Zero, body); world.AddBody(body); }
public Body(World world, Object userData) { FixtureList = new List<Fixture>(32); World = world; UserData = userData; FixedRotation = false; IsBullet = false; SleepingAllowed = true; Awake = true; BodyType = BodyType.Static; Enabled = true; Xf.R.Set(0); world.AddBody(this); }
public Body(World world) : this(world, null) { }