Advertisement
Guest User

teleport walking

a guest
Nov 19th, 2015
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. // room script file
  2.  
  3. #define wa1 1
  4. #define wa2 2
  5. #define tp1_x 260
  6. #define tp1_y 88
  7. #define tp2_x 382
  8. #define tp2_y 314
  9.  
  10. int doStuffafterTeleporting;
  11. int dsat_x, dsat_y;
  12.  
  13. function afterTeleporting() {
  14.   int p = doStuffafterTeleporting;
  15.   // non blocking walk
  16.   if (p == 1) player.Walk(dsat_x, dsat_y);
  17.   // blocking walk
  18.   if (p == 2) player.Walk(dsat_x, dsat_y, eBlock);
  19.  
  20.   doStuffafterTeleporting = 0;
  21. }
  22.  
  23. function WalkTo(this Character*, int x, int y, BlockingStyle blocking) {
  24.   int wa_this = GetWalkableAreaAt(this.x - GetViewportX(), this.y - GetViewportY());
  25.   int wa_target = GetWalkableAreaAt(x - GetViewportX(), y - GetViewportY());
  26.   if (wa_this == wa_target) {
  27.     this.Walk(x, y, blocking);
  28.     return;
  29.   }
  30.   else {
  31.     if (blocking == eBlock) {
  32.       doStuffafterTeleporting = 2;
  33.       dsat_x = x;
  34.       dsat_y = y;
  35.       if (wa_this == wa1) player.Walk(tp1_x, tp1_y, eBlock);
  36.       if (wa_this == wa2) player.Walk(tp2_x, tp2_y, eBlock);
  37.     }
  38.     else {
  39.       // some more work to be done
  40.     }
  41.   }
  42. }
  43.  
  44. function poster_Interact()
  45. {
  46.   player.WalkTo(305, 225, eBlock);
  47. }
  48.  
  49.  
  50.  
  51. function room_RepExec()
  52. {
  53.   if (IsTimerExpired(20)) afterTeleporting();
  54. }
  55.  
  56. bool region1_active = true, region2_active = true;
  57. Region *lastRegion;
  58.  
  59. void repeatedly_execute_always() {
  60.   if (lastRegion == null) lastRegion = region[0];
  61.   Region *currentRegion = Region.GetAtRoomXY(player.x, player.y);
  62.   if (currentRegion != lastRegion) {
  63.     // stepping off lastRegion
  64.     if (lastRegion == region[wa1]) {
  65.       region1_active = true;
  66.     }
  67.     if (lastRegion == region[wa2]) {
  68.       region2_active = true;
  69.     }
  70.     // stepping on currentRegion
  71.     if (currentRegion == region[wa1]) {
  72.       if (region1_active) {
  73.         region2_active = false;
  74.         player.StopMoving();
  75.         player.x = 382;
  76.         player.y = 314;
  77.         currentRegion = region[wa2];
  78.         if (doStuffafterTeleporting > 0) SetTimer(20, 1);
  79.       }
  80.     }
  81.     else if (currentRegion == region[wa2]) {
  82.       if (region2_active) {
  83.         region1_active = false;
  84.         player.StopMoving();
  85.         player.x = 260;
  86.         player.y = 88;
  87.         currentRegion = region[wa1];
  88.         if (doStuffafterTeleporting > 0) SetTimer(20, 1);
  89.       }
  90.     }
  91.   }
  92.   lastRegion = currentRegion;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement