public static List <Fixture> attachRoundedRectangle(this Body body, float width, float height, float xRadius, float yRadius, int segments, float density, Vector2 position = new Vector2()) { width *= FSConvert.displayToSim; height *= FSConvert.displayToSim; xRadius *= FSConvert.displayToSim; yRadius *= FSConvert.displayToSim; position *= FSConvert.displayToSim; return(FixtureFactory.attachRoundedRectangle(width, height, xRadius, yRadius, segments, density, body)); }
public SensorPhysicsComponent(Engine engine, List <Vector2> vertices, Vector2 position) : base(engine) { Vertices farseerVertices = new Vertices(vertices); SensorFixture = FixtureFactory.CreatePolygon(Engine.Physics.World, farseerVertices, 0.0f); SensorFixture.Body.BodyType = BodyType.Static; SensorFixture.IsSensor = true; SensorFixture.CollisionFilter.CollisionCategories = (Category)Global.CollisionCategories.Light; }
protected virtual void CreateShieldPhysics() { var shieldObj = new ShieldCollisionMarker(this); PhysicsShieldBody = BodyFactory.CreateBody(this.GDManager().PhysicsWorld, ConvertUnits2.ToSimUnits(Position), 0, BodyType.Static); FixtureFactory.AttachCircle( ConvertUnits.ToSimUnits(Scale * CANNON_SHIELD_DIAMETER / 2), 1, PhysicsBody, Vector2.Zero, shieldObj); }
private WallHuggingExample() { World.Gravity = new Vector2(0, 0); Fixture rectangle = FixtureFactory.CreateRectangle(World, 15, 15, 1); rectangle.Body.Rotation = 0.3f; rectangle.Body.Position = new Vector2(18, 18); rectangle.Restitution = 1; GenerateParticle(); }
protected override void Handle(SeasonStartedEvent notification) { var fixtures = new FixtureFactory(notification.SeasonId, notification.TeamsDivisions, notification.FirstMatchDate) .Build(); foreach (var fixture in fixtures) { this.fixtureRepository.Save(fixture); } }
public void Collections() { var value = FixtureFactory.CreateMany <int[]>(length: 800, resolver: StandardResolver.EdgeCase).ToLookup(x => x?.Length); value.Count.Should().Be(4); value[null].Count().Should().BeCloseTo(200, 50); value[0].Count().Should().BeCloseTo(200, 50); value[1].Count().Should().BeCloseTo(200, 50); value[9].Count().Should().BeCloseTo(200, 50); }
public Fixture AddCollisionLoopShape(CollisionDefinitionEntry entry) { Vertices verts = new Vertices(); foreach (var point in entry.Vertices) { verts.Add(ConvertUnits.ToSimUnits(point)); } return(FixtureFactory.AttachLoopShape(verts, m_body)); }
public override void Start() { m_goalsCount = 0; m_goalsCountDisplay = 0; m_goalTrigger = new TriggerComponent(); var triggerFixture = FixtureFactory.AttachRectangle( m_size.X, m_size.Y, 0, Vector2.Zero, m_goalTrigger.Body); triggerFixture.IsSensor = true; m_goalTrigger.Body.CollidesWith = (Category)CollisionType.Ball; m_goalTrigger.OnTrigger += new Action <GameObject>(m_goalTrigger_OnTrigger); m_goalTrigger.OnLeave += new Action <GameObject>(m_goalTrigger_OnLeave); Owner.Attach(m_goalTrigger); RigidBodyComponent rbCmp = new RigidBodyComponent(); FixtureFactory.AttachRectangle( m_size.X, m_size.Y, 0, Vector2.Zero, rbCmp.Body); rbCmp.Body.BodyType = BodyType.Static; rbCmp.Body.CollidesWith = (Category)CollisionType.None; Owner.Attach(rbCmp); rbCmp.OnCollision += new CollisionEvent(RigidBodyCmp_OnCollision); Sprite sprite = Sprite.Create("Graphics/goalFx.lua::Sprite"); sprite.Scale = new Vector2(0.7f, 0.55f); //sprite.Playing = true; m_goalSprite = new SpriteComponent(sprite, "ArenaOverlay8"); m_goalSprite.Visible = false; Owner.Attach(m_goalSprite); m_AudioCmpGoal = new AudioComponent("Audio/Sounds.lua::Goal"); Owner.Attach(m_AudioCmpGoal); float goalDisableTimeMS = 0.1f * 1000; m_goalDisableTimer = new Timer(Engine.GameTime.Source, goalDisableTimeMS, TimerBehaviour.Stop); Engine.World.EventManager.AddListener((int)EventId.MatchEnd, OnMatchEnd); m_goalTimer = new Timer(Engine.GameTime.Source, 1000, TimerBehaviour.Stop); }
public void InitGlobalBounds() { globalBounds = new Vector2(ConvertUnits.ToSimUnits(window.Size.X), ConvertUnits.ToSimUnits(window.Size.Y)); Body globalBoundsCollision = BodyFactory.CreateBody(world); FixtureFactory.AttachEdge(new Vector2(0, 0), new Vector2(0, globalBounds.Y), globalBoundsCollision); FixtureFactory.AttachEdge(new Vector2(0, globalBounds.Y), new Vector2(globalBounds.X, globalBounds.Y), globalBoundsCollision); FixtureFactory.AttachEdge(new Vector2(globalBounds.X, globalBounds.Y), new Vector2(globalBounds.X, 0), globalBoundsCollision); FixtureFactory.AttachEdge(new Vector2(globalBounds.X, 0), new Vector2(0, 0), globalBoundsCollision); globalBoundsCollision.CollidesWith = Category.Cat6; }
public void SetBodyFixture(int xRadius, int yRadius, Vector2 offset) { // Remove all the old fixtures while (Body.FixtureList.Count > 0) { Body.DestroyFixture(Body.FixtureList[0]); } //FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(62), ConvertUnits.ToSimUnits(110), 1.0f, ConvertUnits.ToSimUnits(-9, 2), player.Body); FixtureFactory.AttachEllipse(ConvertUnits.ToSimUnits(xRadius), ConvertUnits.ToSimUnits(yRadius), 6, BodyDensity, ConvertUnits.ToSimUnits(offset), Body); }
public void TestGetFakeOf() { var f = FixtureFactory.GetFakeOf <Person>(); Assert.AreEqual(f.GetType(), typeof(Person), "Should return an object of same type with GetFakeOf method"); Assert.IsNotNull(f.Name, "invalid Name"); Assert.IsNotNull(f.Age, "invalid Age"); Assert.IsNotNull(f.DateOfBirth, "Invalid DateOfBirth"); Assert.IsNotNull(f.Designate, "Invalid Designate"); Assert.IsNotNull(f.Gender, "Invalid Gender"); }
public Player(Vector2 pos, VelcroPhysics.Dynamics.World world) { physicsBody = BodyFactory.CreateCircle(world, ConvertUnits.ToSimUnits(100f), 1f, ConvertUnits.ToSimUnits(pos), BodyType.Dynamic); physicsBody.LinearDamping = 10f; label = "player"; textureDimensions = new Vector2(100, 100); origin = textureDimensions / 2; damageBox = FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(30f), ConvertUnits.ToSimUnits(90f), 2f, new Vector2(0, ConvertUnits.ToSimUnits(100f)), physicsBody, null); damageBox.OnCollision += new VelcroPhysics.Collision.Handlers.OnCollisionHandler(this.Dealdamage); }
public void NonFlag() { var xs = FixtureFactory.CreateMany <Fruit>(900); var foo = xs.ToLookup(x => x); foo.Count.Should().Be(3); foo[Fruit.Orange].Count().Should().BeCloseTo(300, 50); foo[Fruit.Apple].Count().Should().BeCloseTo(300, 50); foo[Fruit.Grape].Count().Should().BeCloseTo(300, 50); }
public ArenaRace_Server() : base() { Arena.Interface.Type = GUIType.Normal; Arena.Interface.Mode = GUIMode.NormalRace; World = new World(new Microsoft.Xna.Framework.Vector2(0, -9)); var edgeBody = new Body(World); FixtureFactory.AttachEdge(new Microsoft.Xna.Framework.Vector2(-50, 0), new Microsoft.Xna.Framework.Vector2(50, 0), edgeBody); }
protected void CreateCircularBody() { DynamicBody = BodyFactory.CreateBody(GameScreen.World, ConvertUnits.ToSimUnits(Position)); Fixture fixture = FixtureFactory.AttachCircle(_physicsRadius, 1f, DynamicBody, _physicsOffset); DynamicBody.Restitution = 0.1f; DynamicBody.LinearDamping = 5f; DynamicBody.BodyType = BodyType.Dynamic; DynamicBody.UserData = this; DynamicBody.FixedRotation = true; }
private PooledFarseerBody CreateCircularFarseerStaticBody() { Body body = new Body(WorldManager.World); FixtureFactory.AttachCircle(1f, 1f, body); body.BodyType = BodyType.Static; body.Position = body.Position + new Vector2(body.Position.X + positionX, body.Position.Y); positionX += 100; return(new PooledFarseerBody(body, CircularFarseerStaticBodyPool)); }
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 void AttachToBody(Body body, Vector2 scale) { float scaleD = (scale.X + scale.Y) / 2f; switch (Type) { case ShapeType.Circle: FixtureFactory.AttachCircle(UnitsConverter.ToSimUnits(XRadius) * scaleD, Density, body); break; case ShapeType.Ellipse: FixtureFactory.AttachEllipse(UnitsConverter.ToSimUnits(XRadius) * scale.X, UnitsConverter.ToSimUnits(YRadius) * scale.Y, Edges, Density, body); break; case ShapeType.Edge: FixtureFactory.AttachEdge(UnitsConverter.ToSimUnits(Start) * scale, UnitsConverter.ToSimUnits(End) * scale, body); break; case ShapeType.Rectangle: FixtureFactory.AttachRectangle(UnitsConverter.ToSimUnits(Width) * scale.X, UnitsConverter.ToSimUnits(Height) * scale.Y, Density, UnitsConverter.ToSimUnits(Offset) * scale, body); break; case ShapeType.Polygon: Vertices p = new Vertices(); foreach (Vector2 node in Polygon[0]) { p.Add(UnitsConverter.ToSimUnits(node) * scale); } FixtureFactory.AttachPolygon(p, Density, body); break; case ShapeType.CompoundPolygon: List <Vertices> cp = new List <Vertices>(); foreach (Vertices v in Polygon) { Vertices polygon = new Vertices(); foreach (Vector2 node in v) { polygon.Add(UnitsConverter.ToSimUnits(node) * scale); } cp.Add(polygon); } FixtureFactory.AttachCompoundPolygon(cp, Density, body); break; default: return; } }
public static PayloadChain Connect(SpaceShip spaceShip, Payload payload, Vector2 payloadTarget) { var dynamicWorld = (DynamicEntityWorld)spaceShip.World; var world = dynamicWorld.PhysicsWorld; AABB spaceShipSize; spaceShip.Body.FixtureList.First().GetAABB(out spaceShipSize, 0); AABB payloadSize; payload.Body.FixtureList.First().GetAABB(out payloadSize, 0); var chainSize = new Vector2(1.0f); var chainSizeSingle = Math.Max(chainSize.X, chainSize.Y); var start = new Vector2(spaceShip.Position.X - spaceShipSize.Extents.Y, spaceShip.Position.Y); var length = payloadTarget.Length(); var targetVector = payloadTarget / length; var chainVector = targetVector * chainSizeSingle; start += chainVector; var chainCount = (int)Math.Ceiling(length / chainSizeSingle); var lastBody = spaceShip.Body; var chain = new PayloadChain(spaceShip.Name + "_Chain"); var elements = new List <ChainElement>(); for (var i = 0; i < chainCount; i++) { var chainBody = BodyFactory.CreateBody(world, start + i * chainVector); chainBody.BodyType = BodyType.Dynamic; var chainFixture = FixtureFactory.AttachRectangle(chainSize.X, chainSize.Y, 0.1f, Vector2.Zero, chainBody); chainFixture.CollidesWith = Category.Cat2; JointFactory.CreateRevoluteJoint(world, lastBody, chainBody, -chainVector / 2.0f); lastBody = chainBody; elements.Add(ChainElement.CreateFor(chain, elements.Count, dynamicWorld, chainBody)); } payload.Position = new Vector3(start + chainCount * chainVector + targetVector * 2.5f, 0.0f); JointFactory.CreateRevoluteJoint(world, lastBody, payload.Body, new Vector2(0.0f, -2.5f)); var ropeJoin = new RopeJoint(spaceShip.Body, payload.Body, new Vector2(0.0f, 3.0f), new Vector2(0.0f, -2.5f)); ropeJoin.CollideConnected = true; world.AddJoint(ropeJoin); return(chain); }
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"); }
protected IFixture GetFixture() { var fixture = FixtureFactory.GetFixture(); var sqlConnectionFactory = fixture.Freeze <Mock <ISqlServerConnectionFactory> >(); sqlConnectionFactory .Setup(f => f.CreateAndOpenAsync()) .ReturnsAsync(DatabaseTestConfig.TestDatabase.GetSqlConnection()); return(fixture); }
public override void StartEvent(StartEventType e) { if (e == StartEventType.Loaded) { GameServer.gameServer.WantedScheme.Build(); // Load player entities configuration foreach (var pm in GameServer.gameServer.playersInRoom.Select(p => p.Value.GetManager())) { EntityData entityData = null; pm.Army = tributeSystem.CreateActor <TributeArmyActor>(ActorConstants.ArmyOf + "|" + pm.Player.User.login, true); if (GameServer.gameServer.WantedScheme.GetEntity(ActorConstants.ACScheme.UberHero) != null) { pm.UberHeroActor = entitySystem.CreateActor <EntityUnitActor>(ActorConstants.ArmyOf + "|" + pm.Player.User.login, true); entityData = PlayerManager.LoadoutOfAll[pm.Player].Where(ed => ed.SchemeID == "#uberheroarmy[uberhero,0]").First(); } pm.UberHeroActor.Guid = ArenaExt.FindFreeGUID(entitySystem); pm.UberHeroActor.Data = entityData; pm.UberHeroActor.Tribute = pm.Army; pm.UberHeroActor.EntityPlus = new EntityPlus(); pm.UberHeroActor.EntityPlus.Actor = pm.UberHeroActor; pm.UberHeroActor.EntityPlus.plManager = pm; pm.UberHeroActor.PhysicBody = new Body(World, new Microsoft.Xna.Framework.Vector2(0, 0.4377073f), 0, pm.UberHeroActor); var fix = FixtureFactory.AttachRectangle(1.024947f, 1.70071f, 1, new Microsoft.Xna.Framework.Vector2(0, 0.4377073f), pm.UberHeroActor.PhysicBody, pm.UberHeroActor); var sendMsg = CommunicateActorToClients(pm.UberHeroActor, pm.Player, false, Constants.EventOperation.Arena_SpawnAndSetEquipment); // Send data { sendMsg.Write(entityData.SchemeID); sendMsg.Write((byte)entityData.Type); sendMsg.Write(entityData.ArmyIndex); sendMsg.Write(entityData.CurrentClass); sendMsg.Write(entityData.CurrentRarepon); sendMsg.Write(entityData.ClassesInPossession[entityData.CurrentClass]); if (entityData.CurrentRarepon != "none") { if (entityData.CurrentRarepon != "") { sendMsg.Write(entityData.RareponsInPossession[entityData.CurrentRarepon]); } } } GameServer.UsingPeer.SendMessage(sendMsg, GameServer.GetUserConnections(), Lidgren.Network.NetDeliveryMethod.ReliableOrdered, 0); } } if (e == StartEventType.SyncFinished) { //ArenaExt.UISendMessage(null, "Mission start!", PataponPhotonShared.Enums.UIMessageAlignement.VSBottom, 10); GameServer.RythmEngine.Start(); } }
public void JwtEncode() { foreach (var payload in FixtureFactory.CreateMany <Payload>(99)) { var key = LitJWT.Algorithms.HS256Algorithm.GenerateRandomRecommendedKey(); var encoder = new JwtEncoder(new LitJWT.Algorithms.HS256Algorithm(key)); var result = encoder.Encode(payload, null, (x, writer) => writer.Write(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(x)))); result.Should().Be(GetReferenceToken(key, payload, null)); } }
//--------------------------------------------------------------------------- public void AddPath(Vector2 start, Vector2 end) { PhysicsComponent physics = GetComponent <PhysicsComponent>(); if (physics != null) { Fixture fixture = FixtureFactory.AttachEdge(start / Unit, end / Unit, physics.Body, Entity); fixture.CollisionCategories = m_CategoryMapping[CollisionCategory]; Fixtures.Add(fixture); //fixture.CollidesWith = m_CategoryMapping[CollidesWith]; } }
public ObjectPool(Game1 game) { this.game = game; _instance = this; _pool = new List <GameObject>(); _platforms = new List <GameObject>(); _porings = new List <NPC>(); rng = new Random(); //Systema para gerar uma seed random no começo do jogo for (_height = 3; _height <= 21; _height = _height + 3) { _random = rng.Next(0, 10); if (_random >= 5) //platform big { float Xpos = rng.Next(3, 7); PlatformBig plat = new PlatformBig(game, new Vector2(Xpos, _height)); Body aux = plat.Body; _platforms.Add(plat); _random = rng.Next(0, 10); if (_random >= 5) // Spawn spikes { float posY = _height - 0.5f; SpikesBig sB = new SpikesBig(game, new Vector2(Xpos, posY)); _platforms.Add(sB); Fixture spikes = FixtureFactory.AttachRectangle(sB._size.X, sB._size.Y * 0.1f, 1, new Vector2(0, 0.15f), sB.Body); } _random = rng.Next(0, 10); if (_random >= 5) // Spawn poring { float posY = _height + 0.7f; NPC npc = new NPC(game, new Vector2(Xpos, posY)); _porings.Add(npc); } } else { //platform small float Xpos = rng.Next(3, 7); PlatformSmall plat = new PlatformSmall(game, new Vector2(Xpos, _height)); Body aux = plat.Body; _platforms.Add(plat); _random = rng.Next(0, 10); if (_random >= 5) // Spawn spikes { float posY = _height - 0.5f; SpikesSmall sB = new SpikesSmall(game, new Vector2(Xpos, posY)); _platforms.Add(sB); Fixture spikes = FixtureFactory.AttachRectangle(sB._size.X, sB._size.Y * 0.2f, 1, new Vector2(0, 0.15f), sB.Body); } } } heightaux = 1.5f; }
public override void OnInitGeometry() { Engine.World.EventManager.AddListener((int)EventId.HalfTimeTransition, OnHalfTimeTransition); m_laserTimer = new Timer(Engine.GameTime.Source, 6000, TimerBehaviour.Restart); m_laserTimerEvent = new TimerEvent(m_laserTImer_OnTime); m_laserTimer.OnTime += m_laserTimerEvent; m_laserTimer.Start(); m_laser = new Laser[4]; for (int i = 0; i < 4; i++) { m_laser[i] = new Laser(); } m_laser[0].LaserPosition = new Vector2(241, 219); m_laser[1].LaserPosition = new Vector2(241, -220); m_laser[2].LaserPosition = new Vector2(-239, 219); m_laser[3].LaserPosition = new Vector2(-239, -220); for (int i = 0; i < 4; i++) { GameObject obj = new GameObject("Laser"); obj.Attach(m_laser[i]); } var rbCmp = Arena.Owner.RigidBodyCmp; float width = ConvertUnits.ToSimUnits(Arena.ArenaHalfSize.X); float height = ConvertUnits.ToSimUnits(Arena.ArenaHalfSize.Y); float goalWidth = ConvertUnits.ToSimUnits(100); float goalHeight = ConvertUnits.ToSimUnits(80); //Obstacle FixtureFactory.AttachRectangle( ConvertUnits.ToSimUnits(40), ConvertUnits.ToSimUnits(240), 0, ConvertUnits.ToSimUnits(new Vector2(-240, 0)), rbCmp.Body); //Obstacle FixtureFactory.AttachRectangle( ConvertUnits.ToSimUnits(40), ConvertUnits.ToSimUnits(240), 0, ConvertUnits.ToSimUnits(new Vector2(240, 0)), rbCmp.Body); rbCmp.Body.CollidesWith = (Category)CollisionType.All | (Category)CollisionType.Ball; rbCmp.Body.CollisionCategories = (Category)CollisionType.Wall; }
protected override void SetupPhysics(World world) { #if EDITOR #else // Try and only convert everything once. Vector2 simPosition = ConvertUnits.ToSimUnits(this._position); float simHeight = ConvertUnits.ToSimUnits(_height); float simWidth = ConvertUnits.ToSimUnits(_width); // Assign the world so we can easily access/replace the presolver. this._world = world; this._world.ContactManager.PreSolve += this.PreSolve; // Set up the objects body. this.Body = BodyFactory.CreateBody(world); this.Body.Position = simPosition; this.Body.CollidesWith = Category.Cat10; Fixture fixture = FixtureFactory.AttachRectangle(simWidth, simHeight, 1.0f, Vector2.Zero, this.Body); this.Body.Mass = ConvertUnits.ToSimUnits(10000); this.Body.Rotation = _rotation; this.Body.Friction = 3.0f; this.Body.UserData = MaterialType.None; // The Player wheel radius. radius = ConvertUnits.ToSimUnits(28); // Find the 'top'(side) based on the orientation. switch (_orientation) { case Orientation.Up: top = simPosition.Y - (simHeight * 0.5f); //top = ConvertUnits.ToSimUnits(this._position.Y - (_height * 0.5f)) break; case Orientation.Down: top = simPosition.Y + (simHeight * 0.5f); //top = ConvertUnits.ToSimUnits(this._position.Y + (_height * 0.5f)) break; case Orientation.Left: top = simPosition.X - (simWidth * 0.5f); //top = ConvertUnits.ToSimUnits(this._position.X - (_width * 0.5f)) break; case Orientation.Right: top = simPosition.X + (simWidth * 0.5f); //top = ConvertUnits.ToSimUnits(this._position.X + (_width * 0.5f)) break; } #endif }
internal static void AddMesh(Body body, bool isTrigger, List <Vertices> tris, float density) { if (world == null) { throw new InvalidOperationException("You have to Initialize the Physics system before adding bodies"); } List <Fixture> fixes = FixtureFactory.AttachCompoundPolygon(tris, density, body); for (int i = 0; i < fixes.Count; i++) { fixes[i].IsSensor = isTrigger; } }
public async Task NotUpdateTestAgentStatus_When_NoTestAgentsExists() { // Arrange var testAgents = TestAgentFactory.CreateEmpty(); _testAgentRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(testAgents)); // Act _testAgentStateSwitcher.SetTestAgentAsActiveAsync(FixtureFactory.Create().Create <string>()); // Assert _testAgentRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny <int>(), It.IsAny <TestAgentDto>()), Times.Never); }
public static List <Fixture> AttachCompoundPolygon(this Body body, List <Vertices> list, float density) { for (var i = 0; i < list.Count; i++) { var vertices = list[i]; for (var j = 0; j < vertices.Count; j++) { vertices[j] = FSConvert.DisplayToSim * vertices[j]; } } return(FixtureFactory.AttachCompoundPolygon(list, density, body)); }