Advertisement
Sanjin1

Untitled

Sep 28th, 2021
1,126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. from ursina import *
  2. from random import *
  3. from ursina.prefabs.first_person_controller import FirstPersonController
  4.  
  5. app = Ursina()
  6.  
  7. #Build a floor
  8. floor = Entity(collider = 'box',
  9.                model = 'plane',
  10.                scale = (100,1,100),
  11.                color = color.white.tint(-0.1),
  12.                texture = 'white_cube',
  13.                texture_scale = (100,100))
  14.  
  15. #Create a First person controller (player)
  16. player = FirstPersonController(model ='cube', collider = 'box')
  17.  
  18.  
  19. target = Entity(model = 'sphere',
  20.                 collider = 'box',
  21.                 position = (100, randint(1,50),randint(-100,100)),
  22.                 scale = 5,
  23.                 color = color.yellow,
  24.                 dz = 0)
  25.  
  26. #LISTS:
  27. bullets = []
  28. frame_counter = 0
  29. score = 0
  30. bullet_counter = 0
  31.  
  32. def update():
  33.     global frame_counter,score, bullet_counter
  34.    
  35.     target.z += target.dz
  36.    
  37.     frame_counter += 1
  38.     if frame_counter > 3000:
  39.         application.pause()
  40.         mouse.locked = False
  41.        
  42.        
  43.     for b in bullets:
  44.         b.position += b.forward*10
  45.     t_col = target.intersects()
  46.     if t_col.hit:
  47.         target.position = (100, randint(1,50),randint(-25,25))
  48.         score += 1
  49.         target.dz = uniform(-0.2,0.2)
  50.         print('SCORE',score)
  51.         print('ACCURACY:', score / bullet_counter *100)
  52.         #play around with these numbers
  53.  
  54.  
  55. #spawn bullets when we press left mouse
  56. def input(key):
  57.     global bullet_counter
  58.     if key == 'left mouse down':
  59.         bullet = Entity(model = 'cube',
  60.                         collider = 'box',
  61.                         scale = (0.2,0.2,0.2),
  62.                         color = color.green,
  63.                         position = player.position + (0,1.8,0),
  64.                         rotation_x = player.camera_pivot.rotation_x,
  65.                         rotation_y = player.rotation_y)
  66.         bullets.append(bullet)
  67.         bullet_counter +=1
  68.        #your task is to modify bullet to be elongated int the right direction
  69.     if key == 'c':
  70.         application.pause()
  71.         mouse.locked = False
  72.  
  73. sky = Sky()
  74. sky.color = color.magenta
  75.  
  76. app.run()
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement