/// <summary> /// /// </summary> /// <param name="parent"></param> /// <param name="colorTexture"></param> public RenderableComponent_cl(Entity_cl parent, string colorTexture) : base(parent) { RenderableManager_cl.Instance.RegisterComponent(this); mParentEntity.AddComponent(this); mSprite = new SunburnSprite_cl(); mSprite.LoadContent(colorTexture); mSprite.InitSunburnStuff(); }
/// <summary> /// /// </summary> /// <param name="parent"></param> /// <param name="colorTexture"></param> /// <param name="normalMap"></param> /// <param name="offsetMap"></param> public RenderableComponent_cl(Entity_cl parent, string colorTexture, string normalMap, string offsetMap) : base(parent) { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // TODO: Add in a debug assert that the parent Entity has a PositionComponent. Make the RenderableComponent require that an Entity has // a PositionComponent before it can be added. // [JSD 09/28/11] ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RenderableManager_cl.Instance.RegisterComponent(this); mParentEntity.AddComponent(this); mSprite = new SunburnSprite_cl(); mSprite.LoadContent(colorTexture); mSprite.InitSunburnStuff(); }
/// <summary> /// /// </summary> /// <param name="parent"></param> public RenderableComponent_cl(Entity_cl parent) : base(parent) { RenderableManager_cl.Instance.RegisterComponent(this); mParentEntity.AddComponent(this); mSprite = new SunburnSprite_cl(); mSprite.InitSunburnStuff(); }
/// <summary> /// Constructor for deserialization. /// </summary> /// <param name="info">info is the serialization info to deserialize with</param> /// <param name="context">context is the context in which to deserialize...?</param> protected RenderableComponent_cl(SerializationInfo info, StreamingContext context) : base(info, context) { mSprite = (SunburnSprite_cl)info.GetValue("Sprite", typeof(SunburnSprite_cl)); //mSprite = new SunburnSprite_cl(); //mSprite.Rectangle = (FloatRectangle)info.GetValue("Rectangle", typeof(FloatRectangle)); //mSprite.Size = (Vector2)info.GetValue("SpriteSize", typeof(Vector2)); if (FNA.Game_cl.IsPlayingGame == true) { mSprite.LoadContent(mSprite.MaterialName); mSprite.InitSunburnStuff(); } }
/// <summary> /// /// </summary> public override void Initialize() { if (Game_cl.IsPlayingGame == true) { PositionComponent_cl positionComponent = ((PositionComponent_cl)mParentEntity.GetComponentOfType(typeof(PositionComponent_cl))); switch (mPhysicsType) { case PhysicsObjectType.RECTANGLE: mPhysicsBody = BodyFactory.CreateBody(PhysicsManager_cl.Instance.PhysicsWorld); mPhysicsBody.IgnoreGravity = !mUseGravity; mPhysicsFixture = FixtureFactory.AttachRectangle(mWidth, mHeight, 10, Vector2.Zero, mPhysicsBody); mPhysicsFixture.IsSensor = !mUseGravity; mPhysicsBody.BodyType = mIsStatic ? BodyType.Static : BodyType.Dynamic; mPhysicsFixture.Restitution = 0.0f; mPhysicsFixture.Friction = 0.5f; mPhysicsBody.AngularDamping = 1000.0f; SetPosition(positionComponent.Position3D); break; case PhysicsObjectType.CIRCLE: mPhysicsBody = BodyFactory.CreateBody(PhysicsManager_cl.Instance.PhysicsWorld); mPhysicsBody.IgnoreGravity = !mUseGravity; mPhysicsFixture = FixtureFactory.AttachCircle(mHeight / 2, 10, mPhysicsBody); mPhysicsFixture.IsSensor = !mUseGravity; mPhysicsBody.BodyType = mIsStatic ? BodyType.Static : BodyType.Dynamic; mPhysicsFixture.Restitution = 0.0f; mPhysicsFixture.Friction = 0.5f; SetPosition(positionComponent.Position3D); break; case PhysicsObjectType.CAPSULE: mPhysicsBody = BodyFactory.CreateBody(PhysicsManager_cl.Instance.PhysicsWorld); mPhysicsBody.IgnoreGravity = !mUseGravity; mPhysicsFixture = FixtureFactory.AttachCircle(mHeight / 6, 100, mPhysicsBody);// .AttachRectangle(mWidth, mHeight, 10, Vector2.Zero, mPhysicsBody); mPhysicsFixture.IsSensor = !mUseGravity; mPhysicsBody.BodyType = mIsStatic ? BodyType.Static : BodyType.Dynamic; mPhysicsFixture.Restitution = 0.0f; mPhysicsFixture.Friction = 0.5f; //JointFactory.CreateFixedRevoluteJoint(PhysicsManager_cl.Instance.PhysicsWorld, mPhysicsBody, Vector2.Zero, Vector2.Zero); mPhysicsObjectOffset = new Vector2(0, -2 * mHeight / 6); mPhysicsBody.AngularDamping = 1000.0f; SetPosition(positionComponent.Position3D); break; case PhysicsObjectType.FROM_TEXTURE: mIsTerrain = true; CreatePolygonFromTexture(mCollisionTexture); RenderableComponent_cl renderable = (RenderableComponent_cl)mParentEntity.GetComponentOfType(typeof(RenderableComponent_cl)); renderable.Sprite.Size = new Vector2(mPolygonTexture.Width, mPolygonTexture.Height) * mTextureToVerticesScale; SetPosition(positionComponent.Position3D); break; case PhysicsObjectType.PLAYER: Vector2 fixtureOffset = new Vector2(0, -0.20f); float fixtureDensity = 40.0f / (mWidth * mHeight); //we want a mass of 40kg mPhysicsBody = BodyFactory.CreateBody(PhysicsManager_cl.Instance.PhysicsWorld); mPhysicsFixture = FixtureFactory.AttachRectangle(mWidth, mHeight, fixtureDensity, fixtureOffset / 2, mPhysicsBody); mPhysicsBody.BodyType = mIsStatic ? BodyType.Static : BodyType.Dynamic; mPhysicsFixture.Restitution = 0.0f; mPhysicsFixture.Friction = 0.5f; SunburnSprite_cl rectangleSprite = new SunburnSprite_cl(); rectangleSprite.InitSunburnStuff(); rectangleSprite.LoadContent("debugRectangle"); rectangleSprite.Rectangle = new FloatRectangle(0, 0, 1, 1); rectangleSprite.Size = new Vector2(mWidth, mHeight); mDebugShapeMap.Add(new Vector3(0, -0.1f, -0.1f), rectangleSprite); mPhysicsBody.Inertia = 9999999999.0f; // resist rotation SetPosition(positionComponent.Position3D); /*Adding the falling sensor here */ mFallingFixture = FixtureFactory.AttachRectangle(mWidth, 1.75f, 0, new Vector2(0, -2.5f), mPhysicsBody); mFallingFixture.IsSensor = true; mFallingFixture.OnCollision += Fixture_OnCollision; mFallingFixture.UserData = mParentEntity; SunburnSprite_cl rectangleSprite2 = new SunburnSprite_cl(); rectangleSprite2.InitSunburnStuff(); rectangleSprite2.LoadContent("debugRectangle"); rectangleSprite2.Rectangle = new FloatRectangle(0, 0, 1, 1); rectangleSprite2.Size = new Vector2(mWidth, 1.75f); mDebugShapeMap.Add(new Vector3(0, -2.5f, -0.1f), rectangleSprite2); /*focus camera to player */ mPlayerPosition = ((PositionComponent_cl)mParentEntity.GetComponentOfType(typeof(PositionComponent_cl))); SunburnCameraComponent_cl camera = (SunburnCameraComponent_cl)CameraManager_cl.Instance.ActiveCamera; camera.FocusOnPlayer(mPlayerPosition); break; default: break; } } }