コード例 #1
0
        public void Update(GameTime gameTime)
        {
            ComponentTransform temp     = _entityManager.GetEntity("testEntity").GetComponent <ComponentTransform>();
            ComponentPhysics   tempPhys = _entityManager.GetEntity("testEntity").GetComponent <ComponentPhysics>();

            //Vector2 tempPos = ((MouseInput.CurrentPos - temp.GetPos()).Normalized().MultiplyLength(100.0).MultiplyLength(gameTime.ElapsedGameTime.TotalSeconds));


            if (MouseInput.CheckLeftPressed())
            {
                temp.Pos = MouseInput.CurrentPos;
            }

            if (KeyboardInput.CheckIsKeyDown(Keys.A))
            {
                tempPhys.AddVelocity(new Vector2(-20.0f, 0.0f));
            }
            if (KeyboardInput.CheckIsKeyDown(Keys.D))
            {
                tempPhys.AddVelocity(new Vector2(20.0f, 0.0f));
            }
            if (KeyboardInput.CheckIsKeyDown(Keys.Space))
            {
                tempPhys.AddVelocity(new Vector2(0.0f, -30.0f));
            }

            _entityManager.Update(gameTime);

            if (KeyboardInput.CheckIsPressed(Keys.Escape))
            {
                Game1.State = State.MAIN_MENU;
            }
        }
コード例 #2
0
        public void Update(GameTime gameTime)
        {
            if (MouseInput.CheckLeftPressed())
            {
                if (_textPlay.IsClicked())
                {
                    Game1.State = State.PLAY;
                }
                else if (_textQuit.IsClicked())
                {
                    Game1.State = State.QUIT;
                }
                else if (_textTestMap.IsClicked())
                {
                    Game1.State = State.TEST_MAP;
                }
            }

            if (KeyboardInput.CheckIsPressed(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                Game1.State = State.QUIT;
            }
        }
コード例 #3
0
        public void Update(GameTime gameTime)
        {
            //float speed = 50.0f;
            float parallax = 0.075f;
            float dt       = (float)gameTime.ElapsedGameTime.TotalSeconds;

            ComponentTransform playerTransform = _entityManager.GetEntity("player").GetComponent <ComponentTransform>();
            ComponentPhysics   playerPhysics   = _entityManager.GetEntity("player").GetComponent <ComponentPhysics>();


            // _backgroundPosition.X -= dt * speed * parallax;
            // _entityManager.MoveAllBy(new Vector2(-dt * speed, 0.0f));
            // _position.X += dt * speed;



            if (KeyboardInput.CheckIsKeyDown(Microsoft.Xna.Framework.Input.Keys.A))
            {
                // _backgroundPosition.X += dt * speed * parallax;
                playerPhysics.Velocity = new Vector2(-300.0f, playerPhysics.Velocity.Y);
                //  _entityManager.MoveAllBy(new Vector2(dt * speed,0.0f));
                //   _position.X -= dt * speed;
                //playerTransform.Pos += new Vector2(dt * speed, 0.0f);
            }
            else if (KeyboardInput.CheckIsKeyDown(Microsoft.Xna.Framework.Input.Keys.D))
            {
                //   _backgroundPosition.X -= dt * speed * parallax;
                //playerPhysics.AddVelocity(new Vector2(speed, 0.0f));
                playerPhysics.Velocity = new Vector2(300.0f, playerPhysics.Velocity.Y);
                //  _entityManager.MoveAllBy(new Vector2(-dt * speed, 0.0f));
                //playerTransform.Pos += new Vector2(dt * speed, 0.0f);
                //    _position.X += dt * speed;
            }

            if (KeyboardInput.CheckIsPressed(Microsoft.Xna.Framework.Input.Keys.Space))
            {
                if (!playerPhysics.InAir)
                {
                    playerPhysics.Velocity = new Vector2(playerPhysics.Velocity.X, -450.0f);
                }
            }

            if (KeyboardInput.CheckIsKeyDown(Microsoft.Xna.Framework.Input.Keys.W))
            {
                //_backgroundPosition.Y += dt * speed * parallax;
                // _entityManager.MoveAllBy(new Vector2(0.0f, dt * speed));
                // playerPhysics.AddVelocity(new Vector2(0.0f, -speed));
                // _position.Y -= dt * speed;
            }
            else if (KeyboardInput.CheckIsKeyDown(Microsoft.Xna.Framework.Input.Keys.S))
            {
                //_backgroundPosition.Y -= dt * speed * parallax;
                // _entityManager.MoveAllBy(new Vector2(0.0f, -dt * speed));
                // playerPhysics.AddVelocity(new Vector2(0.0f, +dt * speed));

                // _position.Y += dt * speed;
            }

            Rectangle backgroundBounds = _textureBackground.Bounds;

            if (_backgroundPosition.X > 0)
            {
                _backgroundPosition.X -= backgroundBounds.Width;
            }
            else if (_backgroundPosition.X < -backgroundBounds.Width)
            {
                _backgroundPosition.X += backgroundBounds.Width;
            }
            if (_backgroundPosition.Y > 0)
            {
                _backgroundPosition.Y -= backgroundBounds.Height;
            }
            else if (_backgroundPosition.Y < -backgroundBounds.Height)
            {
                _backgroundPosition.Y += backgroundBounds.Height;
            }

            if (MouseInput.CheckLeftPressed())
            {
                _entityManager.GetEntity("warpBall").GetComponent <ComponentTransform>().Pos = playerTransform.Pos + new Vector2(0, -36.0f);
                ComponentPhysics ballPhys = _entityManager.GetEntity("warpBall").GetComponent <ComponentPhysics>();
                ballPhys.Velocity =
                    new Vector2(MouseInput.CurrentPos.X - playerTransform.Pos.X, MouseInput.CurrentPos.Y - playerTransform.Pos.Y)
                    .Normalized().MultiplyLength(500.0f);
            }

            if (KeyboardInput.CheckIsPressed(Microsoft.Xna.Framework.Input.Keys.E))
            {
                Entity warpBall = _entityManager.GetEntity("warpBall");
                if (!warpBall.GetComponent <ComponentPhysics>().InAir)
                {
                    Entity  player    = _entityManager.GetEntity("player");
                    Vector2 playerPos = player.GetComponent <ComponentTransform>().Pos;
                    playerPos    = warpBall.GetComponent <ComponentTransform>().Pos;
                    playerPos.Y -= 32;
                    playerPos.X += 16;
                    Vector2 vel = player.GetComponent <ComponentPhysics>().Velocity;
                    vel.Y = 0;
                    player.GetComponent <ComponentPhysics>().Velocity = vel;
                    player.GetComponent <ComponentTransform>().Pos    = playerPos;
                }
            }


            _entityManager.Update(gameTime);

            Vector2 delta = playerTransform.WorldTransform.Translate - _oldPlayerPos;



            _backgroundPosition.X += delta.X * parallax;
            _backgroundPosition.Y += delta.Y * parallax;

            _entityManager.MoveAllBy(new Vector2(-delta.X, -delta.Y));
            //playerTransform.Pos += new Vector2(delta.X, delta.Y);
            _position += new Vector2(delta.X, delta.Y);

            _oldPlayerPos = playerTransform.WorldTransform.Translate;
        }