Advertisement
Sanjin1

Untitled

Sep 7th, 2021
949
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 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.     right_paddle.y += held_keys['up arrow']*0.05 - held_keys['down arrow']*0.05
  42.     left_paddle.y += held_keys['w']*0.05 - held_keys['s']*0.05
  43.     #write the code to move left with w and s (or keys of your choice)
  44.     ball.x += ball.dx
  45.     ball.y += ball.dy
  46.     hit_info = ball.intersects()
  47.     if hit_info.hit:
  48.         if hit_info.entity == floor or hit_info.entity == ceiling:
  49.             ball.dy = -ball.dy #reverses the y speed
  50.         if hit_info.entity == right_paddle:
  51.             ball.dx = -ball.dx #reverses the x speed
  52.         if hit_info.entity == left_paddle:
  53.             ball.dx = -ball.dx #reverses the x speed
  54.            
  55. #EditorCamera()
  56.          
  57. app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement