Sanjin1

Untitled

Sep 17th, 2021
5,082
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import stuff
  2. from ursina import *
  3. from ursina.prefabs.first_person_controller import FirstPersonController
  4. from random import *
  5.  
  6. app = Ursina()
  7.  
  8. #create a player
  9. player = FirstPersonController(model = 'cube', collider = 'box', jump_height = 10, gravity = 0.1, speed = 10, health = 100)
  10. #player.cursor.scale = 0.1
  11. #create a floor and 2 walls
  12. floor = Entity(collider = 'box',
  13.                model = 'plane',
  14.                scale = (100,1,100),
  15.                texture = 'white_cube',
  16.                texture_scale = (100,100),
  17.                color = color.white.tint(-0.1),
  18.                health = 10000000)
  19. wall = Entity(collider = 'box', model = 'cube',scale = (2,100,100),position = (50,0,0), texture = 'sky_sunset', health = 10000000)
  20. wall2 = Entity(collider = 'box', model = 'cube',scale = (2,100,100),position = (-50,0,0), texture = 'sky_default', health = 100)
  21.  
  22. counter = 0
  23. bullets = []
  24. enemies = []
  25. loaded = False
  26.  
  27. def update():
  28.     global counter, bullets, enemies,loaded
  29.     counter += 1
  30.    
  31. #enemy CREATION
  32.     if counter % 300 == 0:
  33.         loaded = True
  34.         enemy = Entity(model = 'cube',
  35.                 collider = 'box',
  36.                 d_rot_y = 0,
  37.                 size = randint(1,5),
  38.                 color = color.yellow,
  39.                 position = (50 ,randint(1,20), randint(-50,50)),
  40.                 texture = 'reflection_map_3')
  41.         enemy.scale = (enemy.size,enemy.size,enemy.size)
  42.         enemy.dx = -0.2/enemy.size
  43.         enemy.health = enemy.size*2 + 1
  44.         enemies.append(enemy)
  45.  
  46. #BULLET HANDLING    
  47.     for b in bullets:
  48.         b_hit_info = b.intersects()
  49.         b.position += b.forward*b.speed
  50.        
  51.         if b_hit_info.hit:
  52.             if b_hit_info.entity in enemies or b_hit_info.entity == wall:
  53.                 b_hit_info.entity.health -= 1
  54.             elif b_hit_info.entity in bullets:
  55.                 pass
  56.             else:
  57.                 bullets.remove(b)
  58.                 destroy(b, delay = 0.1)
  59.         if b.x > 100 or b.x <-100 or b.z>100 or b.z<-100 or b.y >100 or b.y<-100:
  60.             if b in bullets:
  61.                 bullets.remove(b)
  62.             destroy(b, delay = 0.1)
  63.            
  64.  
  65. #enemy MOVEMENT AND BULLET COLLISION
  66.     for enemy in enemies:
  67.         ob_hit = enemy.intersects()
  68.         enemy.x += enemy.dx
  69.         if enemy.health <= 2:
  70.             enemy.color =  color.yellow.tint(-0.5)
  71.             enemy.dx = 0
  72.             enemy.rotation_x +=1
  73.             enemy.rotation_y +=1
  74.             enemy.rotation_z +=1
  75.         if enemy.health < 0:
  76.             enemies.remove(enemy)
  77.             destroy(enemy)
  78.          
  79.          
  80. #FREEZE AND EXIT WHEN YOU PRESS C            
  81.     if held_keys['c']:
  82.         application.pause()
  83.         mouse.locked = False
  84.        
  85.     if held_keys['e']:
  86.         player.y += 0.5
  87.  
  88.  
  89. #WHAT HAPPENDS WHEN YOU CLICK MOUSE LEFT
  90. def input(key):
  91.     global bullets, loaded
  92.     if key == 'left mouse down':
  93.         bullet = Entity(model = 'cube',
  94.                     collider = 'box',
  95.                     scale = (0.1,0.1,0.1),
  96.                     color = color.green,
  97.                     rotation_x = player.camera_pivot.rotation_x,
  98.                     rotation_y = player.rotation_y,
  99.                     rotation_z = player.rotation_z,
  100.                     x = player.x,
  101.                     y = player.y+1.9,
  102.                     z = player.z,
  103.                     speed = 25)
  104.         bullets.append(bullet)
  105.        
  106.        
  107.     if key == 'right mouse down' and loaded:
  108.         for i in range(0,20):
  109.             bullet = Entity(model = 'cube',
  110.                         collider = 'box',
  111.                         scale = (0.1,0.1,0.1),
  112.                         color = color.green,
  113.                         rotation_x = uniform(-2,2) + player.camera_pivot.rotation_x,
  114.                         rotation_y = uniform(-2,2) + player.rotation_y,
  115.                         rotation_z = uniform(-2,2) + player.rotation_z,
  116.                         x = player.x ,
  117.                         y = player.y+ 1.9,
  118.                         z = player.z,
  119.                         speed =10)
  120.             bullets.append(bullet)
  121.         loaded = False
  122.          
  123. sky = Sky()        
  124. app.run()
  125.  
RAW Paste Data