Advertisement
Sanjin1

Untitled

Sep 7th, 2021
1,002
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.26 KB | None | 0 0
  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.  
  24. left_paddle = Entity(model = 'cube',
  25.                      position = (-7,0,0),
  26.                      color = color.red,
  27.                      scale =(0.3,2),
  28.                      collider = 'box')
  29.  
  30. ball = Entity(model = 'sphere',
  31.                 position = (0,0,0),
  32.                 color = color.yellow,
  33.                 dx = 0.05, dy = 0.05,
  34.                 collider = 'box',
  35.                 scale =0.4)
  36.  
  37.  
  38. def update(): #special because it runs 60 times per second
  39.     if held_keys['r']:
  40.         ball.position = (0,0,0)
  41.         destroy(right_paddle)
  42.     right_paddle.y += held_keys['up arrow']*0.05 - held_keys['down arrow']*0.05
  43.     left_paddle.y += held_keys['w']*0.05 - held_keys['s']*0.05
  44.    
  45.     if right_paddle.y > 2.8: right_paddle.y = 2.8
  46.     if right_paddle.y < -2.8: right_paddle.y = -2.8
  47.     if left_paddle.y > 2.8: left_paddle.y = 2.8
  48.     if left_paddle.y < -2.8: left_paddle.y = -2.8
  49.  
  50.     #write the code to move left with w and s (or keys of your choice)
  51.     ball.x += ball.dx
  52.     ball.y += ball.dy
  53.     hit_info = ball.intersects()
  54.    
  55.     if hit_info.hit:
  56.         if hit_info.entity == floor or hit_info.entity == ceiling:
  57.             ball.dy = -ball.dy #reverses the y speed
  58.         if hit_info.entity == right_paddle:
  59.             ball.dx = -ball.dx #reverses the x speed
  60.             ball.dy = (ball.y - right_paddle.y)*0.05
  61.         if hit_info.entity == left_paddle:
  62.             ball.dx = -ball.dx #reverses the x speed
  63.             ball.dy = (ball.y - left_paddle.y)*0.05
  64.            
  65. EditorCamera()
  66.          
  67. app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement