Added option to customize enemy image path, and customize weapons

This commit is contained in:
csd4ni3l
2025-06-18 22:35:11 +02:00
parent ab11d92e3a
commit 613ff7eef7
8 changed files with 145 additions and 27 deletions

View File

@@ -1,34 +1,40 @@
from ursina import *
from ursina.shaders import lit_with_shadows_shader
from ursina.prefabs.ursfx import ursfx
from ursina.prefabs.first_person_controller import FirstPersonController
from ursina import *
from utils.constants import weapons, max_enemy_speed
from ursina.shaders import lit_with_shadows_shader
from utils.preload import death_sound
from utils.constants import max_enemy_speed, weapons
import json
from pathlib import Path
class Player(FirstPersonController):
def __init__(self, high_score, info_label, inventory, pypresence_client) -> None:
def __init__(self, settings_dict, high_score, info_label, inventory, pypresence_client) -> None:
super().__init__(model='cube', z=16, color=color.orange, origin_y=-.5, speed=8, collider='box', gravity=True, shader=lit_with_shadows_shader)
self.collider = BoxCollider(self, Vec3(0,1,0), Vec3(1,2,1))
self.gun = Entity(model='cube', parent=camera, position=(.5,-.25,.25), scale=(.3,.2,1), origin_z=-.5, color=color.red, on_cooldown=True, shader=lit_with_shadows_shader)
invoke(setattr, self.gun, 'on_cooldown', False, delay=1)
self.gun.muzzle_flash = Entity(parent=self.gun, z=1, world_scale=.5, model='quad', color=color.yellow, enabled=False, shader=lit_with_shadows_shader)
self.info_label = info_label
self.inventory = inventory
self.pypresence_client = pypresence_client
self.high_score = high_score
self.settings_dict = settings_dict
self.last_presence_update = time.perf_counter()
self.shots_fired = 0
self.shots_hit = 0
self.accuracy = 0
self.score = 0
self.weapon_attack_speed = 0
self.weapon_dmg = 0
self.gun = Entity(model='cube', texture=Texture(Path(self.settings_dict.get("weapons", weapons)[self.inventory.slot_names[self.inventory.current_slot]]["image"])), parent=camera, position=(.5,-.25,.25), scale=(.3,.2,1), origin_z=-.5, on_cooldown=True, shader=lit_with_shadows_shader)
invoke(setattr, self.gun, 'on_cooldown', False, delay=1)
self.gun.muzzle_flash = Entity(parent=self.gun, z=1, world_scale=.5, model='quad', color=color.yellow, enabled=False, shader=lit_with_shadows_shader)
with open("settings.json", "r") as file:
self.settings_dict = json.load(file)
@@ -43,8 +49,9 @@ class Player(FirstPersonController):
self.info_label.text = f"High Score: {self.high_score} Score: {self.score} Hits: {self.shots_fired}/{self.shots_hit} Accuracy: {round(self.accuracy, 2)}%"
weapon_name = self.inventory.slot_names[self.inventory.current_slot]
self.weapon_attack_speed = weapons[weapon_name]["atk_speed"]
self.weapon_dmg = weapons[weapon_name]["dmg"]
self.gun.texture = Texture(Path(self.settings_dict.get("weapons", weapons)[weapon_name]["image"]))
self.weapon_attack_speed = self.settings_dict.get("weapons", weapons)[weapon_name]["atk_speed"]
self.weapon_dmg = self.settings_dict.get("weapons", weapons)[weapon_name]["dmg"]
if self.score > self.high_score:
self.high_score = self.score