public static PhysicWorld Instance() { if (instance == null) { instance = new PhysicWorld(); } return(instance); }
public virtual void Destroy() { pSprite = null; if (pBody != null) { Body b = pBody.GetBody(); if (b != null) { PhysicWorld.GetWorld().DestroyBody(pBody.GetBody()); } } pBody = null; }
//----------------------------------------------------------------------------- // Game::LoadContent() // Allows you to load all content needed for your engine, // such as objects, graphics, etc. //----------------------------------------------------------------------------- public override void LoadContent() { PhysicWorld.Instance(); GameManager.Instance(); ParticleSpawner.Instance(); AudioManager.Instance(); InputQueue.Instance(); OutputQueue.Instance(); MyClient.Instance(); prevTime = GetTime(); GameManager.Start(); }
//----------------------------------------------------------------------------- // Game::Update() // Called once per frame, update data, tranformations, etc // Use this function to control process order // Input, AI, Physics, Animation, and Graphics //----------------------------------------------------------------------------- // static int number = 0; public override void Update() { float curTime = GetTime(); float gameElapsedTime = curTime - prevTime; PhysicWorld.Update(gameElapsedTime); GameManager.Update(gameElapsedTime); InputManager.Update(); InputTest.KeyboardTest(); MyClient.Instance().Update(); OutputQueue.Process(); InputQueue.Process(); GameManager.CleanUp(); prevTime = curTime; }
//----------------------------------------------------------------------------- // Game::Update() // Called once per frame, update data, tranformations, etc // Use this function to control process order // Input, AI, Physics, Animation, and Graphics //----------------------------------------------------------------------------- // static int number = 0; public override void Update() { float curTime = GetTime(); float gameElapsedTime = curTime - prevTime; PhysicWorld.Update(gameElapsedTime); InputManager.Update(); CheckForInput(); GameManager.Update(gameElapsedTime); MyServer.Instance.Update(); InputQueue.Process(); OutputQueue.Process(); GameManager.CleanUp(); prevTime = curTime; }
public PhysicBody(PhysicBody_Data _data, GameObject gameObject) { float xMeters = PhysicWorld.PIXELSTOMETERS * _data.position.X; float yMeters = PhysicWorld.PIXELSTOMETERS * _data.position.Y; float sizeXMeters = PhysicWorld.PIXELSTOMETERS * _data.size.X; float sizeYMeters = PhysicWorld.PIXELSTOMETERS * _data.size.Y; BodyDef bodyDef = new BodyDef(); Debug.Assert(_data.shape_type != PHYSICBODY_SHAPE_TYPE.NULL); if (_data.shape_type == PHYSICBODY_SHAPE_TYPE.DYNAMIC_BOX) { bodyDef.Position.Set(xMeters, yMeters); pBody = PhysicWorld.GetWorld().CreateBody(bodyDef); pBody.AllowSleeping(false); pBody.SetFixedRotation(true); pBody.SetAngle(_data.angle * PhysicWorld.MATH_PI_180); PolygonDef shapeDef = new PolygonDef(); shapeDef.SetAsBox(sizeXMeters / 2, sizeYMeters / 2); shapeDef.Density = 1.0f; shapeDef.Friction = 0.0f; shapeDef.Restitution = 0.9f; shapeDef.UserData = gameObject; shapeDef.IsSensor = _data.isSensor; pBody.CreateFixture(shapeDef); } else if (_data.shape_type == PHYSICBODY_SHAPE_TYPE.DYNAMIC_CIRCLE) { bodyDef.Position.Set(xMeters, yMeters); pBody = PhysicWorld.GetWorld().CreateBody(bodyDef); pBody.SetAngle(_data.angle * PhysicWorld.MATH_PI_180); CircleDef circleDef = new CircleDef(); circleDef.Radius = _data.radius * PhysicWorld.PIXELSTOMETERS; circleDef.Density = 1.0f; circleDef.Friction = 0.0f; circleDef.Restitution = 0.9f; circleDef.LocalPosition = new Vec2(0f, 0f); circleDef.UserData = gameObject; circleDef.IsSensor = _data.isSensor; pBody.CreateFixture(circleDef); } else if (_data.shape_type == PHYSICBODY_SHAPE_TYPE.STATIC_BOX) { bodyDef.Position.Set(xMeters, yMeters); pBody = PhysicWorld.GetWorld().CreateBody(bodyDef); pBody.AllowSleeping(false); pBody.SetAngle(_data.angle * PhysicWorld.MATH_PI_180); PolygonDef shapeDef = new PolygonDef(); shapeDef.SetAsBox(sizeXMeters / 2, sizeYMeters / 2); shapeDef.UserData = gameObject; shapeDef.IsSensor = _data.isSensor; //shapeDef.Density = 1.0f; shapeDef.Friction = 0.0f; shapeDef.Restitution = 0.9f; pBody.CreateFixture(shapeDef); } else if (_data.shape_type == PHYSICBODY_SHAPE_TYPE.SHIP_MANIFOLD) { bodyDef.Position.Set(xMeters, yMeters); pBody = PhysicWorld.GetWorld().CreateBody(bodyDef); pBody.AllowSleeping(false); pBody.SetFixedRotation(true); pBody.SetAngle(_data.angle * PhysicWorld.MATH_PI_180); PolygonDef shapeDef = new PolygonDef(); shapeDef.VertexCount = 3; shapeDef.Vertices[0] = new Vec2(sizeXMeters / 2, 0); shapeDef.Vertices[1] = new Vec2(-sizeXMeters / 2, sizeYMeters / 2); shapeDef.Vertices[2] = new Vec2(-sizeXMeters / 2, -sizeYMeters / 2); shapeDef.UserData = gameObject; shapeDef.IsSensor = _data.isSensor; shapeDef.Density = 1.0f; shapeDef.Friction = 0.0f; shapeDef.Restitution = 0.9f; pBody.CreateFixture(shapeDef); } else { Debug.Assert(false, "You did not set the shape type"); } pBody.SetUserData(this); pBody.SetMassFromShapes(); }