Advertisement
Guest User

SLashC++Programmer

a guest
Jan 28th, 2017
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. 'FRLRT
  3.  
  4. SuperStrict
  5.  
  6. AppTitle$ = "Fixed Rate Logic with Render Tweening"
  7.  
  8. Graphics 800,600
  9.  
  10. Local newTime:Int = MilliSecs()
  11. Local oldtime:Int = newTime
  12. Local dt# = 1000 / 60   '100 FPS logic
  13. Local deltaTime#, accumulator#, alpha#, t#
  14.  
  15. global CurrentvPosX:int = 40;
  16. global CurrentvPosY:int = 50;
  17.  
  18. global PrevvPosX:int = 40;
  19. global PrevvPosY:int = 50;
  20.  
  21.  
  22. global CurrentVelX:int = 2;
  23. global CurrentVelY:int = 2;
  24.  
  25.  
  26.  
  27. SetBlend ALPHABLEND
  28.  
  29. Global imgBall:TImage = LoadImage("ball.png")
  30. MidHandleImage imgBall
  31.  
  32. Global RenderTween:Int = False
  33.  
  34. While Not KeyHit(KEY_ESCAPE)
  35. Cls
  36.  
  37.     newTime = MilliSecs()
  38.     deltaTime# = (newTime - oldTime)
  39.     oldTime = newTime
  40.  
  41.     accumulator :+ deltaTime
  42.  
  43.     While accumulator >= dt
  44.    
  45.         PrevvPosX = CurrentvPosX
  46.         PrevvPosY  = CurrentvPosY
  47.         CurrentvPosX = CurrentvPosX  + CurrentVelX
  48.         CurrentvPosY = CurrentvPosY  + CurrentVelY
  49.  
  50.         If CurrentvPosY <= 0 Or CurrentvPosY  >= 600
  51.             CurrentVelY = -CurrentVelY
  52.         EndIf
  53.         If CurrentvPosX <= 0 Or CurrentvPosX >= 800
  54.             CurrentVelX = -CurrentVelX
  55.         EndIf
  56.  
  57.         accumulator :- dt
  58.        
  59.     Wend
  60.  
  61.     alpha = accumulator / dt
  62.                
  63.        
  64.        
  65.     Local tx#, ty#
  66.     If RenderTween
  67.         tx# = CurrentvPosX * alpha + PrevvPosX * (1.0 - alpha)
  68.         ty# = CurrentvPosY * alpha + PrevvPosY * (1.0 - alpha)
  69.     Else
  70.         tx# = CurrentvPosX
  71.         ty# = CurrentvPosY
  72.     EndIf
  73.    
  74.     DrawImage imgBall, tx#, ty#
  75.  
  76.     If KeyHit(KEY_SPACE) Then RenderTween = 1 - RenderTween
  77.     DrawText "RenderTween: "+RenderTween,5,50
  78.  
  79.  
  80. Flip 1  
  81.  
  82. Wend
  83. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement