|
2 | 2 |
|
3 | 3 | from ursina.shaders import lit_with_shadows_shader |
4 | 4 | from ursina.prefabs.ursfx import ursfx |
5 | | -from ursina.prefabs.first_person_controller import FirstPersonController |
6 | 5 |
|
7 | 6 | from utils.preload import death_sound |
8 | 7 | from utils.constants import weapons |
| 8 | +from utils.utils import FixedFirstPersonController |
9 | 9 |
|
10 | 10 | import json |
11 | 11 | from pathlib import Path |
12 | 12 |
|
13 | | -class Player(FirstPersonController): |
| 13 | +class Player(FixedFirstPersonController): |
14 | 14 | def __init__(self, game_mode, settings_dict, high_score, info_label, inventory, pypresence_client) -> None: |
15 | 15 | super().__init__(model='cube', z=16, color=color.orange, origin_y=-.5, speed=8, collider='box', gravity=True, shader=lit_with_shadows_shader) |
16 | 16 |
|
@@ -47,48 +47,56 @@ def __init__(self, game_mode, settings_dict, high_score, info_label, inventory, |
47 | 47 | self.settings_dict = json.load(file) |
48 | 48 |
|
49 | 49 | def update(self): |
50 | | - super().update() |
| 50 | + if self.enabled: |
| 51 | + super().update() |
51 | 52 |
|
52 | | - if held_keys['left mouse']: |
53 | | - self.shoot() |
| 53 | + if held_keys['left mouse'] or held_keys["gamepad right trigger"]: |
| 54 | + self.shoot() |
54 | 55 |
|
55 | | - self.x = max(-16, min(self.x, 16)) |
56 | | - self.z = max(-16, min(self.z, 16)) |
| 56 | + self.x = max(-16, min(self.x, 16)) |
| 57 | + self.z = max(-16, min(self.z, 16)) |
57 | 58 |
|
58 | | - if self.game_mode == "waves": |
59 | | - info_text = f"Wave: {self.wave_number} Enemies Left: {self.wave_enemies_left} Time Left: {round(self.wave_time - (time.perf_counter() - self.last_wave_time), 2)}s " |
60 | | - elif self.game_mode == "1 minute test": |
61 | | - info_text = f"Time Left: {round(60 - (time.perf_counter() - self.test_start))} " |
62 | | - else: |
63 | | - info_text = "" |
| 59 | + if self.game_mode == "waves": |
| 60 | + info_text = f"Wave: {self.wave_number} Enemies Left: {self.wave_enemies_left} Time Left: {round(self.wave_time - (time.perf_counter() - self.last_wave_time), 2)}s " |
| 61 | + elif self.game_mode == "1 minute test": |
| 62 | + info_text = f"Time Left: {round(60 - (time.perf_counter() - self.test_start))} " |
| 63 | + else: |
| 64 | + info_text = "" |
64 | 65 |
|
65 | | - info_text += f"Score: {self.score} High Score: {self.high_score} Hits: {self.shots_fired}/{self.shots_hit} Accuracy: {round(self.accuracy, 2)}%" |
66 | | - self.info_label.text = info_text |
| 66 | + info_text += f"Score: {self.score} High Score: {self.high_score} Hits: {self.shots_fired}/{self.shots_hit} Accuracy: {round(self.accuracy, 2)}%" |
| 67 | + self.info_label.text = info_text |
67 | 68 |
|
68 | | - weapon_name = self.inventory.slot_names[self.inventory.current_slot] |
69 | | - self.gun.texture = Texture(Path(self.settings_dict.get("weapons", weapons)[weapon_name]["image"])) |
70 | | - self.weapon_attack_speed = self.settings_dict.get("weapons", weapons)[weapon_name]["atk_speed"] |
71 | | - self.weapon_dmg = self.settings_dict.get("weapons", weapons)[weapon_name]["dmg"] |
| 69 | + weapon_name = self.inventory.slot_names[self.inventory.current_slot] |
| 70 | + self.gun.texture = Texture(Path(self.settings_dict.get("weapons", weapons)[weapon_name]["image"])) |
| 71 | + self.weapon_attack_speed = self.settings_dict.get("weapons", weapons)[weapon_name]["atk_speed"] |
| 72 | + self.weapon_dmg = self.settings_dict.get("weapons", weapons)[weapon_name]["dmg"] |
72 | 73 |
|
73 | | - if self.score > self.high_score: |
74 | | - self.high_score = self.score |
| 74 | + if self.score > self.high_score: |
| 75 | + self.high_score = self.score |
75 | 76 |
|
76 | | - if time.perf_counter() - self.last_presence_update >= 3: |
77 | | - self.last_presence_update = time.perf_counter() |
78 | | - self.pypresence_client.update(state='Training Aim', details=f"Score: {self.score} High Score: {self.high_score} Hits: {self.shots_fired}/{self.shots_hit} Accuracy: {round(self.accuracy, 2)}%") |
79 | | - |
| 77 | + if time.perf_counter() - self.last_presence_update >= 3: |
| 78 | + self.last_presence_update = time.perf_counter() |
| 79 | + self.pypresence_client.update(state='Training Aim', details=f"Score: {self.score} High Score: {self.high_score} Hits: {self.shots_fired}/{self.shots_hit} Accuracy: {round(self.accuracy, 2)}%") |
| 80 | + |
80 | 81 | def summon_enemy(self): |
81 | 82 | pass |
82 | 83 |
|
| 84 | + def try_to_disable_muzzle_flash(self): # without this method, 100% accuracy test crashes, because using .disable on a destroyed entity is not allowed |
| 85 | + try: |
| 86 | + self.gun.muzzle_flash.disable() |
| 87 | + except: |
| 88 | + pass |
| 89 | + |
83 | 90 | def shoot(self): |
84 | 91 | if not self.gun.on_cooldown: |
85 | 92 | self.gun.on_cooldown = True |
| 93 | + |
86 | 94 | self.gun.muzzle_flash.enabled = True |
87 | 95 |
|
88 | 96 | if self.settings_dict.get("sfx", True): |
89 | 97 | ursfx([(0.0, 0.0), (0.1, 0.9), (0.15, 0.75), (0.3, 0.14), (0.6, 0.0)], volume=0.5, wave='noise', pitch=random.uniform(-13,-12), pitch_change=-12, speed=3.0) |
90 | 98 |
|
91 | | - invoke(self.gun.muzzle_flash.disable, delay=.05) |
| 99 | + invoke(self.try_to_disable_muzzle_flash, delay=.05) |
92 | 100 | invoke(setattr, self.gun, 'on_cooldown', False, delay=self.weapon_attack_speed) |
93 | 101 | self.shots_fired += 1 |
94 | 102 |
|
|
0 commit comments