Beispiel #1
0
        /// <summary>
        /// Construct an instance of the GameManager
        /// </summary>
        /// <param name="surface">Bitmap that the GameManager will render the scene to</param>
        public GameManager(Bitmap surface, Picturebox host)
        {
            if (surface == null)
              throw new ArgumentNullException("surface");
              if (surface == null)
              throw new ArgumentNullException("host");

              Surface = surface;
              Host = host;
              Enabled = true;
              InputManager = new Input.InputManager();
              Game = this;
        }
Beispiel #2
0
        protected override void SelfRender(float elapsedms, GraphicsDevice g, SpriteBatch sb, Input.InputManager input, float dx, float dy)
        {
            if (PressedTimer > 0)
            {
                PressedTimer--;
            }

            eUIButtonState state = GetState(dx, dy, input);

            if (state == eUIButtonState.HOVER)
            {
                input.Cursor.TrySet(eCursorState.CLICKABLE);
            }
            if (state == eUIButtonState.PRESSED && Hovering(dx, dy, input) && PressedTimer > 0)
            {
                input.Cursor.TrySet(eCursorState.DOWN);
            }

            if (HasBackground)
            {
                Color bc = BackgroundColor;
                switch (state)
                {
                case eUIButtonState.NORMAL:
                    break;

                case eUIButtonState.HOVER:
                    bc = HoverColor;
                    break;

                case eUIButtonState.DISABLED:
                    bc = DisabledColor;
                    break;

                case eUIButtonState.PRESSED:
                    bc = PressedColor;
                    break;

                default:
                    break;
                }
                if (!HoverBackgroundOnly || (state == eUIButtonState.HOVER && HoverBackgroundOnly))
                {
                    Draw.DrawRectangleHandle(sb, (int)dx, (int)dy, Width, Height, bc);
                }
            }

            // render images
            Rectangle irect;
            Color     icol;

            switch (state)
            {
            case eUIButtonState.NORMAL:
                irect = NormalRect;
                icol  = TextureColor;
                break;

            case eUIButtonState.HOVER:
                irect = HoverRect;
                icol  = TextureHoverColor;
                break;

            case eUIButtonState.DISABLED:
                irect = DisabledRect;
                icol  = TextureDisabledColor;
                break;

            case eUIButtonState.PRESSED:
                irect = PressedRect;
                icol  = TexturePressedColor;
                break;

            default:
                irect = NormalRect;
                icol  = TextureColor;
                break;
            }
            sb.Draw(Texture,
                    new Rectangle((int)dx + TextureOffsetX, (int)dy + TextureOffsetY,
                                  irect.Width + TextureOffsetW, irect.Height + TextureOffsetH),
                    irect, icol);

            if (TextLines.Count > 0)
            {
                Color tc = TextColor;
                switch (state)
                {
                case eUIButtonState.NORMAL:
                    break;

                case eUIButtonState.HOVER:
                    tc = HoverTextColor;
                    break;

                case eUIButtonState.DISABLED:
                    tc = DisabledTextColor;
                    break;

                case eUIButtonState.PRESSED:
                    tc = PressedTextColor;
                    break;

                default:
                    break;
                }
                int textheight = SFont.LineSpacing * TextLines.Count;
                int diff       = Height - textheight;
                int mod        = TextOffsetY;
                if (diff > 0)
                {
                    mod += diff / 2;
                }
                int textwidth = TextHelper.GetWidth(SFont, TextLines[0], FontSettings);
                int wdiff     = Width - textwidth;
                int wmod      = TextOffsetX;
                if (wdiff > 0)
                {
                    if (Justified == eUIJustify.CENTER)
                    {
                        wmod += wdiff / 2;
                    }
                    else if (Justified == eUIJustify.LEFT)
                    {
                        wmod += BorderWidth * 2; // add some spacing so it doesn't go off the edge by default
                    }
                    else if (Justified == eUIJustify.RIGHT)
                    {
                        wmod += wdiff - BorderWidth * 2;
                    }
                }
                FontSettings.Color = tc;
                for (int i = 0; i < TextLines.Count; i++)
                {
                    Draw.DrawText(g, sb, SFont, wmod + dx, mod + dy + i * SFont.LineSpacing, TextLines[i], FontSettings);
                }
            }
            if (HasBorder)
            {
                Draw.DrawRectangleHandleOutline(sb, (int)dx, (int)dy, Width, Height, BorderColor, BorderWidth);
            }
        }
Beispiel #3
0
        void UpdateLoop()
        {
            WaitHandle.WaitAll(new WaitHandle[] { RendererReady });

            Physics.Resources.ResourceLoaders.Init(CoreResources, FileSystem);
            Physics.Resources.ResourceLoaders.Init(GameResources, FileSystem);

            DeferredRenderer = new Graphics.Deferred.DeferredRenderer(CoreResources, GraphicsBackend, GraphicsBackend.Width, GraphicsBackend.Height);
            PostEffectManager = new Graphics.Post.PostEffectManager(FileSystem, CoreResources, GraphicsBackend, GraphicsBackend.Width, GraphicsBackend.Height);

            AudioSystem = new Audio.AudioSystem(FileSystem);
            PhysicsWorld = new Triton.Physics.World(GraphicsBackend, GameResources);

            Stage = new Graphics.Stage(GameResources);
            Camera = new Graphics.Camera(new Vector2(GraphicsBackend.Width, GraphicsBackend.Height));

            InputManager = new Input.InputManager(Window.Bounds);

            GameWorld = new World.GameObjectManager(Stage, InputManager, GameResources, PhysicsWorld, Camera);

            LoadCoreResources();

            // Wait until all initial resources have been loaded
            while (!CoreResources.AllResourcesLoaded())
            {
                Thread.Sleep(1);
            }

            Log.WriteLine("Core resources loaded");

            LoadResources();

            while (!GameResources.AllResourcesLoaded())
            {
                Thread.Sleep(1);
            }

            var watch = new System.Diagnostics.Stopwatch();
            watch.Start();

            var accumulator = 0.0f;

            while (Running)
            {
                FrameCount++;
                watch.Restart();

                ElapsedTime += FrameTime;

                if (Window.Focused)
                {
                    InputManager.Update();
                }

                accumulator += FrameTime;
                while (accumulator >= PhysicsStepSize)
                {
                    PhysicsWorld.Update(PhysicsStepSize);
                    accumulator -= PhysicsStepSize;
                }

                AudioSystem.Update();

                GameWorld.Update(FrameTime);

                Update(FrameTime);

                RenderScene(FrameTime, watch);
                FrameTime = (float)watch.Elapsed.TotalSeconds;

                Thread.Sleep(1);
            }
        }