From 8138e0d7cfe904f05e3342babb38903675e8e891 Mon Sep 17 00:00:00 2001 From: ThisBirchWood Date: Tue, 11 Mar 2025 21:51:42 +0100 Subject: [PATCH] FEAT: Added map image (though inaccurate), and added round attr to match --- game.py | 23 ++++++++++++++++++----- match.py | 30 ++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/game.py b/game.py index 5713d4c..224396f 100644 --- a/game.py +++ b/game.py @@ -1,9 +1,10 @@ import pygame from match import Match from player import Player -from utils import mapped_value +from coordinate_manager import CoordinateManager -WIDTH, HEIGHT = 800, 600 +WIDTH, HEIGHT = 800, 800 +MAP_SIZE = 700 FPS = 60 class Game: @@ -19,6 +20,7 @@ class Game: self.running = True self.match = match + self.coordinate_manager = CoordinateManager(WIDTH, HEIGHT) def handle_events(self): """Handles user inputs.""" @@ -33,16 +35,27 @@ class Game: def draw(self): """Draws everything on screen.""" self.screen.fill((30, 30, 30)) # Clear screen + + # Draw map from image + map_image = pygame.image.load(f"maps/{self.match.map_name}.png") + map_x, map_y = self.coordinate_manager.get_top_left(WIDTH, HEIGHT, MAP_SIZE) + + map_image = pygame.transform.scale(map_image, (MAP_SIZE, MAP_SIZE)) + map_image = pygame.transform.rotate(map_image, 270) + self.screen.blit(map_image, (map_x, map_y)) # Draw current tick text = self.font.render(f"Tick: {self.match.tick}/{self.match.max_tick}", True, (255, 255, 255)) self.screen.blit(text, (10, 10)) + # Draw current round + text = self.font.render(f"Round: {self.match.round}", True, (255, 255, 255)) + self.screen.blit(text, (10, 50)) + for player in self.match.players: if player.dead: continue - mapped_x = mapped_value(player.x, -4000, 4000, 0, WIDTH) - mapped_y = mapped_value(player.y, -4000, 4000, 0, HEIGHT) + mapped_x, mapped_y = self.coordinate_manager.coord_to_pixel(player.x, player.y) pygame.draw.circle(self.screen, (255, 255, 255), (mapped_x, mapped_y), 5) # Draw player name @@ -65,7 +78,7 @@ if __name__ == "__main__": import demoparser2 demo_parser = demoparser2.DemoParser("demo.dem") - game_info = demo_parser.parse_ticks(["X", "Y", "Z", "pitch", "yaw", "is_alive", "team", "player_steamid"]) + game_info = demo_parser.parse_ticks(["X", "Y", "Z", "pitch", "yaw", "is_alive", "team", "player_steamid", "team_rounds_total"]) header_info = demo_parser.parse_header() map_name = header_info['map_name'] players = demo_parser.parse_player_info() diff --git a/match.py b/match.py index e7c55d3..ef1988a 100644 --- a/match.py +++ b/match.py @@ -4,8 +4,12 @@ class Match: def __init__(self, map_name, game_info, tick_rate=64): self.players = [] self.map_name = map_name - self.round = 0 - self.tick = 0 + + self.tick = 1 + self.current_tick = game_info[game_info["tick"] == self.tick] + + self.round = self.current_tick["team_rounds_total"].values[0] + self.max_tick = game_info.index[-1] self.game_info = game_info # pd dataframe sorted by tick self.tick_rate = tick_rate @@ -15,20 +19,26 @@ class Match: def next_tick(self) -> None: self.tick += 1 + self.current_tick = self.game_info[self.game_info["tick"] == self.tick] self._update_player_positions() + self._update_round() def _update_player_positions(self) -> None: # inefficient, might need to change - current_tick = self.game_info[self.game_info["tick"] == self.tick] # empty tick - if current_tick.empty: + if self.current_tick.empty: return for player in self.players: - player.x = current_tick[current_tick["player_steamid"] == player.steam_id]["X"].values[0] - player.y = current_tick[current_tick["player_steamid"] == player.steam_id]["Y"].values[0] - player.z = current_tick[current_tick["player_steamid"] == player.steam_id]["Z"].values[0] - player.pitch = current_tick[current_tick["player_steamid"] == player.steam_id]["pitch"].values[0] - player.yaw = current_tick[current_tick["player_steamid"] == player.steam_id]["yaw"].values[0] - player.dead = current_tick[current_tick["player_steamid"] == player.steam_id]["is_alive"].values[0] == 0 + player.x = self.current_tick[self.current_tick["player_steamid"] == player.steam_id]["Y"].values[0] + player.y = self.current_tick[self.current_tick["player_steamid"] == player.steam_id]["X"].values[0] + player.z = self.current_tick[self.current_tick["player_steamid"] == player.steam_id]["Z"].values[0] + player.pitch = self.current_tick[self.current_tick["player_steamid"] == player.steam_id]["pitch"].values[0] + player.yaw = self.current_tick[self.current_tick["player_steamid"] == player.steam_id]["yaw"].values[0] + player.dead = self.current_tick[self.current_tick["player_steamid"] == player.steam_id]["is_alive"].values[0] == 0 + + def _update_round(self) -> None: + if self.current_tick.empty: + return + self.round = self.current_tick["team_rounds_total"].values[0] \ No newline at end of file