Advertisement
rishabbansal21

Covid Fighter Part-3

Jun 4th, 2021
1,389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | None | 0 0
  1. from ursina import *
  2. import random
  3.  
  4. app = Ursina()
  5. shoot = False
  6. v = 0
  7. score = 0
  8. hit = False
  9. over = False
  10.  
  11.  
  12. def update():
  13.     global doctor, shoot, vaccine_list, virus_list, score, hit, over, v
  14.  
  15.     if not(over):
  16.  
  17.         if held_keys['right arrow']:
  18.             doctor.x += 0.007
  19.         if held_keys['left arrow']:
  20.             doctor.x -= 0.007
  21.  
  22.         if shoot:
  23.             vaccine_list[v].y += 0.015
  24.  
  25.             if vaccine_list[v].y > 0.3 or hit:
  26.                 destroy(vaccine_list[v])
  27.                 shoot = False
  28.                 hit = False
  29.  
  30.             hit_info = vaccine_list[v].intersects()
  31.             if hit_info.hit:
  32.                 hit = True
  33.                 score += 1
  34.                
  35.                 if hit_info.entity in virus_list:
  36.                     j = virus_list.index(hit_info.entity)
  37.                     destroy(virus_list[j])
  38.                     virus_list[j] = duplicate(virus, x=random.randint(-45,45)/100, y=random.randint(-3,-1)/100)
  39.  
  40.         for i in virus_list:
  41.             i.y -= 0.001
  42.             if i.y< -0.8:
  43.                 over = True
  44.  
  45.         print_on_screen("SCORE: "+str(score), position=(-0.8,0.5))
  46.  
  47.     elif over == True:
  48.         for i in vaccine_list:
  49.             destroy(i)
  50.  
  51.         for i in virus_list:
  52.             destroy(i)
  53.  
  54.         destroy(doctor)
  55.  
  56.         print_on_screen("GAME OVER!", position=(-0.05,0.2))
  57.         print_on_screen("FINAL SCORE: "+str(score), position=(-0.07,0.15))
  58.  
  59.  
  60.  
  61. def input(key):
  62.     global shoot, vaccine_list, v
  63.     st = -0.8
  64.     if key == "space":
  65.         shoot = True
  66.         v += 1
  67.         vaccine_list.append(duplicate(vaccine, x=doctor.x, y=st))
  68.  
  69.  
  70. Entity(model="quad", scale=70, texture="back.jpg")
  71.  
  72. back_size = 22
  73. back = Entity(model='quad', color=color.rgba(255,255,255,0), scale=(12,18),
  74.               position=(back_size//2, back_size//2, -0.01))
  75.  
  76.  
  77. doctor = Entity(model="cube", parent=back, texture='doctor.png', scale=0.2,
  78.                 position=(0,-0.75,0))
  79.  
  80.  
  81. vaccine = Entity(model="quad", parent=back, texture='vaccine.png', scale=0.1,
  82.                  position=(2,2), collider="box")
  83. vaccine_list = [duplicate(vaccine, y=2,x=2)]
  84.  
  85.  
  86. virus = Entity(model="quad", parent=back, texture='virus.png', scale=0.15,
  87.                position=(2,2), collider="box")
  88. virus_list = []
  89.  
  90. for i in range(5):
  91.     virus_list.append(duplicate(virus, x=random.randint(-45,45)/100, y=random.randint(-3,-1)/100))
  92.  
  93. camera.position = (back_size//2, -15, -11)
  94. camera.rotation_x = -60
  95. app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement