Sanjin1

Untitled

Sep 14th, 2021
757
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from ursina import * # imports all the Ursina tools uvfusdyvf56
  2.  
  3. app = Ursina()
  4.  
  5. #create a floor and a ceiling
  6. ceiling = Entity(model = 'cube',
  7.                       position = (0,4,0),
  8.                       color = color.green,
  9.                       scale =(15,0.3),
  10.                       collider = 'box')
  11.  
  12. floor = Entity(model = 'cube',
  13.                       position = (0,-4,0),
  14.                       color = color.green,
  15.                       scale =(15,0.3),
  16.                       collider = 'box')
  17.  
  18. right_paddle = Entity(model = 'cube',
  19.                       position = (7,0,0),
  20.                       color = color.blue,
  21.                       scale =(0.3,2),
  22.                       collider = 'box',
  23.                       score = 0)
  24.  
  25. left_paddle = Entity(model = 'cube',
  26.                      position = (-7,0,0),
  27.                      color = color.red,
  28.                      scale =(0.3,2),
  29.                      collider = 'box',
  30.                      score = 0)
  31.  
  32. ball = Entity(model = 'sphere',
  33.                 position = (0,0,0),
  34.                 color = color.yellow,
  35.                 dx = 0.05, dy = 0.05,
  36.                 collider = 'box',
  37.                 scale =0.4)
  38.  
  39.  
  40. def update(): #special because it runs 60 times per second
  41.     if held_keys['r']:
  42.         ball.position = (0,0,0)
  43.         destroy(right_paddle)
  44.     right_paddle.y += held_keys['up arrow']*0.05 - held_keys['down arrow']*0.05
  45.     left_paddle.y += held_keys['w']*0.05 - held_keys['s']*0.05
  46.    
  47.     if right_paddle.y > 2.8: right_paddle.y = 2.8
  48.     if right_paddle.y < -2.8: right_paddle.y = -2.8
  49.     if left_paddle.y > 2.8: left_paddle.y = 2.8
  50.     if left_paddle.y < -2.8: left_paddle.y = -2.8
  51.  
  52.     #write the code to move left with w and s (or keys of your choice)
  53.     ball.x += ball.dx
  54.     ball.y += ball.dy
  55.    
  56.     hit_info = ball.intersects()
  57.    
  58.     if hit_info.hit:
  59.         if hit_info.entity == floor or hit_info.entity == ceiling:
  60.             ball.dy = -ball.dy #reverses the y speed
  61.         if hit_info.entity == right_paddle:
  62.             ball.dx = -ball.dx * 1.1
  63.             ball.dy = (ball.y - right_paddle.y)*0.05 * 1.1
  64.         if hit_info.entity == left_paddle:
  65.             ball.dx = -ball.dx  * 1.1
  66.             ball.dy = (ball.y - left_paddle.y)*0.05 * 1.1
  67.  
  68. #scoring code
  69.     if ball.x > 8:
  70.         left_paddle.score += 1
  71.         ball.position = (0,0,0)
  72.         ball.dx = 0.05
  73.         ball.dy = 0.05
  74.     if ball.x < -8:
  75.         right_paddle.score += 1
  76.         ball.position = (0,0,0)
  77.         ball.dx = 0.05
  78.         ball.dy = 0.05
  79.  
  80.     if right_paddle.score == 3:
  81.         scene.clear()
  82.         message = Text(text = 'BLUE WINS')
  83.         application.pause()
  84.     if left_paddle.score == 3:
  85.         scene.clear()
  86.         message = Text(text = 'RED WINS')
  87.         application.pause()
  88.     #status = Text(text = 'RED: '+ str(left_paddle.score), origin = (-4,0), background = True)
  89. EditorCamera()
  90.          
  91. app.run()
RAW Paste Data