예제 #1
0
        /*private void ResetScreen()
         * {
         *  Engine.Graphics.GraphicsDevice.Textures[0] = null;
         *  Engine.Graphics.GraphicsDevice.Textures[1] = null;
         *
         *  for (var x = 0; x < 128; x++)
         *  for (var y = 0; y < 128; y++)
         *      pixels[x + y * 128] = Color.Black;
         *  buffer.Target.SetData(pixels);
         * }*/

        public override void Update()
        {
            base.Update();

            // pause menu
            //if (pauseMenu != null)
            //pauseMenu.Update();
            //else if (!leaving && (Input.Pause.Pressed || Input.ESC.Pressed))
            //CreatePauseMenu();
            //pauseFade = Calc.Approach(pauseFade, pauseMenu != null ? 0.75f : 0f, Engine.DeltaTime * 6f);

            // this is a pretty dumb hack but because Celeste is locked to 60fps
            // and PICO-8 runs at 30 ... we just skip every 2nd frame
            // the game buffers inputs so they wont get eaten
            skipFrame = !skipFrame;
            if (skipFrame)
            {
                return;
            }

            // don't update the game
            gameDelay -= Engine.DeltaTime;
            if (!gameActive || gameDelay > 0)
            {
                return;
            }

            // recreating the PICO-8 Boot Sequence
            if (booting)
            {
                /*Engine.Graphics.GraphicsDevice.Textures[0] = null;
                 * Engine.Graphics.GraphicsDevice.Textures[1] = null;
                 *
                 * gameFrame++;
                 * var t = gameFrame - 20;
                 *
                 * if (t == 1)
                 * {
                 *  for (var y = 0; y < 128; y++)
                 *      for (var x = 2; x < 128; x += 8)
                 *          pixels[x + y * 128] = colors[Calc.Random.Next(4) + (y / 32)];
                 *  //buffer.Target.SetData(pixels);
                 * }
                 * if (t == 4)
                 * {
                 *  for (var y = 0; y < 128; y += 2)
                 *      for (var x = 0; x < 128; x += 4)
                 *          pixels[x + y * 128] = colors[6 + (((x + y) / 8) & 7)];
                 *  //buffer.Target.SetData(pixels);
                 * }
                 * if (t == 7)
                 * {
                 *  for (var y = 0; y < 128; y += 3)
                 *      for (var x = 2; x < 128; x += 4)
                 *          pixels[x + y * 128] = colors[10 + Calc.Random.Next(4)];
                 *  //buffer.Target.SetData(pixels);
                 * }
                 *
                 * // wide
                 * if (t == 9)
                 * {
                 *  for (var y = 0; y < 128; y++)
                 *      for (var x = 1; x < 127; x += 2)
                 *          pixels[x + y * 128] = pixels[x + 1 + y * 128];
                 *  buffer.Target.SetData(pixels);
                 * }
                 *
                 * // stripe blank
                 * if (t == 12)
                 * {
                 *  for (var y = 0; y < 128; y++)
                 *      if ((y & 3) > 0)
                 *          for (var x = 0; x < 128; x++)
                 *              pixels[x + y * 128] = colors[0];
                 *  buffer.Target.SetData(pixels);
                 * }
                 *
                 * // clear
                 * if (t == 15)
                 * {
                 *  for (var y = 0; y < 128; y++)
                 *      for (var x = 0; x < 128; x++)
                 *          pixels[x + y * 128] = colors[0];
                 *  buffer.Target.SetData(pixels);
                 * }
                 *
                 * if (t == 30)
                 *  Audio.Play(Sfxs.music_pico8_boot);
                 *
                 * // logo
                 * if (t == 30 || t == 35 || t == 40)
                 * {
                 *  Engine.Graphics.GraphicsDevice.SetRenderTarget(buffer);
                 *  Engine.Graphics.GraphicsDevice.Clear(colors[0]);
                 *  Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, RasterizerState.CullNone);
                 *  picoBootLogo.Draw(new Vector2(1, 1));
                 *  if (t >= 35)
                 *      print("pico-8 0.1.9B", 1, 18, 6);
                 *  if (t >= 40)
                 *  {
                 *      print("(c) 2014-16 lexaloffle games llp", 1, 24, 6);
                 *      print("booting cartridge..", 1, 36, 6);
                 *  }
                 *  Draw.SpriteBatch.End();
                 *  Engine.Graphics.GraphicsDevice.SetRenderTarget(null);
                 * }*/

                // start it up
                //if (t == 90)
                //{
                gameFrame = 0;
                game      = new Classic();
                game.Init(this);
                if (bootLevel.X != 0 || bootLevel.Y != 0)
                {
                    game.load_room(bootLevel.X, bootLevel.Y);
                }
                //}
            }
            else
            {
                gameFrame++;
                game.Update();

                if (game.freeze <= 0)
                {
                    // draw
                    {
                        engine.GraphicsDevice.SetRenderTarget(buffer);
                        engine.GraphicsDevice.Clear(colors[0]);
                        Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, RasterizerState.CullNone, null, Matrix.CreateTranslation(-offset.X, -offset.Y, 0));
                        game.Draw();
                        Draw.SpriteBatch.End();

                        // unset in case we do a palette swap
                        engine.GraphicsDevice.SetRenderTarget(null);
                    }

                    // do a palette swap
                    // this could be done with a shader but on a 128x128 screen ... I don't really care
                    if (paletteSwap.Count > 0)
                    {
                        buffer.GetData(pixels);

                        for (var i = 0; i < pixels.Length; i++)
                        {
                            var index = 0;
                            if (paletteSwap.TryGetValue(pixels[i], out index))
                            {
                                pixels[i] = colors[index];
                            }
                        }

                        buffer.SetData(pixels);
                    }
                }
            }
        }