Exemplo n.º 1
0
        protected override void Initialize()
        {
            inputManager = new InputComponent(this);
            Components.Add(inputManager);

            Audio.Initialize();

            //initaliser kamera
            Camera.ViewPortWidth = GraphicsDevice.Viewport.Width;
            Camera.ViewPortHeight = GraphicsDevice.Viewport.Height;
            Camera.WorldRectangle = GraphicsDevice.Viewport.Bounds;
            Camera.Position = new Vector2(0, Camera.WorldRectangle.Height - Camera.ViewPortHeight);

            //initialiser TileMap
            TileMap.EditorMode = false;
            TileMap.Initialize(Content.Load<Texture2D>(@"Textures\PlatformTiles"));
            TileMap.spriteFont = Content.Load<SpriteFont>(@"Fonts\Pericles8");

            base.Initialize();
        }
Exemplo n.º 2
0
        public void Update(GameTime gt, InputComponent input)
        {
            //oppdater animasjonen hvis man ikke trykke noen knapper
            CurrentAnimation = NextAnimation;

            //Animasjon av spilleren mot venstre
            if (input.KeyDown(Keys.Left))
            {
                CurrentAnimation = "runLeft";
                NextAnimation = "idleLeft";
                MoveLeft();
                facingRight = false;
            }

            //Animasjon av spilleren mot høyre
            if (input.KeyDown(Keys.Right))
            {
                CurrentAnimation = "runRight";
                NextAnimation = "idleRight";
                MoveRight();
                facingRight = true;
            }

            //hopplogikk
            if (!playerOnGround)
            {
                this.Position.Y += jumpspeed;
                jumpspeed++;

                if (CheckMapCollision())
                {
                    playerOnGround = true;
                    if (facingRight)
                    {
                        NextAnimation = "idleRight";
                    }
                    else
                    {
                        NextAnimation = "idleLeft";
                    }
                }
            }

            else
            {
                if (input.KeyDown(Keys.Up))
                {
                    if (facingRight)
                    {
                        CurrentAnimation = "jumpRight";
                        NextAnimation = "jumpRight";
                    }

                    else
                    {
                        CurrentAnimation = "jumpLeft";
                        NextAnimation = "jumpLeft";
                    }
                    playerOnGround = false;
                    jumpspeed = -15;
                }
            }

            int screenLocation = (int)Camera.WorldToScreen(new Vector2(this.Position.X, this.Position.Y)).X;

            if (screenLocation > 500)
            {
                Camera.Move(new Vector2(screenLocation - 500, 0));
            }

            if(screenLocation < 200)
            {
                Camera.Move(new Vector2(screenLocation - 200, 0));
            }

            base.Update(gt);
        }