Exemplo n.º 1
0
        protected override void PreUpdate()
        {
            _background.Transform.Translate2D(new Vector2(-16, -16) * Time.DeltaTime * _defaultZoom);

            if (InputManager.Instance.MouseKeyHeld(MouseKey.LeftMouse))
            {
                DefaultCamera.Parent.Transform.Translate2D((InputManager.Instance.MouseDelta * new Vector2(0, GraphicsManager.Instance.Height)) / DefaultCamera.Zoom / Config.ConfigValues.PixelSize);

                _audio.Play();
                _audio.Loop(true);
            }

            DefaultCamera.Zoom = _defaultZoom + JMath.Clamp(JMath.Sin(Time.TotalSeconds * JMath.TWO_PI * (BPM / 60)), 0, 1) * 0.025f;

            if (DefaultCamera.Parent.Transform.Position2D.Y > 0)
            {
                DefaultCamera.Parent.Transform.Position2D = new Vector2(DefaultCamera.Parent.Transform.Position2D.X, 0);
            }

            if (DefaultCamera.Parent.Transform.Position2D.Y < _lowestScroll)
            {
                DefaultCamera.Parent.Transform.Position2D = new Vector2(DefaultCamera.Parent.Transform.Position2D.X, _lowestScroll);
            }

            _title.Transform.Rotation2D = JMath.Sin(Time.TotalSeconds) * (JMath.PI_OVER_TWO / 16);
            _start.Transform.Rotation2D = JMath.Sin(Time.TotalSeconds + 1) * (JMath.PI_OVER_TWO / 16);
        }
Exemplo n.º 2
0
        protected override void InitializeScene()
        {
            ScaleGame();

            Text text = new Text(GUI.Root);

            text.Pivot        = UIDefaults.TopCenter;
            text.Anchor       = UIDefaults.TopCenter;
            text.ShadowOffset = new Point(1, -1);
            text.DisplayText  = "Created by Mathijs Koning and Thom Zeilstra for Ludum Dare 48";
            text.ResizeToText(16);

            _background = AddGameObject("Background");
            TileMap map = _background.AddComponent <TileMap>();

            map.TileSize     = 16;
            map.MapData      = ResourceManager.Load <Texture2D>("Textures/backgroundData.png");
            map.MapData.Wrap = Texture2D.WrapMode.Repeat;
            map.Sprites      = ResourceManager.Load <Texture2D>("Textures/background.png");

            _audio = _background.AddComponent <AudioComponent>();
            _audio.SetAudioClip(ResourceManager.Load <AudioClip>("Sounds/menu.mp3"));
            _audio.Play();
            _audio.Loop(true);

            _title = AddGameObject("Title");
            _title.Transform.Position2D = new Vector2(0, 64);
            Sprite titleSprite = _title.AddComponent <Sprite>();

            titleSprite.Texture = ResourceManager.Load <Texture2D>("Textures/Title.png");
            titleSprite.Offset  = new Vector2(-titleSprite.Texture.Width / 2, -titleSprite.Texture.Height / 2);
            titleSprite.Size    = new Vector2(2, 2);

            _leaderboardText             = AddGameObject().AddComponent <TextComponent>();
            _leaderboardText.Alignment   = TextAlignment.Center;
            _leaderboardText.DisplayText = "Loading leaderboard...";
            _leaderboardText.Color       = Color.Black;

            _leaderboardText.Parent.Transform.Position2D = new Vector2(0, -48);

            _nameText             = AddGameObject().AddComponent <TextComponent>();
            _nameText.Alignment   = TextAlignment.Center;
            _nameText.DisplayText = "Logging in...";
            _nameText.Color       = Color.Black;

            UIElement ui = new EmptyUIElement(GUI.Root);

            ui.Dimensions = new Vector2(128, 16) * _defaultZoom * 2;
            ui.Pivot      = UIDefaults.BottomCenter;

            ui.OnMouseUp += (ev) =>
            {
                AskUsername("Leaderboard user name:");
            };

            ui.OnMouseEnter += (ev) =>
            {
                _nameText.Color = Color.White;
            };

            ui.OnMouseExit += (ev) =>
            {
                _nameText.Color = Color.Black;
            };

            UIComponent uiComp = _nameText.Parent.AddComponent <UIComponent>();

            uiComp.Setup(ui, this);

            _nameText.Parent.Transform.Position2D = new Vector2(0, 16);

            EmptyUIElement startelement = new EmptyUIElement(GUI.Root);

            startelement.Dimensions = new Vector2(80, 20) * _defaultZoom * 2;
            startelement.Pivot      = UIDefaults.Centered;

            startelement.OnMouseEnter += (ev) =>
            {
                CoroutineManager.StartCoroutine(DefaultRoutines.Linear(0.3f, (x) =>
                {
                    _start.GetComponent <Sprite>().Size = new Vector2(1, 1) * (1 + Easings.CircularEaseOut(x) / 4.0f);
                }));
            };

            startelement.OnMouseExit += (ev) =>
            {
                CoroutineManager.StartCoroutine(DefaultRoutines.Linear(0.3f, (x) =>
                {
                    _start.GetComponent <Sprite>().Size = new Vector2(1, 1) * (1 + Easings.QuadraticEaseOut(1.0f - x) / 4.0f);
                }));
            };

            startelement.OnMouseUp += (x) =>
            {
                if (PlayfabManager.Identity.Username == null)
                {
                    AskUsername("Leaderboard user name:");
                }
                else
                {
                    SceneManager.SwitchToScene(new MainScene(ResourceManager));
                }
            };

            _start = AddGameObject("Start");
            _start.Transform.Position2D = new Vector2(0, 0);

            _start.AddComponent <UIComponent>().Setup(startelement, this);

            Sprite startSprite = _start.AddComponent <Sprite>();

            startSprite.Texture         = ResourceManager.Load <Texture2D>("Textures/buttons.png");
            startSprite.SourceRectangle = new Rectangle(0, 0, 128, 20);
            startSprite.Offset          = new Vector2(-35, -9);

            Login();
        }