def generate_player(self): self.player = FirstPersonController(enabled=True) self.player.speed += 2 self.player.mouse_sensitivity = Vec2(50, 50) self.player.jump_duration = .3 self.player.gravity *= .8 self.player.y = 0 self.player.x = len(self.phoneme_store.phonemes) // 2 self.player.z = 1
from ursina import * # 5. 1st person view from ursina.prefabs.first_person_controller import FirstPersonController player = FirstPersonController() # Maps the player to the 1st person view player_speed = player.x = 1 # 14. Sprinting class Sprint(Entity): global player_speed if held_keys['ctrl', 'w'] or held_keys['w', 'ctrl']: player_speed = player_speed * 2
x = random.randrange(-90, 90) z = random.randrange(-90, 90) rot_y = random.randrange(0, 90) magic_box = Entity( model="cube", color=color.red, position=(x, 0, z), origin=(0, -0.5, 0), scale=(0.2, 0.2, 0.2), rotation_y=rot_y, collider="box", ) magic_box.pickable = True player = FirstPersonController(x=0, y=1, z=0) player.gun = None player.rotation_y = 270 def input(key): if key == "left mouse down": for hitinfo in mouse.collisions: try: if hitinfo.distance < 2.0 and hitinfo.entity.pickable: print("Picking up...") destroy(hitinfo.entity) except AttributeError: pass
voxel = Voxel(position=self.position + mouse.normal, texture=stone_texture) if block_pick == 4: voxel = Voxel(position=self.position + mouse.normal, texture=grass_texture) if block_pick == 5: voxel = Voxel(position=self.position + mouse.normal, texture=SpiderBlock) if block_pick == 6: voxel = Voxel(position=self.position + mouse.normal, texture=glass_texture) if block_pick == 7: voxel = Voxel(position=self.position + mouse.normal, texture=leaf_texture) if key == 'left mouse down': destroy(self) for z in range(20): for x in range(20): for y in range(1): voxel = Voxel(position=(x, y, z)) player = FirstPersonController(speed=4.1, jump_height=1.3, jump_duration=0.2, origin_y=+1, air_time=0.2) app.run()
@movable.setter def movable(self, value): if value: self.color = color.orange else: self.color = self.org_col self._movable = value for z in range(8): for x in range(8): voxel = Voxel(position=(x, 0, z)) player = FirstPersonController(position=(4, 10, 4)) def update(): if level_parent: ray = raycast(player.position, player.down, distance=.1, traverse_target=level_parent) # print(ray.hit) if not ray.hit: player.y -= 10 * time.dt def input(key): if key == 'f':
model = 'sphere', texture = sky_texture, scale = 230, double_sided = True) class Hand(Entity): def __init__(self): super().__init__( parent = camera.ui, model = 'assets/arm', texture = arm_texture, scale = 0.2, rotation = Vec3(150,-10,0), position = Vec2(0.4,-0.7)) def active(self): self.position = Vec2(0.3,-0.6) def passive(self): self.position = Vec2(0.4,-0.7) for z in range(80): for x in range(80): voxel = Voxel(position = (x, 0, z)) player = FirstPersonController(jump_height = 0.07, jump_duration = 0.2, color = color.white33) sky = Sky() hand = Hand() app.run()
e.model.colorize() from ursina.prefabs.first_person_controller import FirstPersonController ground = Entity(model='plane', scale=32, texture='white_cube', texture_scale=(32, 32), collider='box') box = Entity(model='cube', collider='box', texture='white_cube', scale=(10, 2, 2), position=(2, 1, 5), color=color.light_gray) player = FirstPersonController(y=1, enabled=True) ec = EditorCamera(rotation_smoothing=3) ec.enabled = False rotation_info = Text(position=window.top_left) def update(): rotation_info.text = str(int(ec.rotation_y)) + '\n' + str( int(ec.rotation_x)) def input(key): if key == 'tab': # press tab to toggle edit/play mode ec.enabled = not ec.enabled player.enabled = not player.enabled app.run()
scale=(1, 5, 10), x=2, y=.01, rotation_y=45, collider='box', texture='white_cube') e.texture_scale = (e.scale_z, e.scale_y) e = Entity(model='cube', scale=(1, 5, 10), x=-2, y=.01, collider='box', texture='white_cube') e.texture_scale = (e.scale_z, e.scale_y) player = FirstPersonController(model='cube', y=1, origin_y=-.5) player.gun = None gun = Button(parent=scene, model='cube', color=color.blue, origin_y=-.5, position=(3, 0, 3), collider='box') gun.on_click = Sequence(Func(setattr, gun, 'parent', camera), Func(setattr, player, 'gun', gun)) gun_2 = duplicate(gun, z=7, x=8) slope = Entity(model='cube', collider='box', position=(0, 0, 8),
perlin = generateBlockPositions(16, 32, 16) # for z in range(8): # for x in range(8): # for y in range(1): # block = Block(position=(x,y,z), texture=grass_texture) block_list = [] terrain = Entity() for a in perlin: block = Block(position=(a[0], a[1], a[2]), parent=terrain) block_list.append(block) terrain.combine() player = FirstPersonController(gravity=0) player.add_script(NoclipMode()) def update(): player.y += held_keys['q'] * 1 player.y -= held_keys['e'] * 1 # cast = boxcast(player.world_position, thickness=(10,10), debug=True) # print(cast.entities) # for block in block_list: # if block not in cast.entities: # block.visible = False # elif block in cast.entities: # block.visible = True
from ursina import * app = Ursina() # Make a simple game so we have something to test with from ursina.prefabs.first_person_controller import FirstPersonController player = FirstPersonController(gravity=0, model='cube', color=color.azure) camera.z = -10 ground = Entity(model='plane', texture='grass', scale=10) # Create an Entity for handling pausing an unpausing. # Make sure to set ignore_paused to True so the pause handler itself can still receive input while the game is paused. pause_handler = Entity(ignore_paused=True) pause_text = Text( 'PAUSED', origin=(0, 0), scale=2, enabled=False ) # Make a Text saying "PAUSED" just to make it clear when it's paused. def pause_handler_input(key): if key == 'escape': application.paused = not application.paused # Pause/unpause the game. pause_text.enabled = application.paused # Also toggle "PAUSED" graphic. pause_handler.input = pause_handler_input # Assign the input function to the pause handler. app.run()
app = Ursina() random.seed(0) Entity.default_shader = lit_with_shadows_shader ground = Entity(model='plane', collider='box', scale=64, texture='grass', texture_scale=(4, 4)) editor_camera = EditorCamera(enabled=False, ignore_paused=True) player = FirstPersonController(model='cube', z=-10, color=color.orange, origin_y=-.5, speed=8) player.collider = BoxCollider(player, Vec3(0, 1, 0), Vec3(1, 2, 1)) gun = Entity(model='cube', parent=camera, position=(.5, -.25, .25), scale=(.3, .2, 1), origin_z=-.5, color=color.red, on_cooldown=False) gun.muzzle_flash = Entity(parent=gun, z=1, world_scale=.5, model='quad',
def 第1人稱視角(): if not common.is_engine_created: Engine3D() common.stage.editor_camera.enabled = False common.player = FirstPersonController()
level.bow.parent = camera level.bow.position = (.5, 0, 1) level.bow.enabled = False level.bow.shader = colored_lights_shader level.gate.collider = 'box' level.gate_001.collider = 'box' level.gate_pattern.world_parent = level.gate level.gate_pattern_001.world_parent = level.gate_001 level.eye_trigger.collider = 'box' level.goat.collider = 'mesh' from ursina.prefabs.first_person_controller import FirstPersonController player = FirstPersonController(position=level.start_point.position, speed=10) level.start_point.enabled = False for e in level.children: if not 'terrain' in e.name: e.shader = colored_lights_shader if 'box_collider' in e.name: e.visible = False e.collider = 'box' if 'pebble' in e.name: e.position = raycast(e.position, Vec3(0, -1, 0)).world_point elif 'rock' in e.name: e.collider = 'box'
-(z / z_slices) - (1 / x_slices / 2)) grid[x][z].model.vertices.extend([ terrain.model.generated_vertices[i] + offset, terrain.model.generated_vertices[i + 1] + offset, terrain.model.generated_vertices[i + 2] + offset, ]) for z in range(z_slices): for x in range(x_slices): grid[x][z].model.generate() # Entity(parent=grid[x][z], model='cube', scale=.01, color=color.red, always_on_top=True) # grid[x][z].enabled = False grid[x][z].collider = 'mesh' # grid[x][z].model = None from ursina.prefabs.first_person_controller import FirstPersonController player = FirstPersonController(position=(0, 200, 0)) player.add_script(NoclipMode()) # player = EditorCamera(rotation_x=90, y=128) def update(): for part in terrain.children: part.enabled = distance_xz(part.world_position, player.world_position) < 256 / 8 # print(distance_xz(part.world_position, camera.world_position), 256/4) app.run()
#for z in range(0, height): # for x in range(0, width): # voxel = Voxel(position=(x,0,z)) for y in range(size_wall): for i in range(0, height): for j in range(0, width): if y == 0: voxel = Voxel(position=(i, y, j)) elif (maze[i][j] == 'u'): pass elif (maze[i][j] == 'c'): pass else: voxel = Voxel(position=(i, y, j)) """ for z in range(size_room): for x in range(size_room): for y in range(size_wall): if x ==0 or z==0 or x == size_room-1 or z==size_room-1: voxel = Voxel(position=(x,y,z)) else: voxel = Voxel(position=(x,0,z)) """ CreateRoom() player = FirstPersonController(position=(5, 0, 5)) #sky = Sky() #hand = Hand() app.run()
class Spider(Button): def __init__(self, x, y, z): super().__init__(parent=scene, model="assets/spider.obj", scale=.02, position=(x, y, z), rotation=(0, 90, 0), collider="box") app = Ursina() Sky() player = FirstPersonController(y=2, origin_y=-.5) ground = Entity(model='plane', scale=(100, 1, 100), color=color.lime, texture="white_cube", texture_scale=(100, 100), collider='box') wall_1 = Entity(model="cube", collider="box", position=(-8, 0, 0), scale=(8, 5, 1), rotation=(0, 0, 0), texture="brick", texture_scale=(5, 5), color=color.rgb(255, 128, 0))
from ursina import * app = Ursina() e = Entity(model=Terrain('loddefjord_height_map', skip=8), texture='loddefjord_color', scale=100, scale_y=50) Sky(rotation_y=125) scene.fog_color = color.gray scene.fog_density = .01 from ursina.prefabs.first_person_controller import FirstPersonController fpc = FirstPersonController(speed=10) window.exit_button.visible = False window.fps_counter.enabled = False mouse.visible = False # from ursina .shaders import camera_vertical_blur_shader # camera.shader = camera_vertical_blur_shader # camera.set_shader_input('blur_size', .0) # # camera.blur_amount = 0 # def update(): # camera.set_shader_input("blur_size", camera.blur_amount) # # t = Text('It was like a dream', enabled=False, scale=3, origin=(0,0), color=color.dark_text) #
skel = uniform(siz - (siz // 3), siz + (siz // 3)) skel /= 10 r = randint(0, 200) g = randint(0, 200) b = randint(0, 200) texta = choice(moonse) mun = Entity(parent=i, model='sphere', x=uniform(prevd + 2, prevd * 2), y=0, z=choice((-prevd, prevd, 0)), scale=(skel, skel, skel), color=color.rgb(r, g, b), shader=basic_lighting_shader, texture=texta) moons.append(mun) prevx *= 1.7 #for i in range(randint(2, 7)): # planit(i) window.color = color.rgb(0, 0, 0) player = FirstPersonController(gravity=0, speed=10) #EditorCamera() camera.rotation_x = 0 #player.add_script(NoclipMode()) app.run()
if __name__ == '__main__': ''' This will only enable mesh colliders' collision polygons within a certain range, in order to improve performance. ''' from ursina.shaders import basic_lighting_shader window.vsync = False app = Ursina() application.asset_folder = application.asset_folder.parent terrain = Entity(model='heightmap_test', scale=32, texture='grass', collider='mesh', shader=basic_lighting_shader) from ursina.prefabs.first_person_controller import FirstPersonController player = FirstPersonController(speed=10) collision_zone = CollisionZone(parent=player, radius=32) def input(key): if key == 'c': terrain.collision = not terrain.collision # def update(): # collision_zone.x += (held_keys['d'] - held_keys['a']) * time.dt * 2 # collision_zone.z += (held_keys['w'] - held_keys['s']) * time.dt * 2 # # hit_info = raycast(collision_zone.world_position+Vec3(0,2,0), Vec3(0,-1,0)) # if hit_info.hit: # collision_zone.y = hit_info.world_point.y
exit() # water.on_trigger_enter = Func(math, player.y += 1) globaltimer += 1 localtimer += 1 if held_keys['o']: player.y += 10 if held_keys['i']: player.x, player.y, player.z = player.x, player.y, player.z # player settings player = FirstPersonController() player.collider = 'sphere' player.speed = 15 if mapp == 1: pivot = Entity(shape='sphere') world1 = DirectionalLight(parent=pivot, x=10, y=50, z=200, shadows=True, color=color.rgb(150, 150, 150), direction=(1, 100, 100), shader=triplanar_shader) world2 = AmbientLight(color=color.rgb(125, 125, 125),
class Voxel(Button): def __init__(self, position=(0, 0, 0)): super().__init__( parent=scene, position=position, model='cube', origin_y=.5, texture='white_cube', color=color.color(0, 0, random.uniform(.9, 1.0)), highlight_color=color.lime, ) def input(self, key): if self.hovered: if key == 'left mouse down': voxel = Voxel(position=self.position + mouse.normal) if key == 'right mouse down': destroy(self) for z in range(30): for x in range(30): voxel = Voxel(position=(x, 0, z)) player = FirstPersonController(jump_duration=0.3, jump_height=1.2, speed=10) app.run()