Exemplo n.º 1
0
        public GrandpaStory()
        {
            Game1.changeMusicTrack("none");
            this.content = Game1.content.CreateTemporary();
            this.texture = this.content.Load <Texture2D>("Minigames\\jojacorps");
            this.backgroundFadeChange = 0.0003f;
            this.grandpaSpeech        = new Queue <string>();
            this.grandpaSpeech.Enqueue(Game1.player.isMale ? Game1.content.LoadString("Strings\\StringsFromCSFiles:GrandpaStory.cs.12026") : Game1.content.LoadString("Strings\\StringsFromCSFiles:GrandpaStory.cs.12028"));
            this.grandpaSpeech.Enqueue(Game1.content.LoadString("Strings\\StringsFromCSFiles:GrandpaStory.cs.12029"));
            this.grandpaSpeech.Enqueue(Game1.content.LoadString("Strings\\StringsFromCSFiles:GrandpaStory.cs.12030"));
            this.grandpaSpeech.Enqueue(Game1.content.LoadString("Strings\\StringsFromCSFiles:GrandpaStory.cs.12031"));
            this.grandpaSpeech.Enqueue(Game1.content.LoadString("Strings\\StringsFromCSFiles:GrandpaStory.cs.12034"));
            this.grandpaSpeech.Enqueue(Game1.content.LoadString("Strings\\StringsFromCSFiles:GrandpaStory.cs.12035"));
            this.grandpaSpeech.Enqueue(Game1.player.isMale ? Game1.content.LoadString("Strings\\StringsFromCSFiles:GrandpaStory.cs.12036") : Game1.content.LoadString("Strings\\StringsFromCSFiles:GrandpaStory.cs.12038"));
            this.grandpaSpeech.Enqueue(Game1.content.LoadString("Strings\\StringsFromCSFiles:GrandpaStory.cs.12040"));
            Game1.player.position = new Vector2(this.panX, (float)(Game1.graphics.GraphicsDevice.Viewport.Height / 2 - 180 * Game1.pixelZoom / 2)) + new Vector2(3000f, 376f);
            Game1.viewport.X      = 0;
            Game1.viewport.Y      = 0;
            Map            m = this.content.Load <Map>("Maps\\FarmHouse");
            IDisplayDevice mapDisplayDevice = Game1.mapDisplayDevice;

            m.LoadTileSheets(mapDisplayDevice);
            string name = "FarmHouse";

            Game1.currentLocation        = (GameLocation) new FarmHouse(m, name);
            Game1.player.currentLocation = Game1.currentLocation;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Allows the game to perform any initialization it needs to before starting to run.
 /// This is where it can query for any required services and load any non-graphic
 /// related content.  Calling base.Initialize will enumerate through any components
 /// and initialize them as well.
 /// </summary>
 protected override void Initialize()
 {
     // TODO: Add your initialization logic here
     xnaDisplayDevice = new xTile.Display.XnaDisplayDevice(Content, GraphicsDevice);
     viewport = new xTile.Dimensions.Rectangle(new xTile.Dimensions.Size(this.Window.ClientBounds.Width, this.Window.ClientBounds.Height));
     base.Initialize();
 }
Exemplo n.º 3
0
 /// <summary>
 /// Frees the resources of all the TileSheets contained in this Map
 /// from the given display device
 /// </summary>
 /// <param name="displayDevice">Display device from which to dispose the TileSheets</param>
 public void DisposeTileSheets(IDisplayDevice displayDevice)
 {
     foreach (TileSheet tileSheet in m_tileSheets)
     {
         displayDevice.DisposeTileSheet(tileSheet);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Loads all the TileSheets contained in this Map into the given
 /// display device
 /// </summary>
 /// <param name="displayDevice">Display device in which to load the TileSheets</param>
 public void LoadTileSheets(IDisplayDevice displayDevice)
 {
     foreach (TileSheet tileSheet in m_tileSheets)
     {
         displayDevice.LoadTileSheet(tileSheet);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            map = Content.Load <Map>(@"Levels\Level1");

            mapDisplayDevice = new XnaDisplayDevice(this.Content, this.GraphicsDevice);

            map.LoadTileSheets(mapDisplayDevice);
            xTile.Layers.Layer layer = map.GetLayer("Foreground");

            World.viewport = new xTile.Dimensions.Rectangle(new xTile.Dimensions.Size(800, 600));

            particleManager = new ParticleManager(map);
            particleManager.LoadContent(Content);

            mario  = Content.Load <Texture2D>("tiles");
            player = new Player(this.Content, new Vector2(350, this.Window.ClientBounds.Height - (48 * 2) - 48), Vector2.Zero, map, particleManager);

            xTile.Layers.Layer elayer = map.GetLayer("Enemy");
            elayer.Visible = false;
            for (int x = 0; x < elayer.LayerWidth; x++)
            {
                for (int y = 0; y < elayer.LayerHeight; y++)
                {
                    xTile.Tiles.Tile tile = elayer.Tiles[x, y];

                    if (tile != null)
                    {
                        if (tile.Properties.Keys.Contains("type"))
                        {
                            Vector2 vel = Vector2.Zero;

                            if (tile.Properties.Keys.Contains("velocity"))
                            {
                                vel = new Vector2(90 * tile.Properties["velocity"], 0);
                            }

                            int x_left = -1, x_right = -1;

                            if (tile.Properties.Keys.Contains("x_left"))
                            {
                                x_left = tile.Properties["x_left"];
                            }

                            if (tile.Properties.Keys.Contains("x_right"))
                            {
                                x_right = tile.Properties["x_right"];
                            }

                            if (tile.Properties.Keys.Contains("type") && tile.Properties["type"] == "goomba")
                            {
                                enemies.Add(new Enemy(this.Content, new Vector2(x * 48, y * 48), vel, x_left, x_right, map));
                            }
                        }
                    }
                }
            }
        }
 /*********
 ** Private methods
 *********/
 /// <summary>The method to call before <see cref="Layer.Draw"/>.</summary>
 private static void Before_Draw(Layer __instance, IDisplayDevice displayDevice, xTile.Dimensions.Rectangle mapViewport, Location displayOffset, bool wrapAround, int pixelZoom)
 {
     if (__instance.Id == "Back" && xTileLayerPatcher.Rendering == 0 && Game1.currentLocation.Map.Properties.TryGetValue("RenderBehind", out PropertyValue renderBehind))
     {
         xTileLayerPatcher.Rendering++;
         try
         {
             string[] fields = renderBehind.ToString().Split(' ');
             string   locName = fields[0];
             int      offsetX = 0, offsetY = 0;
             if (fields.Length >= 3)
             {
                 offsetX = int.Parse(fields[1]);
                 offsetY = int.Parse(fields[2]);
             }
             float scale = 1f;
             if (fields.Length >= 4)
             {
                 scale = float.Parse(fields[3]);
             }
             xTileLayerPatcher.DoRendering(locName, offsetX, offsetY, scale);
         }
         catch (Exception e)
         {
             Log.Error("Exception while rendering: " + e);
         }
         xTileLayerPatcher.Rendering--;
     }
 }
Exemplo n.º 7
0
 public Calculator(ICommandSubject input, IDisplayDevice output, ICpu processor)
 {
     this.Input  = input;
     this.Output = output;
     this.CPU    = processor;
     this.Input.Attach(this);
     this.State = new ClearState(this);
 }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
            mapDisplayDevice = new XnaDisplayDevice(this.Content, this.GraphicsDevice);
            map.LoadTileSheets(mapDisplayDevice);
            viewport = new xTile.Dimensions.Rectangle(new Size(800, 480));
        }
Exemplo n.º 9
0
 /// <summary>
 /// Loads an xTile map into memory.
 /// </summary>
 public void LoadMap(string mapDirectory)
 {
     Display  = new XnaDisplayDevice(Game.Content, Game.GraphicsDevice);
     Viewport =
         new xTile.Dimensions.Rectangle(new Size(Game.GraphicsDevice.PresentationParameters.BackBufferWidth,
                                                 Game.GraphicsDevice.PresentationParameters.BackBufferHeight));
     XMap = Game.Content.Load <xTile.Map>(mapDirectory);
     XMap.LoadTileSheets(Display);
 }
Exemplo n.º 10
0
        internal static void PatchMapDisplayDevice(ref IDisplayDevice __result)
        {
            if (MapDisplayDevice == null)
            {
                MapDisplayDevice = new MapTKDisplayDevice(Game1.content, Game1.graphics.GraphicsDevice, MapTKMod.CompatOptions.Contains("SpriteMaster"));
            }

            __result = MapDisplayDevice;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
            mapDisplayDevice = new XnaDisplayDevice(this.Content, this.GraphicsDevice);
            map.LoadTileSheets(mapDisplayDevice);
            viewport = new xTile.Dimensions.Rectangle(new Size(800, 480));
        }
Exemplo n.º 12
0
 /// <summary>
 /// Visually renders the layer using the given display device,
 /// pixel offset from the map origin and display viewport. If
 /// wrapAround is set to True, the layer wraps around at the
 /// edges across and / or down.
 /// </summary>
 /// <param name="displayDevice">Display device on which to render layer</param>
 /// <param name="mapViewport">viewport on the dipslay device</param>
 /// <param name="displayOffset">offset in pixel coordinates into the map from the top left</param>
 /// <param name="wrapAround">Flag indicating if layer wrap-around is performed</param>
 public void Draw(IDisplayDevice displayDevice, Rectangle mapViewport, Location displayOffset, bool wrapAround)
 {
     if (wrapAround)
     {
         DrawWrapped(displayDevice, mapViewport, displayOffset);
     }
     else
     {
         DrawNormal(displayDevice, mapViewport, displayOffset);
     }
 }
Exemplo n.º 13
0
        public static void Layer_Draw_Postfix(Layer __instance, IDisplayDevice displayDevice, Rectangle mapViewport, Location displayOffset, bool wrapAround, int pixelZoom)
        {
            if (!config.EnableMod || Regex.IsMatch(__instance.Id, "[0-9]$"))
            {
                return;
            }

            foreach (Layer layer in Game1.currentLocation.Map.Layers)
            {
                if (layer.Id.StartsWith(__instance.Id) && int.TryParse(layer.Id.Substring(__instance.Id.Length), out int layerIndex))
                {
                    thisLayerDepth = layerIndex;
                    layer.Draw(displayDevice, mapViewport, displayOffset, wrapAround, pixelZoom);
                    thisLayerDepth = 0;
                }
            }
        }
Exemplo n.º 14
0
        public void Initialize(Game game, ContentManager content, ref GraphicsDeviceManager graphics)
        {
            uno = new Unicorn(game, content);
            // Create a world for physics to act
            world = new World(new Vector2(0f, 9.8f));

            this.graphics = graphics;

            this.uno     = uno;
            this.content = content;
            level        = 0;

            mapDisplayDevice = new XnaDisplayDevice(content, graphics.GraphicsDevice);

            viewport = new xTile.Dimensions.Rectangle(new Size(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));

            nextLevelCallDelay = false;
        }
        public static GameRoot CreateGameRoot(
            IInputDevice inputDevice,
            IDisplayDevice displayDevice,
            IAudioDevice audioDevice,
            IHiScoresStorage hiScoresStorage,
            ILogger logger)
        {
            Verify.NotNull(inputDevice, nameof(inputDevice));
            Verify.NotNull(displayDevice, nameof(displayDevice));
            Verify.NotNull(audioDevice, nameof(audioDevice));
            Verify.NotNull(hiScoresStorage, nameof(hiScoresStorage));
            Verify.NotNull(logger, nameof(logger));

            var hal = new HardwareAccessLayer(inputDevice, displayDevice, audioDevice);

            var sleeper = new Sleeper();

            var gameRoot = new GameRoot(hal, sleeper, logger);

            return(gameRoot);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Visually renders this Map using the given display device and
        /// viewport into the map. The viewport is rendered at the given
        /// display offset. If wrapAround is set to True, the map wraps
        /// around at the edges across and / or down.
        /// </summary>
        /// <param name="displayDevice">Display device on which to render the Map</param>
        /// <param name="mapViewport">Viewport into the Map to be rendered</param>
        /// <param name="displayOffset">Pixel offset on the device where to render the map</param>
        /// <param name="wrapAround">Flag indicating if map wrap-around is performed</param>
        public void Draw(IDisplayDevice displayDevice, Rectangle mapViewport, Location displayOffset, bool wrapAround)
        {
            Rectangle deviceViewport = new Rectangle(displayOffset, mapViewport.Size);

            displayDevice.Viewport = deviceViewport;

            displayDevice.BeginScene();

            foreach (Layer layer in m_layers)
            {
                if (!layer.Visible)
                {
                    continue;
                }

                Rectangle layerViewport = layer.ConvertMapToLayerViewport(mapViewport);
                layer.Draw(displayDevice, layerViewport, displayOffset, wrapAround);
            }

            displayDevice.EndScene();
        }
Exemplo n.º 17
0
        public void LoadContent(ContentManager cm, GraphicsDevice gd, Map map, Character spoon)
        {
            _map = map;
            _mapDisplayDevice = new XnaDisplayDevice(cm, gd);
            _map.LoadTileSheets(_mapDisplayDevice);
            _aspectRatio = gd.Viewport.AspectRatio;

            _spoon = spoon;
            _spoon._model = cm.Load<Model>("Models/Spoon");

            // Test
            texture = cm.Load<Texture2D>("Models/SpoonTexture");

            _viewport.X -= Defs.ScreenWidth / 2;

            _gd = gd;
        }
Exemplo n.º 18
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Set the sharing mode of the graphics device to turn on XNA rendering
            SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(true);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(SharedGraphicsDeviceManager.Current.GraphicsDevice);

            golfball = new Sprite(contentManager.Load<Texture2D>("golfball"));
            golfball.X = ballScreenX;
            golfball.Y = 128;

            int w = SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Width;
            int h = SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Height;

            // Create xTile mandatory objects

            camera = new xTile.Dimensions.Rectangle(new xTile.Dimensions.Size(w, h));
            mapDisplayDevice = new XnaDisplayDevice(contentManager, SharedGraphicsDeviceManager.Current.GraphicsDevice);

            // Load xTile tilemap from content, some hacking required to load file without processor+importer from contentlib

            // Map file must have; build action set to "none", and copy to output dir
            // set to "always" to be able open this way. Also "Rebuild solution" must
            // be invoked in Visual Studio when resource is initially added.

            System.IO.Stream stream = TitleContainer.OpenStream("Content\\Map02.tbin");

            // Seems that only tbin type of maps are supported by libs

            map = FormatManager.Instance.BinaryFormat.Load(stream);
            fixTileLocationsBug(map);
            map.LoadTileSheets(mapDisplayDevice);

            // Setup Box2D physics

            physics = new Physics();

            // Add golf ball to Box2D world

            physics.addBallSprite(golfball);

            // Add the ground and water hit area rectables to Box2D world
            // Each tile is 16x16 pixels

            TileArray groundTiles = map.GetLayer("HitGround").Tiles;
            TileArray waterTiles = map.GetLayer("HitWater").Tiles;

            for (int y = 0; y < 48; y++)
            {
                for (int x = 0; x < 800; x++)
                {

                    Tile tgroup = groundTiles[x, y];
                    Tile twater = waterTiles[x, y];

                    if (tgroup != null)
                    {
                        physics.addRect(x * 16, y * 16, 16, 16, Physics.TYPE_GROUND);
                    }

                    if (twater != null)
                    {
                        physics.addRect(x * 16, y * 16, 16, 16, Physics.TYPE_WATER);
                    }

                }
            }

            // Start the timer

            timer.Start();

            base.OnNavigatedTo(e);
        }
Exemplo n.º 19
0
Arquivo: Map.cs Projeto: dekk7/xEngine
        /// <summary>
        /// Visually renders this Map using the given display device and
        /// viewport into the map. The viewport is rendered at the given
        /// display offset. If wrapAround is set to True, the map wraps
        /// around at the edges across and / or down.
        /// </summary>
        /// <param name="displayDevice">Display device on which to render the Map</param>
        /// <param name="mapViewport">Viewport into the Map to be rendered</param>
        /// <param name="displayOffset">Pixel offset on the device where to render the map</param>
        /// <param name="wrapAround">Flag indicating if map wrap-around is performed</param>
        public void Draw(IDisplayDevice displayDevice, Rectangle mapViewport, Location displayOffset, bool wrapAround)
        {
            displayDevice.BeginScene();

            Rectangle deviceViewport = new Rectangle(displayOffset, mapViewport.Size);
            displayDevice.SetViewport(deviceViewport);

            foreach (Layer layer in m_layers)
            {
                if (!layer.Visible)
                    continue;

                Rectangle layerViewport = layer.ConvertMapToLayerViewport(mapViewport);
                layer.Draw(displayDevice, layerViewport, displayOffset, wrapAround);
            }

            displayDevice.EndScene();
        }
Exemplo n.º 20
0
Arquivo: Map.cs Projeto: dekk7/xEngine
 /// <summary>
 /// Loads all the TileSheets contained in this Map into the given
 /// display device
 /// </summary>
 /// <param name="displayDevice">Display device in which to load the TileSheets</param>
 public void LoadTileSheets(IDisplayDevice displayDevice)
 {
     foreach (TileSheet tileSheet in m_tileSheets)
         displayDevice.LoadTileSheet(tileSheet);
 }
Exemplo n.º 21
0
        public void Patch(Map targetMap, Diff mapDiff, ITileSheetProvider tileSheetProvider, IDisplayDevice displayDevice)
        {
            Utilities.MergeProperties(targetMap.Properties, mapDiff.Map.Properties);

            Diff.MapData mapData = mapDiff.Map;

            // Add tilesheets
            MergeTileSheets(targetMap, mapData.TileSheets, tileSheetProvider, displayDevice);

            MergeLayers(targetMap, mapData.Layers);
        }
Exemplo n.º 22
0
Arquivo: Map.cs Projeto: dekk7/xEngine
 /// <summary>
 /// Visually renders this Map using the given display device and
 /// viewport into the map. The viewport is rendered at the display
 /// device's origin
 /// </summary>
 /// <param name="displayDevice">Display device on which to render the Map</param>
 /// <param name="mapViewport">Viewport into the Map to be rendered</param>
 public void Draw(IDisplayDevice displayDevice, Rectangle mapViewport)
 {
     Draw(displayDevice, mapViewport, Location.Origin, false);
 }
Exemplo n.º 23
0
        protected override void Initialize()
        {
            try
            {
                IceProfiler.StartProfiling(IceProfilerNames.GAME_INITIALIZE);
                graphics.PreferredBackBufferWidth = this.NativeResolution.X;
                graphics.PreferredBackBufferHeight = this.NativeResolution.Y;
                #if !REACH
                graphics.SynchronizeWithVerticalRetrace = true;
                #endif
                graphics.ApplyChanges();
                string _path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
                //ComponentTypeContainer.SetAppDomain(AppDomain.CurrentDomain);
                ComponentTypeContainer.LoadAssemblyInformation(_path);
                Drawing.DrawingManager.Intialize();
                IceCore.graphicsDevice = graphics.GraphicsDevice;

                //xTile
                try
                {
                    mapDisplayDevice = new XnaDisplayDevice(this.Content, graphics.GraphicsDevice);

                    if (map != null)
                        map.LoadTileSheets(mapDisplayDevice);

                }
                catch (Exception exd)
                {
                    Console.WriteLine(exd.Message);
                }
                base.Initialize();
                IceProfiler.StopProfiling(IceProfilerNames.GAME_INITIALIZE);

            }
            catch (Exception err)
            {
                Console.WriteLine(err.ToString());
                throw err;
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            mapDisplayDevice = new XnaDisplayDevice(Content, GraphicsDevice);
            spriteBatch = new SpriteBatch(GraphicsDevice);
            map = Content.Load<xTile.Map>("Background");
            map.LoadTileSheets(mapDisplayDevice);
            viewport = new xTile.Dimensions.Rectangle(0, 0, 1280, 1280);

            projectiles = Content.Load<Texture2D>("New Projectiles");
            FootSoldiers = Content.Load<Texture2D>("FootSoldiers");
            towers = Content.Load<Texture2D>("Towers");
            titleScreen = Content.Load<Texture2D>("dday");
            screenBounds = new Rectangle(0, 0, 1920, 1280);

            naziManager = new NaziManager(
                FootSoldiers,
                new Rectangle(79, 51, 24, 26),
                3,
                new Rectangle(
                    0,
                    0,
                    this.Window.ClientBounds.Width,
                    this.Window.ClientBounds.Height));

            towerManager = new TowerManager(
                towers,
                new Rectangle(4, 3, 33, 46)
                );

            //TowerShotManager = new ShotManager(
            //   projectiles,
            //   new Rectangle(18, 9, 6, 6),
            //   4,
            //   2,
            //   250f,
            //   screenBounds);

            // TODO: use this.Content to load your game content here
        }
Exemplo n.º 25
0
        public override void init()
        {
            //Shader stuff
            mDevice = mManager.mGraphicsDevice;
            tempBinding = mDevice.GetRenderTargets();
            tempRenderTarget = new RenderTarget2D(mDevice, 1280, 720);

            blurShader = new BlurFocusShader(mDevice, tempRenderTarget, mManager.blur);
            //rippleShader = new RippleShader(mDevice, tempRenderTarget, mManager.ripple);
            //Shader stuff ends

            //Map stuff
            map = mManager.mGame.Content.Load<Map>("maps\\" + mManager.mLevelName);
            mapDisplayDevice = new XnaDisplayDevice(mManager.mGame.Content, mDevice);
            map.LoadTileSheets(mapDisplayDevice);
            viewport = new xTile.Dimensions.Rectangle(new Size(1280, 720));
            //Map stuff done

            scoreCounter = new ScoreCounter();
            camera = new Camera();
            runEffect = new ParticleEffect(mManager.particleEffect, ParticleEffect.ParticleType.Dust, BlendState.AlphaBlend, camera);
            explosion = new ParticleEffect(mManager.particleEffect, ParticleEffect.ParticleType.Explosion, BlendState.Additive, camera);
            input = new GetInput(PlayerIndex.One);
            player = new Hero(mManager.heroSprites);
            shotList = new List<Shot>();
            puncheeList = new List<Punchee>();
            scoreAreaList = new List<ScoreArea>();
            chargingSoundEffect = mManager.chargingSound.CreateInstance();
            chargingSoundEffect.Pitch = 0.2f;

            attachEventListener();

            for (int i = 0; i < map.Layers[0].LayerWidth; i++)
            {
                for (int j = 0; j < map.Layers[0].LayerHeight; j++)
                {
                    Layer collision = map.Layers[0];
                    Location tileLocation = new Location(i, j);
                    Tile tile = collision.Tiles[tileLocation];

                    if (tile.TileIndex == 90)
                    {
                        ParticleEffect trail = new ParticleEffect(mManager.particleEffect, ParticleEffect.ParticleType.Knockback, BlendState.AlphaBlend, camera);
                        Punchee punched = new Punchee(mManager.startScreen, trail);
                        FollowAI followAI = new FollowAI(punched, player);
                        punched.addAI(followAI);
                        punched.mPosition.X = 32 * i;
                        punched.mPosition.Y = 32 * j;
                        puncheeList.Add(punched);
                    }

                    if (tile.TileIndex == 77)
                    {
                        int posX = i * 32;
                        int posY = j * 32;

                        ScoreArea scoreArea = new ScoreArea(posX, posY);
                        scoreAreaList.Add(scoreArea);
                    }
                }
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            ScaleFactorX = (((int)ScreenResolution.Y / (int)AspectRatio.Y) * (int)AspectRatio.X);
            //destinationRect.X = ((int)ScreenResolution.X / 2);
            //destinationRect.Y = ((int)ScreenResolution.Y / 2);
            //destinationRect.Height = (int)ScreenResolution.Y;
            //destinationRect.Width = (ScaleFactorX);

            Camera.X = 0;
            Camera.Y = 0;
            mapDisplayDevice = new XnaDisplayDevice(
                this.Content, this.GraphicsDevice);

            viewport = new xTile.Dimensions.Rectangle(new Size((int)TempResolution.X, (int)TempResolution.Y));
            //viewportL = new xTile.Dimensions.Rectangle(new Size( (int)TempResolution.X, (int)TempResolution.Y) );
            //viewportR = new xTile.Dimensions.Rectangle(new Size( (int)TempResolution.X, (int)TempResolution.Y) );
            renderTarget = new RenderTarget2D(GraphicsDevice, (int)TempResolution.X, (int)TempResolution.Y, false, SurfaceFormat.Color, 0);

            ///Initialize Objects
            //Characters
            mapCharacter = new MapCharacter[255];
            for (int i = 0; i < 255; i++)
                mapCharacter[i] = new MapCharacter(Content.Load<Texture2D>("Texture//Character//00"), 9, 0, 0);
            mapCharacter[0].Visible = true;
            mapCharacter[1].Visible = true;
            //Maps
            GameMap.LoadTileSheets(mapDisplayDevice);
        }
 public HardwareAccessLayer(IInputDevice inputDevice, IDisplayDevice displayDevice, IAudioDevice audioDevice)
 {
     InputDevice   = Verify.NotNull(inputDevice, nameof(inputDevice));
     DisplayDevice = Verify.NotNull(displayDevice, nameof(displayDevice));
     AudioDevice   = Verify.NotNull(audioDevice, nameof(audioDevice));
 }
Exemplo n.º 28
0
 public LEDStrip(IDisplayDevice device)
 {
     this.Device = device;
     Pixels = new Color[device.Length];
 }
Exemplo n.º 29
0
 public LEDStrip(IDisplayDevice device)
 {
     this.Device = device;
     Pixels      = new Color[device.Length];
 }
Exemplo n.º 30
0
 /// <summary>
 /// Visually renders this Map using the given display device and
 /// viewport into the map. The viewport is rendered at the display
 /// device's origin
 /// </summary>
 /// <param name="displayDevice">Display device on which to render the Map</param>
 /// <param name="mapViewport">Viewport into the Map to be rendered</param>
 public void Draw(IDisplayDevice displayDevice, Rectangle mapViewport)
 {
     Draw(displayDevice, mapViewport, Location.Origin, false);
 }
Exemplo n.º 31
0
        private void MergeTileSheets(Map targetMap, Diff.TileSheetData[] tileSheets, ITileSheetProvider tileSheetProvider, IDisplayDevice displayDevice)
        {
            if (tileSheets == null)
            {
                return;
            }

            void AddTileSheet(Diff.TileSheetData tileSheetData)
            {
                string    imageSource = tileSheetProvider.GetTileSheetPath(tileSheetData.Id);
                TileSheet tileSheet   = new TileSheet(
                    id: tileSheetData.Id,
                    map: targetMap,
                    imageSource: imageSource ?? tileSheetData.ImageSource,
                    sheetSize: tileSheetData.SheetSize,
                    tileSize: tileSheetData.TileSize
                    );

                targetMap.AddTileSheet(tileSheet);
            }

            foreach (Diff.TileSheetData tileSheetData in tileSheets)
            {
                TileSheet tileSheet = targetMap.GetTileSheet(tileSheetData.Id);
                switch (tileSheetData.EditType)
                {
                case EditType.Add:
                    AddTileSheet(tileSheetData);
                    break;

                case EditType.Delete:
                    targetMap.RemoveTileSheet(tileSheet);
                    break;

                case EditType.Merge:
                case EditType.Replace:
                    targetMap.RemoveTileSheet(tileSheet);
                    AddTileSheet(tileSheetData);
                    break;
                }
            }

            targetMap.LoadTileSheets(displayDevice);
        }
Exemplo n.º 32
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

              base.Initialize();

              mapDisplayDevice = new XnaDisplayDevice(this.Content, this.GraphicsDevice);
              map.LoadTileSheets(mapDisplayDevice);
              camera = new xTile.Dimensions.Rectangle(new Size(820, 480));

              //cameraPosition = new Vector2(0, 0);
              //screenCenter = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2f, graphics.GraphicsDevice.Viewport.Height / 2f);
              //view = Matrix.CreateTranslation(new Vector3(cameraPosition - screenCenter, 0f)) * Matrix.CreateTranslation(new Vector3(screenCenter, 0f));

              //physicsDebug = new DebugViewXNA(world);
              //physicsDebug.LoadContent(this.GraphicsDevice, this.Content);
              //physicsDebug.AppendFlags(DebugViewFlags.Shape);
              //physicsDebug.AppendFlags(DebugViewFlags.PolygonPoints);

              //Vector2 bodyPosition = new Vector2(260, 220);
              //myBody = BodyFactory.CreateCircle(world, 16.0f, 1f, bodyPosition);
              //myBody.BodyType = BodyType.Dynamic;
              //myBody.Mass = 1.0f;
              //myBody.Restitution = 100f;
              //myBody.Friction = 0.5f;
              //myBody.LinearVelocity = new Vector2(0, 0);

              //Layer layer = map.GetLayer("HitGround");
              //TileArray groundTiles = layer.Tiles;

              //for (int x = 0; x < 800; x++)
              //{
              //    for (int y = 0; y < 48; y++)
              //    {
              //        Tile tile = groundTiles[x, y];

              //        if (tile != null)
              //        {
              //            Body bd = BodyFactory.CreateRectangle(world, 16.0f, 16.0f, 1.0f);
              //            bd.BodyType = BodyType.Static;
              //            bd.Restitution = 1.0f;
              //            bd.Mass = 1.0f;
              //            bd.Position = new Vector2((x * 16) + 7, (y * 16) + 7);
              //        }
              //    }
              //}
        }
Exemplo n.º 33
0
        private void DrawWrapped(IDisplayDevice displayDevice, Rectangle mapViewport, Location displayOffset)
        {
            if (BeforeDraw != null)
                BeforeDraw(this, new LayerEventArgs(this, mapViewport));

            // store local values for performance
            int tileWidth = m_tileSize.Width;
            int tileHeight = m_tileSize.Height;
            int layerWidth = m_layerSize.Width;
            int layerHeight = m_layerSize.Height;

            // determine internal tile offset
            Location tileInternalOffset = new Location(
                Wrap(mapViewport.X, tileWidth),
                Wrap(mapViewport.Y, tileHeight));

            // determine tile-level viewport location
            int tileXMin = mapViewport.X >= 0 ? mapViewport.X / tileWidth : (mapViewport.X - tileWidth + 1) / tileWidth;
            int tileYMin = mapViewport.Y >= 0 ? mapViewport.Y / tileHeight : (mapViewport.Y - tileHeight + 1) / tileHeight;

            // determine tile-level viewport size
            int tileColumns = 1 + (mapViewport.Size.Width - 1) / tileWidth;
            int tileRows = 1 + (mapViewport.Size.Height - 1) / tileHeight;

            // increment tile-level viewport size if display not tile-aligned
            if (tileInternalOffset.X != 0)
                ++tileColumns;
            if (tileInternalOffset.Y != 0)
                ++tileRows;

            // determine tile-level viewport size limits
            int tileXMax = tileXMin + tileColumns;
            int tileYMax = tileYMin + tileRows;

            Location tileLocation = displayOffset - tileInternalOffset;

            for (int tileY = tileYMin; tileY < tileYMax; tileY++)
            {
                tileLocation.X = displayOffset.X - tileInternalOffset.X;
                for (int tileX = tileXMin; tileX < tileXMax; tileX++)
                {
                    Tile tile = m_tiles[Wrap(tileX, layerWidth), Wrap(tileY, layerHeight)];

                    if (tile != null)
                        displayDevice.DrawTile(tile, tileLocation);

                    tileLocation.X += tileWidth;
                }
                tileLocation.Y += tileHeight;
            }

            if (AfterDraw != null)
                AfterDraw(this, new LayerEventArgs(this, mapViewport));
        }
Exemplo n.º 34
0
Arquivo: Map.cs Projeto: dekk7/xEngine
 /// <summary>
 /// Frees the resources of all the TileSheets contained in this Map
 /// from the given display device
 /// </summary>
 /// <param name="displayDevice">Display device from which to dispose the TileSheets</param>
 public void DisposeTileSheets(IDisplayDevice displayDevice)
 {
     foreach (TileSheet tileSheet in m_tileSheets)
         displayDevice.DisposeTileSheet(tileSheet);
 }
Exemplo n.º 35
0
        public void Initialize(Game game, ContentManager content, ref GraphicsDeviceManager  graphics)
        {
            uno = new Unicorn(game, content);
            // Create a world for physics to act
            world = new World(new Vector2(0f, 9.8f));

            this.graphics = graphics;

            this.uno = uno;
            this.content = content;
            level = 0;

            mapDisplayDevice = new XnaDisplayDevice(content, graphics.GraphicsDevice);

            viewport = new xTile.Dimensions.Rectangle(new Size(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));

            nextLevelCallDelay = false;
        }
Exemplo n.º 36
0
        private void DrawWrapped(IDisplayDevice displayDevice, Rectangle mapViewport, Location displayOffset)
        {
            if (BeforeDraw != null)
            {
                BeforeDraw(this, new LayerEventArgs(this, mapViewport));
            }

            // store local values for performance
            int tileWidth   = m_tileSize.Width;
            int tileHeight  = m_tileSize.Height;
            int layerWidth  = m_layerSize.Width;
            int layerHeight = m_layerSize.Height;

            // determine internal tile offset
            Location tileInternalOffset = new Location(
                Wrap(mapViewport.X, tileWidth),
                Wrap(mapViewport.Y, tileHeight));

            // determine tile-level viewport location
            int tileXMin = mapViewport.X >= 0 ? mapViewport.X / tileWidth : (mapViewport.X - tileWidth + 1) / tileWidth;
            int tileYMin = mapViewport.Y >= 0 ? mapViewport.Y / tileHeight : (mapViewport.Y - tileHeight + 1) / tileHeight;

            // determine tile-level viewport size
            int tileColumns = 1 + (mapViewport.Size.Width - 1) / tileWidth;
            int tileRows    = 1 + (mapViewport.Size.Height - 1) / tileHeight;

            // increment tile-level viewport size if display not tile-aligned
            if (tileInternalOffset.X != 0)
            {
                ++tileColumns;
            }
            if (tileInternalOffset.Y != 0)
            {
                ++tileRows;
            }

            // determine tile-level viewport size limits
            int tileXMax = tileXMin + tileColumns;
            int tileYMax = tileYMin + tileRows;

            Location tileLocation = displayOffset - tileInternalOffset;

            for (int tileY = tileYMin; tileY < tileYMax; tileY++)
            {
                tileLocation.X = displayOffset.X - tileInternalOffset.X;
                for (int tileX = tileXMin; tileX < tileXMax; tileX++)
                {
                    Tile tile = m_tiles[Wrap(tileX, layerWidth), Wrap(tileY, layerHeight)];

                    if (tile != null)
                    {
                        displayDevice.DrawTile(tile, tileLocation);
                    }

                    tileLocation.X += tileWidth;
                }
                tileLocation.Y += tileHeight;
            }

            if (AfterDraw != null)
            {
                AfterDraw(this, new LayerEventArgs(this, mapViewport));
            }
        }
Exemplo n.º 37
0
        private static void DoRendering(string locName, int offsetX, int offsetY, float scale)
        {
            if (xTileLayerPatcher.DisplayDevice == null)
            {
                var ddType = Type.GetType("StardewModdingAPI.Framework.Rendering.SDisplayDevice, StardewModdingAPI");
                var ddCon  = ddType.GetConstructor(new[] { typeof(ContentManager), typeof(GraphicsDevice) });
                xTileLayerPatcher.DisplayDevice = (IDisplayDevice)ddCon.Invoke(new object[] { Game1.content, Game1.graphics.GraphicsDevice });
                xTileLayerPatcher.SpriteBatch   = new SpriteBatch(Game1.graphics.GraphicsDevice);
            }
            if (xTileLayerPatcher.RenderTarget == null || xTileLayerPatcher.RenderTarget.Width != Game1.graphics.GraphicsDevice.Viewport.Width || xTileLayerPatcher.RenderTarget.Height != Game1.graphics.GraphicsDevice.Viewport.Height)
            {
                xTileLayerPatcher.RenderTarget = new RenderTarget2D(Game1.graphics.GraphicsDevice, Game1.graphics.GraphicsDevice.Viewport.Width, Game1.graphics.GraphicsDevice.Viewport.Height, false, Game1.graphics.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);

                /*
                 * if (Game1.game1.screen.RenderTargetUsage != RenderTargetUsage.PreserveContents)
                 *  Game1.game1.screen = new RenderTarget2D(Game1.graphics.GraphicsDevice, screen.Width, screen.Height, false, screen.Format, screen.DepthStencilFormat, screen.MultiSampleCount, RenderTargetUsage.PreserveContents);
                 */
            }
            xTileLayerPatcher.LightMap ??= xTileLayerPatcher.AllocateLightMapNoDispose();

            var lightmapField = Mod.Instance.Helper.Reflection.GetField <RenderTarget2D>(typeof(Game1), "_lightmap");
            var lightingBlend = Mod.Instance.Helper.Reflection.GetField <BlendState>(Game1.game1, "lightingBlend");

            var  oldDd         = Game1.mapDisplayDevice;
            var  oldSb         = Game1.spriteBatch;
            var  oldLoc        = Game1.currentLocation;
            var  oldTarget     = (RenderTarget2D)(Game1.graphics.GraphicsDevice.GetRenderTargets().Length > 0 ? Game1.graphics.GraphicsDevice.GetRenderTargets()[0].RenderTarget : null);
            var  oldDebris     = Game1.debrisWeather;
            bool oldLighting   = Game1.drawLighting;
            var  oldLights     = Game1.currentLightSources;
            var  oldLightmap   = Game1.lightmap;
            var  oldOutdoor    = Game1.outdoorLight;
            var  oldAmbient    = Game1.ambientLight;
            var  oldLightBlend = lightingBlend.GetValue();

            Game1.displayHUD       = false;
            Game1.mapDisplayDevice = xTileLayerPatcher.DisplayDevice;
            Game1.spriteBatch      = xTileLayerPatcher.SpriteBatch;
            Game1.currentLocation  = Game1.getLocationFromName(locName);
            Game1.debrisWeather    = null;
            //Game1.drawLighting = false;
            Game1.currentLightSources = new HashSet <LightSource>(); xTileLayerPatcher.BuildLightSources();
            lightmapField.SetValue(xTileLayerPatcher.LightMap);
            //Game1.outdoorLight = Color.White;
            Game1.ambientLight = new Color(254, 254, 254, 0);
            lightingBlend.SetValue(BlendState.Additive);
            Game1.graphics.GraphicsDevice.SetRenderTarget(xTileLayerPatcher.RenderTarget);
            try
            {
                Game1.currentLocation.map.LoadTileSheets(Game1.mapDisplayDevice);
                Mod.Instance.Helper.Reflection.GetMethod(Game1.game1, "_draw").Invoke(new GameTime(), xTileLayerPatcher.RenderTarget);
            }
            catch (Exception e)
            {
                Log.Trace("Exception rendering: " + e);
            }
            Game1.displayHUD                = true;
            Game1.mapDisplayDevice          = oldDd;
            Game1.spriteBatch               = oldSb;
            Game1.currentLocation           = oldLoc;
            Game1.debrisWeather             = oldDebris;
            Game1.game1.takingMapScreenshot = false;
            Game1.drawLighting              = oldLighting;
            Game1.currentLightSources       = oldLights;
            lightmapField.SetValue(oldLightmap);
            Game1.outdoorLight = oldOutdoor;
            Game1.ambientLight = oldAmbient;
            lightingBlend.SetValue(oldLightBlend);
            Game1.graphics.GraphicsDevice.SetRenderTarget(oldTarget);

            Game1.spriteBatch.Draw(xTileLayerPatcher.RenderTarget, new Vector2(offsetX * Game1.tileSize, offsetY * Game1.tileSize), null, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
        }
Exemplo n.º 38
0
 /// <summary>
 /// Visually renders the layer using the given display device,
 /// pixel offset from the map origin and display viewport. If
 /// wrapAround is set to True, the layer wraps around at the
 /// edges across and / or down.
 /// </summary>
 /// <param name="displayDevice">Display device on which to render layer</param>
 /// <param name="mapViewport">viewport on the dipslay device</param>
 /// <param name="displayOffset">offset in pixel coordinates into the map from the top left</param>
 /// <param name="wrapAround">Flag indicating if layer wrap-around is performed</param>
 public void Draw(IDisplayDevice displayDevice, Rectangle mapViewport, Location displayOffset, bool wrapAround)
 {
     if (wrapAround)
         DrawWrapped(displayDevice, mapViewport, displayOffset);
     else
         DrawNormal(displayDevice, mapViewport, displayOffset);
 }
Exemplo n.º 39
0
        public static void Run()
        {
            int initialVSyncSetting = 0;

            try {
                initialVSyncSetting = GL.GetBufferSwapInterval();
                GameConfig.Load();

                GameDebugger.EngineLog(LogLevel.Debug, "Running application specific configuration event handlers");
                if (ConfigureEvent != null)
                {
                    ConfigureEvent();
                }

                GameDebugger.EngineLog(LogLevel.Debug, "Opening display device '{0}'", GameConfig.DisplayDevice);
                IDisplayDevice cur_dev = API.GetDisplayDevice(GameConfig.DisplayDevice);
                // GameDebugger.Log("Primary display device {0}", cur_dev.ToString());
                if (GameConfig.DisplayDevice != null && !GameConfig.DisplayDevice.Equals(cur_dev.Id))
                {
                    GameConfig.DisplayDevice = null;                     // needed to save a "primary display device" setting since the one in config was not found
                }
                List <IMonitor> monitors = cur_dev.GetMonitors();
                if (monitors == null || monitors.Count == 0)
                {
                    throw new UserFriendlyException("No monitors could be found on the selected device. Could there be a bug somewhere?", "Failed initializing graphics");
                }
                IMonitor first_monitor = monitors[0];
                // foreach( Rectangle mon in monitors )
                //	GameDebugger.Log("\tMonitor at {0}", mon.ToString());

                // Thanks to someone in Microsoft determining current refresh rate and bits per pixel of a monitor is quite a pain in the ass
                int current_width        = first_monitor.Width;
                int current_height       = first_monitor.Height;
                int current_bpp          = first_monitor.BitsPerPixel;
                int current_refresh_rate = first_monitor.RefreshRate;

                int cfg_width        = (GameConfig.ResX <= 0 || GameConfig.ResY <= 0) ? current_width : GameConfig.ResX;
                int cfg_height       = (GameConfig.ResX <= 0 || GameConfig.ResY <= 0) ? current_height : GameConfig.ResY;
                int cfg_bpp          = (GameConfig.BitsPerPixel <= 0) ? current_bpp : GameConfig.BitsPerPixel;
                int cfg_refresh_rate = (GameConfig.RefreshRate <= 0) ? current_refresh_rate : GameConfig.RefreshRate;

                // GameDebugger.Log("Searching for {0}bit {1}x{2} @{3}", GameConfig.BitsPerPixel, GameConfig.ResX, GameConfig.ResY, GameConfig.RefreshRate);

                if (GameConfig.FullScreen)
                {
                    List <IDisplayMode> modes = cur_dev.GetModes();
                    if (modes == null || modes.Count == 0)
                    {
                        throw new Exception(String.Format("Device {0} is invalid and has no modes suitable for graphics", cur_dev.ToString()));
                    }

                    IDisplayMode selected_mode = null;
                    foreach (IDisplayMode mode in modes)
                    {
                        // GameDebugger.Log("\t{0}", mode.ToString()); // Uncomment this to log all supported video modes for the chosen display device
                        if (cfg_width == mode.Width &&
                            cfg_height == mode.Height &&
                            cfg_bpp == mode.BitsPerPixel &&
                            cfg_refresh_rate == mode.RefreshRate)
                        {
                            selected_mode = mode;
                            // GameDebugger.Log("Selected mode: {0}", selected_mode.ToString());
                            //break;
                        }
                    }

                    if (selected_mode == null)
                    {
                        // in case the mode in the config is specified incorrectly we try to use current screen settings. also reset config so later it won't try this bothersome thing
                        GameConfig.ResX         = -1;
                        GameConfig.ResY         = -1;
                        GameConfig.BitsPerPixel = -1;
                        GameConfig.RefreshRate  = -1;
                        foreach (IDisplayMode mode in modes)
                        {
                            //GameDebugger.Log("\t{0}", mode.ToString());
                            if (current_width == mode.Width &&
                                current_height == mode.Height &&
                                current_bpp == mode.BitsPerPixel &&
                                current_refresh_rate == mode.RefreshRate)
                            {
                                selected_mode = mode;
                                break;
                            }
                        }
                    }

                    if (selected_mode == null)
                    {
                        // this should not happen but still ... if no current resolution we deperately search for any 1024x768x32 mode (should be present on all computers by now)
                        foreach (IDisplayMode mode in modes)
                        {
                            //GameDebugger.Log("\t{0}", mode.ToString());
                            if (1024 == mode.Width &&
                                768 == mode.Height &&
                                32 == mode.BitsPerPixel)
                            {
                                selected_mode = mode;
                                break;
                            }
                        }
                    }

                    //
                    if (selected_mode == null)
                    {
                        // OMG this is totally f****d up! just pick out the first one :|
                        selected_mode = modes[0];
                    }

                    if (selected_mode.Width != current_width ||
                        selected_mode.Height != current_height ||
                        selected_mode.BitsPerPixel != current_bpp ||
                        selected_mode.RefreshRate != current_refresh_rate)
                    {
                        // TODO: add support for non full screen modes
                        if (selected_mode.Set(true))
                        {
                            current_width        = selected_mode.Width;
                            current_height       = selected_mode.Height;
                            current_bpp          = selected_mode.BitsPerPixel;
                            current_refresh_rate = selected_mode.RefreshRate;
                        }

                        // After changing resolution monitor positions will change so we have to read them again!
                        monitors = cur_dev.GetMonitors();
                        if (monitors == null || monitors.Count == 0)
                        {
                            throw new Exception("No monitors could be found on the selected device. Could there be a bug somewhere?");
                        }
                        first_monitor = monitors[0];
                    }
                }
                else
                {
                    Size2 size = API.AdjustWindowSize(cfg_width, cfg_height);
                    current_width  = size.Width;
                    current_height = size.Height;
                }

                // GameDebugger.Log("{0},{1}-{2},{3}", first_monitor.X, first_monitor.Y, current_width, current_height);

                using (IOpenGLWindow window = GL.CreateWindow(null, first_monitor.X, first_monitor.Y, current_width, current_height)) {
                    m_Window = window;
                    window.BeforeRenderFrameEvent += OnBeforeFrame;
                    window.RenderFrameEvent       += OnFrame;
                    window.AfterRenderFrameEvent  += OnAfterFrame;
                    window.ResizeEvent            += OnResize;

                    m_Keyboard = IL.FirstKeyboardDevice;

                    Mouse         = IL.FirstMouseDevice;
                    Mouse.Window  = window;                    // mouse must be attached to window before showing since it watches move and resize events
                    Mouse.Visible = GameConfig.ShowHardwareCursor;
                    Mouse.Clipped = GameConfig.ClipMouseCursor;

                    window.Show();

                    GL.SetBufferSwapInterval(GameConfig.VSync ? 1 : 0);
                    GameConfig.VSyncChangedEvent += OnVSyncSettingChanged;

                    OnLoad();
                    if (LoadEvent != null)
                    {
                        LoadEvent();
                    }
                    // GameDebugger.Log("Running main loop at last");
                    Application.Run();
                    // GameDebugger.Log("ByeBye!");
                }
            }

            catch (Exception ex) {
                GameDebugger.EngineLog(LogLevel.Error, "IGE or application has crashed!");
                GameDebugger.EngineLog(LogLevel.Error, ex);
            }

            finally {
                try {
                    CacheableObject.DisposeAll();
                }
                catch (Exception ex) {
                    GameDebugger.EngineLog(LogLevel.Error, "IGE automatic resource unloading has crashed!");
                    GameDebugger.EngineLog(LogLevel.Error, ex);
                }

                try {
                    if (UnloadEvent != null)
                    {
                        UnloadEvent();
                    }
                }
                catch (Exception ex) {
                    GameDebugger.Log(LogLevel.Error, "Application has crashed on UnloadEvent!");
                    GameDebugger.Log(LogLevel.Error, ex);
                }

                try {
                    OnUnload();
                }
                catch (Exception ex) {
                    GameDebugger.EngineLog(LogLevel.Error, "IGE final unloading has crashed!");
                    GameDebugger.EngineLog(LogLevel.Error, ex);
                }

                try {
                    GameConfig.Save();
                }
                catch (Exception ex) {
                    GameDebugger.EngineLog(LogLevel.Error, "IGE could not automatically save the configuration!");
                    GameDebugger.EngineLog(LogLevel.Error, ex);
                }

                try { GameConfig.VSyncChangedEvent -= OnVSyncSettingChanged; } catch {}

                GL.SetBufferSwapInterval(initialVSyncSetting);
                m_Window = null;
            }
        }