Exemplo n.º 1
0
        /// <summary>
        /// Initializes this <see cref="IGameState"/> with references to the game
        /// engine and animation store repository instances.
        /// </summary>
        /// <param name="gameReference">
        /// A reference to the game engine instance.
        /// </param>
        /// <param name="animationStore">
        /// A reference to the animation store repository instance.
        /// </param>
        /// <returns>True if the initialization routine was successful.</returns>
        public bool Initialize(JunkbotGame gameReference, AnimationStore animationStore)
        {
            Game      = gameReference;
            Interface = new JunkbotInterface();

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes this <see cref="GlWorldRenderStrategy"/>.
        /// </summary>
        /// <param name="gameReference">
        /// A reference to the Junkbot game engine.
        /// </param>
        /// <returns>True if the initialization process was successful.</returns>
        public override bool Initialize(JunkbotGame gameReference)
        {
            Game = gameReference;

            ActorAtlas = GlUtil.LoadAtlas(Environment.CurrentDirectory + @"\Content\Atlas\actors-atlas");

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes this <see cref="GlMenuRenderStrategy"/>.
        /// </summary>
        /// <param name="gameReference">
        /// A reference to the Junkbot game engine.
        /// </param>
        /// <returns>True if the initialization process was successful.</returns>
        public override bool Initialize(JunkbotGame gameReference)
        {
            Game       = gameReference;
            TitleAtlas = GlSpriteAtlas.FromFileSet(
                Environment.CurrentDirectory + @"\Content\Atlas\menu-atlas.png"
                );

            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes this <see cref="IGameState"/> with references to the game
        /// engine and animation store repository instances.
        /// </summary>
        /// <param name="gameReference">
        /// A reference to the game engine instance.
        /// </param>
        /// <param name="animationStore">
        /// A reference to the animation store repository instance.
        /// </param>
        /// <returns>True if the initialization routine was successful.</returns>
        public bool Initialize(JunkbotGame gameReference, AnimationStore animationStore)
        {
            AnimationStore = animationStore;
            Game           = gameReference;
            Interface      = new JunkbotInterface();
            Scene          = Scene.FromLevel(
                File.ReadAllLines(Environment.CurrentDirectory + @"\Content\Levels\loading_level.txt"),
                AnimationStore
                );

            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Starts this renderer.
        /// </summary>
        /// <param name="gameInstance">
        /// A reference to the Junkbot game engine instance.
        /// </param>
        public void Start(JunkbotGame gameInstance)
        {
            Game = gameInstance;
            CurrentInputState = new InputEvents();

            // Setup GLFW parameters and create window
            //
            Glfw.Init();

            Glfw.SetErrorCallback(OnError);

            Glfw.WindowHint(WindowHint.ContextVersionMajor, 3);
            Glfw.WindowHint(WindowHint.ContextVersionMinor, 2);
            Glfw.WindowHint(WindowHint.OpenGLForwardCompat, 1);
            Glfw.WindowHint(WindowHint.OpenGLProfile, (int)OpenGLProfile.Core);

            WindowPtr = Glfw.CreateWindow(650, 420, "Junkbot (OpenGL 3.2)", GlfwMonitorPtr.Null, GlfwWindowPtr.Null);

            IsOpen = true;

            Glfw.MakeContextCurrent(WindowPtr);

            // Set GL pixel storage parameter
            //
            GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);

            // Set up VAO
            //
            GlVaoId = GL.GenVertexArray();
            GL.BindVertexArray(GlVaoId);

            // Set up enabled features
            //
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            // Set up viewport defaults
            //
            GL.ClearColor(0.39f, 0.58f, 0.93f, 1.0f); // Approx. cornflower blue
            GL.Viewport(0, 0, (int)JUNKBOT_VIEWPORT.X, (int)JUNKBOT_VIEWPORT.Y);

            // Set up input callbacks
            //
            Glfw.SetCharCallback(WindowPtr, OnChar);
            Glfw.SetCursorPosCallback(WindowPtr, OnCursorPos);
            Glfw.SetKeyCallback(WindowPtr, OnKey);
            Glfw.SetMouseButtonCallback(WindowPtr, OnMouseButton);
            Glfw.SetWindowSizeCallback(WindowPtr, OnWindowSize);

            // Now attach the game state event to update our strategies
            //
            Game.ChangeState += Game_ChangeState;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes this <see cref="GlWorldRenderStrategy"/>.
        /// </summary>
        /// <param name="gameReference">
        /// A reference to the Junkbot game engine.
        /// </param>
        /// <returns>True if the initialization process was successful.</returns>
        public override bool Initialize(JunkbotGame gameReference)
        {
            ActorAtlas = GlSpriteAtlas.FromFileSet(
                Environment.CurrentDirectory + @"\Content\Atlas\actors-atlas"
                );

            Game        = gameReference;
            GlProgramId = Resources.GetShaderProgram("SimpleUVs");
            Origin      = Point.Empty;
            SceneSize   = Game.GameState.Scene.Size;

            return(true);
        }
Exemplo n.º 7
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            var renderer  = new GlRenderer();
            var game      = new JunkbotGame();
            var gameTimer = new Stopwatch();

            renderer.Start(game);
            game.Begin();
            gameTimer.Start();

            while (renderer.IsOpen)
            {
                TimeSpan deltaTime = gameTimer.Elapsed;
                gameTimer.Reset();

                InputEvents inputs = renderer.GetInputEvents();

                game.Update(deltaTime, inputs);
                renderer.RenderFrame();
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes this <see cref="GlRenderStrategy"/>.
 /// </summary>
 /// <param name="gameReference">
 /// A reference to the Junkbot game engine.
 /// </param>
 /// <returns>True if the initialization process was successful.</returns>
 public abstract bool Initialize(JunkbotGame gameReference);
Exemplo n.º 9
0
        /// <summary>
        /// Initializes this <see cref="GlMenuRenderStrategy"/>.
        /// </summary>
        /// <param name="gameReference">
        /// A reference to the Junkbot game engine.
        /// </param>
        /// <returns>True if the initialization process was successful.</returns>
        public override bool Initialize(JunkbotGame gameReference)
        {
            Game = gameReference;

            return(true);
        }