Advertisement
rishabbansal21

Breakout Game

May 26th, 2021
1,312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. from ursina import *
  2.  
  3. app = Ursina()
  4.  
  5. dx = 0.05
  6. dy = 0.05
  7. score = 0
  8. dead = False
  9.  
  10. def update():
  11.     global dx, dy, score, dead
  12.  
  13.     if not(dead):
  14.         if held_keys['right arrow']:board.x += 0.07
  15.         if held_keys['left arrow']: board.x -= 0.07
  16.  
  17.         ball.x += dx
  18.         ball.y += dy
  19.  
  20.         if ball.x >= 7 or ball.x <= -7: dx *= -1
  21.         if ball.y <= -4: dead = True
  22.  
  23.         hit_info = ball.intersects()
  24.         if hit_info.hit:
  25.             dy *= -1
  26.  
  27.             if hit_info.entity in boxes:
  28.                 destroy(hit_info.entity)
  29.                 score += 1
  30.            
  31.         print_on_screen("SCORE: "+str(score), position=(-0.8,0.5))
  32.  
  33.     else:
  34.         destroy(board)
  35.         destroy(ball)
  36.         for i in boxes:
  37.             destroy(i)
  38.             print_on_screen("GAME OVER!", position=(-0.05,0.2))
  39.             print_on_screen("FINAL SCORE: "+str(score), position=(-0.07,0.15))
  40.  
  41. box_1 = Entity(model="cube", color=color.cyan, texture="brick", scale=(1,0.5,0.5), position=(-10,4,0), collider="box")
  42. boxes = []
  43. for i in range(6,-7,-1):
  44.     for j in range(1,7):
  45.         boxes.append(duplicate(box_1, x=i, y=j/2 + 0.5, color=color.random_color()))
  46.  
  47. board = Entity(model="cube", color=color.orange, texture="brick", scale=(4,0.5,0.5), position=(0,-4,0), collider="box")
  48. ball = Entity(model="sphere", color=color.orange, scale=0.5, position=(0,-2,0), collider="box")
  49. app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement