from ursina import * from ursina.prefabs.first_person_controller import FirstPersonController app = Ursina(fullscreen=True) # Set fullscreen mode to True window.title = "My First Person Game" player = FirstPersonController() player.speed = 10 player.jump_height = 15 * player.height # Set jump height to three times the player's height run_speed = 20 # Define the running speed dash_speed = 75 # Define the dash speed # Ground ground = Entity(model="plane", scale=(400, 1, 400)) # Increase scale to make the map larger ground.texture_scale = (40, 40) # Adjust texture scale accordingly ground.texture = "grass" ground.collider = BoxCollider(ground) # Sky with clouds sky = Sky(color=color.rgb(135, 206, 235)) # Gun sprite frame_count = 5 # Number of frames in the shooting animation frames = [f'frame_{i}_delay-0.2s.gif' for i in range(frame_count)] # Initial static gun image (frame 0) gun_sprite = Entity(parent=camera.ui, model='quad', texture=frames[0], position=(0.6, -0.3), scale=(0.4, 0.4)) # Pause menu 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': # Use input event instead of held_keys for pause toggle toggle_pause_menu() if key == 'e': # Activate dash ability with the e key activate_dash() if key == 'left mouse down': # Shoot when left mouse button is pressed shoot() shift_ability = False # State for the shift ability dash_ability = False # State for the dash ability dash_duration = 0.2 # Duration of the dash in seconds dash_timer = 0 # Timer to track dash duration def activate_dash(): global dash_ability, dash_timer dash_ability = True dash_timer = dash_duration # Reset the timer to the dash duration def shoot(): global gun_sprite bullet = Entity(model='sphere', color=color.red, scale=0.1, position=gun_sprite.world_position + Vec3(0, 0, -0.2)) bullet.collider = 'box' bullet.direction = camera.forward bullet.damage = 10 # Set the bullet damage bullets.append(bullet) # Play shooting animation for i in range(1, frame_count): invoke(setattr, gun_sprite, 'texture', frames[i], delay=0.05 * i) invoke(setattr, gun_sprite, 'texture', frames[0], delay=0.05 * frame_count) bullets = [] def update(): global player, dash_ability, dash_timer 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 elif dash_ability: player.speed = dash_speed else: player.speed = 10 # Handle dash ability timer if dash_ability: dash_timer -= time.dt if dash_timer <= 0: dash_ability = False # Restrict player within the map borders border_x = 190 # Adjust these values according to your new map size border_z = 190 # Adjust these values according to your new map size player.x = clamp(player.x, -border_x, border_x) player.z = clamp(player.z, -border_z, border_z) # Move enemy towards the player's position enemy_speed = 10 dx = player.x - enemy.x dz = player.z - enemy.z distance_to_player = math.sqrt(dx ** 2 + dz ** 2) if distance_to_player > 1: # Move enemy only if it's at a distance from the player 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 # Check for collision between player and enemy if player.intersects(enemy).hit: application.quit() # Quit the game if collided with the enemy # Update bullets for bullet in bullets: bullet.position += bullet.direction * time.dt * 100 # Adjust speed as necessary if bullet.intersects(enemy).hit: enemy.health -= bullet.damage # Reduce enemy health by bullet damage bullets.remove(bullet) destroy(bullet) if enemy.health <= 0: destroy(enemy) elif bullet.position.y < -10 or bullet.position.y > 10 or bullet.position.z < -200 or bullet.position.z > 200: bullets.remove(bullet) destroy(bullet) # Create an enemy entity with the PNG image enemy = Entity(model='cube', texture=load_texture('blackbeard-writing.png'), scale=20) enemy.collider = 'box' enemy.health = 100 # Set enemy health app.run()