Загрузить файлы в «/»

This commit is contained in:
2025-11-04 06:15:33 +03:00
parent 46b75d19e4
commit 17b7d856a6
5 changed files with 4403 additions and 0 deletions

264
main.py Normal file
View File

@@ -0,0 +1,264 @@
import pygame
import sys
from typing import List, Dict
class GameMain:
def __init__(self):
pygame.init()
self.screen_width = 1200
self.screen_height = 800
self.screen = pygame.display.set_mode((self.screen_width, self.screen_height))
pygame.display.set_caption("Strategy Game")
self.clock = pygame.time.Clock()
self.running = True
self.dt = 0.0
self.fixed_dt = 1.0 / 60.0
self.accumulator = 0.0
self.modules = {}
self.game_state = None
self.current_scene = "game"
def init_game(self) -> None:
from input_events import InputEvents
from input_commands import InputCommands
from state_loader import StateLoader
from state_updater import StateUpdater
from entity_creation import EntityCreation
from entity_behavior import EntityBehavior
from ai_decision import AIDecision
from render_tiles import RenderTiles
from render_entities import RenderEntities
from ui_panels import UIPanels
from sound_manager import SoundManager
self.modules['input_events'] = InputEvents()
self.modules['input_commands'] = InputCommands()
self.modules['state_loader'] = StateLoader()
self.modules['state_updater'] = StateUpdater()
self.modules['entity_creation'] = EntityCreation()
self.modules['entity_behavior'] = EntityBehavior()
self.modules['ai_decision'] = AIDecision()
self.modules['render_tiles'] = RenderTiles()
self.modules['render_entities'] = RenderEntities()
self.modules['ui_panels'] = UIPanels(self.screen_width, self.screen_height)
self.modules['sound_manager'] = SoundManager()
self.game_state = self.modules['state_loader'].load_level('level_1.json')
def game_loop(self) -> None:
while self.running:
self.dt = self.clock.tick(60) / 1000.0
self.accumulator += self.dt
while self.accumulator >= self.fixed_dt:
self._fixed_update()
self.accumulator -= self.fixed_dt
self._render()
self.shutdown()
def _fixed_update(self) -> None:
events = self.modules['input_events'].poll_events()
if self.modules['input_events'].quit_requested:
self.running = False
return
player_commands = self.modules['input_commands'].generate_commands(events, self.game_state)
ai_commands = self.modules['ai_decision'].decide(self.game_state, self.fixed_dt)
all_commands = player_commands + ai_commands
actions = self.modules['state_updater'].apply_commands(self.game_state, all_commands)
self.modules['state_updater'].tick(self.game_state, self.fixed_dt)
behavior_actions = self.modules['entity_behavior'].process_behaviors(self.game_state, self.fixed_dt)
sound_events = self._extract_sound_events(actions + behavior_actions)
visual_effects = self.modules['sound_manager'].handle_events(sound_events)
self._apply_visual_effects(visual_effects)
def _render(self) -> None:
self.screen.fill((0, 0, 0))
camera = self.game_state.camera if hasattr(self.game_state, 'camera') else {'x': 0, 'y': 0, 'zoom': 1.0}
self.modules['render_tiles'].draw_map(self.screen, self.game_state.map_tiles, camera)
self.modules['render_entities'].draw_entities(self.screen, self.game_state.entities, camera)
self.modules['ui_panels'].draw(self.screen)
pygame.display.flip()
def _extract_sound_events(self, actions: List[Dict]) -> List[Dict]:
sound_events = []
for action in actions:
if action.get('type') in ['deal_damage', 'building_completed', 'gather_resources']:
sound_events.append({'type': self._map_action_to_sound(action['type'])})
return sound_events
def _map_action_to_sound(self, action_type: str) -> str:
sound_map = {
'deal_damage': 'unit_attack',
'building_completed': 'building_complete',
'gather_resources': 'resource_gathered'
}
return sound_map.get(action_type, '')
def _apply_visual_effects(self, visual_effects: List[Dict]) -> None:
for effect in visual_effects:
if hasattr(self.game_state, 'visual_effects'):
self.game_state.visual_effects.append(effect)
else:
self.game_state.visual_effects = [effect]
def handle_state_transition(self, scene: str) -> None:
self.current_scene = scene
if scene == "menu":
pass
elif scene == "game":
self.game_state = self.modules['state_loader'].load_level('level_1.json')
def shutdown(self) -> None:
pygame.quit()
sys.exit()
if __name__ == "__main__":
game = GameMain()
game.init_game()
game.game_loop()