Cosmo224

free! draw scene code [2020-01-04]

Jan 3rd, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.86 KB | None | 0 0
  1. public void DrawScene() // draws the scene, starting with the lowest priority objects and then going up to the highest priority ones, then draws any text objects and the debug display if it is on.
  2.         {
  3.             Priority currentPriority = Priority.Background1;
  4.             Game.Children.Clear();
  5.             while (currentPriority <= Priority.High)
  6.             {
  7.                 if (currentPriority != Priority.Invisible)
  8.                 {
  9.                     if (Gamestate == GameState.Game || Gamestate == GameState.EditMode)
  10.                     {
  11.                         // v2 for 0.06+
  12.                         for (int i = 0; i < currentlevel.OBJLAYOUT.Count; i++)
  13.                         {
  14.                             if (currentlevel.OBJLAYOUT[i].OBJX - Scrollbar.HorizontalOffset > 0 - currentlevel.OBJLAYOUT[i].OBJIMAGE.PixelWidth & currentlevel.OBJLAYOUT[i].OBJX - Scrollbar.HorizontalOffset < this.Width + currentlevel.OBJLAYOUT[i].OBJIMAGE.PixelWidth & currentlevel.OBJLAYOUT[i].OBJY - Scrollbar.VerticalOffset > 0 - currentlevel.OBJLAYOUT[i].OBJIMAGE.PixelHeight & currentlevel.OBJLAYOUT[i].OBJY - Scrollbar.VerticalOffset < this.Height + currentlevel.OBJLAYOUT[i].OBJIMAGE.PixelHeight | IsSentientBeing(currentlevel.OBJLAYOUT[i]))
  15.                             { // optimization (bld 1037-41)
  16.                                 if (currentlevel.OBJLAYOUT[i].OBJPRIORITY == currentPriority)
  17.                                 {
  18.                                     if (currentlevel.OBJLAYOUT[i].OBJPLAYER == true & Gamestate == GameState.Game)
  19.                                     {
  20.                                         Scrollbar.ScrollToHorizontalOffset(currentlevel.OBJLAYOUT[i].OBJX - this.Width / 6); // level scrolling
  21.                                         Scrollbar.ScrollToVerticalOffset(currentlevel.OBJLAYOUT[i].OBJY - this.Width / 6); // vertical level scrolling
  22.                                     }
  23.  
  24.                                     Rectangle rectangle = new Rectangle();
  25.                                     rectangle.Height = currentlevel.OBJLAYOUT[i].OBJIMAGE.Height;
  26.                                     rectangle.Width = currentlevel.OBJLAYOUT[i].OBJIMAGE.Width;
  27.                                     rectangle.StrokeThickness = 0;
  28.                                     HandleAnimations(currentlevel.OBJLAYOUT[i]);
  29.  
  30.                                     if (Gamestate == GameState.Game & currentlevel.OBJLAYOUT[i].OBJGRAV != false)
  31.                                     {
  32.                                         HandlePhys(currentlevel.OBJLAYOUT[i]);
  33.                                     }
  34.  
  35.                                     HandleAI(currentlevel.OBJLAYOUT[i]);
  36.                                     Canvas.SetLeft(rectangle, currentlevel.OBJLAYOUT[i].OBJX);
  37.                                     Canvas.SetTop(rectangle, currentlevel.OBJLAYOUT[i].OBJY);
  38.                                     rectangle.Fill = new ImageBrush(currentlevel.OBJLAYOUT[i].OBJIMAGE);
  39.                                     Game.Children.Add(rectangle);
  40.  
  41.                                     if (currentlevel.OBJLAYOUT[i].OBJHELDWEAPON != null) // weapon drawing
  42.                                     {
  43.                                         Rectangle WeaponRectangle = new Rectangle();
  44.                                         WeaponRectangle.Height = currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONIMAGE.Height;
  45.                                         WeaponRectangle.Width = currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONIMAGE.Width;
  46.                                         WeaponRectangle.StrokeThickness = 0;
  47.                                         currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONPOSITIONX = currentlevel.OBJLAYOUT[i].OBJX + currentlevel.OBJLAYOUT[i].OBJIMAGE.PixelWidth / 1.33;
  48.                                         currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONPOSITIONY = currentlevel.OBJLAYOUT[i].OBJY + currentlevel.OBJLAYOUT[i].OBJIMAGE.PixelHeight / 2;
  49.                                         Canvas.SetLeft(WeaponRectangle, currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONPOSITIONX);
  50.                                         Canvas.SetTop(WeaponRectangle, currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONPOSITIONY);
  51.                                         WeaponRectangle.Fill = new ImageBrush(currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONIMAGE); // the image.
  52.                                         Game.Children.Add(WeaponRectangle);
  53.  
  54.                                         if (currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONAMMOLIST.Count > 0) // ammo
  55.                                         {
  56.                                             for (int j = 0; j < currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONAMMOLIST.Count; j++ )
  57.                                             {
  58.                                                 Ammo ammo = currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONAMMOLIST[j];
  59.                                                 if (ammo.X - Scrollbar.HorizontalOffset > 0 - currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONIMAGEAMMO.PixelWidth & ammo.X - Scrollbar.HorizontalOffset < this.Width + currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONIMAGEAMMO.PixelWidth & ammo.Y - Scrollbar.VerticalOffset > 0 - currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONIMAGEAMMO.PixelHeight & ammo.Y - Scrollbar.VerticalOffset < this.Width + currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONIMAGEAMMO.PixelHeight)
  60.                                                 {
  61.                                                     Rectangle AmmoRectangle = new Rectangle();
  62.                                                     AmmoRectangle.Width = currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONIMAGEAMMO.Width;
  63.                                                     AmmoRectangle.Height = currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONIMAGEAMMO.Height;
  64.                                                     AmmoRectangle.StrokeThickness = 0;
  65.                                                     Canvas.SetLeft(AmmoRectangle, ammo.X);
  66.                                                     Canvas.SetTop(AmmoRectangle, ammo.Y);
  67.                                                     AmmoRectangle.Fill = new ImageBrush(ammo.AMMOIMAGE);
  68.                                                     Game.Children.Add(AmmoRectangle);
  69.                                                 }
  70.                                                 else
  71.                                                 {
  72.                                                     currentlevel.OBJLAYOUT[i].OBJHELDWEAPON.WEAPONAMMOLIST.RemoveAt(j);
  73.                                                 }
  74.                                             }
  75.                                         }
  76.                                     }
  77.                                 }
  78.                             }
  79.                         }
  80.  
  81.                         if (currentPriority == Priority.High)
  82.                         {
  83.                             if (TextList.Count > 0)
  84.                             {
  85.                                 foreach (AGTextBlock Textblock in TextList)
  86.                                 {
  87.                                     if (Textblock.IsDisplayed == true)
  88.                                     {
  89.                                         Canvas.SetLeft(Textblock, Textblock.GamePos.X);
  90.                                         Canvas.SetTop(Textblock, Textblock.GamePos.Y);
  91.  
  92.                                         // DEBUG CODE //
  93.                                         if (Textblock.TextName == "GlobalTimerDebug" & Settings.DebugMode)
  94.                                         {
  95.                                             int minutes = GlobalTimer / 60 / 60;
  96.                                             int seconds = (GlobalTimer / 60) % 60;
  97.                                             double hundredths = RoundNearest(((GlobalTimer * 60) % 59) * 1.4, 1);
  98.  
  99.                                             if (seconds > 9)
  100.                                             {
  101.                                                 SetText(Textblock, $"--DEBUG--\nFrame No: {GlobalTimer.ToString()}\nLevel Time: {minutes.ToString()}:{seconds.ToString()}.{hundredths.ToString()}\nCurrent Window Size: {this.Width},{this.Height}\n\n-Settings-\nDebug Mode: {Settings.DebugMode}\nDemo Mode: {Settings.DemoMode}\nDemo Mode Max Level: {Settings.DemoModeMaxLevel}\nGame Name: {Settings.GameName}\nResolution: {Settings.Resolution}\nTitle Screen Path: {Settings.TitleScreenPath} \nWindow Size: {Settings.WindowType}");
  102.                                             }
  103.                                             else
  104.                                             {
  105.                                                 SetText(Textblock, $"--DEBUG--\nFrame No: {GlobalTimer.ToString()}\nLevel Time: {minutes.ToString()}:0{seconds.ToString()}.{hundredths.ToString()}\nCurrent Window Size: {this.Width},{this.Height}\n\n-Settings-\nDebug Mode: {Settings.DebugMode}\nDemo Mode: {Settings.DemoMode}\nDemo Mode Max Level: {Settings.DemoModeMaxLevel}\nGame Name: {Settings.GameName}\nResolution: {Settings.Resolution}\nTitle Screen Path: {Settings.TitleScreenPath} \nWindow Size: {Settings.WindowType}");
  106.                                             }
  107.  
  108.                                             Canvas.SetLeft(Textblock, Scrollbar.HorizontalOffset);
  109.                                             Canvas.SetTop(Textblock, Scrollbar.VerticalOffset);
  110.                                         }
  111.                                         // END DEBUG CODE //
  112.  
  113.                                         Game.Children.Add(Textblock);
  114.                                     }
  115.                                 }
  116.                             }
  117.                         }
  118.                         currentPriority++; // increment the object priority we are currently drawing. this allows us to put objects in front of each other etc (currently 5 layers)
  119.                     }
  120.                 }
  121.             }
Add Comment
Please, Sign In to add comment