Advertisement
LettuceCookie

Pong Clone code: obj_ball Ver.3

Jul 12th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///obj_ball code
  2. ///Create Event
  3.  
  4. //Movement
  5. yv = 4;
  6. xv = 4;
  7.  
  8. //Ball starts off in random direction
  9. //This needs to be tweaked, but is not too important right now
  10. ChooseX = choose (-xv, xv);
  11. ChooseY = choose (-yv, yv);
  12.  
  13. ///Step Event
  14.  
  15. //The actual collision
  16. if (place_meeting(x,y,obj_paddle))
  17. {
  18. if (obj_paddle.spd = 0)
  19. {
  20.     xv *= -1;
  21.     yv *= -1;
  22.    
  23. }
  24.  
  25.     //If paddle and ball are moving in the same direction
  26. if ((obj_paddle.spd < 0) && (yv < 0) || obj_paddle.spd > 0) && (yv > 0)
  27. {
  28.    xv *= -1;
  29.    yv = obj_paddle.spd - yv;
  30.    direction = 360;
  31. }
  32.    
  33.     //If paddle and ball are not moving in same direction
  34.     if((obj_paddle.spd < 0) && (yv > 0) || obj_paddle.spd > 0) && (yv < 0)
  35. {
  36.         //Don't know what to do here (!!!)
  37.         xv *= -1;
  38.         yv *= -1;
  39.         direction = 360;
  40. }
  41. }
  42.  
  43. //}
  44. //x = nextX;
  45. //y = nextY
  46.  
  47.  
  48.  
  49. //Checking if ball hits wall, bounces it back
  50. if(y <= sprite_height/2 || y >= room_height - (sprite_height/2))
  51. {
  52.     yv *= -1; //if vspeed goes up, -1 * -1 = 1, down, opp. for other
  53. }
  54.  
  55.  
  56. //Brings ball back to original position if goes offscreen, gives points
  57. if (x >= room_width)
  58. {
  59.     //Give Player 2 a point
  60.     with (obj_gamecontrol) player2points = player2points + 1;
  61.    
  62.     //Reset position, send Player 2's way
  63.     x = xstart;
  64.     y = ystart;
  65.  
  66.     xv = -4;
  67.     yv = -4;
  68.    
  69.     //PickDirection = choose (xv, yv)
  70. }
  71.  
  72. if (x <= 0)
  73. {
  74.     //give Player 1 a point
  75.     with (obj_gamecontrol) player1points = player1points + 1;
  76.    
  77.     //Reset position, send Player 1's way
  78.     x = xstart;
  79.     y = ystart;
  80.  
  81.     xv = 4;
  82.     yv = 4;
  83.    
  84.     //How can this work?
  85.     //PickDirection = choose (xv, yv)
  86.    
  87.    
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement