Example #1
0
 public void Update(GameTime gameTime)
 {
     if (!moving)
     {
         if (KeyMouseReader.KeyDown(Keybinds.binds["moveLeft"]))
         {
             animation.ChangeAnimationLoop("walk_left");
             ChangeDirection(new Vector2(-1, 0));
             rotation = MathHelper.ToRadians(-180);
         }
         if (KeyMouseReader.KeyDown(Keybinds.binds["moveRight"]))
         {
             animation.ChangeAnimationLoop("walk_right");
             ChangeDirection(new Vector2(1, 0));
             rotation = MathHelper.ToRadians(0);
         }
         if (KeyMouseReader.KeyDown(Keybinds.binds["moveUp"]))
         {
             animation.ChangeAnimationLoop("walk_up");
             ChangeDirection(new Vector2(0, -1));
             rotation = MathHelper.ToRadians(-90);
         }
         if (KeyMouseReader.KeyDown(Keybinds.binds["moveDown"]))
         {
             animation.ChangeAnimationLoop("walk_down");
             ChangeDirection(new Vector2(0, 1));
             rotation = MathHelper.ToRadians(-270);
         }
     }
     else
     {
         animation.Update(gameTime);
         Move(gameTime);
     }
 }
Example #2
0
        public override void Update(GameTime gameTime)
        {
            if (KeyMouseReader.KeyPressed(Keys.P))
            {
                ClickCounter++;

                switch (ClickCounter % 7)
                {
                case 0:
                    SelectedObject = ObjectEnum.Platform;
                    break;

                case 1:
                    SelectedObject = ObjectEnum.VerticalPlatform;
                    break;

                case 2:
                    SelectedObject = ObjectEnum.HorizontalPlatform;
                    break;

                case 3:
                    SelectedObject = ObjectEnum.SpikePlatform;
                    break;

                case 4:
                    SelectedObject = ObjectEnum.CloudPlatform;
                    break;

                case 5:
                    SelectedObject = ObjectEnum.IcePlatform;
                    break;

                case 6:
                    SelectedObject = ObjectEnum.FadingPlatform;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            if (KeyMouseReader.KeyPressed(Keys.U))
            {
                SelectedObject = ObjectEnum.Player;
            }
            if (KeyMouseReader.KeyPressed(Keys.G))
            {
                SelectedObject = ObjectEnum.Goal;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.E))
            {
                SelectedObject = ObjectEnum.Enemy;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.R))
            {
                SelectedObject = ObjectEnum.WalkingEnemy;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.C))
            {
                SelectedObject = ObjectEnum.None;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Q))
            {
                SelectedObject = ObjectEnum.UnlimitedPower;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.W))
            {
                SelectedObject = ObjectEnum.SlowWorld;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.H))
            {
                SelectedObject = ObjectEnum.HpGain;
            }
            if (KeyMouseReader.KeyPressed(Keys.S))
            {
                SaveToFile();
            }
            if (KeyMouseReader.KeyPressed(Keys.L))
            {
                ReadFromFile();
            }
            if (KeyMouseReader.KeyDown(Keys.Right))
            {
                CamPos.X += 1;
                CamPos.Y += 0;
            }
            else if (KeyMouseReader.KeyDown(Keys.Left))
            {
                CamPos.X += -1;
                CamPos.Y += 0;
            }

            if (KeyMouseReader.KeyDown(Keys.Up))
            {
                CamPos.X += 0;
                CamPos.Y += -1;
            }
            else if (KeyMouseReader.KeyDown(Keys.Down))
            {
                CamPos.X += 0;
                CamPos.Y += 1;
            }

            Cam.SetPos(CamPos);


            MousePosition = KeyMouseReader.MousePosition;
            var transform = Matrix.Invert(Cam.GetTransform());

            Vector2.Transform(ref MousePosition, ref transform, out MousePosition);

            PlacePosition = MousePosition;

            if (Objects.Count > 0 && SelectedObject != ObjectEnum.Player)
            {
                var closestObj = Objects[0];
                foreach (var obj in Objects)
                {
                    if (Vector2.Distance(obj.GetCenter(), MousePosition) <
                        Vector2.Distance(closestObj.GetCenter(), MousePosition))
                    {
                        closestObj = obj;
                    }
                }

                if (Vector2.Distance(closestObj.GetCenter(), MousePosition) < 25)
                {
                    PlacePosition = closestObj.GetCenter().X - MousePosition.X < 0
                        ? new Vector2(closestObj.Dest.Right, closestObj.Dest.Top)
                        : new Vector2(closestObj.Dest.Left - closestObj.Dest.Width, closestObj.Dest.Top);
                }
            }


            if (KeyMouseReader.LeftClick())
            {
                switch (SelectedObject)
                {
                case ObjectEnum.Platform:
                    Objects.Add(new Platform(PlacePosition, TextureManager.PlatformSpritesheet));
                    break;

                case ObjectEnum.VerticalPlatform:
                    Objects.Add(new VerticalPlatform(PlacePosition, TextureManager.PlatformSpritesheet));
                    break;

                case ObjectEnum.HorizontalPlatform:
                    Objects.Add(new HorizontalPlatform(PlacePosition, TextureManager.PlatformSpritesheet));
                    break;

                case ObjectEnum.SpikePlatform:
                    Objects.Add(new SpikePlatform(PlacePosition, TextureManager.PlatformSpritesheet));
                    break;

                case ObjectEnum.CloudPlatform:
                    Objects.Add(new CloudPlatform(PlacePosition, TextureManager.PlatformSpritesheet));
                    break;

                case ObjectEnum.IcePlatform:
                    Objects.Add(new IcePlatform(PlacePosition, TextureManager.PlatformSpritesheet));
                    break;

                case ObjectEnum.FadingPlatform:
                    Objects.Add(new FadingPlatform(PlacePosition, TextureManager.PlatformSpritesheet));
                    break;

                case ObjectEnum.Player:
                    Objects.Add(new Player(PlacePosition, TextureManager.NogardAbilitySpritesheet));
                    break;

                case ObjectEnum.Enemy:
                    Objects.Add(new BaseEnemy(MousePosition, TextureManager.EnemySpritesheet));
                    break;

                case ObjectEnum.WalkingEnemy:
                    Objects.Add(new StandardEnemy(MousePosition, TextureManager.EnemySpritesheet));
                    break;

                case ObjectEnum.FlyingEnemy:
                    Objects.Add(new FlyingEnemy(MousePosition, TextureManager.EnemySpritesheet));
                    break;

                case ObjectEnum.Goal:
                    Objects.Add(new Goal(PlacePosition, TextureManager.PlatformSpritesheet));
                    break;

                case ObjectEnum.None:
                    Objects.RemoveAll(item => Vector2.Distance(item.GetCenter(), MousePosition) < 25);
                    break;

                case ObjectEnum.UnlimitedPower:
                    Objects.Add(new UnlimitedPowerObject(PlacePosition, TextureManager.UnlimitedPowerTex));
                    break;

                case ObjectEnum.SlowWorld:
                    Objects.Add(new SlowWorldPowerObject(PlacePosition, TextureManager.SlowWorldTex));
                    break;

                case ObjectEnum.HpGain:
                    Objects.Add(new HealthGain(PlacePosition, TextureManager.HpGainTex));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }