Initial version

This commit is contained in:
csd4ni3l
2025-06-10 11:05:55 +02:00
commit 333a4e307e
27 changed files with 1880 additions and 0 deletions

72
game/game.py Normal file
View File

@@ -0,0 +1,72 @@
from game.inventory import Inventory
from game.player import Player
from game.enemy import Enemy
from utils.constants import weapons, min_enemy_y, max_enemy_y
from ursina import *
from ursina.shaders import lit_with_shadows_shader
import os
file_names = os.listdir("enemy_images")
class Game():
def __init__(self, pypresence_client) -> None:
self.pypresence_client = pypresence_client
pypresence_client.update(state='Training Aim', details=f'Hits: 0/0 Accuracy: 0%')
self.ground = Entity(model='plane', collider='box', scale=64, texture='grass', texture_scale=(4,4), shader=lit_with_shadows_shader)
self.info_label = Text("Score: 0 Hits: 0/0 Accuracy: 0%", parent=camera.ui, position=(-0.1, 0.475))
self.inventory = Inventory(slots=len(weapons))
for n, weapon in enumerate(weapons):
self.inventory.append(weapons[weapon]["image"], weapon, n)
self.player = Player(self.info_label, self.inventory, pypresence_client)
self.shootables_parent = Entity()
mouse.traverse_target = self.shootables_parent
self.enemies = []
for i in range(15):
self.summon_enemy()
self.player.summon_enemy = self.summon_enemy
self.sun = DirectionalLight()
self.sun.look_at(Vec3(1,-1,-1))
self.sky = Sky()
self.sky.update = self.update
def summon_enemy(self):
if not len(self.enemies) >= 50:
self.enemies.append(Enemy(self.player, self.shootables_parent, self.player.x + (random.randint(12, 24) * random.choice([1, -1])), random.randint(min_enemy_y, max_enemy_y), self.player.z + (random.randint(12, 24) * random.choice([1, -1])), "enemy_images/" + random.choice(file_names)))
def update(self):
Sky.update(self.sky)
if held_keys["escape"]:
self.back_to_main_menu()
elif held_keys["space"]:
self.summon_enemy()
def back_to_main_menu(self):
self.hide()
from menus.main import Main
Main(self.pypresence_client)
def hide(self):
destroy(self.ground)
destroy(self.sun)
destroy(self.sky)
Sky.instances.remove(self.sky)
destroy(self.info_label)
self.inventory.hide()
self.player.hide()
destroy(self.shootables_parent)
for enemy in self.enemies:
destroy(enemy)