/// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="parent">The parent entity for this Component.</param>
        /// <note>The parent Entity MUST have a PositionComponent in order to construct this Component.</note>
        /// <note>The parent Entity MUST have an InputComponent in order to construct this Component.</note>
        public TheFinaleCameraComponent_cl(Entity_cl parent)
            : base(parent)
        {
            // Asserting here to ensure that the TheFinaleCameraComponent has all the required Components
            // These will be compiled out of the Release build
            Debug.Assert(mParentEntity.GetComponentOfType(typeof(PositionComponent_cl)) != null, "TheFinaleCameraComponent: No PositionComponent exists on parent Entity!");
            Debug.Assert(mParentEntity.GetComponentOfType(typeof(InputComponent_cl)) != null, "TheFinaleCameraComponent: No InputComponent exists on parent Entity!");

            mPositionComponent = (PositionComponent_cl)mParentEntity.GetComponentOfType(typeof(PositionComponent_cl));
            mInputComponent = (InputComponent_cl)mParentEntity.GetComponentOfType(typeof(InputComponent_cl));

            mInputComponent.AddKey("moveN", Keys.Up);
            mInputComponent.AddKey("moveW", Keys.Left);
            mInputComponent.AddKey("moveS", Keys.Down);
            mInputComponent.AddKey("moveE", Keys.Right);

            mInputComponent.AddKey("ShakeIt", Keys.N);

            // Items at the same position as the camera should appear at the bottom of the screen, horizontally centered
            mScreenOffsetMatrix = Matrix.CreateTranslation(new Vector3((float)Game_cl.BaseInstance.WindowWidth * 0.5f, (float)Game_cl.BaseInstance.WindowHeight, 0));

            RecalculateTransformationMatrix();
        }
Beispiel #2
0
        /// <summary>
        /// 
        /// </summary>
        protected override void Initialize()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            mSpriteBatch = new SpriteBatch(GraphicsDevice);

            mDebugFont = Content.Load<SpriteFont>("Fonts\\DebugFont");

            PositionComponent_cl cameraPosition = new PositionComponent_cl(mCameraEntity, 0, 0);

            /************************************************************************
             * HACK:
             * We're using Sunburn now, so the camera's getting changed to the SunburnCameraComponent_cl.
             * Is this really a hack? At what point do we say Sunburn is official, or do we always want
             * backward compatibility with the original FNA?
             *
             * Larsson Burch - 2011/11/11 - 10:07
             ************************************************************************/
            SunburnCameraComponent_cl cameraComponent = new SunburnCameraComponent_cl(mCameraEntity);
            cameraComponent.ViewWidth = 30.0f;

            mManagers.Add(RenderableManager_cl.Instance);
            mManagers.Add(TriggerManager_cl.Instance);
            mManagers.Add(CameraManager_cl.Instance);
            mManagers.Add(PartyManager_cl.Instance);

            this.IsMouseVisible = true;

            #if WORLD_EDITOR
            mManagers.Add(EditingManager_cl.Instance);
            #endif

            base.Initialize();
        }
Beispiel #3
0
        /// <summary>
        /// Constructor.
        /// Automagically adds a PositionComponent with given position.
        /// </summary>
        /// <param name="x">Initial X position of the Entity.</param>
        /// <param name="y">Initial Y position of the Entity.</param>
        public Entity_cl(float x, float y)
        {
            mUniqueID = EntityManager_cl.Instance.RegisterNewEntity(this);
            mName = "Entity" + mUniqueID;

            // Initialize all component slots to null (empty)
            //for (int i = 0; i < mComponents.Length; i++)
            //{
            //    mComponents[i] = null;
            //}

            PositionComponent_cl pc = new PositionComponent_cl(this, x, y);
        }
Beispiel #4
0
        /// <summary>
        /// 
        /// </summary>
        public void InitializePhysics(PhysicsObjectType type)
        {
            PositionComponent_cl positionComponent = ((PositionComponent_cl)mParentEntity.GetComponentOfType(typeof(PositionComponent_cl)));

            switch(type)
            {
                case PhysicsObjectType.RECTANGLE:
                    mPhysicsBody = BodyFactory.CreateBody(PhysicsManager_cl.Instance.PhysicsWorld);
                    mPhysicsFixture = FixtureFactory.AttachRectangle(mWidth, mHeight, 10, Vector2.Zero, mPhysicsBody);
                    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);
                    mPhysicsFixture = FixtureFactory.AttachCircle(mHeight / 2, 10, mPhysicsBody);
                    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);
                    mPhysicsFixture = FixtureFactory.AttachCircle(mHeight / 6, 100, mPhysicsBody);// .AttachRectangle(mWidth, mHeight, 10, Vector2.Zero, mPhysicsBody);
                    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.0f, 0, new Vector2(0, -2.0f), 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;
            }

            /************************************************************************
             * HACK:
             * Setting the physics rotation off of the position component's rotation.
             *
             * Larsson Burch - 2011/12/02 - 13:29
             ************************************************************************/
            mPhysicsBody.Rotation = -positionComponent.Rotation;
        }