Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var handler = GetConsoleHandle();
- using (var graphics = Graphics.FromHwnd(handler))
- using (var sprSky = Properties.Resources.sky) // Set sky sprite (first layer);
- using (var sprBackgroundClouds = Properties.Resources.background_clouds)
- using (var sprMountains = Properties.Resources.mountains)
- using (var sprCameraClouds = Properties.Resources.camera_clouds)
- using (var sprGrass1 = Properties.Resources.grass_1) // Set the frame 1 sprite of grass;
- using (var sprRoad1 = Properties.Resources.road_1) // Set the frame 1 sprite of road;
- using (var sprGrass2 = Properties.Resources.grass_2) // Set the frame 2 sprite of grass;
- using (var sprRoad2 = Properties.Resources.road_2) // Set the frame 2 sprite of road;
- while (true)
- {
- Console.Title = Convert.ToString(sprAnimSpeed); // Show the delay time (in ms) between the frames of an animated sprite in the console title;
- Cls(); // Clear console;
- graphics.Clear(Color.Transparent); // Clear sprites;
- xMountains = xMountains + 5; // x position of mountains sprite; for parallax effect;
- xBackgroundClouds = xBackgroundClouds - 5; // x position of background clouds sprite; for parallax effect;
- xCameraClouds = xCameraClouds - 2; // x position of camera clouds; for parallax effect;
- // Draw/redaw the sprites:
- graphics.DrawImage(sprSky, 0, 0, 800, 500); // (sprite, x, y, w, h);
- graphics.DrawImage(sprBackgroundClouds, xBackgroundClouds, yBackgroundClouds, 800, 500);
- graphics.DrawImage(sprMountains, xMountains, yMountains, 800, 500);
- graphics.DrawImage(sprCameraClouds, xCameraClouds, yCameraClouds, 800, 500);
- graphics.DrawImage(sprGrass1, 0, 0, 800, 500); // Frame 1;
- graphics.DrawImage(sprRoad1, xRoad, yRoad, 800, 500); // Frame 1;
- Delay(sprAnimSpeed); // Delay time between the last and the next frames;
- graphics.DrawImage(sprGrass2, 0, 0, 800, 500); // Frame 2;
- graphics.DrawImage(sprRoad2, xRoad, yRoad, 800, 500); // Frame 2
- Delay(sprAnimSpeed); // Wait for redraw the sprites in new x positions;
- ConsoleKeyInfo control = Console.ReadKey(true); // When the up arrow is pressed;
- 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;
- {
- sprAnimSpeed = sprAnimSpeed - 10;
- }
- }
Add Comment
Please, Sign In to add comment