Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.67 KB | None | 0 0
  1. //Step
  2. //Main Actions
  3.  
  4. //Movement
  5. move = input.left + input.right;
  6.  
  7. //Move right
  8. if (move == 1)
  9. {
  10. hsp += acc;
  11. if (hsp >= maxSpeed) hsp = maxSpeed;
  12. }
  13. else if (hsp > 0)
  14. {
  15. hsp -= acc;
  16. if (hsp <= 0) hsp = 0;
  17. }
  18. //Move left
  19. if (move == -1)
  20. {
  21. hsp -= acc;
  22. if (hsp <= -maxSpeed) hsp = -maxSpeed;
  23. }
  24. else if (hsp < 0)
  25. {
  26. hsp += acc;
  27. if (hsp >= 0) hsp = 0;
  28. }
  29. //Jumping
  30. if (vsp < 5) vsp += grv; //Gravity
  31.  
  32. if (input.a)
  33. {
  34. jumpTime += 1;
  35. if(jumpTime < 8) vsp = -jumpSpeed;
  36. }
  37. else if (place_meeting(x, y+1, obj_wall)) jumpTime = 0;
  38. else jumpTime = 20;
  39.  
  40. //Collisions
  41.  
  42. //Horizontal
  43. if (place_meeting(x+hsp, y, obj_wall))
  44. {
  45. while (!place_meeting(x+sign(hsp), y, obj_wall))
  46. {
  47. x += sign(hsp)
  48. }
  49. hsp = 0;
  50. }
  51. x += hsp;
  52. //Vertical
  53. if (place_meeting(x, y+vsp, obj_wall))
  54. {
  55. while (!place_meeting(x, y+sign(vsp), obj_wall))
  56. {
  57. y += sign(vsp)
  58. }
  59. vsp = 0;
  60. }
  61. y += vsp;
  62.  
  63. //Create
  64. ///Set variables
  65.  
  66. //Movement
  67. hsp = 0;
  68. vsp = 0;
  69. maxSpeed = 10;
  70. acc = 0.05;
  71.  
  72. //Jumping
  73. grv = 0.3;
  74. jumpSpeed = 5;
  75. jumpTime = 0;
  76.  
  77. /////Sonic.gmk
  78. //Create
  79. acc = 0.1;
  80. global.vel = 0;
  81. maxSpeed = 10;
  82. ground = true;
  83. ducking = false;
  84. rolling = false;
  85. canMove = true;
  86. spindash = false;
  87. spindashTimer = 0;
  88. drawAngle = 0;
  89. canHit = true;
  90. canSpriteChange = true;
  91. start_x = x;
  92. start_y = y;
  93. lives = 5;
  94.  
  95. //Step
  96. //Movement
  97. if keyboard_check(vk_left) && !place_meeting(x+(abs(global.vel)*-1)-1, y, objSolid) && (canMove == true or (rolling == true && global.vel > 0))
  98. {
  99. global.vel -= acc * (1+ground);
  100. if global.vel > 0 && ground == false
  101. global.vel -= acc;
  102.  
  103. if rolling == false
  104. image_xscale = -1;
  105. }
  106. if keyboard_check(vk_right) && !place_meeting(x+abs(global.vel)+1, y, objSolid) && (canMove == true or (rolling == true && global.vel < 0))
  107. {
  108. global.vel += acc * (1+ground);
  109. if global.vel < 0 && ground == false
  110. global.vel += acc;
  111.  
  112. if rolling == false
  113. image_xscale = 1;
  114. }
  115.  
  116. //Deacceleration
  117. if ground == true
  118. {
  119. if global.vel > 0
  120. global.vel -= acc/(rolling+1);
  121. else if global.vel < 0
  122. global.vel += acc/(rolling+1);
  123. }
  124.  
  125. closestSolid1 = instance_place(x+abs(global.vel)+1, y, objSolid);
  126. closestSolid2 = instance_place(x+(abs(global.vel)*-1)-1, y, objSolid);
  127. if (global.vel > 0 && closestSolid1 > 0) or (global.vel < 0 && closestSolid2 > 0)
  128. {
  129. if closestSolid1 > 0
  130. {
  131. if closestSolid1.canWall == true
  132. global.vel = 0;
  133. }
  134. else if closestSolid2 > 0
  135. {
  136. if closestSolid2.canWall == true
  137. global.vel = 0;
  138. }
  139. }
  140.  
  141. //Speed Limit
  142. if global.vel > maxSpeed
  143. global.vel = maxSpeed;
  144. else if global.vel < -maxSpeed
  145. global.vel = -maxSpeed;
  146.  
  147. if global.vel > -acc && global.vel < acc
  148. {
  149. global.vel = 0;
  150. rolling = false;
  151. }
  152.  
  153. x += global.vel;
  154.  
  155. //Gravity
  156. if (place_meeting(x, y+vspeed+1, objSolid) or place_meeting(x, y+vspeed+1, objSlopeParent)) && vspeed >= 0
  157. {
  158. ground = true;
  159. gravity = 0;
  160. }
  161. else
  162. {
  163. ground = false;
  164. gravity = 0.25;
  165. if vspeed > 8
  166. vspeed = 8;
  167. }
  168.  
  169. //Handle Sprites
  170. if sprite_index == sprSonicHit
  171. {
  172. if image_index < 1
  173. image_speed = 0.1;
  174. }
  175. if canSpriteChange == true
  176. {
  177. if ground == true && ducking == false && rolling == false && spindash == false
  178. {
  179. if global.vel == 0
  180. sprite_index = sprSonicStand;
  181. else if global.vel > -8 && global.vel < 8
  182. sprite_index = sprSonicWalk;
  183. else
  184. sprite_index = sprSonicRun;
  185.  
  186. image_speed = abs(global.vel / 20);
  187. }
  188. else if sprite_index == sprSonicJump
  189. {
  190. image_speed = 0.2 + abs(global.vel / 20);
  191. }
  192. }
  193.  
  194. //Jumping
  195. if ground == true && keyboard_check_pressed(ord('Z')) && ducking == false && canMove == true
  196. {
  197. vspeed = -7;
  198. sprite_index = sprSonicJump;
  199. }
  200.  
  201. if rolling == true && keyboard_check_pressed(ord('Z'))
  202. {
  203. vspeed = -7;
  204. }
  205. else if rolling == false
  206. {
  207. canMove = true;
  208. }
  209.  
  210. //Ducking
  211. if global.vel == 0 && ground == true && ducking == false && rolling == false && keyboard_check(vk_down)
  212. {
  213. ducking = true;
  214. image_index = 0;
  215. }
  216. //Rolling
  217. else if global.vel != 0 && ground == true && ducking == false && rolling == false && keyboard_check(vk_down)
  218. {
  219. rolling = true;
  220. }
  221.  
  222. if ducking == true && (!keyboard_check(vk_down) or ground == false)
  223. {
  224. ducking = false;
  225. canMove = true;
  226. }
  227.  
  228. if rolling == true && (ground == false or global.vel == 0)
  229. {
  230. rolling = false;
  231. canMove = true;
  232. }
  233.  
  234. if ducking == true && spindash == false
  235. {
  236. mask_index = sprSonicDuckMask;
  237. sprite_index = sprSonicDuck;
  238. if image_index < 1
  239. image_speed = 0.1;
  240. else
  241. image_speed = 0;
  242. canMove = false;
  243. }
  244. else if rolling == true
  245. {
  246. mask_index = sprSonicRollMask;
  247. sprite_index = sprSonicJump;
  248. canMove = false;
  249. }
  250. else if spindash == true
  251. {
  252. mask_index = sprSonicRollMask;
  253. sprite_index = sprSonicSpindash;
  254. image_speed = 0.25;
  255. canMove = false;
  256. }
  257. else
  258. {
  259. mask_index = sprSonicMask;
  260. }
  261.  
  262. //Ducking Animation in the Air Fix
  263. if ground == false && sprite_index == sprSonicDuck
  264. sprite_index = sprSonicJump;
  265.  
  266. //Spindash
  267. if ground == true && ducking == true && keyboard_check_pressed(ord('Z'))
  268. {
  269. spindash = true;
  270.  
  271. if spindashTimer < 64
  272. spindashTimer += 8;
  273.  
  274. if spindashTimer > 64
  275. spindashTimer = 24;
  276.  
  277. sprite_index = sprSonicSpindash;
  278. }
  279.  
  280. spindashTimer = spindashTimer - ((spindashTimer div 0.125) / 256);
  281.  
  282. if ground == true && spindash == true && keyboard_check_released(vk_down)
  283. {
  284. rolling = true;
  285. global.vel = image_xscale * (2 + spindashTimer);
  286. spindash = false;
  287. spindashTimer = 0;
  288. }
  289.  
  290. //Slope Collision
  291. collideSlopes();
  292.  
  293. //Return control when player falls on the ground when getting hit
  294. if (place_meeting(x, y+2*vspeed+2, objSolid) or place_meeting(x, y+2*vspeed+2, objSlopeParent)) && sprite_index == sprSonicHit
  295. {
  296. canMove = false;
  297. canSpriteChange = true;
  298. image_alpha = 0.5;
  299. alarm[0] = 90;
  300. global.vel = 0;
  301. }
  302.  
  303. //Look Up
  304. if ground == false && sprite_index == sprSonicLookUp
  305. sprite_index = sprSonicJump;
  306.  
  307. if keyboard_check(vk_up) && ground == true
  308. {
  309. sprite_index = sprSonicLookUp;
  310. }
  311.  
  312. if keyboard_check(vk_up) && sprite_index == sprSonicLookUp
  313. {
  314. canMove = false;
  315. global.vel = 0;
  316. }
  317.  
  318. if rolling == true && keyboard_check(vk_up)
  319. {
  320. rolling = true;
  321. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement