Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from ursina import * # imports all the Ursina tools uvfusdyvf56
- app = Ursina()
- #create a floor and a ceiling
- ceiling = Entity(model = 'cube',
- position = (0,4,0),
- color = color.green,
- scale =(15,0.3),
- collider = 'box')
- floor = Entity(model = 'cube',
- position = (0,-4,0),
- color = color.green,
- scale =(15,0.3),
- collider = 'box')
- right_paddle = Entity(model = 'cube',
- position = (7,0,0),
- color = color.blue,
- scale =(0.3,2),
- collider = 'box',
- score = 0)
- left_paddle = Entity(model = 'cube',
- position = (-7,0,0),
- color = color.red,
- scale =(0.3,2),
- collider = 'box',
- score = 0)
- ball = Entity(model = 'sphere',
- position = (0,0,0),
- color = color.yellow,
- dx = 0.05, dy = 0.05,
- collider = 'box',
- scale =0.4)
- def update(): #special because it runs 60 times per second
- if held_keys['r']:
- ball.position = (0,0,0)
- destroy(right_paddle)
- right_paddle.y += held_keys['up arrow']*0.05 - held_keys['down arrow']*0.05
- left_paddle.y += held_keys['w']*0.05 - held_keys['s']*0.05
- if right_paddle.y > 2.8: right_paddle.y = 2.8
- if right_paddle.y < -2.8: right_paddle.y = -2.8
- if left_paddle.y > 2.8: left_paddle.y = 2.8
- if left_paddle.y < -2.8: left_paddle.y = -2.8
- #write the code to move left with w and s (or keys of your choice)
- ball.x += ball.dx
- ball.y += ball.dy
- hit_info = ball.intersects()
- if hit_info.hit:
- if hit_info.entity == floor or hit_info.entity == ceiling:
- ball.dy = -ball.dy #reverses the y speed
- if hit_info.entity == right_paddle:
- ball.dx = -ball.dx * 1.1
- ball.dy = (ball.y - right_paddle.y)*0.05 * 1.1
- if hit_info.entity == left_paddle:
- ball.dx = -ball.dx * 1.1
- ball.dy = (ball.y - left_paddle.y)*0.05 * 1.1
- #scoring code
- if ball.x > 8:
- left_paddle.score += 1
- ball.position = (0,0,0)
- ball.dx = 0.05
- ball.dy = 0.05
- if ball.x < -8:
- right_paddle.score += 1
- ball.position = (0,0,0)
- ball.dx = 0.05
- ball.dy = 0.05
- if right_paddle.score == 3:
- scene.clear()
- message = Text(text = 'BLUE WINS')
- application.pause()
- if left_paddle.score == 3:
- scene.clear()
- message = Text(text = 'RED WINS')
- application.pause()
- EditorCamera()
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement