SHARE
TWEET

Codigo.

a guest Jul 9th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Create:
  2. hsp = 0; //velocidade horizontal
  3. vsp = 0; //velocidade vertical
  4. grv = 0.4; //gravidade
  5. walksp = 3; //velocidade do personagem
  6.  
  7. Step:
  8. //get player input
  9. key_left = keyboard_check(vk_left);
  10. key_righ = keyboard_check(vk_right);
  11. key_jump = keyboard_check_pressed(vk_space);
  12.  
  13. //calculate movement
  14. var move = key_righ - key_left;
  15. hsp = move * walksp;   
  16. vsp = vsp + grv;
  17. if (place_meeting(x,y+1,oWall)) && (key_jump)
  18. {
  19.     vsp = -7;
  20. }
  21.  
  22. //horizontal collision
  23. if (place_meeting(x+hsp,y,oWall))
  24. {
  25.     while (!place_meeting(x+sign(hsp),y,oWall))
  26.         {
  27.             x=x+sign(hsp);
  28.         }
  29.     hsp = 0;
  30. }
  31. x=x+hsp;
  32.  
  33. //horizontal collision
  34. if (place_meeting(x+hsp,y,oWall))
  35. {
  36.     while (!place_meeting(x+sign(hsp),y,oWall))
  37.         {
  38.             x=x+sign(hsp);
  39.         }
  40.     hsp = 0;
  41. }
  42. x=x+hsp;
  43.  
  44. //vertical collision
  45. if (place_meeting(x,y+vsp,oWall))
  46. {
  47.     while (!place_meeting(x,y+sign(vsp),oWall))
  48.         {
  49.             y=y+sign(vsp);
  50.         }
  51.     vsp = 0;
  52. }
  53. y=y+vsp;
  54.  
  55. //aqui ficam as animações:
  56. //Animation
  57. if (!place_meeting(x,y+1,oWall))
  58. {
  59.     sprite_index= sPlayerA;
  60.     image_speed= 0;
  61.     if (sign(vsp)>0) image_index= 1; else image_index= 0;
  62. }
  63. else
  64. {
  65.     image_speed= 1;
  66.     if(hsp==0)
  67.     {
  68.         sprite_index=sPlayer;
  69.     }
  70.     else
  71.     {
  72.         sprite_index=sPlayerR;
  73.     }
  74.    
  75. }
  76. //fazer o sprite do personagem virar ao mudar a direção esquerda ou direita
  77. if(hsp != 0) image_xscale=sign(hsp);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top