Advertisement
Sanjin1

Untitled

Sep 28th, 2021
1,140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 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. #Create a First person controller (player)
  15. player = FirstPersonController(model ='cube', collider = 'box')
  16.  
  17.  
  18. target = Entity(model = 'sphere',
  19.                 collider = 'box',
  20.                 position = (100, randint(1,50),randint(-100,100)),
  21.                 scale = 5,
  22.                 color = color.yellow)
  23.  
  24. #LISTS:
  25. bullets = []
  26.  
  27. def update():
  28.     for b in bullets:
  29.         b.position += b.forward*5
  30.     t_col = target.intersects()
  31.     if t_col.hit:
  32.         target.position = (100, randint(1,50),randint(-100,100))
  33.        
  34.  
  35.  
  36. #spawn bullets when we press left mouse
  37. def input(key):
  38.     if key == 'left mouse down':
  39.         bullet = Entity(model = 'cube',
  40.                         collider = 'box',
  41.                         scale = (0.2,0.2,0.2),
  42.                         color = color.green,
  43.                         position = player.position + (0,1.8,0),
  44.                         rotation_x = player.camera_pivot.rotation_x,
  45.                         rotation_y = player.rotation_y)
  46.         bullets.append(bullet)
  47.        #your task is to modify bullet to be elongated int the right direction
  48.     if key == 'c':
  49.         application.pause()
  50.         mouse.locked = False
  51.  
  52. sky = Sky()
  53. sky.color = color.magenta
  54.  
  55. app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement