Esempio n. 1
0
        /// <summary>
        /// Updates all the routines.  The coroutine in the Game automatically runs this.
        /// </summary>
        public void Update()
        {
            Instance = this;

            for (int i = 0; i < routines.Count; i++) {
                if (routines[i].Current is IEnumerator)
                    if (MoveNext((IEnumerator)routines[i].Current))
                        continue;
                if (!routines[i].MoveNext())
                    routines.RemoveAt(i--);
            }

            events.Clear();
        }
Esempio n. 2
0
 internal Coroutine(Game game)
 {
     this.game = game;
     Instance = this;
 }
Esempio n. 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;
        }