Exemple #1
0
        /// <summary>
        /// Creates a new game to run in the program.
        /// </summary>
        /// <param name="title">The title of the window.</param>
        /// <param name="width">The width of the internal game resolution.</param>
        /// <param name="height">The height of the internal game resolution.</param>
        /// <param name="targetFramerate">The target framerate (for fixed framerate.)</param>
        /// <param name="fullscreen">Run the game in fullscreen.</param>
        public Game(string title = "Game", int width = 640, int height = 480, int targetFramerate = 60, bool fullscreen = false)
        {
#if Unix
            XInitThreads();
#endif

            Sessions = new List <Session>();
            Scenes   = new Stack <Scene>();
            Surfaces = new List <Surface>();

            GameOptions = new Dictionary <string, string>();
            ConfigFile  = new Dictionary <string, string>();

            QuitButton.AddKey(Key.Escape);

            cameraZoom       = 1;
            cameraAngle      = 0;
            Width            = width;
            Height           = height;
            Title            = title;
            WindowWidth      = width;
            WindowHeight     = height;
            WindowFullscreen = fullscreen;

            ShowDebugger = false;

            TargetFramerate = (int)Util.Clamp(targetFramerate, 999);

            Surface = new Surface(width, height);
            Surface.CenterOrigin();
            Surface.Game = this;

            AspectRatio = width / (float)height;

            Draw.Target     = Surface;
            Draw.GameTarget = Surface;

            Input      = new Input(this);
            DebugInput = new DebugInput(this);
            Coroutine  = new Coroutine(this);

            for (int i = 0; i < fpsLogSize; i++)
            {
                fpsTimes.Add(targetFramerate);
            }

            frameTime = 1000f / TargetFramerate;
            skipTime  = frameTime * 2;

#if DEBUG
            Console.WriteLine("[ Otter is running in debug mode! ]");
            Debugger = new Debugger(this);
#endif

            HasFocus = true;

            Instance = this;
        }
Exemple #2
0
        void UpdateSurfaceSize()
        {
            float width  = WindowWidth;
            float height = WindowHeight;

            if (ResizeToWindow)
            {
                Width  = (int)width;
                Height = (int)height;

                Surface.Resize(Width, Height);
                Surface.CenterOrigin();

                Surface.X = HalfWidth;
                Surface.Y = HalfHeight;
            }
            else
            {
                float newAspectRatio = width / height;

                if (LockAspectRatio)
                {
                    if (AspectRatio < newAspectRatio)
                    {
                        Surface.ScaleY = height / Surface.Height;
                        Surface.ScaleX = Surface.ScaleY;
                        Surface.X      = (width - Surface.ScaledWidth) * 0.5f + Surface.OriginX * Surface.ScaleX;
                        Surface.Y      = Surface.OriginY * Surface.ScaleY;
                    }
                    else
                    {
                        Surface.ScaleX = width / Surface.Width;
                        Surface.ScaleY = Surface.ScaleX;
                        Surface.Y      = (height - Surface.ScaledHeight) * 0.5f + Surface.OriginY * Surface.ScaleY;
                        Surface.X      = Surface.OriginX * Surface.ScaleX;
                    }
                }
                else
                {
                    Surface.ScaleX = width / Surface.Width;
                    Surface.ScaleY = height / Surface.Height;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Creates a new game to run in the program.
        /// </summary>
        /// <param name="title">The title of the window.</param>
        /// <param name="width">The width of the internal game resolution.</param>
        /// <param name="height">The height of the internal game resolution.</param>
        /// <param name="targetFramerate">The target framerate (for fixed framerate.)</param>
        /// <param name="fullscreen">Run the game in fullscreen.</param>
        public Game(string title    = "Game", int width = 640, int height = 480, int targetFramerate = 60,
                    bool fullscreen = false)
        {
#if Unix
            XInitThreads();
#endif

            Sessions = new List <Session>();
            Scenes   = new Stack <Scene>();
            Surfaces = new List <Surface>();

            SaveData              = new DataSaver(Filepath);
            OptionsData           = new DataSaver(Filepath);
            ConfigData            = new DataSaver(Filepath);
            ConfigData.ExportMode = DataSaver.DataExportMode.Config;
            GameFolder            = "ottergame";

            QuitButton.AddKey(Key.Escape);

            cameraZoom       = 1;
            cameraAngle      = 0;
            Width            = width;
            Height           = height;
            this.title       = title;
            WindowWidth      = width;
            WindowHeight     = height;
            WindowFullscreen = fullscreen;

            ShowDebugger = false;

            TargetFramerate = (int)Util.Clamp(targetFramerate, 999);

            Surface = new Surface(width, height);
            Surface.CenterOrigin();
            Surface.Game = this;

            AspectRatio = width / (float)height;

            Draw.Target     = Surface;
            Draw.GameTarget = Surface;

            Input      = new Input(this);
            DebugInput = new DebugInput(this);
            Coroutine  = new Coroutine(this);
            Tweener    = new Tweener();

            for (int i = 0; i < fpsLogSize; i++)
            {
                fpsTimes.Add(targetFramerate);
            }

            frameTime = 1000f / TargetFramerate;
            skipTime  = frameTime * 2;

#if DEBUG
            try
            {
                Console.Title = string.Format("{0} Debug Console ᶜ(ᵔᴥᵔ)ᵓ", title);
            }
            catch
            {
                // No console
            }

            Console.WriteLine("[ Otter is running in debug mode! ]");
            Debugger = new Debugger(this);
#endif

            HasFocus = true;

            Instance = this;
        }
Exemple #4
0
        internal void UpdateSurface()
        {
            renderSurface = new Surface((int)game.WindowWidth, (int)game.WindowHeight);
            renderSurface.CenterOrigin();
            renderSurface.X      = game.Surface.X;
            renderSurface.Y      = game.Surface.Y;
            renderSurface.Smooth = false;

            cameraMoveRate = (int)((renderSurface.Width + renderSurface.Height) * 0.5f * 0.1f);

            imgOverlay        = Image.CreateRectangle(renderSurface.Width, renderSurface.Height, Color.Black);
            imgOverlay.Scroll = 0;

            imgError        = Image.CreateRectangle(renderSurface.Width, renderSurface.Height, Color.Red);
            imgError.Scroll = 0;
            imgError.Alpha  = 0;

            float fontScale = Util.ScaleClamp(renderSurface.Height, 400, 800, 0.67f, 1);

            padding = (int)Util.Clamp(paddingMax * fontScale, paddingMax * 0.25f, paddingMax);

            textInput.FontSize            = (int)(textSizeLarge * fontScale);
            textPastCommands.FontSize     = (int)(textSizeMedium * fontScale);
            textPastCommandsLive.FontSize = (int)(textSizeMedium * fontScale);
            textCommandsBuffered.FontSize = (int)(textSizeSmall * fontScale);
            textCountdown.FontSize        = (int)(textSizeHuge * fontScale);
            textFramesLeft.FontSize       = (int)(textSizeMedium * fontScale);
            textPerformance.FontSize      = (int)(textSizeMedium * fontScale);
            textCamera.FontSize           = (int)(textSizeLarge * fontScale);

            imgOtter.Scale = fontScale;

            textFramesLeft.Y = renderSurface.Height - textFramesLeft.LineSpacing;

            textInput.Y = renderSurface.Height - textInput.LineSpacing - padding;
            textInput.X = padding;

            textCommandsBuffered.X = textInput.X;
            textCommandsBuffered.Y = textInput.Y + textInput.LineSpacing + 3;

            textAreaHeight = renderSurface.Height - padding * 3 - textInput.LineSpacing;

            maxLines = textAreaHeight / textPastCommands.LineSpacing;
            maxChars = (int)((renderSurface.Width - padding * 2) / (textInput.FontSize * 0.6));

            textPastCommands.Y = padding;
            textPastCommands.X = padding;

            textPastCommandsLive.Y = padding / 2;
            textPastCommandsLive.X = padding / 2;

            textCountdown.X = renderSurface.HalfWidth;
            textCountdown.Y = renderSurface.HalfHeight;

            imgScrollBarBg = Image.CreateRectangle(scrollBarWidth, textAreaHeight, Color.Black);
            imgScrollBar   = Image.CreateRectangle(scrollBarWidth, textAreaHeight, Color.White);

            imgScrollBarBg.X = renderSurface.Width - padding - imgScrollBarBg.Width;
            imgScrollBarBg.Y = padding;

            imgScrollBar.X = imgScrollBarBg.X;
            imgScrollBar.Y = imgScrollBarBg.Y;

            imgOtter.X = renderSurface.HalfWidth;
            imgOtter.Y = renderSurface.HalfHeight;

            imgScrollBar.Scroll   = 0;
            imgScrollBarBg.Scroll = 0;

            textCamera.CenterTextOrigin();
            textCamera.X = renderSurface.HalfWidth;
            textCamera.Y = renderSurface.Height - padding - textCamera.LineSpacing;
        }
        internal void UpdateSurface()
        {
            renderSurface = new Surface((int)game.WindowWidth, (int)game.WindowHeight);
            renderSurface.CenterOrigin();
            renderSurface.X = game.Surface.X;
            renderSurface.Y = game.Surface.Y;
            renderSurface.Smooth = false;

            cameraMoveRate = (int)((renderSurface.Width + renderSurface.Height) * 0.5f * 0.1f);

            imgOverlay = Image.CreateRectangle(renderSurface.Width, renderSurface.Height, Color.Black);
            imgOverlay.Scroll = 0;

            imgError = Image.CreateRectangle(renderSurface.Width, renderSurface.Height, Color.Red);
            imgError.Scroll = 0;
            imgError.Alpha = 0;

            float fontScale = Util.ScaleClamp(renderSurface.Height, 400, 800, 0.67f, 1);
            padding = (int)Util.Clamp(paddingMax * fontScale, paddingMax * 0.25f, paddingMax);

            textInput.FontSize = (int)(textSizeLarge * fontScale);
            textPastCommands.FontSize = (int)(textSizeMedium * fontScale);
            textCommandsBuffered.FontSize = (int)(textSizeSmall * fontScale);
            textCountdown.FontSize = (int)(textSizeHuge * fontScale);
            textFramesLeft.FontSize = (int)(textSizeMedium * fontScale);
            textPerformance.FontSize = (int)(textSizeMedium * fontScale);
            textCamera.FontSize = (int)(textSizeLarge * fontScale);

            imgOtter.Scale = fontScale;

            textFramesLeft.Y = renderSurface.Height - textFramesLeft.LineSpacing;
            textPerformance.Y = 0;

            textInput.Y = renderSurface.Height - textInput.LineSpacing - padding;
            textInput.X = padding;

            textCommandsBuffered.X = textInput.X;
            textCommandsBuffered.Y = textInput.Y + textInput.LineSpacing + 3;

            textAreaHeight = renderSurface.Height - padding * 3 - textInput.LineSpacing;

            maxLines = textAreaHeight / textPastCommands.LineSpacing;
            maxChars = (int)((renderSurface.Width - padding * 2) / (textInput.FontSize * 0.6));

            textPastCommands.Y = padding;
            textPastCommands.X = padding;

            textCountdown.X = renderSurface.HalfWidth;
            textCountdown.Y = renderSurface.HalfHeight;

            imgScrollBarBg = Image.CreateRectangle(scrollBarWidth, textAreaHeight, Color.Black);
            imgScrollBar = Image.CreateRectangle(scrollBarWidth, textAreaHeight, Color.White);

            imgScrollBarBg.X = renderSurface.Width - padding - imgScrollBarBg.Width;
            imgScrollBarBg.Y = padding;

            imgScrollBar.X = imgScrollBarBg.X;
            imgScrollBar.Y = imgScrollBarBg.Y;

            imgOtter.X = renderSurface.HalfWidth;
            imgOtter.Y = renderSurface.HalfHeight;

            imgScrollBar.Scroll = 0;
            imgScrollBarBg.Scroll = 0;

            textCamera.CenterOrigin();
            textCamera.X = renderSurface.HalfWidth;
            textCamera.Y = renderSurface.Height - padding - textCamera.LineSpacing;
        }