Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. ///Main
  2.  
  3. //Mouse controls
  4. direction -= sensitivity * (display_mouse_get_x() - display_get_width() *.5)
  5. pitch += sensitivity * (display_mouse_get_y() - display_get_height() *.5)
  6. //Limit Pitch
  7. if pitch > 80 {
  8. pitch=80;
  9. }
  10. if pitch < -80 {
  11. pitch=-80;
  12. }
  13.  
  14.  
  15. //Center mouse
  16. if !keyboard_check(ord("M")) {
  17. display_mouse_set(display_get_width()*.5,display_get_height()*.5);
  18. }
  19. //Get keys
  20. fbkeys = keyboard_check(ord("W"))-keyboard_check(ord("S"));
  21. rlkeys = keyboard_check(ord("D"))-keyboard_check(ord("A"));
  22.  
  23. //Add velocity
  24. fbvel += fbkeys*acc;
  25. rlvel += rlkeys*acc;
  26.  
  27. //Speed limit
  28. if fbvel < -maxspd {
  29. fbvel = -maxspd;
  30. }
  31. if fbvel > maxspd {
  32. fbvel = maxspd;
  33. }
  34. if rlvel < -maxspd {
  35. rlvel = -maxspd;
  36. }
  37. if rlvel > maxspd {
  38. rlvel = maxspd;
  39. }
  40.  
  41. //Decelerate
  42. if (fbkeys=0 && abs(fbvel) >= acc) {
  43. fbvel-=sign(fbvel)*acc;
  44. }
  45. if (rlkeys=0 && abs(rlvel) >= acc) {
  46. rlvel-=sign(rlvel)*acc;
  47. }
  48.  
  49. //Set Z velocity
  50. if !place_meeting_ext(x,y,z,o_psolid) {
  51. zvel-=grav;
  52. }
  53.  
  54. //Jumping
  55. if place_meeting_ext(x,y,z-1,o_psolid) {
  56. if keyboard_check_pressed(vk_space) {
  57. zvel+=jumpheight;
  58. }
  59. }
  60.  
  61. //Running
  62. if (keyboard_check(vk_shift) && fbvel > 0 && height = walkheight) {
  63. maxspd=runmaxspd;
  64. if fov<runfov {
  65. fov+=2;
  66. }
  67. }
  68. else {
  69. maxspd=walkmaxspd;
  70. if fov>walkfov {
  71. fov-=2;
  72. }
  73. }
  74.  
  75. //Crouching
  76. if keyboard_check(vk_control) {
  77. maxspd=crouchmaxspd;
  78. if height > crouchheight {
  79. height-=2;
  80. }
  81. }
  82. else {
  83. if !place_meeting_ext(x,y,z+walkheight, o_psolid) {
  84. maxspd=walkmaxspd;
  85. if height < walkheight {
  86. height+=2;
  87. }
  88. }
  89. }
  90.  
  91. //Translate Velocities
  92. xvel = lengthdir_x(fbvel, direction) + lengthdir_x(rlvel, direction-90);
  93. yvel = lengthdir_y(fbvel, direction) + lengthdir_y(rlvel, direction-90);
  94.  
  95.  
  96. //Collisions
  97.  
  98. //X
  99. if !place_meeting_ext(x+xvel,y, z, o_psolid) {
  100. x+=xvel;
  101. }
  102. else {
  103. while (!place_meeting_ext(x+sign(xvel),y, z, o_psolid)) {
  104. x+=sign(xvel);
  105. }
  106. xvel=0;
  107. }
  108. //Y
  109. if !place_meeting_ext(x,y+yvel, z, o_psolid) {
  110. y+=yvel;
  111. }
  112. else {
  113. while (!place_meeting_ext(x,y+sign(yvel), z, o_psolid)) {
  114. y+=sign(yvel);
  115. }
  116. yvel=0;
  117. }
  118. //Z
  119. if !place_meeting_ext(x,y, z+zvel, o_psolid) {
  120. z+=zvel;
  121. }
  122. else {
  123. while (!place_meeting_ext(x,y, z+sign(zvel), o_psolid)) {
  124. z+=sign(zvel);
  125. }
  126. zvel=0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement