Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. //Bezier curve movement for enemies and objects
  2.  
  3. function MapBezier(array,frames,t){ //array of points, frames, current frame
  4. if(length(array)==2){
  5. return [array[0][0] + (array[1][0]-array[0][0])/frames*t , array[0][1] + (array[1][1]-array[0][1])/frames*t];
  6. }else{
  7. let newarray = [];
  8. ascent(i in 0..length(array)-1){
  9. newarray = newarray ~ [[array[i][0] + (array[i+1][0]-array[i][0])/frames*t , array[i][1] + (array[i+1][1]-array[i][1])/frames*t]];
  10. }
  11. return MapBezier(newarray,frames,t);
  12. }
  13. }
  14.  
  15. //Move from first to last xy points in a quadratic bezier curve motion, in "frames" amount of frames
  16. task SetMovePositionBezier(originalarray,frames){
  17. let currentpos;
  18. ascent(t in 0..frames){
  19. currentpos = MapBezier(originalarray,frames,t);
  20. SetX(currentpos[0]);
  21. SetY(currentpos[1]);
  22. yield;
  23. }
  24. }
  25.  
  26. task Obj_Move_Bezier(obj,originalarray,frames){
  27. let currentpos;
  28. ascent(t in 0..frames){
  29. currentpos = MapBezier(originalarray,frames,t);
  30. Obj_SetX(obj,currentpos[0]);
  31. Obj_SetY(obj,currentpos[1]);
  32. yield;
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement