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 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 Asteroid(GameContent gameContent, int index, Body body) { this.gameContent = gameContent; tex = gameContent.asteroid[index]; this.body = body; body.SetUserData(this); originalPosition = body.Position; for (int i = 0; i < 5; i++) blastTex[i] = gameContent.asteroid[(index + i) % 16]; blastSound = gameContent.boom[index % 3]; blastSoundInstance = blastSound.CreateInstance(); blastSoundInstance.Volume = 0.8f; }
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 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 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 virtual Body AddBodyInstanceToRuntime() { // box2D body if (this.polygons.Count > 0) { BodyDef bodyDef = new BodyDef(); Vector2 pos = GetGlobalOffset(Vector2.Zero); bodyDef.position = new Vector2(pos.X / V2DScreen.WorldScale, pos.Y / V2DScreen.WorldScale); bodyDef.angle = GetGlobalRotation(0); bodyDef.fixedRotation = this.fixedRotation; bodyDef.angularDamping = this.angularDamping; bodyDef.linearDamping = this.linearDamping; IsStatic = isStatic; // todo: add kinematic if (isStatic) { bodyDef.type = BodyType.Static; } else { bodyDef.type = BodyType.Dynamic; } //// todo: this needs to allow for nested levels //if (!fixedRotation) //{ // for (int i = 0; i < transforms.Length; i++) // { // transforms[i].Position = transforms[i].Position - pos + State.Position; // transforms[i].Rotation = transforms[i].Rotation - bodyDef.Angle + State.Rotation; // //this.transforms[i].Scale /= bodyDef.Scale; // } //} if (attributeProperties != null) { attributeProperties.ApplyAttribtues(bodyDef); } body = v2dScreen.CreateBody(bodyDef); body.SetUserData(this); for (int i = 0; i < this.polygons.Count; i++) { AddPoly(body, this.polygons[i]); } if (attributeProperties != null) { if (attributeProperties.mass != 0f) { MassData md; body.GetMassData(out md); md.mass = attributeProperties.mass; body.SetMassData(ref md); } if (attributeProperties.centerOfMassX != 0 || attributeProperties.centerOfMassY != 0) { MassData md; body.GetMassData(out md); md.center = new Vector2(attributeProperties.centerOfMassX, attributeProperties.centerOfMassY); body.SetMassData(ref md); } } } return body; }
private void LoadShip() { Vector2 position = new Vector2(Width * TileWidth / 2, Height * TileHeight - 600 + FrontClearance); Texture2D texture = GameContent.ship; BodyDef bd = new BodyDef(); bd.fixedRotation = true; bd.type = BodyType.Dynamic; bd.linearDamping = 0.5f; bd.angularDamping = 0.1f; bd.position = position; ship = world.CreateBody(bd); ship.SetUserData(texture); PolygonShape pShape = new PolygonShape(); Vector2[] vertices = new Vector2[3]; vertices[0] = new Vector2(0, -texture.Height / 2); vertices[1] = new Vector2(texture.Width / 2, texture.Height / 2); vertices[2] = new Vector2(-texture.Width / 2, texture.Height / 2); pShape.Set(vertices, 3); FixtureDef fd = new FixtureDef(); fd.density = 0.1f; fd.shape = pShape; fd.friction = 5; fd.restitution = .5f; ship.CreateFixture(fd); originalShipPos = ship.Position; }