private void AddArchitectureCollision() { RigidBody.VelocityRestriction[] velocityRestrictions = new RigidBody.VelocityRestriction[3]; velocityRestrictions[0] = RigidBody.VelocityRestriction.Down; velocityRestrictions[1] = RigidBody.VelocityRestriction.Left; velocityRestrictions[2] = RigidBody.VelocityRestriction.Right; platformRigidBodies = new RigidBody[mapArchitecture.MapPlatforms.Length]; for (int i = 0; i < mapArchitecture.MapPlatforms.Length; i++) { platformRigidBodies[i] = new RigidBody(new RotationRectangle(new RectangleF(mapArchitecture.MapPlatforms[i].Position, new Vector2(mapArchitecture.MapPlatforms[i].TileLength * MapStandards.TILE_SIZE, 0)), 0), 1, ReferenceMap, allowedCollisions: velocityRestrictions, staticBody: true, friction: .1F); new RigidBody(new RotationRectangle(new RectangleF(mapArchitecture.MapPlatforms[i].Position, new Vector2(mapArchitecture.MapPlatforms[i].TileLength * MapStandards.TILE_SIZE, .1F)), 0), 1, ParticleReferenceMap, allowedCollisions: velocityRestrictions, staticBody: true, friction: .1F); } }
public Particle(GameMap gameMap, GameTime gameTime, RectangleF collisionRectangle, Vector2 initialVelocity, int lifetime = DEFAULT_PARTICLE_LIFETIME, bool ignoreCollisions = false, bool enableRotation = false) { strictBounds = enableRotation; this.collisionRectangle = collisionRectangle; this.lifetime = lifetime; timeOfCreation = gameTime.TotalGameTime.TotalMilliseconds; if (ignoreCollisions) { RigidBody.VelocityRestriction[] velocityRestrictions = new RigidBody.VelocityRestriction[Enum.GetNames(typeof(RigidBody.VelocityRestriction)).Length]; for (int i = 0; i < velocityRestrictions.Length; i++) { velocityRestrictions[i] = (RigidBody.VelocityRestriction)i; } rigidBody = new RigidBody(new RotationRectangle(collisionRectangle), DEFAULT_PARTICLE_MASS, gameMap.NoCollideMap, velocityRestrictions, staticBody: false, rotationOnForce: enableRotation); } else { rigidBody = new RigidBody(new RotationRectangle(collisionRectangle), DEFAULT_PARTICLE_MASS, gameMap.ParticleReferenceMap, new RigidBody.VelocityRestriction[0], staticBody: false, rotationOnForce: enableRotation); } rigidBody.SetTranslationalVelocity(initialVelocity, isGlobal: false); }
public static RigidBody CreateRigidBody(Texture2D boundaryTexture, float mass, CollisionReferenceMap <RigidBody> referenceMap, Vector2 drawDimensions, GameMap gameMap, bool noCollide = false) { int spriteHighest = SpriteHighestPixel(boundaryTexture); int spriteLowest = SpriteLowestPixel(boundaryTexture); int spriteLeftmost = SpriteLeftmostPixel(boundaryTexture); int spriteRightmost = SpriteRightmostPixel(boundaryTexture); Vector2 colliderSize = new Vector2((spriteRightmost - spriteLeftmost + 2) * (drawDimensions.X / boundaryTexture.Height), (spriteLowest - spriteHighest + 2) * (drawDimensions.Y / boundaryTexture.Height)); Platform spawnPlatform = gameMap.MapArchitecture.MapPlatforms[gameMap.gameSession.LocalRandom.Next(0, gameMap.MapArchitecture.MapPlatforms.Length)]; int spawnTile = gameMap.gameSession.LocalRandom.Next(0, spawnPlatform.TileLength); Vector2 initialPosition = new Vector2(spawnPlatform.Position.X + (MapStandards.TILE_SIZE * (spawnTile + .5F)) - (colliderSize.X / 2), spawnPlatform.Position.Y - colliderSize.Y); //Create polygon RotationRectangle rotRec = new RotationRectangle(new RectangleF(initialPosition.X, initialPosition.Y, colliderSize.X, colliderSize.Y)); RigidBody.VelocityRestriction[] velocityRestrictions = new RigidBody.VelocityRestriction[Enum.GetNames(typeof(RigidBody.VelocityRestriction)).Length]; for (int i = 0; i < velocityRestrictions.Length; i++) { velocityRestrictions[i] = (RigidBody.VelocityRestriction)i; } return(new RigidBody(rotRec, mass, referenceMap, velocityRestrictions, staticBody: true, rotationOnForce: false)); }