Пример #1
0
        public override void Update(GameTime gameTime)
        {
            bool mapUpdate = false;

            target.X += (Mouse.GetState().X - mousePos.X) * MouseSpeed / 1000;
            target.Y += (Mouse.GetState().Y - mousePos.Y) * MouseSpeed / 1000;

            if (MathHelper.ToDegrees(target.Y) > 90)
            {
                target.Y = MathHelper.ToRadians(90);
            }
            else if (MathHelper.ToDegrees(target.Y) < -90)
            {
                target.Y = MathHelper.ToRadians(-90);
            }
            mousePos.X = Mouse.GetState().X;
            mousePos.Y = Mouse.GetState().Y;

            if (game.IsActive)
            {
                if (mousePos.X <= 0)
                {
                    mousePos.X = game.GraphicsDevice.Viewport.Width;
                    Mouse.SetPosition((int)mousePos.X, (int)mousePos.Y);
                }
                else if (mousePos.X >= game.GraphicsDevice.Viewport.Width)
                {
                    mousePos.X = 0;
                    Mouse.SetPosition((int)mousePos.X, (int)mousePos.Y);
                }

                if (mousePos.Y <= 0)
                {
                    mousePos.Y = 0;
                    Mouse.SetPosition((int)mousePos.X, (int)mousePos.Y);
                }
                else if (mousePos.Y >= game.GraphicsDevice.Viewport.Height)
                {
                    mousePos.Y = game.GraphicsDevice.Viewport.Height;
                    Mouse.SetPosition((int)mousePos.X, (int)mousePos.Y);
                }
            }

            Matrix forwardMovement = Matrix.CreateRotationY(target.X);
            KeyboardState state = Keyboard.GetState();
            if (state.IsKeyDown(Keys.W))
            {
                Vector3 v = new Vector3(0, 0, Speed);
                v = Vector3.Transform(v, forwardMovement);
                fppCamera.Move(v.X, v.Z);
                Move(v.X, v.Z);
                mapUpdate = true;
            }

            if (state.IsKeyDown(Keys.S))
            {
                Vector3 v = new Vector3(0, 0, -Speed);
                v = Vector3.Transform(v, forwardMovement);
                fppCamera.Move(v.X, v.Z);
                Move(v.X, v.Z);
                mapUpdate = true;
            }

            if (state.IsKeyDown(Keys.A))
            {
                Vector3 v = new Vector3(-Speed, 0, 0);
                v = Vector3.Transform(v, forwardMovement);
                fppCamera.Move(v.X, v.Z);
                Move(v.X, v.Z);
                mapUpdate = true;
            }

            if (state.IsKeyDown(Keys.D))
            {
                Vector3 v = new Vector3(Speed, 0, 0);
                v = Vector3.Transform(v, forwardMovement);
                fppCamera.Move(v.X, v.Z);
                Move(v.X, v.Z);
                mapUpdate = true;
            }

            if (Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                MouseClickLeft(ref mapUpdate);
            }
            else if (Mouse.GetState().LeftButton == ButtonState.Released)
            {
                clickingCount = 0;
                clickingCountPositive = true;
                clickingCube = null;
            }

            if (Mouse.GetState().RightButton == ButtonState.Pressed)
            {
                if (!rightPressed)
                {
                    rightPressed = true;
                    MouseClickRight();
                    mapUpdate = true;
                }
            }
            else if (Mouse.GetState().RightButton == ButtonState.Released)
            {
                rightPressed = false;
            }

            if (target != targetRemember)
            {
                mapUpdate = true;
                targetRemember = target;
            }

            UpdateItemInHand(state);

            fppCamera.Target = new Vector3(target.X, target.Y, 0);
            Rotate(target.X, target.Y);

            if (mapUpdate || map.Loading)
            {
                if (map.Loading)
                {
                    Debug.AddString("Loading");
                }

                map.Update(Position);
            }
        }
Пример #2
0
        private void MouseClickLeft(ref bool update)
        {
            if (clickingCountPositive)
            {
                clickingCount += 3;

                if (clickingCount > 20)
                {
                    clickingCount = 20;
                    clickingCountPositive = false;

                    Cube cube = (Cube)CheckClickedModel(map.GetNearestCubes(new Vector3(Position.X, Position.Y + 1, Position.Z)));
                    if (cube != null)
                    {
                        if (clickingCube == null || clickingCube != cube)
                        {
                            clickingCube = cube;
                        }

                        if (inHand != null)
                        {
                            inHand.Hit(clickingCube);
                            update = true;
                        }
                    }
                }
            }
            else
            {
                --clickingCount;

                if (clickingCount < 0)
                {
                    clickingCount = 0;
                    clickingCountPositive = true;
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Usuwa cuba z mapy
 /// </summary>
 /// <param name="cube"></param>
 public void DeleteCube(Cube cube)
 {
     memoryMap.DeleteCube(cube);
 }
Пример #4
0
        public void Hit(Cube cube)
        {
            if (Exists)
            {
                int hitPower = 0;
                short bonus = 0;

                foreach (Cube.Bonus bonusObject in cube.BonusObjects)
                {
                    if (bonusObject.type == this.GetType())
                    {
                        bonus = bonusObject.bonus;
                        break;
                    }
                }

                hitPower = Power + bonus;

                if (!(this is Cube))
                {
                    --life;
                }

                if (life <= 0)
                {
                    Exists = false;
                }

                cube.Life -= hitPower;
            }
        }
Пример #5
0
 /// <summary>
 /// Dodaje cuba do mapy
 /// </summary>
 /// <param name="cube"></param>
 public void AddCube(Cube cube)
 {
     memoryMap.AddCube(cube);
 }