Advertisement
Sanjin1

Untitled

Sep 17th, 2021
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.24 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', 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, 20, 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. lava_blocks.append(target)
  39.  
  40.  
  41. def update():
  42.     global frame_counter, lava_blocks
  43.     frame_counter += 1
  44.     if frame_counter % 180 == 0:
  45.         lava = Entity(model = 'cube',
  46.                 scale = (randint(1,3),randint(1,3),randint(1,3)),
  47.                 position = (randint(-25,25) + 0.5, 100, randint(-25,25) + 0.5),
  48.                 collider = 'box',
  49.                 color = color.red)
  50.         lava_blocks.append(lava)
  51.  
  52.     for block in lava_blocks:
  53.         hit_info = block.intersects()
  54.         if hit_info.hit == False:
  55.             block.y -= 0.2
  56.  
  57.     hit_info = player.intersects()
  58.     if hit_info.hit:
  59.         if hit_info.entity in lava_blocks:
  60.             if hit_info.entity == target:
  61.                 message = Text(text = 'YOU WIN', origin = (0,0), background = True, color=color.blue)
  62.             else:
  63.                 message = Text(text = 'YOU LOSE', origin = (0,0), background = True, color=color.blue)
  64.             application.pause()
  65.             mouse.locked = False
  66.  
  67. sky = Sky()
  68. app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement