Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from ursina import *
- from random import *
- #create a first person player
- from ursina.prefabs.first_person_controller import FirstPersonController
- app = Ursina()
- frame_counter = 0
- player = FirstPersonController(collider ='box', model = 'cube', speed = 5, y=5)
- #create a plane (ground to walk on)
- ground = Entity(model = 'cube',
- scale = (100,2,100),
- texture = 'white_cube',
- color = color.white.tint(-0.2),
- collider = 'box',
- texture_scale = (50,50))
- #create a lime green target cube at a random location
- target = Entity(model = 'cube',
- scale = (1,1,1),
- position = (randint(-25,25) + 0.5, 25, randint(-25,25) + 0.5),
- collider = 'box',
- color = color.green)
- #obstacles to jump on they obscure the view
- for i in range(1000):
- obstacles = Entity(model = 'cube',
- scale = (randint(1,3),randint(1,10),randint(1,3)),
- position = (randint(-50,50) + 0.5, 0.5, randint(-50,50) + 0.5),
- collider = 'box',
- color = color.yellow.tint(-0.3),
- texture = 'brick')
- #obstacles that end you
- lava_blocks = []
- g_counter = 300
- delta_g_counter = 0.3
- def update():
- global frame_counter, lava_blocks, g_counter,delta_g_counter
- target.x += uniform(-0.1,0.1)
- target.z += uniform(-0.1,0.1)
- g_counter += delta_g_counter
- if g_counter < 0:
- g_counter = 0
- delta_g_counter = 0.3
- player.gravity = 1
- player.jump_height = 2
- frame_counter += 1
- if frame_counter % 180 == 0:
- lava = Entity(model = 'cube',
- scale = (randint(1,3),randint(1,3),randint(1,3)),
- position = (randint(-25,25) + 0.5, 100, randint(-25,25) + 0.5),
- collider = 'box',
- color = color.red)
- lava_blocks.append(lava)
- for block in lava_blocks:
- hit_info = block.intersects()
- if hit_info.hit == False:
- block.y -= 0.2
- hit_info = player.intersects()
- if hit_info.hit:
- if hit_info.entity in lava_blocks:
- if hit_info.entity == target:
- message = Text(text = 'YOU WIN', origin = (0,0), background = True, color=color.blue)
- else:
- message = Text(text = 'YOU LOSE', origin = (0,0), background = True, color=color.blue)
- application.pause()
- mouse.locked = False
- if held_keys['c']:
- application.pause()
- mouse.locked = False
- if held_keys['g'] and g_counter > 300:
- player.gravity = 0.1
- player.jump_height = 12
- delta_g_counter = -1
- def input(key):
- if key == 'left mouse down':
- block = Entity(model = 'cube',
- scale = (1,1,1),
- position = mouse.world_point,
- collider = 'box',
- color = color.blue.tint(0.5),
- texture = 'brick',
- gravity = 1)
- sky = Sky()
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement