Guest User

Untitled

a guest
Jun 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. package{
  2.  
  3. import flash.events.*;
  4. import flash.display.*;
  5. import flash.utils.*;
  6.  
  7. public class physicsTest extends MovieClip{
  8.  
  9. public var listPosY:Array=new Array(6);
  10. public var timer:Timer =new Timer(10);
  11.  
  12. public function physicsTest(){
  13. listPosY[0]=0;
  14. listPosY[1]=50;
  15. listPosY[2]=100;
  16. listPosY[3]=150;
  17. listPosY[4]=200;
  18. listPosY[5]=250;
  19. timer.addEventListener(TimerEvent.TIMER, updateFxn);
  20. }
  21. /*update, lol*/
  22. public function updateFxn(event:Event):void
  23. {
  24. listPosY=listPosY.map(wrap(addVerticalVelocity(g(1))));
  25. trace(listPosY);
  26. }
  27. /*wrap function taken from that site you showed me so I could avoid errors.*/
  28. public function wrap(f:Function):Function
  29. {
  30. return(
  31. function( x : *, index : int, array : Array ) : *
  32. {
  33. return f( x )
  34. }
  35. )//end return
  36. }
  37. /*addVertical velocity should be adding the velocity of the current moment to the base position in yPosArray*/
  38. public function addVerticalVelocity(value:Number):Function
  39. {
  40. return(
  41. function(y:int, index:int, array:Array):Number{
  42. return (y+value);
  43. }
  44. )//end return
  45. }
  46. /*this function should apply g to the velocity, with the argument used (1, in this instance) and adding gravity to it*/
  47. public function g(value:Number):Function
  48. {
  49. return(
  50. function(y:int, index:int, array:Array):Number
  51. {
  52. return(value+.098);
  53. }
  54. )//end return
  55. }
  56. }
  57. }
Add Comment
Please, Sign In to add comment