Exemple #1
0
        public Engine(TCODConsole mainConsole)
        {
            instance  = this;
            isRunning = false;

            this.mainConsole = mainConsole;
            consoleWidth     = mainConsole.getWidth();
            consoleHeight    = mainConsole.getHeight();

            // Frame rate intialization
            TCODSystem.setFps(FRAME_RATE);
            internalTimer = new Stopwatch();
            MS_PER_UPDATE = 1000 / FRAME_RATE;

            renderer   = new Renderer();
            mainCamera = new Camera(20, 2, consoleWidth - 40, consoleHeight - 12);

            // Load blueprint data files
            data = new DataManager();
            data.LoadContent();

            // load data tables
            dataTables = new TableManager();
            dataTables.LoadData(TableManager.LoadDataFileList("DataTables.dir"));

#if ENTRY_GAME
            StartNewGame(null);
#else
            OpenMenu(new WindowMainMenu(0, 0, consoleWidth, consoleHeight, null, Window.EBorderStyle.NONE, null, null));
#endif
        }
 public ConsoleView()
 {
     RConsole.InitializeRootConsole((int)(1920d / 8 / 2), (int)(1080d / 8 / 2));
     TCODSystem.setFps(30);
     RConsole.RootConsole.SetBackgroundColour(TCODColor.black);
     RConsole.RootConsole.SetForegroundColour(TCODColor.white);
 }
Exemple #3
0
        /// <summary>
        /// Called after Application.Start has been called.  Override and place application specific
        /// setup code here after calling base method.
        /// </summary>
        /// <param name="info"></param>
        protected virtual void Setup(ApplicationInfo info)
        {
            if (!string.IsNullOrEmpty(info.Font))
            {
                TCODConsole.setCustomFont(info.Font, (int)info.FontFlags);
            }

            FpsLimit        = info.FpsLimit;
            _fpsFrameLength = FpsLimit == 0 ? 0 : MilliSecondsPerSecond / FpsLimit;
            _lastDrawMilli  = 0;

            UpdatesPerSecondLimit = info.UpdatesPerSecondLimit;
            _upsFrameLength       = UpdatesPerSecondLimit == 0 ? 0 : MilliSecondsPerSecond / UpdatesPerSecondLimit;
            _lastUpdateMilli      = 0;

            _delayFps = FpsLimit > UpdatesPerSecondLimit;

            TCODSystem.setFps(FpsLimit);

            TCODConsole.initRoot(info.ScreenSize.Width, info.ScreenSize.Height, info.Title,
                                 info.Fullscreen, info.RendererType);
            TCODConsole.setKeyboardRepeat(info.InitialDelay, info.IntervalDelay);

            TCODMouse.showCursor(true);

            if (SetupEventHandler != null)
            {
                SetupEventHandler(this, EventArgs.Empty);
            }

            Pigments = new PigmentMap(DefaultPigments.FrameworkDefaults,
                                      info.Pigments);
        }
Exemple #4
0
        private int Run()
        {
            if (StateCount <= 0)
            {
                Window win = new Window(new WindowTemplate());
                Push(win);
            }

            while (!TCODConsole.isWindowClosed() && !IsQuitting)
            {
                var newUpdateMilli    = TCODSystem.getElapsedMilli();
                var elapsedUpdateTime = newUpdateMilli - _lastUpdateMilli;
//				if (elapsedUpdateTime > upsFrameLength) {
                _lastUpdateMilli = newUpdateMilli;
                Update(elapsedUpdateTime);
//				}

                var newDrawMilli    = TCODSystem.getElapsedMilli();
                var elapsedDrawTime = newDrawMilli - _lastDrawMilli;
//				if (elapsedDrawTime > fpsFrameLength) {
                _lastDrawMilli = newDrawMilli;
                Draw(elapsedDrawTime);
//				}
            }

            return(0);
        }
Exemple #5
0
        private void PanelDraw(object sender, EventArgs e)
        {
            if ((!(sender is MapPanel)))
            {
                return;
            }
            var mapPanel  = (MapPanel)sender;
            var pointList = Bresenham.GeneratePointsFromLine(_origin, _selectedPosition, false).ToList();

            bool path = true;

            for (int i = 0; i < pointList.Count; i++)
            {
                var point = pointList[i];
                if (path)
                {
                    path = mapPanel.World.CurrentLevel.IsWalkable(point);
                }

                var adjusted = point - mapPanel.ViewOffset;
                if (i == pointList.Count - 1)
                {
                    mapPanel.Canvas.Console.setCharBackground(adjusted.X, adjusted.Y,
                                                              path ? ColorPresets.Green.TCODColor : ColorPresets.Red.TCODColor,
                                                              TCODSystem.getElapsedMilli() % 1000 > 500 ? TCODBackgroundFlag.Lighten : TCODBackgroundFlag.None);
                }
                else
                {
                    mapPanel.Canvas.Console.setCharBackground(adjusted.X, adjusted.Y,
                                                              path ? ColorPresets.Green.TCODColor : ColorPresets.Red.TCODColor,
                                                              TCODBackgroundFlag.Lighten);
                }
            }
        }
Exemple #6
0
 public static void InitDisplay()
 {
     TCODConsole.setCustomFont(font2, (int)TCODFontFlags.LayoutAsciiInRow, 16, 16);                       //Init font
     TCODSystem.setFps(30);                                                                               //Set draw speed
     TCODConsole.initRoot(CONSOLE_WIDTH, CONSOLE_HEIGHT, "Wizard's Peril", false, TCODRendererType.GLSL); //Init the console
     displayConsole = TCODConsole.root;
 }
Exemple #7
0
        public void Start()
        {
            isRunning = true;
            while (isRunning)
            {
                // Check for scene change
                if (sceneChanged)
                {
                    CurrentScene = newScene;
                    newScene     = null;
                    sceneChanged = false;
                }

                // Check if the game is still running.
                if (TCODConsole.isWindowClosed() || CurrentScene == null)
                {
                    Stop();
                    break;
                }

                // Update
                CurrentScene.Update(TCODSystem.getLastFrameLength());

                // Render
                TCODConsole.root.clear();
                CurrentScene.Render(TCODSystem.getLastFrameLength());
                TCODConsole.flush();

                // Handle user input
                CheckForKeyboardEvents();
                CheckForMouseEvents();
            }
            CleanUp();
        }
Exemple #8
0
        protected override void Redraw()
        {
            base.Redraw();

            var person = _player.Get <Creature>();
            int i      = 1;

            Canvas.PrintString(1, i++, _player.Get <Identifier>().Name);
            i++;
            PrintAttribute(1, i++, _player.Get <BodyComponent>().Health);
            PrintAttribute(1, i++, person.Stats["stat_stamina"]);
            PrintAttribute(1, i++, person.Stats["stat_composure"]);
            i++;
            PrintAttribute(1, i++, person.Stats["stat_energy"]);
            PrintAttribute(1, i++, person.Stats["stat_food"]);
            PrintAttribute(1, i++, person.Stats["stat_water"]);
            PrintAttribute(1, i++, person.Stats["stat_bladder"]);
            PrintAttribute(1, i++, person.Stats["stat_cleanliness"]);
            i++;
            i++;
            Canvas.PrintString(1, i++, String.Format("{0:0.00}", person.EncumbrancePenalty));
            Canvas.PrintString(1, i++, person.Posture.ToString());
            i++;
            i++;
            Canvas.PrintString(1, i++, _calendar.DateTime.ToShortDateString());
            Canvas.PrintString(1, i++, _calendar.DateTime.ToLongTimeString());
            i++;
            i++;
            i++;
            Canvas.PrintString(1, i++, String.Format("FPS: {0}", TCODSystem.getFps()));
        }
Exemple #9
0
        /// <summary>
        /// Get the size, in pixels, of a single character, as per TCODSystem.getCharSize().
        /// </summary>
        /// <returns></returns>
        static public Size GetCharSize()
        {
            int w, h;

            TCODSystem.getCharSize(out w, out h);

            return(new Size(w, h));
        }
Exemple #10
0
 static void Main(string[] args)
 {
     TCODConsole.initRoot(80, 50, "Z-Day", false);
     TCODSystem.setFps(30);
     TCODMouse.showCursor(false);
     Game.Current = new Game();
     Game.Current.Initialize();
     Game.Current.Play();
 }
Exemple #11
0
        private void createWindow()
        {
            int fontflags = (int)TCODFontFlags.Greyscale | (int)TCODFontFlags.LayoutAsciiInRow;

            TCODConsole.setCustomFont(FONT, fontflags);
            TCODConsole.setKeyboardRepeat(500, 5000 / TARGET_FPS);
            TCODConsole.initRoot(WINDOW_WIDTH / FONT_WIDTH, WINDOW_HEIGHT / FONT_HEIGHT, windowName, false, TCODRendererType.SDL);
            TCODSystem.setFps(CONTROL_FPS);

            terminalManager = new TerminalManager(WINDOW_WIDTH / FONT_WIDTH, WINDOW_HEIGHT / FONT_HEIGHT);
        }
Exemple #12
0
        // /////////////////////////////////////////////////////////////////////////////////

        // /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Called each iteration of the main loop (each frame).
        /// Override and add specific logic update code after calling base method.
        /// </summary>
        protected virtual void Update()
        {
            if (UpdateEventHandler != null)
            {
                UpdateEventHandler(this, EventArgs.Empty);
            }

            uint elapsed = TCODSystem.getElapsedMilli();

            CurrentWindow.OnTick();
            Input.Update(elapsed);
        }
Exemple #13
0
        public void printDebug()
        {
            GameTerminal debugTerminal = terminalManager.findTerminal("Debug");

            if (debugTerminal != null)
            {
                if (parent.debug)
                {
                    debugTerminal.clear((char)0, new RColor(255, 255, 255, 255), new RColor(0, 0, 0, 30));
                    debugTerminal.write("Playtime: " + string.Format("{0:0.00}", TCODSystem.getElapsedSeconds()) + " FPS: " + TCODSystem.getFps().ToString(), 1, 0, new RColor(255, 255, 255, 255), new RColor(0, 0, 0, 30));
                }
            }
        }
Exemple #14
0
 public void adjustFPS()
 {
     if (TCODSystem.getFps() < TARGET_FPS)
     {
         CONTROL_FPS++;
         TCODSystem.setFps(CONTROL_FPS);
     }
     else if (TCODSystem.getFps() > TARGET_FPS)
     {
         CONTROL_FPS--;
         TCODSystem.setFps(CONTROL_FPS);
     }
 }
Exemple #15
0
        static void Main()
        {
            TCODConsole.initRoot(80, 61, "Lights Out");
            TCODSystem.setFps(100);
            TCODConsole.setKeyboardRepeat(250, 100);
            Game game = new Game();

            game.Draw();
            while (!TCODConsole.isWindowClosed() && !game.Exit)
            {
                game.Update();
            }
        }
Exemple #16
0
        // Constructor
        public Window(string fontBitmap, int numberCharsHorz, int numberCharsVert, string windowTitle)
        {
            // Initialise the custom default font
            int           fontNumberCharsHorz = 16;
            int           fontNumberCharsVert = 16;
            TCODFontFlags flags = TCODFontFlags.LayoutAsciiInRow;

            TCODConsole.setCustomFont(fontBitmap, (int)flags, fontNumberCharsHorz, fontNumberCharsVert);

            // Set up the console dimensions
            TCODConsole.initRoot(numberCharsHorz, numberCharsVert, windowTitle, false, TCODRendererType.SDL);
            consoleWidth  = numberCharsHorz;
            consoleHeight = numberCharsVert;

            // Get the console handle
            rootConsole = TCODConsole.root;

            // Set the framerate;
            TCODSystem.setFps(30);

            // Initialise the Menu
            Menu[0] = "[S]tart a new Adventure ";
            Menu[1] = "[C]ontinue an existing Adventure";
            Menu[2] = "[Q]uit";

            // Initialise the Intro
            Intro[0]  = "A time was when we could live above ground.";
            Intro[1]  = "A time when life flourished on the surface,";
            Intro[2]  = "and all the races were warmed by the Sun.";
            Intro[3]  = String.Empty;
            Intro[4]  = "That time was no more. Darkness claimed the Earth.";
            Intro[5]  = "The pious extolled that we were punished by wrathful gods.";
            Intro[6]  = "Penance and pilgrimage to atone for our sins our only hope";
            Intro[7]  = "  at redemption.";
            Intro[8]  = String.Empty;
            Intro[9]  = "The sorcerers, the artificers, they sought other solutions.";
            Intro[10] = "Mystical archaic incantations or mechanical miracles from";
            Intro[11] = "  the minds of men.";
            Intro[12] = "That would bring back the Sun.";
            Intro[13] = "That would restore life to our world.";
            Intro[14] = String.Empty;
            Intro[15] = "The Sun is now but a memory, and hope fades along with the";
            Intro[16] = "  last of the heat.";
            Intro[17] = "Driving us further into the deep dark places in the Earth.";
            Intro[18] = "Monsters lurk in these caverns.";
            Intro[19] = "And men who have turned monster prey on their own kind.";
            Intro[20] = String.Empty;
            Intro[21] = "Welcome to the end of our time.";
            Intro[22] = "Welcome to Stygia...";
        }
Exemple #17
0
        private void PanelDraw(object sender, EventArgs e)
        {
            if (!(sender is MapPanel))
            {
                return;
            }

            var mapPanel = (MapPanel)sender;

            var adjusted = SelectedPosition - mapPanel.ViewOffset;

            mapPanel.Canvas.Console.setCharBackground(adjusted.X, adjusted.Y,
                                                      ColorPresets.Green.TCODColor,
                                                      TCODSystem.getElapsedMilli() % 1000 > 500 ? TCODBackgroundFlag.Lighten : TCODBackgroundFlag.None);
        }
Exemple #18
0
        public static int Main()
        {
            Console.WriteLine("Started Game");
            TCODSystem.setFps(30);
            engine.initialize(false);
            while (!TCODConsole.isWindowClosed() && !exit)
            {
                engine.update();
                engine.render();
            }



            Console.WriteLine("Game exited with code " + exitCode.ToString());
            return(exitCode);
        }
Exemple #19
0
        public void Initialize(BaseScene initialScene = null)
        {
            Logger.Initialize();
            windowTitle = "Emergence";
            Settings    = LoadSettings("Assets/config.json");
            if (Settings == null)
            {
                throw new Exception("Error loading config file.");
            }

            TCODConsole.setCustomFont($"Assets/Fonts/{Settings.Font}",
                                      (int)TCODFontFlags.LayoutAsciiInRow);
            TCODSystem.setFps(Settings.Fps);
            TCODConsole.initRoot(Settings.ScreenWidth, Settings.ScreenHeight,
                                 windowTitle, false, Settings.GetRendererType());
            previousMouseData = TCODMouse.getStatus();
            CurrentScene      = initialScene;
        }
Exemple #20
0
        static void Main()
        {
            TCODConsole.initRoot(80, 50, "my game", false);
            TCODSystem.setFps(25);
            bool endGame = false;

            while (!endGame && !TCODConsole.isWindowClosed())
            {
                TCODConsole.root.print(0, 0, "Hello, world");
                TCODConsole.flush();
                var key = TCODConsole.checkForKeypress();

                if (key.KeyCode == TCODKeyCode.Escape)
                {
                    endGame = true;
                }
            }
        }
Exemple #21
0
        // /////////////////////////////////////////////////////////////////////////////////

        // /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Called each application loop iteration.  Override to add specific update code.
        /// </summary>
        internal protected virtual void OnTick()
        {
            uint milli = TCODSystem.getElapsedMilli();

            LastTickElapsed = milli - TotalElapsed;
            TotalElapsed    = milli;

            if (Tick != null)
            {
                Tick(this, EventArgs.Empty);
            }

            if (scheduleList.Count > 0)
            {
                foreach (Schedule s in scheduleList)
                {
                    s.Update(LastTickElapsed);
                }
            }

            if (scheduleRemoveList.Count > 0)
            {
                foreach (Schedule s in scheduleRemoveList)
                {
                    scheduleList.Remove(s);
                }
                scheduleRemoveList.Clear();
            }

            if (scheduleAddList.Count > 0)
            {
                foreach (Schedule s in scheduleAddList)
                {
                    scheduleList.Add(s);
                }
                scheduleAddList.Clear();
            }
        }
Exemple #22
0
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (CurrentDomain_UnhandledException);
            TCODColor fogOfWarColour = new TCODColor(80, 80, 80);

            int horizontalPixels, verticalPixels;

            TCODSystem.getCurrentResolution(out horizontalPixels, out verticalPixels);

            //string font = "celtic_garamond_10x10_gs_tc.png";
            string font = "arial12x12.png";

            TCODConsole.setCustomFont(
                font,
                (int)(TCODFontFlags.Grayscale | TCODFontFlags.LayoutTCOD),
                32,
                8);

            int fontWidth, fontHeight;

            TCODSystem.getCharSize(out fontWidth, out fontHeight);

            int screenWidth  = horizontalPixels / fontWidth;
            int screenHeight = verticalPixels / fontHeight;



            var screenBounds = new Rectangle(0, 0, screenWidth,
                                             screenHeight);

            int infoPanelWidth = 42;
            var playBounds     = new Rectangle(0, 0, screenBounds.Width - infoPanelWidth, screenBounds.Height);
            var playerBounds   = new Rectangle(playBounds.Right, 0, infoPanelWidth, 6);
            //var threatBounds = new Rectangle(playBounds.Right, playerBounds.Bottom, infoPanelWidth, 10);
            var competitorBounds = new Rectangle(playBounds.Right, playerBounds.Bottom, infoPanelWidth, 27);
            var eventBounds      = new Rectangle(playBounds.Right, competitorBounds.Bottom, infoPanelWidth,
                                                 screenBounds.Height -
                                                 (playerBounds.Height + competitorBounds.Height));

            Game game = CreateGame();

            Logger.Info("Initializing RootConsole...");

            TCODConsole.initRoot(screenBounds.Width, screenBounds.Height, "Last Man Standing v1.0", true, TCODRendererType.SDL);

            TCODSystem.setFps(30);
            var rootConsole = TCODConsole.root;

            rootConsole.setForegroundColor(ColorPresets.White);
            rootConsole.setAlignment(TCODAlignment.LeftAlignment);
            rootConsole.setBackgroundFlag(TCODBackgroundFlag.Set);

            Logger.Info("Initializing playConsole...");
            TCODConsole playConsole = new TCODConsole(playBounds.Width, playBounds.Height);

            //Logger.Info("Initializing threatConsole...");
            //Console threatConsole = RootConsole.GetNewConsole(threatBounds.Width, threatBounds.Height);
            Logger.Info("Initializing playerConsole...");
            TCODConsole playerConsole = new TCODConsole(playerBounds.Width, playerBounds.Height);

            Logger.Info("Initializing competitorConsole...");
            TCODConsole competitorConsole = new TCODConsole(competitorBounds.Width, competitorBounds.Height);

            Logger.Info("Initializing eventsConsole...");
            TCODConsole eventsConsole = new TCODConsole(eventBounds.Width, eventBounds.Height);

            Logger.Info("Starting Game Loop...");
            do
            {
                TCODKey keyStroke = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);

                if (game.IsActive)
                {
                    game.ProcessTurn();

                    if (keyStroke.KeyCode != TCODKeyCode.NoKey)
                    {
                        ((PlayerAI)game.Player.Intellect).EvaluateKeyPress(keyStroke);
                    }
                }

                RenderAllConsoles(game, rootConsole, playConsole, fogOfWarColour, playerConsole,
                                  competitorConsole, eventsConsole, playBounds, playerBounds,
                                  competitorBounds, eventBounds);

                if (!game.IsActive)
                {
                    rootConsole.printEx((screenBounds.Width - 30) / 2, (screenBounds.Height - 10) / 2, TCODBackgroundFlag.Set,
                                        TCODAlignment.LeftAlignment, "Press SPACE to start a new game. Press ESC to quit.");
                    if (keyStroke.KeyCode == TCODKeyCode.Space)
                    {
                        rootConsole.print(1, 1, "Creating new game...");
                        TCODConsole.flush();
                        game = CreateGame();
                    }
                }

                TCODConsole.flush();

                if (keyStroke.KeyCode == TCODKeyCode.Escape)
                {
                    return;
                }
            } while (!TCODConsole.isWindowClosed());
        }