daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Jan 17th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var handler = GetConsoleHandle();
  2.             using (var graphics = Graphics.FromHwnd(handler))
  3.             using (var sprSky = Properties.Resources.sky) // Set sky sprite (first layer);
  4.             using (var sprBackgroundClouds = Properties.Resources.background_clouds)
  5.             using (var sprMountains = Properties.Resources.mountains)
  6.             using (var sprCameraClouds = Properties.Resources.camera_clouds)
  7.             using (var sprGrass1 = Properties.Resources.grass_1) // Set the frame 1 sprite of grass;
  8.             using (var sprRoad1 = Properties.Resources.road_1) // Set the frame 1 sprite of road;
  9.             using (var sprGrass2 = Properties.Resources.grass_2) // Set the frame 2 sprite of grass;
  10.             using (var sprRoad2 = Properties.Resources.road_2) // Set the frame 2 sprite of road;
  11.                 while (true)
  12.                 {
  13.                     Console.Title = Convert.ToString(sprAnimSpeed); // Show the delay time (in ms) between the frames of an animated sprite in the console title;
  14.                     Cls(); // Clear console;
  15.                     graphics.Clear(Color.Transparent); // Clear sprites;
  16.  
  17.                     xMountains = xMountains + 5; // x position of mountains sprite; for parallax effect;
  18.                     xBackgroundClouds = xBackgroundClouds - 5; // x position of background clouds sprite; for parallax effect;
  19.                     xCameraClouds = xCameraClouds - 2; // x position of camera clouds; for parallax effect;
  20.  
  21.                     // Draw/redaw the sprites:
  22.  
  23.                     graphics.DrawImage(sprSky, 0, 0, 800, 500); // (sprite, x, y, w, h);
  24.                     graphics.DrawImage(sprBackgroundClouds, xBackgroundClouds, yBackgroundClouds, 800, 500);
  25.                     graphics.DrawImage(sprMountains, xMountains, yMountains, 800, 500);
  26.                     graphics.DrawImage(sprCameraClouds, xCameraClouds, yCameraClouds, 800, 500);
  27.  
  28.                     graphics.DrawImage(sprGrass1, 0, 0, 800, 500); // Frame 1;
  29.                     graphics.DrawImage(sprRoad1, xRoad, yRoad, 800, 500); // Frame 1;
  30.                     Delay(sprAnimSpeed); // Delay time between the last and the next frames;
  31.                     graphics.DrawImage(sprGrass2, 0, 0, 800, 500); // Frame 2;
  32.                     graphics.DrawImage(sprRoad2, xRoad, yRoad, 800, 500); // Frame 2
  33.                     Delay(sprAnimSpeed); // Wait for redraw the sprites in new x positions;
  34.  
  35.                     ConsoleKeyInfo control = Console.ReadKey(true); // When the up arrow is pressed;
  36.                     if (control.Key == ConsoleKey.UpArrow && sprAnimSpeed > 60) // Values for sprAnimSpeed less than 60 ms make it difficult to view due to flickers on the screen;
  37.                     {
  38.                         sprAnimSpeed = sprAnimSpeed - 10;
  39.                     }
  40.  
  41.                 }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top