Sanjin1

Untitled

Sep 14th, 2021
771
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.  
  5.  
  6. app = Ursina()
  7.  
  8. #create a player
  9. player = FirstPersonController(model = 'cube', collider = 'box', jump_height = 2, gravity = 1, speed = 5)
  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,2,20),
  31.                 dx = 0,dz = 0,
  32.                 texture = 'brick',
  33.                 texture_scale = (3,3))
  34.  
  35.  
  36.  
  37. def update():
  38.     enemy_collision = enemy.intersects()
  39.     if enemy_collision.hit:
  40.         enemy.x -= 2*enemy.dx
  41.         enemy.z -= 2*enemy.dz
  42.     else:
  43.         enemy.x += enemy.dx
  44.         enemy.z += enemy.dz
  45.    
  46.     if player.x > enemy.x:
  47.         enemy.dx = 0.01
  48.     else:
  49.         enemy.dx = -0.01
  50.        
  51.     #change the enemy dy
  52.     if player.z > enemy.z:
  53.         enemy.dz = 0.01
  54.     else:
  55.         enemy.dz = -0.01
  56.    
  57.     hit_info = player.intersects()
  58.     if hit_info.hit:
  59.         if hit_info.entity == target:
  60.             player.jump_height = 20
  61.             player.gravity = 0.1
  62.         else:
  63.             player.jump_height = 2
  64.             player.gravity = 1            
  65.            
  66.     if held_keys['c']:
  67.         application.pause()
  68.         mouse.locked = False
  69.  
  70. app.run()
RAW Paste Data