Advertisement
Sanjin1

Untitled

Sep 17th, 2021
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.56 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 = '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. zero_g = 300
  39. game_gravity = True
  40.  
  41.  
  42. def update():
  43.     global frame_counter, lava_blocks, zero_g, game_gravity
  44.     target.x += uniform(-0.1,0.1)
  45.     target.z += uniform(-0.1,0.1)
  46.     frame_counter += 1
  47.     if frame_counter % 180 == 0:
  48.         lava = Entity(model = 'cube',
  49.                 scale = (randint(1,3),randint(1,3),randint(1,3)),
  50.                 position = (randint(-25,25) + 0.5, 100, randint(-25,25) + 0.5),
  51.                 collider = 'box',
  52.                 color = color.red)
  53.         lava_blocks.append(lava)
  54.  
  55.     for block in lava_blocks:
  56.         hit_info = block.intersects()
  57.         if hit_info.hit == False:
  58.             block.y -= 0.2
  59.  
  60.     hit_info = player.intersects()
  61.     if hit_info.hit:
  62.         if hit_info.entity in lava_blocks:
  63.             if hit_info.entity == target:
  64.                 message = Text(text = 'YOU WIN', origin = (0,0), background = True, color=color.blue)
  65.             else:
  66.                 message = Text(text = 'YOU LOSE', origin = (0,0), background = True, color=color.blue)
  67.             application.pause()
  68.             mouse.locked = False
  69.            
  70.     if held_keys['c']:
  71.         application.pause()
  72.         mouse.locked = False
  73.        
  74.        
  75.     if held_keys['g']:
  76.         player.gravity = 0.1
  77.         player.jump_height = 12
  78.  
  79.        
  80.  
  81. sky = Sky()
  82. app.run()
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement