from ursina import * import math import random app = Ursina(fullscreen=True) window.title = "My First Person Game" from ursina.prefabs.first_person_controller import FirstPersonController player = FirstPersonController() player.speed = 4 run_speed = 70 player.jump_height = 20 # Increased jump height ground = Entity(model="plane", scale=(400, 1, 400)) ground.texture_scale = (40, 40) ground.texture = "grass" ground.collider = BoxCollider(ground) sky = Sky(texture="sky_sunset", scale=500) pause_menu_enabled = False pause_menu = Text(text='PAUSED', color=color.black, scale=2, position=(0, 0.2), enabled=pause_menu_enabled) def toggle_pause_menu(): global pause_menu_enabled pause_menu_enabled = not pause_menu_enabled pause_menu.enabled = pause_menu_enabled player.enabled = not pause_menu_enabled def input(key): if key == 'p': toggle_pause_menu() enemy = Entity(model='quad', texture='earl.gif', scale=3) enemy.collider = BoxCollider(enemy) enemy.billboard = True enemy.y = 1.5 enemy.x = random.uniform(-180, 180) enemy.z = random.uniform(-180, 180) building = Entity(model='cube', color=color.white) building.scale = (50, 100, 50) building.y = 50 def generate_room(x, z): room = Entity(model='cube', color=color.gray, scale=(30, 10, 30), position=(x * 40, 55, z * 40)) room.collider = BoxCollider(room) return room def generate_stairs(): stairs = Entity(model='cube', color=color.gray, scale=(20, 5, 50), position=(0, 55, 0)) stairs.collider = BoxCollider(stairs) return stairs # Generate rooms inside the building for i in range(-1, 2): for j in range(-1, 2): if i == 0 and j == 0: continue # Skip creating a room where the stairs are located generate_room(i, j) # Generate stairs inside the building stairs = generate_stairs() def update(): global player if not pause_menu_enabled: forward = player.camera_pivot.forward right = player.camera_pivot.right forward.y = 0 right.y = 0 forward.normalize() right.normalize() if held_keys["d"]: player.x += player.speed * time.dt * right.x player.z += player.speed * time.dt * right.z if held_keys["a"]: player.x -= player.speed * time.dt * right.x player.z -= player.speed * time.dt * right.z if held_keys["w"]: player.x += player.speed * time.dt * forward.x player.z += player.speed * time.dt * forward.z if held_keys["s"]: player.x -= player.speed * time.dt * forward.x player.z -= player.speed * time.dt * forward.z if held_keys["shift"]: player.speed = run_speed else: player.speed = 20 border_x = 190 border_z = 190 player.x = clamp(player.x, -border_x, border_x) player.z = clamp(player.z, -border_z, border_z) enemy_speed = 30 dx = player.x - enemy.x dz = player.z - enemy.z distance_to_player = math.sqrt(dx ** 2 + dz ** 2) if distance_to_player < 2000 : move_x = dx / distance_to_player * enemy_speed * time.dt move_z = dz / distance_to_player * enemy_speed * time.dt enemy.x += move_x enemy.z += move_z if distance_to_player < 5: # Only damage player when they are within 5 units application.quit() app.run()