Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from ursina import *
- from random import *
- from ursina.prefabs.first_person_controller import FirstPersonController
- app = Ursina()
- #Build a floor
- floor = Entity(collider = 'box',
- model = 'plane',
- scale = (100,1,100),
- color = color.white.tint(-0.1),
- texture = 'white_cube',
- texture_scale = (100,100))
- #Create a First person controller (player)
- player = FirstPersonController(model ='cube', collider = 'box')
- target = Entity(model = 'sphere',
- collider = 'box',
- position = (100, randint(1,50),randint(-100,100)),
- scale = 5,
- color = color.yellow,
- dz = 0)
- #LISTS:
- bullets = []
- frame_counter = 0
- score = 0
- bullet_counter = 0
- def update():
- global frame_counter,score, bullet_counter
- target.z += target.dz
- frame_counter += 1
- if frame_counter > 3000:
- application.pause()
- mouse.locked = False
- for b in bullets:
- b.position += b.forward*10
- t_col = target.intersects()
- if t_col.hit:
- target.position = (100, randint(1,50),randint(-25,25))
- score += 1
- target.dz = uniform(-0.2,0.2)
- print('SCORE',score)
- print('ACCURACY:', score / bullet_counter *100)
- #play around with these numbers
- #spawn bullets when we press left mouse
- def input(key):
- global bullet_counter
- if key == 'left mouse down':
- bullet = Entity(model = 'cube',
- collider = 'box',
- scale = (0.2,0.2,0.2),
- color = color.green,
- position = player.position + (0,1.8,0),
- rotation_x = player.camera_pivot.rotation_x,
- rotation_y = player.rotation_y)
- bullets.append(bullet)
- bullet_counter +=1
- #your task is to modify bullet to be elongated int the right direction
- if key == 'c':
- application.pause()
- mouse.locked = False
- sky = Sky()
- sky.color = color.magenta
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement