Advertisement
Guest User

Untitled

a guest
Oct 27th, 2013
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. Class GuyRunningToTheRightAllTheTime
  2. {
  3.     private Vector2 lastPosition;
  4.     private Vector2 currentPosition;
  5.    
  6.     public GuyRunningToTheRightAllTheTime(Vector2 position)
  7.     {
  8.         // Set both last and current to this position
  9.         lastPosition = position;
  10.         currentPosition = position;
  11.     }  
  12.  
  13.     public void UpdateLogic()
  14.     {
  15.         // Store our current position as our last position
  16.         lastPosition = currentPosition;
  17.  
  18.         // Update current position by a fixed-step
  19.         currentPosition += new Vector3(0.2, 0);
  20.     }
  21.    
  22.     // Delta is a number between 0 and 1. It represents how much time has passed since the last logical frame
  23.     public void UpdateGraphics(float delta)
  24.     {
  25.         // Calculate the difference between the 2 last frames, starting at the last position
  26.         Vector2 differenceBetweenLast2Frames = (currentPosition - lastPosition);
  27.  
  28.         // Calculate the point on this vector based on how long it's been since the last logical frame
  29.         Vector2 pointOnDifference = differenceBetweenLast2Frames * delta;
  30.        
  31.         // Add that difference to the lastPosition
  32.         Vector2 graphicalPosition = pointOnDifference  + lastPosition;
  33.        
  34.         // Draw the guy
  35.         DrawAGuyAt(graphicalPosition );
  36.     }
  37. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement