Guest User

Untitled

a guest
Apr 24th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. Information about object: obj_dude
  2.  
  3. Sprite: spr_dude
  4. Solid: false
  5. Visible: true
  6. Depth: -1
  7. Persistent: false
  8. Parent: <no parent>
  9. Mask: <same as sprite>
  10.  
  11. Create Event:
  12. execute code:
  13.  
  14. //controller variables for returning the current velocity of movment
  15. yspeed=0
  16. xspeed=0
  17. //variables to check player input
  18. ymove=0
  19. xmove=0
  20. //inital velocity, and momentum
  21. inivel=2.5
  22. inimo=0.2
  23.  
  24. //create an instance of our window controlling tool
  25. //instance_create(x,y,obj_windowcontrol)
  26. //create an instance of our debug tool
  27. instance_create(x,y,obj_debug)
  28. //and set the speed of animation down so we don't have to repeat frames manually
  29. image_speed=0.1
  30.  
  31.  
  32.  Step Event:
  33. execute code:
  34.  
  35. //shoot
  36. if keyboard_check(ord("Z")){
  37.     instance_create(x+24,y+10,obj_bullet1)
  38. }
  39. //this codeblock controls movement
  40. //move up
  41. if keyboard_check(vk_up){
  42.     if yspeed<inivel{
  43.         yspeed+=inimo
  44.     }
  45.     ymove=1
  46. }
  47. //move down
  48. if keyboard_check(vk_down){
  49.     if yspeed>-inivel{
  50.         yspeed-=inimo
  51.     }
  52.     ymove=1
  53. }
  54. //move left
  55. if keyboard_check(vk_left){
  56.     if xspeed<inivel{
  57.         xspeed+=inimo
  58.     }
  59.     xmove=1
  60. }
  61. //move right
  62. if keyboard_check(vk_right){
  63.     if xspeed>-inivel{
  64.         xspeed-=inimo
  65.     }
  66.     xmove=1
  67. }
  68. //now we check to see if the player is pressing multiple keys at once, or pressing no keys
  69. if !keyboard_check(vk_right)&&!keyboard_check(vk_left){
  70.     xmove=0
  71. }
  72.  
  73. if !keyboard_check(vk_up)&&!keyboard_check(vk_down){
  74.     ymove=0
  75. }
  76.  
  77. if keyboard_check(vk_right)&&keyboard_check(vk_left){
  78.     xmove=0
  79. }
  80.  
  81. if keyboard_check(vk_up)&&keyboard_check(vk_down){
  82.     ymove=0
  83. }
  84. //and finally, this codeblock controls the decending momentum
  85. if xmove=0&&xspeed>0{
  86.     xspeed-=inimo
  87. }
  88. if ymove=0&&yspeed>0{
  89.     yspeed-=inimo
  90. }
  91. if xmove=0&&xspeed<0{
  92.     xspeed+=inimo
  93. }
  94. if ymove=0&&yspeed<0{
  95.     yspeed+=inimo
  96. }
  97. //now we just update the x and y position of the player relative to our variables and we are good to go
  98. x-=xspeed
  99. if place_meeting(x,y,obj_block) { x+=xspeed; xspeed=0; }
  100. y-=yspeed
  101. if place_meeting(x,y,obj_block) { y+=yspeed; yspeed=0; }
  102.  
  103. //debug controlling
  104. if keyboard_check_pressed(ord("O")){
  105.     inimo+=0.1
  106. }
  107. if keyboard_check_pressed(ord("L")){
  108.      inimo-=0.1  
  109. }
  110. if keyboard_check_pressed(ord("I")){
  111.     inivel+=0.5
  112. }
  113. if keyboard_check_pressed(ord("K")){
  114.      inivel-=0.5  
  115. }
  116.  
  117.  
  118. Draw Event:
  119. execute code:
  120.  
  121. //fix graphics tearing
  122. draw_sprite(sprite_index,image_index,round(x),round(y))
Add Comment
Please, Sign In to add comment