Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 18th, 2012  |  syntax: None  |  size: 2.29 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Jumping Vs. Gravity
  2. if (FaKeyboard.IsKeyDown(Keys.Space))
  3.         {
  4.             Jumping = true;
  5.             xPosition -= new Vector2(0, 5);
  6.         }
  7.  
  8.         if (xPosition.Y >= 10)
  9.         {
  10.             Jumping = false;
  11.             Grounded = false;
  12.         }
  13.        
  14. if (!Grounded && !Jumping)
  15.         {
  16.             xPosition += new Vector2(1, 3) * speed;
  17.         }
  18.        
  19. Rectangle MegamanRectangle = new Rectangle((int)xPosition.X, (int)xPosition.Y, FrameSizeDraw.X, FrameSizeDraw.Y);
  20.         Rectangle Block1Rectangle = new Rectangle((int)0, (int)73, Block1.Width, Block1.Height);
  21.         Rectangle Block2Rectangle = new Rectangle((int)500, (int)73, Block2.Width, Block2.Height);
  22.  
  23.         if ((MegamanRectangle.Intersects(Block1Rectangle) || (MegamanRectangle.Intersects(Block2Rectangle))))
  24.         {
  25.             Grounded = true;
  26.         }
  27.         else
  28.         {
  29.             Grounded = false;
  30.         }
  31.        
  32. foreach (Object obj in GameWorld)
  33. {
  34.     obj.Velocity *= 0.5; // Slow it down slightly
  35.     obj.Velocity += GravityPerSecond * FrameTime; // Gravity adjusted for time
  36.     obj.Move(obj.Velocity); // Handle collision and movement here
  37. }
  38.        
  39. OnKeyDown(Key k)
  40. {
  41.     if (k == Key.Space)
  42.     {
  43.         obj.Velocity += Vector2(0, 10); // Add an upward impulse
  44.     }
  45. }
  46.        
  47. if (FaKeyboard.IsKeyDown(Keys.Space))
  48.     {
  49.         Jumping = true;
  50.         xPosition -= new Vector2(0, 5);
  51.     }
  52.  
  53.     if (xPosition.Y >= 10)
  54.     {
  55.         Jumping = false;
  56.         Grounded = false;
  57.     }
  58.        
  59. if (!Jumping && FaKeyboard.IsKeyDown(Keys.Space))
  60.     {
  61.         Jumping = true;
  62.         Grounded = false;
  63.     }
  64.  
  65.     if (Jumping)
  66.     {
  67.         xPosition -= new Vector2(0, 5);
  68.     }
  69.  
  70.     if (xPosition.Y >= 10)
  71.     {
  72.         Jumping = false;
  73.     }
  74.        
  75. const float SCALE = 20.0f; //SPEED!!!
  76. if (jump <= 15 && jump != 0)
  77.             {
  78.                 humanPosition.Y -= SCALE * speed;
  79.                 jump++;
  80.             }
  81.             else if (jump > 15)
  82.             {
  83.                 humanPosition.Y += SCALE * speed;
  84.                 jump++;
  85.                 if (jump == 32)
  86.                 {
  87.                     jump = 0;
  88.                     humanPosition.Y = 307;
  89.                 }
  90.             }
  91.        
  92. else if (keyboard.IsKeyDown(Keys.Up))
  93.         {
  94.             jump = 1;
  95.             humanPosition.Y -= SCALE * speed;
  96.         }
  97.        
  98. if (humanPosition.Y != GROUNDLEVEL){}