示例#1
0
        public void LoadContent(GraphicsDevice Graphics, ContentManager Content)
        {
            this.graphics = Graphics;
            //_vertexDeclaration = new VertexDeclaration(VertexPositionColor.VertexDeclaration.GetVertexElements());
            CameraController.Inialized(new Rectangle(Width / 3, Height / 3, Width / 3, Height / 3), EnvironmentVariable.graphics.GraphicsDevice);

            this.spriteFont = Content.Load<SpriteFont>("font/Hud");

            Texture2D texture = Content.Load<Texture2D>("textures/Idle");
            Player = new Character(texture, EnvironmentVariable.worldPhysic, EnvironmentVariable.content, CameraController.effect,new Vector2(0,20));

            Controller = new PlayerController();
        }
示例#2
0
        public static void update(Character player, GraphicsDevice graphics)
        {
            Vector2 positionTete = new Vector2();
            positionTete = player.ObjectPhysicCircleTete.FixtureObject.Body.Position;

            var onScreenPositon = graphics.Viewport.Project(new Vector3(positionTete, 0),
                                proj, view, Matrix.Identity);
            //Vector3 rightAndDownShift = onScreenPositon - new Vector3(Border.X + Border.Width, Border.Y + Border.Height, 0);
            //Vector3 leftAndUpShift = onScreenPositon - new Vector3(Border.X, Border.Y, 0);

            if (onScreenPositon.X > Border.X + Border.Width)
            {
                //camPosition = camPosition + new Vector3(onScreenPositon.X - Border.X - Border.Width, 0, 0);
                camPosition = camPosition + new Vector3((onScreenPositon.X - Border.X - Border.Width)/(Border.X/2), 0, 0);
            }
            if (onScreenPositon.X < Border.X)
            {
                //camPosition = camPosition + new Vector3(onScreenPositon.X - Border.X, 0, 0);
                camPosition = camPosition + new Vector3((onScreenPositon.X - Border.X) / (Border.X / 2), 0, 0);
            }
            //camPosition = new Vector3(positionTete.X, positionTete.Y, 0);
            cameraLookat = camPosition - new Vector3(0, 0, 1);

            View = Matrix.CreateLookAt(camPosition, cameraLookat, new Vector3(0.0f, 1.0f, 0.0f));

            Effect.View = view;
            EffectPlayer.View = view;
        }
示例#3
0
        public void UpdateInteraction(Character player, GraphicsDevice graphics)
        {
            gamePadState = GamePad.GetState(PlayerIndex.One);
            keyboardState = Keyboard.GetState();
            mouseState = Mouse.GetState();

            Player = player;

            Player.oldMoving        = Player.isMoving;
            Player.oldMovingRight   = Player.isMovingRight;
            Player.oldJumping       = Player.isJumping;
            Player.oldShooting      = Player.isShooting;

            Player.isMoving         = false;
            Player.isMovingRight    = false;
            Player.isJumping        = false;
            Player.isShooting       = false;

            if (gamePadState.IsButtonDown(Buttons.DPadLeft) ||
                keyboardState.IsKeyDown(Keys.Left) ||
                keyboardState.IsKeyDown(Keys.A))
            {
                InteractionLeft();

                Player.isMoving         = true;
                Player.isMovingRight    = false;
                Player.isJumping        = false;

            }
            if (gamePadState.IsButtonDown(Buttons.DPadRight) ||
                 keyboardState.IsKeyDown(Keys.Right) ||
                 keyboardState.IsKeyDown(Keys.D))
            {
                InteractionRight();

                Player.isMoving         = true;
                Player.isMovingRight    = true;
                Player.isJumping        = false;
            }
            if (keyboardState.IsKeyDown(Keys.S))
            {
                if (Player.bulletJuncture != null && Player.bulletJuncture.isHung)
                    InteractionButtonS();
            }
            if (gamePadState.IsButtonDown(Buttons.A) ||
                 keyboardState.IsKeyDown(Keys.Space) ||
                 keyboardState.IsKeyDown(Keys.W))
            {
                InteractionButtonA();

                Player.isMoving         = true;
                Player.isJumping        = true;
            }
            if (!(gamePadState.IsButtonDown(Buttons.DPadRight) ||
                 keyboardState.IsKeyDown(Keys.Right) ||
                 keyboardState.IsKeyDown(Keys.D)) && !(gamePadState.IsButtonDown(Buttons.DPadLeft) ||
                keyboardState.IsKeyDown(Keys.Left) ||
                keyboardState.IsKeyDown(Keys.A)))
            {
                Vector2 t1 = -Player.PlayerPhysic.FixtureObject.Body.LinearVelocity;
                Vector2 t2 = new Vector2(0.0f, 0.0f);
                //Player.PlayerPhysic.FixtureObject.Body.ApplyForce(ref t1, ref t2);
                if (Player.PlayerPhysic.FixtureObject.Body.LinearVelocity.Y > -0.01f && Player.PlayerPhysic.FixtureObject.Body.LinearVelocity.Y < 0.01f)
                    Player.PlayerPhysic.FixtureObject.Body.ResetDynamics();

                Player.isMoving         = false;
                Player.isMovingRight    = false;
                Player.isJumping        = false;
            }
            if (!gamePadState.IsConnected)
            {
                Vector2 positionTete = new Vector2();
                positionTete = Player.ObjectPhysicCircleTete.FixtureObject.Body.Position;

                var screenPositon = graphics.Viewport.Project(new Vector3(positionTete, 0),
                                    CameraController.proj, CameraController.view, Matrix.Identity);
                positionTete.X = screenPositon.X;
                positionTete.Y = screenPositon.Y;
                Vector2 diff = new Vector2(mouseState.X - positionTete.X, mouseState.Y - positionTete.Y);

                if(diff.X < 0)
                    Player.isMovingRight = false;
                else
                    Player.isMovingRight = true;

                Player.angleTir = -Math.Atan(diff.Y / diff.X);
                Player.distanceTir = (float)Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y);
            }
            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                Player.isShooting = true;
            }
            if (mouseState.RightButton == ButtonState.Pressed)
            {
                Player.isShooting = false;
                if (Player.bulletJuncture != null)
                {
                    Player.bulletJuncture.remove();
                    Player.bulletJuncture = null;
                }
            }
        }