Sanjin1

Untitled

Sep 17th, 2021
824
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', speed = 5, y=5)
  11. #create a plane (ground to walk on)
  12. ground = Entity(model = 'plane',
  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.  
  39.  
  40. def update():
  41.     global frame_counter, lava_blocks
  42.     target.x += uniform(-0.1,0.1)
  43.     target.z += uniform(-0.1,0.1)
  44.     frame_counter += 1
  45.     if frame_counter % 180 == 0:
  46.         lava = Entity(model = 'cube',
  47.                 scale = (randint(1,3),randint(1,3),randint(1,3)),
  48.                 position = (randint(-25,25) + 0.5, 100, randint(-25,25) + 0.5),
  49.                 collider = 'box',
  50.                 color = color.red)
  51.         lava_blocks.append(lava)
  52.  
  53.     for block in lava_blocks:
  54.         hit_info = block.intersects()
  55.         if hit_info.hit == False:
  56.             block.y -= 0.2
  57.  
  58.     hit_info = player.intersects()
  59.     if hit_info.hit:
  60.         if hit_info.entity in lava_blocks:
  61.             if hit_info.entity == target:
  62.                 message = Text(text = 'YOU WIN', origin = (0,0), background = True, color=color.blue)
  63.             else:
  64.                 message = Text(text = 'YOU LOSE', origin = (0,0), background = True, color=color.blue)
  65.             application.pause()
  66.             mouse.locked = False
  67.            
  68.     if held_keys['c']:
  69.         application.pause()
  70.         mouse.locked = False
  71.     if held_keys['space']:
  72.         player.y += 0.5
  73.  
  74. sky = Sky()
  75. app.run()
  76.  
RAW Paste Data