Sanjin1

Untitled

Sep 14th, 2021
758
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import stuff
  2. from ursina import *
  3. from ursina.prefabs.first_person_controller import FirstPersonController
  4. from random import *
  5.  
  6. app = Ursina()
  7.  
  8. #create a player
  9. player = FirstPersonController(model = 'cube', collider = 'box', jump_height = 2, gravity = 1, speed = 5, health = 100)
  10.  
  11. #create a floor
  12. floor = Entity(collider = 'box',
  13.                model = 'plane',
  14.                scale = (100,1,100),
  15.                texture = 'white_cube',
  16.                texture_scale = (100,100),
  17.                color = color.white.tint(-0.1))
  18.  
  19. #build a target
  20. target = Entity(model = 'cube',
  21.                 collider = 'box',
  22.                 scale = (2,2,2),
  23.                 color = color.green,
  24.                 position = (30,1,30))
  25.  
  26. enemy = Entity(model = 'cube',
  27.                 collider = 'box',
  28.                 scale = (2,2,2),
  29.                 color = color.red,
  30.                 position = (20,1,20),
  31.                 dx = 0,dz = 0,
  32.                 texture = 'brick')
  33.  
  34. obstacles = []
  35.  
  36.  
  37. counter = 0
  38.  
  39. def update():
  40.     global counter
  41.     counter += 1
  42.     if counter % 60 == 0:
  43.         obstacle = Entity(model = 'cube',
  44.                 collider = 'box',
  45.                 scale = (2,2,2),
  46.                 color = color.red,
  47.                 position = (randint(-50,50) ,100, randint(-50,50)),
  48.                 dy = -0.2,
  49.                 texture = 'brick')
  50.         obstacles.append(obstacle)
  51.     for obstacle in obstacles:
  52.         obstacle.y += obstacle.dy
  53.        
  54.     enemy_collision = enemy.intersects()
  55.     if enemy_collision.hit and enemy_collision.entity == target:
  56.         enemy.x -= 2*enemy.dx
  57.         enemy.z -= 2*enemy.dz
  58.     if enemy_collision.hit and enemy_collision.entity == player:
  59.         player.health -= 5
  60.         print(player.health)
  61.     else:
  62.         enemy.x += enemy.dx
  63.         enemy.z += enemy.dz
  64.    
  65.     if player.x > enemy.x:
  66.         enemy.dx = 0.01
  67.     else:
  68.         enemy.dx = -0.01
  69.        
  70.     #change the enemy dy
  71.     if player.z > enemy.z:
  72.         enemy.dz = 0.01
  73.     else:
  74.         enemy.dz = -0.01
  75.    
  76.     hit_info = player.intersects()
  77.     if hit_info.hit:
  78.         if hit_info.entity == target:
  79.             player.jump_height = 20
  80.             player.gravity = 0.1
  81.         else:
  82.             player.jump_height = 2
  83.             player.gravity = 1            
  84.            
  85.     if held_keys['c']:
  86.         application.pause()
  87.         mouse.locked = False
  88.     if player.health <0:
  89.         message = Text(text = 'YOU LOSE', origin = (0,0), background = True, color=color.red)
  90.         application.pause()
  91.         mouse.locked = False
  92.  
  93. app.run()
RAW Paste Data