rishabbansal21

Learn 3D Games in Python | Ursina Engine | Part-4 User Input & Controls

May 6th, 2021
508
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from ursina import *
  2.  
  3. def input(key):
  4.     if key == 'right arrow':
  5.         box.x += 2
  6.     if key == 'left arrow':
  7.         box.x -= 2
  8.     if key == 'up arrow':
  9.         box.y += 2
  10.     if key == 'down arrow':
  11.         box.y -= 2
  12.  
  13.     if key == 'c':
  14.         box.color = color.random_color()
  15.    
  16.     if key == 'x':
  17.         box.rotation_x += 45
  18.     if key == 'y':
  19.         box.rotation_y += 45
  20.     if key == 'z':
  21.         box.rotation_z += 45
  22.  
  23. def update():
  24.     if held_keys['w']:
  25.         box.y += 0.05
  26.     if held_keys['s']:
  27.         box.y -= 0.05
  28.     if held_keys['a']:
  29.         box.x -= 0.05
  30.     if held_keys['d']:
  31.         box.x += 0.05
  32.  
  33.     if held_keys['r']:
  34.         box.rotation_z += 30
  35.  
  36.     if held_keys['q']:
  37.         box.color = color.random_color()
  38.  
  39.  
  40. app = Ursina()
  41.  
  42. box = Entity(model="cube", texture="white_cube", scale=1.5, color=color.red)
  43.  
  44. app.run()
RAW Paste Data