Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. //////////////// Platform movement engine ////////////////////
  2. //
  3. // Copyright Simon Donkers 3-7-2006
  4. // www.simondonkers.com - gmmentor@simondonkers.com
  5. //
  6. // the arguments are: behind is recommandable value
  7. // argument0 is horizontal speed 4
  8. // argument1 is jump speed 10
  9. // argument2 is gravity 0.3
  10. // argument3 is speed on ladder 3
  11. // [argument4 is object ladder ? (optional)]
  12. //
  13. // This script will if placed in the step event
  14. // generate a correct movement in a platform game
  15. // all solid objects are ground
  16. // replace //sprite_index := ...; discription with:
  17. // sprite_index := the sprite matching the discription;
  18. //
  19. /////////////////////////////////////////////////////
  20.  
  21. right_button = keyboard_check(vk_right) or keyboard_check(ord("D"))
  22. left_button = keyboard_check(vk_left) or keyboard_check(ord("A"))
  23. up_button = keyboard_check(vk_up) or keyboard_check(ord("W"))
  24. down_button = keyboard_check(vk_down) or keyboard_check(ord("S"))
  25.  
  26.  
  27.  
  28. if !left_button and !right_button and !up_button and !down_button and vspeed = 0 then
  29. {//If nothing is happening
  30. //sprite_index := ...; sprite stand still
  31. }
  32. gravity := argument2;
  33. if (vspeed >= 0 && not place_free(x,y + vspeed + 1)) then
  34. {//if falling and there's ground below you
  35. move_contact_solid(270,vspeed + 1);
  36. vspeed = 0;
  37. gravity := 0;
  38. }
  39. if left_button and (not up_button) then
  40. {//if moving left and not flying
  41. for (i = 0; i<= 8; i += 1;)
  42. {//check to see if you are goin up a ramp.
  43. if place_free(x-argument0,y-i)
  44. {
  45. sprite_index = spr_main_idle_left;
  46. x -= argument0; y-= i; exit;
  47. }
  48. }
  49. }
  50. else
  51. {//if moving left and flying
  52. if place_free(x-argument0,y + vspeed + argument2) and left_button then
  53. {
  54. x := x-argument0;
  55. //sprite_index := ...; sprite flying/falling
  56. }
  57. }
  58. if right_button and (not up_button) then
  59. {//if moving right and not flying
  60. for (i = 0; i<= 8; i += 1;)
  61. {//check to see if you are goin up a ramp
  62. if place_free(x + argument0,y-i)
  63. {
  64. sprite_index = spr_main_idle_right;
  65. x += argument0; y-= i; exit;
  66. }
  67. }
  68. }
  69. else
  70. {//if moving right and flying
  71. if place_free(x + argument0,y + vspeed + argument2) and right_button then
  72. {
  73. x := x + argument0;
  74. //sprite_index := ...; sprite flying/falling
  75. }
  76. }
  77. if (argument[4]!=0)
  78. {//if argument4, stair object is given
  79. if place_meeting(x,y,argument4) then
  80. {//if on a stair
  81. gravity = 0; vspeed = 0;
  82. //sprite_index := ...; sprite climbing
  83. }
  84. if (up_button) then
  85. {//if moving up
  86. if place_meeting(x,y,argument4) then
  87. {//if moving up on a stair
  88. if place_free(x,y-argument3) y -= argument3;
  89. //sprite_index := ...; sprite climbing
  90. }
  91. else
  92. if place_free(x,y + 1) = false then
  93. {//if moving up not on a stair and on the ground
  94. vspeed = -argument1;
  95. }
  96. }
  97. if (down_button) then
  98. {//if moving down
  99. if place_meeting(x,y + argument3 + sprite_height-sprite_yoffset,argument4) and place_free(x,y + argument3) then
  100. {//if moving down on a stair and no ground below
  101. y := y + argument3;
  102. vspeed := 0;
  103. //sprite_index := ...; sprite climbing
  104. }
  105. else
  106. {
  107. if place_meeting(x,y + sprite_height-sprite_yoffset,argument4) then
  108. {//if moving down a stair with ground below
  109. move_contact_solid(270,argument3);
  110. vspeed := 0;
  111. }
  112. }
  113. }
  114. }
  115. else //if argument4 (object stair) is not passed along
  116. if up_button and !place_free(x,y + 1) then
  117. vspeed = -argument1; //jump
  118.  
  119. if (not place_free(x,y-sprite_yoffset + vspeed)) then
  120. {//if not place free below the object
  121. vspeed := argument2;
  122. }
  123. if (not place_free(x,y)) and place_free(x,y-1) then
  124. {//if stuck just below surface
  125. y := y-1;
  126. vspeed := 0;
  127. }
  128. if vspeed!= 0 then
  129. {
  130. //sprite_index := ...; sprite flying/falling
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement