示例#1
0
        /// <summary>
        /// Updates which ladder si the current one.
        /// </summary>
        protected void updateLadder()
        {
            if (Ladder != null && !IsLadderInRange(Ladder))
            {
                Ladder = null;
                LastLadder = null;
            }

            if (Ladder == null)
            {
                foreach (Element i in scene.Elements)
                {
                    if (i as Ladder != null && IsLadderInRange((Ladder)i))
                    {
                        Ladder = (Ladder)i;
                        break;
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Returns if the ladder close enough to climb or not
        /// </summary>
        public bool IsLadderInRange(Ladder ladder)
        {
            Vector2 headPosition = torso.Position;

            if (Math.Abs(headPosition.X - ladder.Position.X) < Conversion.ToWorld(40))
            {
                if (ladder.Position.Y - ladder.Height / 2 <= headPosition.Y - Height / 2 + 0.5f && headPosition.Y - 0.5f <= ladder.Position.Y + ladder.Height / 2)
                {
                    return true;
                }
            }
            return false;
        }
示例#3
0
 /// <summary>
 /// Checks if the characters position against the ladders position in order to see if the character
 /// is able to move up on the ladder.
 /// </summary>
 public bool IsLadderInRangeToGoUp(Ladder ladder)
 {
     Vector2 headPosition = torso.Position;
     if (Math.Abs(headPosition.X - ladder.Position.X) < Conversion.ToWorld(40))
         if (ladder.Position.Y - ladder.Height / 2 <= headPosition.Y - Height / 2)
             return true;
     return false;
 }
        public override void Update(GameTime gameTime)
        {
            if (Selection != null && IsFocusOnWindow())
            {
                float speed = Conversion.ToWorld(1);
                if (Keyboard.GetState().IsKeyDown(Keys.LeftShift))
                    speed = Conversion.ToWorld(20);

                if (Keyboard.GetState().IsKeyDown(Keys.OemBackslash))
                    speed = Conversion.ToWorld(0.02f);

                if (Keyboard.GetState().IsKeyDown(Keys.W))
                    Selection.Position = Selection.Position - Vector2.UnitY * speed;
                if (Keyboard.GetState().IsKeyDown(Keys.S))
                    Selection.Position = Selection.Position + Vector2.UnitY * speed;
                if (Keyboard.GetState().IsKeyDown(Keys.A))
                    Selection.Position = Selection.Position - Vector2.UnitX * speed;
                if (Keyboard.GetState().IsKeyDown(Keys.D))
                    Selection.Position = Selection.Position + Vector2.UnitX * speed;

                if (Keyboard.GetState().IsKeyDown(Keys.Add) && Keyboard.GetState().IsKeyDown(Keys.LeftControl))
                    Selection.Height = Selection.Height + speed;
                else if (Keyboard.GetState().IsKeyDown(Keys.Add))
                    Selection.Width = Selection.Width + speed;
                if (Keyboard.GetState().IsKeyDown(Keys.Subtract) && Keyboard.GetState().IsKeyDown(Keys.LeftControl))
                    Selection.Height = Math.Max(0.001f, Selection.Height - speed);
                else if (Keyboard.GetState().IsKeyDown(Keys.Subtract))
                    Selection.Width = Math.Max(0.001f, Selection.Width - speed);
                if (Keyboard.GetState().IsKeyDown(Keys.Delete) || Keyboard.GetState().IsKeyDown(Keys.Back))
                {
                    selection.Dispose();
                    Selection = null;
                }

                if (Keyboard.GetState().IsKeyDown(Keys.W) || Keyboard.GetState().IsKeyDown(Keys.S) || Keyboard.GetState().IsKeyDown(Keys.A) || Keyboard.GetState().IsKeyDown(Keys.D) ||
                    Keyboard.GetState().IsKeyDown(Keys.Add) || Keyboard.GetState().IsKeyDown(Keys.Subtract))
                {
                    form.Selection = selection;
                }
            }

            if (Mouse.GetState().LeftButton == ButtonState.Pressed && previous.LeftButton == ButtonState.Released && IsMouseInWindow(Mouse.GetState()))
            {
                Console.WriteLine(scene.Camera.ScreenToWorld(Mouse.GetState()));
                Element newSelection = null;
                List<Element> elements = new List<Element>();
                elements.AddRange(scene.Elements);
                foreach (Element i in elements)
                {
                    if (Vector2.Distance(scene.Camera.WorldToScreen(i.Position), new Vector2(Mouse.GetState().X, Mouse.GetState().Y)) < 8)
                    {
                        newSelection = i;
                        Console.WriteLine("Selected one at " + i.Position + ", Width " + i.Width + ", Height " + i.Height);
                        break;
                    }
                }
                if (newSelection != Selection)
                    Selection = newSelection;
                else
                    Selection = null;
            }

            if (Mouse.GetState().RightButton == ButtonState.Pressed && previous.RightButton == ButtonState.Released)
            {
                Element element = null;
                switch (form.NewElementType)
                {
                    case "Platform":
                        element = new Platform(Game, scene, scene.Camera.ScreenToWorld(previous), Vector2.One);
                        break;
                    case "Bridge":
                        element = new Bridge(Game, scene, scene.Camera.ScreenToWorld(previous), Vector2.One);
                        break;
                    case "Ladder":
                        element = new Ladder(Game, scene, 1, scene.Camera.ScreenToWorld(previous));
                        break;
                    case "Character":
                        element = new Character(Game, scene, scene.Camera.ScreenToWorld(previous));
                        scene.Camera.Target = element;
                        //scene.InputManager.Target = (Character)element;
                        break;
                }
                if (element != null)
                    scene.Elements.Add(element);

            }

            previous = Mouse.GetState();
        }