Inheritance: AbstractGameLoop
コード例 #1
0
ファイル: Program.cs プロジェクト: eropple/sharplike
        static void Main(String[] args)
        {
            AbstractWindow gameWindow;

            Game.Initialize();	// creates a game object pathed to the
                                // executable root

            using (Stream imgStream = File.OpenRead(Game.PathTo("curses_640x300.png")))
            {
                // create the glyph palette; specifies how many rows/cols there are
                GlyphPalette glyphPalette = new GlyphPalette(imgStream, 16, 16);

                // the size, in pixels, of the game window
                WindowDimensions = new Size(glyphPalette.GlyphDimensions.Width * WindowSize.Width,
                                                 glyphPalette.GlyphDimensions.Height * WindowSize.Height);
            #if !DEBUG
                try
                {
            #endif
                    Game.SetRenderSystem("OpenTK"); // no other render systems exist
                    gameWindow = Game.RenderSystem.CreateWindow(WindowDimensions, glyphPalette);
                    Game.SetInputSystem("OpenTK");
            //					Game.SetAudioSystem("OpenTK"); // audio still has trouble starting
            #if !DEBUG
                }
                catch (NullReferenceException e)
                {
                    Console.WriteLine("Exception in startup: " + e.ToString());
                    Console.ReadLine();
                    return;
                }
            #endif
            }

            // load the INI file with proper game configuration...
            Game.InputSystem.LoadConfiguration(Game.PathTo("commands.ini"));

            gameWindow.Clear();

            // Creates the core game state machine, and gives it the MainMenuState as a start state.
            // When we invoke the state machine, that will be the first state that pops up. The state
            // machine is one of Sharplike's most powerful concepts, and will save you a boatload of
            // time during development.
            StateMachine gameState = new StateMachine(new State.MainMenuState());

            StepwiseGameLoop gameLoop = new StepwiseGameLoop(gameState);
            Game.Run(gameLoop); // and off we go!
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: eropple/sharplike
        static void Main()
        {
            Game.Initialize(".");

            AbstractWindow gwin;

            String glyphPath = Game.PathTo("curses_640x300.png");
            using (Stream imgstream = File.OpenRead(glyphPath))
            {
                GlyphPalette pal = new GlyphPalette(imgstream, 16, 16);

                Int32 width = 80 * pal.GlyphDimensions.Width;
                Int32 height = 25 * pal.GlyphDimensions.Height;

                try
                {
                    Game.SetRenderSystem("OpenTK");
                    gwin = Game.RenderSystem.CreateWindow(new Size(width, height), pal);

                    Game.SetInputSystem("OpenTK");
                }
                catch (System.NullReferenceException e)
                {
                    Console.WriteLine("Error when loading plugin: " + e.Message + "\n" + e.Source);
                    return;
                }

            }

            Game.InputSystem.LoadConfiguration(Game.PathTo("commands.ini"));

            gwin.Clear();

            map = new MapStack(Game.RenderSystem.Window.WindowSize, 20, 15, "SandboxMap");
            map.AddPage(new YellowWallPage(map.PageSize), new Vector3(0, 0, 0));
            map.AddPage(new YellowWallPage(map.PageSize), new Vector3(1, 0, 0));
            map.AddPage(new YellowWallPage(map.PageSize), new Vector3(0, 1, 0));
            map.AddPage(new YellowWallPage(map.PageSize), new Vector3(1, 1, 0));
            map.AddPage(new YellowWallPage(map.PageSize), new Vector3(-1, 0, 0));
            map.AddPage(new YellowWallPage(map.PageSize), new Vector3(1, 1, 1));
            map.AddPage(new YellowWallPage(map.PageSize), new Vector3(-1, 0, 1));

            cache = new ZColdCachingAlgorithm(map);

            ent = new WanderingEntity();
            ent.Location = new Vector3(2, 2, 0);
            ent.Map = map;

            gwin.AddRegion(map);

            Sharplike.UI.Controls.Label l = new UI.Controls.Label(new Size(50, 1), new Point(0, 0));
            l.Text = "Label on the map.";
            map.AddRegion(l);

            Sharplike.UI.Controls.Window win = new UI.Controls.Window(new Size(20, 10), new Point(5, 5));
            win.Title = "Dialog Window";
            win.BackgroundColor = Color.FromArgb(100, 0, 0, 200);
            map.AddRegion(win);

            Game.OnGameInitialization += new EventHandler<EventArgs>(game_OnGameInitialization);
            Game.GameProcessing += new EventHandler<EventArgs>(game_GameProcessing);
            StepwiseGameLoop loop = new StepwiseGameLoop(RunGame);
            Game.Run(loop);

            Game.Terminate();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: eropple/sharplike
        static void Main()
        {
            Game.Initialize();

            AbstractWindow gwin;
            Assembly ea = Assembly.GetExecutingAssembly();

            using (Stream imgstream = ea.GetManifestResourceStream("Sharplike.Tests.TKTest.curses_640x300.png"))
            {
                GlyphPalette pal = new GlyphPalette(imgstream, 16, 16);

                Int32 width = 80 * pal.GlyphDimensions.Width;
                Int32 height = 25 * pal.GlyphDimensions.Height;

                try
                {
                    //game.SetAudioSystem("OpenTK");
                    Game.SetRenderSystem("OpenTK");
                    gwin = Game.RenderSystem.CreateWindow(new Size(width, height), pal);
                    Game.SetInputSystem("OpenTK");
                }
                catch (System.NullReferenceException e)
                {
                    Console.WriteLine("Error when loading plugin: " + e.Message + "\n" + e.Source);
                    return;
                }

            }

            //Game.Scripting.Run(Game.PathTo("Test.py"));
            //game.Scripting.Run(game.PathTo("Test.rb"));

            Game.InputSystem.LoadConfiguration(Game.PathTo("commands.ini"));
            Game.InputSystem.SaveConfiguration(Game.PathTo("commands.out.ini"));

            gwin.Clear();

            //ac.Play();
            Game.GameProcessing += new EventHandler<EventArgs>(game_GameProcessing);
            StepwiseGameLoop loop = new StepwiseGameLoop(RunGame);
            Game.Run(loop);

            Game.Terminate();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: eropple/sharplike
        static Boolean RunGame(StepwiseGameLoop loop)
        {
            CommandData cmd = null;
            do
            {
                map.BroadcastMessage(cameraVector, new Vector3(5, 5, 1), "Ping");

                cache.ActiveLevel = cameraVector.z;
                cache.AssessCache();

                cmd = loop.WaitForInput();
                Console.WriteLine(cmd.ToString());
                //if (ent != null)
                //	ent.Wander();
                switch (cmd.Command)
                {
                    case "move_left":
                        cameraVector = new Vector3(cameraVector.x - 1,
                                            cameraVector.y, cameraVector.z);
                        cameraMoved = true;
                        break;
                    case "move_right":
                        cameraVector = new Vector3(cameraVector.x + 1,
                                            cameraVector.y, cameraVector.z);
                        cameraMoved = true;
                        break;
                    case "move_up":
                        cameraVector = new Vector3(cameraVector.x,
                                            cameraVector.y - 1, cameraVector.z);
                        cameraMoved = true;
                        break;
                    case "move_down":
                        cameraVector = new Vector3(cameraVector.x,
                                            cameraVector.y + 1, cameraVector.z);
                        cameraMoved = true;
                        break;
                    case "move_in":
                        cameraVector = new Vector3(cameraVector.x,
                                            cameraVector.y, cameraVector.z + 1);
                        cameraMoved = true;
                        break;
                    case "move_out":
                        cameraVector = new Vector3(cameraVector.x,
                                            cameraVector.y, cameraVector.z - 1);
                        cameraMoved = true;
                        break;
                    case "spacebar":
                        ent.Dispose();
                        ent = null;
                        break;
                }
            } while (cmd.Command != "quit");

            return false;
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: eropple/sharplike
        static Boolean RunGame(StepwiseGameLoop loop)
        {
            CommandData cmd = null;
            do
            {
                cmd = loop.WaitForInput();
                Console.WriteLine(cmd.Command);
            } while (cmd.Command != "quit");

            return false;
        }