public Car(Vector2 position, GameContent gameContent, World world) { this.world = world; this.gameContent = gameContent; BodyDef bd = new BodyDef(); bd.position = position / gameContent.Scale; bd.type = BodyType.Dynamic; bd.bullet = true; body = world.CreateBody(bd); body.SetLinearDamping(1f); body.SetAngularDamping(0.1f); float width = gameContent.playerCar.Width, height = gameContent.playerCar.Height; FixtureDef fd = new FixtureDef(); fd.density = 0.1f; //fd.restitution = .1f; CircleShape cs = new CircleShape(); cs._p = new Vector2(0, -(height - width / 2)) / gameContent.Scale; cs._radius = width / 2 / gameContent.Scale; fd.shape = cs; body.CreateFixture(fd); PolygonShape ps = new PolygonShape(); ps.SetAsBox(width / 2 / gameContent.Scale, (height - width / 2) / 2 / gameContent.Scale, new Vector2(0, -(height - width / 2) / 2) / gameContent.Scale, 0); fd.shape = ps; body.CreateFixture(fd); CreateWheels(); }
public Body CreateBall(World world, float ScaleFactor) { var bodyDef = new BodyDef(); bodyDef.type = BodyType.Dynamic; var ballShape = new CircleShape(); ballShape._radius = (texture.Width / 2f) * ScaleFactor; var ballFixture = new FixtureDef(); ballFixture.friction = 0.0f; // no friction ballFixture.restitution = 1.0f; // give the ball a perfect bounce ballFixture.density = 1.0f; ballFixture.shape = ballShape; var ballBody = world.CreateBody(bodyDef); ballBody.CreateFixture(ballFixture); // ballBody.Position = new Vector2(((float)r.NextDouble() * 4.5f + .3f), (float)r.NextDouble() * 4.5f + .3f); //ballBodies.Add(ballBody); return ballBody; }
public Player(GameContent gameContent, World world, Vector2 position) { this.gameContent = gameContent; this.world = world; idle = new Animation(gameContent.playerIdle, 2, 2f, true, new Vector2(0.5f)); walk = new Animation(gameContent.playerWalk, 2, 0.2f, true, new Vector2(0.5f)); die = new Animation(gameContent.playerDie, 2, 0.2f, false, new Vector2(0.5f)); animationPlayer.PlayAnimation(idle); BodyDef bd = new BodyDef(); bd.position = position / gameContent.b2Scale; bd.type = BodyType.Dynamic; bd.linearDamping = 10; body = world.CreateBody(bd); CircleShape cs = new CircleShape(); cs._radius = (float)(idle.FrameWidth - 1) / gameContent.b2Scale / 2; FixtureDef fd = new FixtureDef(); fd.shape = cs; fd.filter.groupIndex = -1; body.CreateFixture(fd); }
public Soldier(Shape shape, Vector2 position, GameContent gameContent, World world) { this.gameContent = gameContent; this.world = world; idle = new Animation(gameContent.idle[(int)shape], 20f, false); walk = new Animation(gameContent.walk[(int)shape], 0.15f, true); animationPlayer.PlayAnimation(idle); MaxHealth = 10; health = gameContent.random.Next(2, 10); MaxReloadTime = gameContent.random.Next(50); reloadTime = 0; CircleShape cShape = new CircleShape(); cShape._radius = (Size + 2) / 2 / gameContent.b2Scale; BodyDef bd = new BodyDef(); bd.fixedRotation = true; bd.type = BodyType.Dynamic; bd.position = position / gameContent.b2Scale; body = world.CreateBody(bd); //body.SetLinearDamping(10); FixtureDef fd = new FixtureDef(); fd.shape = cShape; fd.restitution = 0.5f; fd.friction = .1f; fd.density = .1f; body.CreateFixture(fd); body.SetUserData(this); }
public Tutorial(GameContent gameContent, World world) : base(gameContent, world) { instructions = gameContent.content.Load<List<string>>("Levels/tutorial"); NextMsg(); }
public Enemy(World world, GameContent gameContent, int index, Vector2 position) { this.gameContent = gameContent; walk = new Animation(gameContent.enemy[index], 2, 0.15f, true, new Vector2(0.5f)); animationPlayer.PlayAnimation(walk); if (index == 0) linearImpulse = 1f / 2; else linearImpulse = 0.75f / 2; BodyDef bd = new BodyDef(); bd.position = position / gameContent.b2Scale; bd.type = BodyType.Dynamic; bd.linearDamping = 10; body = world.CreateBody(bd); CircleShape cs = new CircleShape(); cs._radius = (float)(walk.FrameWidth - 1) / gameContent.b2Scale / 2; FixtureDef fd = new FixtureDef(); fd.shape = cs; fd.filter.groupIndex = -1; body.CreateFixture(fd); body.SetUserData(this); }
public Apple(Fixture connectedFixture, GameContent gameContent, World world) { this.world = world; this.gameContent = gameContent; texture = gameContent.apple; fallenFromAir = false; CreatBody(); State = LeafState.Grow; if (connectedFixture != null) { this.connectedFixture = connectedFixture; AABB aabb; connectedFixture.GetAABB(out aabb); body.Position = aabb.GetCenter(); RevoluteJointDef rjd = new RevoluteJointDef(); rjd.bodyA = body; rjd.bodyB = connectedFixture.GetBody(); rjd.localAnchorA = Vector2.Zero; rjd.localAnchorB = connectedFixture.GetBody().GetLocalPoint(body.Position); revoJoint = (RevoluteJoint)world.CreateJoint(rjd); } }
public PhysicsCircle(Texture2D sprite_texture, World physicsWorld, float radius, float positionX, float positionY, float rotation, float density) : base(sprite_texture) { this.scaleToFitTheseDimensions(radius*2.0f, radius*2.0f); this.position.X = positionX; this.position.Y = positionY; this.rotation = rotation; BodyDef dynamicBodyDef = new BodyDef(); dynamicBodyDef.type = BodyType.Dynamic; dynamicBodyDef.position = new Vector2(positionX / ScreenPixelsPerMeter, positionY / ScreenPixelsPerMeter); dynamicBodyDef.linearDamping = 0.0f; Body dynamicBody = physicsWorld.CreateBody(dynamicBodyDef); CircleShape dynamicCircleShape = new CircleShape(); dynamicCircleShape._radius = radius/DynamicPhysicsGameObject.ScreenPixelsPerMeter; //dynamicBoxShape. //dynamicBoxShape.SetAsBox(box_width / 2.0f, box_height / 2.0f); //experiment with / 2.0f FixtureDef dynamicCircleFixtureDef = new FixtureDef(); dynamicCircleFixtureDef.shape = dynamicCircleShape; dynamicCircleFixtureDef.density = density; dynamicCircleFixtureDef.friction = 0.3f; dynamicBody.CreateFixture(dynamicCircleFixtureDef); this.physicsBody = dynamicBody; }
public Gun(World world, Vector2 position, Player player) { ObjectType = EObjectType.Gun; mPosition = position; mWorld = world; mPlayer = player; CurrentMagazine = new List<int>(); Vector2 size = new Vector2(10, 8); mBaseBox = new Box(world, position, size, "gun", true, player); size = new Vector2(10, 2); mBarrelBox = new Box(world, position, size, "barrel", true, player); Filter filter = new Filter(); filter.maskBits = 0; Fixture fixture = mBarrelBox.mBody.GetFixtureList(); fixture.SetFilterData(ref filter); fixture = mBaseBox.mBody.GetFixtureList(); fixture.SetFilterData(ref filter); mIsActive = false; mFilter = new Filter(); if (mPlayer.PlayerType == EntityCategory.Player2) mFilter.maskBits = (ushort)(EntityCategory.Player1); else mFilter.maskBits = (ushort)(EntityCategory.Player2); mFilter.categoryBits = (ushort)mPlayer.PlayerType; }
public Level(GameContent gameContent) { world = new World(atomGravity, false); this.gameContent = gameContent; if (gameContent.levelIndex == -1) this.isLAB = true; camera = new Camera2D(gameContent.viewportSize, false); if (!isLAB) LoadLevelComponent(); else { labComponent = new LabComponent(gameContent, world); editMode = true; world.Gravity = equipGravity; camera.Scale = targetScale = scale = labComponent.EqScale; camera.Position = new Vector2(labComponent.Width, labComponent.Height) / 2; camera.Speed = 15; camera.ScrollBar = new Vector2(100, 50); camera.ScrollWidth = labComponent.Width; camera.ScrollHeight = labComponent.Height; } mouseGroundBody = world.CreateBody(new BodyDef()); }
public override bool init() { if (!base.init()) return false; if (!base.init()) { return false; } CCSize winSize = CCDirector.sharedDirector().getWinSize(); title = CCLabelTTF.labelWithString("FootBall", "Arial", 24); title.position = new CCPoint(winSize.width / 2, winSize.height - 50); this.addChild(title, 1); ball = CCSprite.spriteWithFile(@"images/ball"); ball.position = new CCPoint(100, 300); this.addChild(ball); Vector2 gravity = new Vector2(0.0f, -30.0f); bool doSleep = true; world = new World(gravity, doSleep); ///////////////////////// BodyDef groundBodyDef = new BodyDef(); groundBodyDef.position = new Vector2(0, 0); Body groundBody = world.CreateBody(groundBodyDef); PolygonShape groundBox = new PolygonShape(); FixtureDef boxShapeDef = new FixtureDef(); boxShapeDef.shape = groundBox; groundBox.SetAsEdge(new Vector2(0, 0), new Vector2((float)(winSize.width / PTM_RATIO), 0)); groundBody.CreateFixture(boxShapeDef); groundBox.SetAsEdge(new Vector2(0, 0), new Vector2(0, (float)(winSize.height / PTM_RATIO))); groundBody.CreateFixture(boxShapeDef); groundBox.SetAsEdge(new Vector2(0, (float)(winSize.height / PTM_RATIO)), new Vector2((float)(winSize.width / PTM_RATIO), (float)(winSize.height / PTM_RATIO))); groundBody.CreateFixture(boxShapeDef); groundBox.SetAsEdge(new Vector2((float)(winSize.width / PTM_RATIO), (float)(winSize.height / PTM_RATIO)), new Vector2((float)(winSize.width / PTM_RATIO), 0)); groundBody.CreateFixture(boxShapeDef); BodyDef ballBodyDef = new BodyDef(); ballBodyDef.type = BodyType.Dynamic; ballBodyDef.position = new Vector2( (float)(100 / PTM_RATIO), (float)(300 / PTM_RATIO)); ballBodyDef.userData = ball; body = world.CreateBody(ballBodyDef); CircleShape circle = new CircleShape(); circle._radius = (float)(26.0 / PTM_RATIO); FixtureDef ballShapeDef = new FixtureDef(); ballShapeDef.shape = circle; ballShapeDef.density = 1.0f; ballShapeDef.friction = 0.0f; ballShapeDef.restitution = 1.0f; body.CreateFixture(ballShapeDef); this.schedule(tick); return true; }
public Terrain(World world) { mWorld = world; mBodyDef = new BodyDef(); mBody = world.CreateBody(mBodyDef); Generate(); GenerateDrawVertexs(); }
public World(Vector2 gravity, EventManager eventManager) : base(Constants.TIME_TICKS_EVENT) { _world = new Box2D.XNA.World(gravity, true); _world.ContactListener = new ContactListener(); _timeStep = Variables.TargetFrameMilliseconds/1000.0f; _eventManager = eventManager; }
/// <summary> /// Deletes all entities from this world and anything related to entities is reset. /// </summary> public void deleteAllEntities() { physicsWorld = new Box2D.XNA.World(gravity, true); physicsWorld.ContactFilter = new PCContactFilter(); physicsWorld.ContactListener = new PCContactListener(); navStuff = new NavMeshManager((int)sizeInPixels.X, (int)sizeInPixels.Y, game); entities = new List <Entity>(); bodyDict = new Dictionary <string, Body>(); }
public Builder(World world, Camera camera, GameObjectCollection gameObjectCollection) { mWorld = world; mCamera = camera; mGameObjectCollection = gameObjectCollection; IsActive = false; mTexture = "block3"; }
public Apple(Vector2 position, Body ground, GameContent gameContent, World world) : this(null, gameContent, world) { this.ground = ground; body.Position = position; originalPostion = position; State = LeafState.Drop; fallenFromAir = true; }
public Tutorial(GameContent gameContent, World world) : base(gameContent, world) { #if WINDOWS instructions = gameContent.content.Load<List<string>>("Levels/tutorial"); #endif #if WINDOWS_PHONE instructions = gameContent.content.Load<List<string>>("Levels/tutorialPhone"); #endif NextMsg(); }
/// <summary> /// Creates a new ground component /// </summary> /// <param name="world">The Box2D world that will hold this component</param> /// <param name="content">Used ContentManager</param> /// <param name="pos">The position of this component</param> /// <param name="angle">The rotation angle of this component</param> /// <param name="width">The width of this component</param> /// <param name="height">The height of this component</param> public Ground(World world, ContentManager content, Vector2 pos, float angle, float width, float height) : base(world, content, pos, angle, width, height) { Name = "grass"; texture = content.Load<Texture2D>("Images/" + Name); PolygonShape shape = new PolygonShape(); shape.SetAsBox(width * 0.5f / Level.FACTOR, height * 0.5f / Level.FACTOR); body.CreateFixture(shape, 1.0f).SetFriction(1.0f); origin = new Vector2(screenPos.Width * 0.5f, texture.Height * 0.5f); sourceRect = new Rectangle(0, 0, (int)width, texture.Height); }
public Atom(Symbol symbol, Vector2 position, GameContent gameContent, World world) { this.gameContent = gameContent; this.world = world; if (symbol == Symbol.Ra) eye = EyeState.Angry; this.symbol = symbol; this.symbolStr = symbol.ToString(); symbolCenter = gameContent.symbolFont.MeasureString(this.symbolStr); symbolCenter.X *= 0.5f; symbolCenter.Y *= 0.92f; bondsLeft = (int)symbol; BodyDef bd = new BodyDef(); bd.type = BodyType.Dynamic; bd.position = this.position = position / gameContent.b2Scale; bd.bullet = true; body = world.CreateBody(bd); body.SetUserData(this); CircleShape cs = new CircleShape(); cs._radius = gameContent.atomRadius / gameContent.b2Scale; FixtureDef fd = new FixtureDef(); fd.shape = cs; fd.restitution = 0.2f; fd.friction = 0.5f; fixture = body.CreateFixture(fd); electroShockAnimation = new Animation(gameContent.electroShock, 3, 0.1f, true, new Vector2(0.5f, 0.5f)); radiationSmoke = new RadiationSmoke(gameContent, this); // Collide only with Ground but not with itself and bonded Filter mouseFilter = new Filter(); mouseFilter.categoryBits = 0x0002; mouseFilter.maskBits = 0x0001; mouseFilter.groupIndex = -2; // Collide with every thing atomFilter = new Filter(); atomFilter.categoryBits = 0x0001; atomFilter.maskBits = 0x0001; atomFilter.groupIndex = 1; fixture.SetFilterData(ref atomFilter); SetMode(false, false); }
public LevelComponent(GameContent gameContent, World world) { this.gameContent = gameContent; this.world = world; levelData = gameContent.content.Load<LevelData>("Levels/level" + gameContent.levelIndex); MaxAtoms = levelData.MaxAtoms; int totalProbability = 0; for (int i = 0; i < levelData.AtomProbability.Length; i++) totalProbability += levelData.AtomProbability[i]; if (totalProbability != 100) throw new Exception("must be 100"); entryPoint = levelData.Entry; bonusType = levelData.BonusType; BodyDef bd = new BodyDef(); Body ground = world.CreateBody(bd); PolygonShape ps = new PolygonShape(); List<Vector2> v = levelData.ContinuousBoundry; for (int i = 0; i < v.Count - 1; i++) { if (v[i + 1].X == -1 && v[i + 1].Y == -1) { i++; continue; } ps.SetAsEdge(v[i] / gameContent.scale, v[i + 1] / gameContent.scale); ground.CreateFixture(ps, 0); } for (int i = 0; i < levelData.EquipmentDetails.Count; i++) { Equipment eq = new Equipment(levelData.EquipmentDetails[i].EquipmentName, gameContent, world); eq.body.Position = levelData.EquipmentDetails[i].Position / gameContent.scale; eq.body.Rotation = levelData.EquipmentDetails[i].RotationInDeg / 180 * (float)MathHelper.Pi; eq.isClamped = levelData.EquipmentDetails[i].IsClamped; eq.body.SetType(BodyType.Static); equipments.Add(eq); if (eq.equipName == EquipmentName.thermometer) thermometer = eq; if (eq.equipName == EquipmentName.pHscale) pHscale = eq; } }
/// <summary> /// Creates a new jump component /// </summary> /// <param name="world">The Box2D world that will hold this component</param> /// <param name="content">Used ContentManager</param> /// <param name="pos">The position of this component</param> /// <param name="angle">The rotation angle of this component</param> /// <param name="width">The width of this component</param> /// <param name="height">The height of this component</param> public Jump(World world, ContentManager content, Vector2 pos, float angle, float width, float height) : base(world, content, pos, angle, width, height) { Name = "jump"; texture = content.Load<Texture2D>("Images/" + Name); origin = new Vector2(texture.Width * 0.5f, texture.Height * 0.5f); sourceRect = new Rectangle(1, 1, texture.Width, texture.Height); PolygonShape shape = new PolygonShape(); Vector2[] vertices = {new Vector2(-width*0.5f/ Level.FACTOR, height*0.5f/ Level.FACTOR), new Vector2(width*0.5f/ Level.FACTOR, -height*0.5f/ Level.FACTOR), new Vector2(width*0.5f/ Level.FACTOR, height*0.5f/ Level.FACTOR)}; shape.Set(vertices, 3); body.CreateFixture(shape, 1.0f); }
/// <summary> /// Resets the game world. /// Removes and reloads all entities. /// </summary> public void resetWorld() { if (fileLoadedFrom == null) { return; } entityManager.player.deleteBody(name); physicsWorld = new Box2D.XNA.World(new Vector2(0, 0f), true); physicsWorld.ContactFilter = new PCContactFilter(); navStuff = new NavMeshManager((int)sizeInPixels.X, (int)sizeInPixels.Y, game); viewport = new Viewport(0, 0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height); entities = new List <Entity>(); bodyDict = new Dictionary <string, Body>(); checkpoints = new List <Vector2>(); idsOfThingsThatDontCollideWithThePlayer = new List <string>(); loadGameWorld(fileLoadedFrom); entityManager.player.enteringWorld = 24; }
/// <summary> /// Constructor /// </summary> /// <param name="_game"></param> public GameWorld(Game _game, float width, float height, int tileWidth, String _name) { sizeInPixels = new Vector2(width * tileWidth, height * tileWidth); game = _game; entityManager = EntityManager.getEntityManager(game); entities = new List <Entity>(); physicsWorld = new Box2D.XNA.World(new Vector2(0, 0f), true); physicsWorld.ContactFilter = new PCContactFilter(); physicsWorld.ContactListener = new PCContactListener(); navStuff = new NavMeshManager((int)sizeInPixels.X, (int)sizeInPixels.Y, game); viewport = new Viewport(0, 0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height); name = _name; bodyDict = new Dictionary <string, Body>(); idsOfThingsThatDontCollideWithThePlayer = new List <string>(); entered = false; walls = new bool[4]; checkpoints = new List <Vector2>(); aiDict = new Dictionary <string, AIBase>(); }
public Box(World world, Vector2 position, Vector2 size, string texture, bool isStatic, Player player, float health = 100) { ObjectType = EObjectType.Box; mHealth = health; mStartHealth = health; mIsDestroyed = false; mSize = size; mWorld = world; mTexture = texture; mPlayer = player; DestroyTime = null; PolygonShape polygonShape = new PolygonShape(); polygonShape.SetAsBox(size.X / 2f, size.Y / 2f); BodyDef bodyDef = new BodyDef(); bodyDef.position = position; bodyDef.bullet = true; if (isStatic) { bodyDef.type = BodyType.Static; } else { bodyDef.type = BodyType.Dynamic; } mBody = world.CreateBody(bodyDef); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = polygonShape;//Форма fixtureDef.density = 0.1f;//Плотность fixtureDef.friction = 0.3f;//Сила трения fixtureDef.restitution = 0f;//Отскок Filter filter = new Filter(); filter.maskBits = (ushort)(EntityCategory.Player1 | EntityCategory.Player2); filter.categoryBits = (ushort)player.PlayerType; var fixture = mBody.CreateFixture(fixtureDef); fixture.SetFilterData(ref filter); MassData data = new MassData(); data.mass = 0.01f; mBody.SetUserData(this); }
public LabComponent(GameContent gameContent, World world) { this.gameContent = gameContent; EqScale = 0.4f; AtomScale = 0.7f; Width = (int)(gameContent.viewportSize.X * 2 / EqScale); Height = (int)(gameContent.viewportSize.Y * 1 / EqScale); gameContent.clampDistance = (int)(gameContent.viewportSize.X / 2 / EqScale); PolygonShape ps = new PolygonShape(); Body ground = world.CreateBody(new BodyDef()); Vector2 pos = new Vector2(Width / 2, Height) / gameContent.scale; ps.SetAsBox(Width / 2 / gameContent.scale, (float)gameContent.labTable.Height / gameContent.scale, pos, 0); ground.CreateFixture(ps, 0); }
public Body CreateWall(World world, float ScaleFactor) { var grounDef = new BodyDef(); grounDef.type = BodyType.Static; var groundFix = new FixtureDef(); groundFix.restitution = 1.0f; groundFix.friction = 0.0f; groundFix.density = 0.0f; var groundShape = new PolygonShape(); //groundShape.SetAsEdge(new Vector2(0, 8), new Vector2(4.8f, 8.0f)); groundShape.SetAsBox(texture.Width * ScaleFactor / 2f, texture.Height * ScaleFactor / 2f); var groundBody = world.CreateBody(grounDef); groundBody.Position = new Vector2(2.4f, 4); groundFix.shape = groundShape; groundBody.CreateFixture(groundFix); return groundBody; }
/// <summary> /// Creates a new predefined level /// </summary> /// <param name="number">The number of the level (1, 2 or 3)</param> /// <param name="pAudioPlayer">The AudioPlayer intance that playes all the sound /// effects</param> /// <param name="pContent">Used ContentManager</param> /// <param name="pSpriteBatch">Used SpriteBatch</param> public Level(int number, AudioPlayer pAudioPlayer, ContentManager pContent) { content = pContent; audioPlayer = pAudioPlayer; world = new World(new Vector2(0.0f, 5.0f), true); world.ContactListener = this; rotationData = new RotationData(); bike = new Bike(bikeSpeed, rotationData, world, camPos, content); provider.NumberDecimalSeparator = "."; try { using (Stream stream = TitleContainer.OpenStream("Content/Levels/Level_" + number + ".lvl")) { LoadLevel(stream); } } catch (FileNotFoundException) { } }
/// <summary> /// Creates a new level component /// </summary> /// <param name="world">The Box2D world that will hold this component</param> /// <param name="content">Used ContentManager</param> /// <param name="pSpriteBatch">Used SpriteBatch</param> /// <param name="pos">The position of the component</param> /// <param name="angle">The angle of the component</param> /// <param name="pWidth">The width of the component</param> /// <param name="pHeight">The height of the component</param> public LevelComponent(World world, ContentManager content, Vector2 pos, float angle, float pWidth, float pHeight) { Pos = new Vector2(); x = pos.X; y = pos.Y; width = pWidth; height = pHeight; sourceRect = new Rectangle(0, 0, (int)width, (int)height); screenPos = new Rectangle(0, 0, (int)width, (int)height); origin = new Vector2(sourceRect.Width * 0.5f, sourceRect.Height * 0.5f); BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.Static; bodyDef.position = pos; bodyDef.position.X /= Level.FACTOR; bodyDef.position.Y /= Level.FACTOR; bodyDef.angle = angle * Level.DEG_TO_RAD; body = world.CreateBody(bodyDef); }
public Branch(Path2D path, GameContent gameContent, World world, Branch nearestBranch) { this.gameContent = gameContent; dot = gameContent.dot; circle = gameContent.jointCircle; square = gameContent.jointSquare; cursor = gameContent.cursor; BodyDef bd = new BodyDef(); bd.position = path.Keys[0]; bd.type = BodyType.Dynamic; body = world.CreateBody(bd); fixtureCount = path.Keys.Count; for (int i = 0; i < path.Keys.Count; i++) CreateFixture(path.Keys[i] - path.Keys[0]); if (nearestBranch != null) { RevoluteJointDef revJd = new RevoluteJointDef(); revJd.bodyA = body; revJd.bodyB = nearestBranch.body; revJd.localAnchorA = Vector2.Zero; AABB aabb; nearestBranch.nearestFixture.GetAABB(out aabb); Vector2 p = aabb.GetCenter(); revJd.localAnchorB = nearestBranch.nearestFixture.GetBody().GetLocalPoint(p); revJd.enableMotor = true; revJd.referenceAngle = nearestBranch.nearestFixture.GetBody().Rotation; revoJoint = (RevoluteJoint)world.CreateJoint(revJd); revoJoint.SetUserData((Branch)nearestBranch); nearestBranch.nearestFixture.SetUserData((Branch)this); } newGrow = true; }
public Bullet(World world, Vector2 position, float maxDamageValue, Player player,int bulletType) { mPlayer = player; ObjectType = EObjectType.Bullet; switch (bulletType) { case 1: mDamageRadius = 10; break; case 2: mDamageRadius = 20; break; } mMaxDamageValue = maxDamageValue; Vector2 size = new Vector2(5, 5); mBox = new Box(world, position, size, "bullet", true, player); MassData massData = new MassData(); massData.mass = 1000; mBox.mBody.SetMassData(ref massData); mIsActive = false; mIsDestoyed = false; Body.SetUserData(this); }
public Equipment(EquipmentName equipName, GameContent gameContent, World world) { this.gameContent = gameContent; this.world = world; this.equipName = equipName; BodyDef bd = new BodyDef(); bd.type = BodyType.Dynamic; body = world.CreateBody(bd); equipmentData = gameContent.content.Load<EquipmentData>("Graphics/" + equipName.ToString()); topLeftVertex = equipmentData.TopLeftVertex; origin = equipmentData.Origin; rotationButtonPos = equipmentData.RotationButtonPosition; rightClampPositionX = equipmentData.ClampData.RightClampPositionX; clampRotation = equipmentData.ClampData.RotationInDeg / 180f * (float)Math.PI; clampEnabled = equipmentData.ClampData.ClampEnabled; SetFixtures(); // Collide only with Ground but not with itself and bonded Filter mouseFilter = new Filter(); mouseFilter.categoryBits = 0x0002; mouseFilter.maskBits = 0x0001; mouseFilter.groupIndex = -2; // Collide with every thing groundFilter = new Filter(); groundFilter.categoryBits = 0x0001; groundFilter.maskBits = 65535; groundFilter.groupIndex = 0; equipFilter = new Filter(); equipFilter.categoryBits = 0x0002; equipFilter.maskBits = 0x0001; equipFilter.groupIndex = 2; //SetMode(false, false); body.SetUserData((EquipmentName)equipName); }
public PhysicsBox(Texture2D sprite_texture, World physicsWorld, float box_width, float box_height, float positionX, float positionY, float rot, float density) : base(sprite_texture) { this.scaleToFitTheseDimensions(box_width, box_height); this.position.X = positionX; this.position.Y = positionY; BodyDef dynamicBodyDef = new BodyDef(); dynamicBodyDef.type = BodyType.Dynamic; dynamicBodyDef.position = new Vector2(positionX/DynamicPhysicsGameObject.ScreenPixelsPerMeter, positionY/DynamicPhysicsGameObject.ScreenPixelsPerMeter); dynamicBodyDef.angle = rot; Body dynamicBody = physicsWorld.CreateBody(dynamicBodyDef); PolygonShape dynamicBoxShape = new PolygonShape(); dynamicBoxShape.SetAsBox((box_width/ScreenPixelsPerMeter) / 2.0f, (box_height/ScreenPixelsPerMeter) / 2.0f); //experiment with / 2.0f FixtureDef dynamicBoxFixtureDef = new FixtureDef(); dynamicBoxFixtureDef.shape = dynamicBoxShape; dynamicBoxFixtureDef.density = density; dynamicBoxFixtureDef.friction = 0.3f; dynamicBody.CreateFixture(dynamicBoxFixtureDef); this.physicsBody = dynamicBody; }
public static List<Box> Destroy(Box box, World world, float explosionDistance, Player player) { List<Box> boxes = new List<Box>(); Vector2 pos = box.mBody.GetPosition(); Vector2 size = box.mSize; Vector2 partBoxSize = size / 2; if (size.X < 1f || size.Y < 1) { return boxes; } Vector2 force = new Vector2(1.1f / explosionDistance); Vector2 partBoxPos = pos - partBoxSize / 2; Box partBox = new Box(world, partBoxPos, partBoxSize, box.Texture, false, player); partBox.mBody.ApplyLinearImpulse(force * partBox.mBody.GetMass(), Vector2.Zero); boxes.Add(partBox); partBoxPos = pos + partBoxSize / 2; partBox = new Box(world, partBoxPos, partBoxSize, box.Texture, false, player); partBox.mBody.ApplyLinearImpulse(force * partBox.mBody.GetMass(), Vector2.Zero); boxes.Add(partBox); partBoxPos = new Vector2(pos.X + partBoxSize.X / 2, pos.Y - partBoxSize.Y / 2); partBox = new Box(world, partBoxPos, partBoxSize, box.Texture, false, player); partBox.mBody.ApplyLinearImpulse(force * partBox.mBody.GetMass(), Vector2.Zero); boxes.Add(partBox); partBoxPos = new Vector2(pos.X - partBoxSize.X / 2, pos.Y + partBoxSize.Y / 2); partBox = new Box(world, partBoxPos, partBoxSize, box.Texture, false, player); partBox.mBody.ApplyLinearImpulse(force * partBox.mBody.GetMass(), Vector2.Zero); boxes.Add(partBox); return boxes; }
/// <summary> /// Constructor. /// </summary> public PhysicsManager() { mPhysicsWorld = new Box2D.XNA.World(new Vector2(0, 10.0f), true); }