Sanjin1

Untitled

Sep 17th, 2021
1,006
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from ursina import *
  2. from random import *
  3. #create a first person player
  4. from ursina.prefabs.first_person_controller import FirstPersonController
  5.  
  6.  
  7. app = Ursina()
  8. frame_counter = 0
  9.  
  10. player = FirstPersonController(collider ='box', model = 'cube', speed = 5, y=5)
  11. #create a plane (ground to walk on)
  12. ground = Entity(model = 'cube',
  13.                 scale = (100,2,100),
  14.                 texture = 'white_cube',
  15.                 color = color.white.tint(-0.2),
  16.                 collider = 'box',
  17.                 texture_scale = (50,50))
  18.  
  19.  
  20. #create a lime green target cube at a random location
  21. target = Entity(model = 'cube',
  22.                 scale = (1,1,1),
  23.                 position = (randint(-25,25) + 0.5, 25, randint(-25,25) + 0.5),
  24.                 collider = 'box',
  25.                 color = color.green)
  26.  
  27. #obstacles to jump on they obscure the view
  28. for i in range(1000):
  29.     obstacles = Entity(model = 'cube',
  30.                     scale = (randint(1,3),randint(1,10),randint(1,3)),
  31.                     position = (randint(-50,50) + 0.5, 0.5, randint(-50,50) + 0.5),
  32.                     collider = 'box',
  33.                     color = color.yellow.tint(-0.3),
  34.                     texture = 'brick')
  35.  
  36. #obstacles that end you
  37. lava_blocks = []
  38. g_counter = 300
  39. delta_g_counter = 0.3
  40. block_count = 100
  41.  
  42. def update():
  43.     global frame_counter, lava_blocks, g_counter,delta_g_counter
  44.     target.x += uniform(-0.1,0.1)
  45.     target.z += uniform(-0.1,0.1)
  46.     g_counter += delta_g_counter
  47.     if g_counter < 0:
  48.         g_counter = 0
  49.         delta_g_counter = 0.3
  50.         player.gravity = 1
  51.         player.jump_height = 2
  52.        
  53.    
  54.     frame_counter += 1
  55.     if frame_counter % 180 == 0:
  56.         lava = Entity(model = 'cube',
  57.                 scale = (randint(1,3),randint(1,3),randint(1,3)),
  58.                 position = (randint(-25,25) + 0.5, 100, randint(-25,25) + 0.5),
  59.                 collider = 'box',
  60.                 color = color.red)
  61.         lava_blocks.append(lava)
  62.  
  63.     for block in lava_blocks:
  64.         hit_info = block.intersects()
  65.         if hit_info.hit == False:
  66.             block.y -= 0.2
  67.  
  68.     hit_info = player.intersects()
  69.     if hit_info.hit:
  70.         if hit_info.entity in lava_blocks:
  71.             message = Text(text = 'YOU LOSE', origin = (0,0), background = True, color=color.blue)
  72.             application.pause()
  73.             mouse.locked = False
  74.         if hit_info.entity == target:
  75.             message = Text(text = 'YOU WIN', origin = (0,0), background = True, color=color.blue)
  76.             application.pause()
  77.             mouse.locked = False
  78.  
  79.            
  80.     if held_keys['c']:
  81.         application.pause()
  82.         mouse.locked = False
  83.        
  84.        
  85.     if held_keys['g'] and g_counter > 300:
  86.         player.gravity = 0.1
  87.         player.jump_height = 12
  88.         delta_g_counter = -1
  89.  
  90. def input(key):
  91.     global block_count
  92.     if key == 'left mouse down' and block_count > 0:
  93.         block_count -= 1
  94.         block = Entity(model = 'cube',
  95.                     scale = (1,1,1),
  96.                     position = mouse.world_point,
  97.                     collider = 'box',
  98.                     color = color.blue.tint(0.5),
  99.                     texture = 'brick',
  100.                     gravity = 1)
  101.    
  102.  
  103. sky = Sky()
  104. app.run()
  105.  
  106.  
  107.  
RAW Paste Data