Advertisement
Sanjin1

Untitled

Sep 17th, 2021
1,090
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.14 KB | None | 0 0
  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.  
  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.             if hit_info.entity == target:
  72.                 message = Text(text = 'YOU WIN', origin = (0,0), background = True, color=color.blue)
  73.             else:
  74.                 message = Text(text = 'YOU LOSE', origin = (0,0), background = True, color=color.blue)
  75.             application.pause()
  76.             mouse.locked = False
  77.            
  78.     if held_keys['c']:
  79.         application.pause()
  80.         mouse.locked = False
  81.        
  82.        
  83.     if held_keys['g'] and g_counter > 300:
  84.         player.gravity = 0.1
  85.         player.jump_height = 12
  86.         delta_g_counter = -1
  87.  
  88. def input(key):
  89.     if key == 'left mouse down':
  90.         block = Entity(model = 'cube',
  91.                     scale = (1,1,1),
  92.                     position = mouse.world_point,
  93.                     collider = 'box',
  94.                     color = color.blue.tint(0.5),
  95.                     texture = 'brick',
  96.                     gravity = 1)
  97.    
  98.  
  99. sky = Sky()
  100. app.run()
  101.  
  102.  
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement