commit 2c860be64bb0a18566abbbe9a346a3ecf38a1f6e Author: ThisBirchWood Date: Sun Mar 9 18:52:52 2025 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1fd1563 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +demo.dem \ No newline at end of file diff --git a/__pycache__/game.cpython-310.pyc b/__pycache__/game.cpython-310.pyc new file mode 100644 index 0000000..a81b02e Binary files /dev/null and b/__pycache__/game.cpython-310.pyc differ diff --git a/__pycache__/player.cpython-310.pyc b/__pycache__/player.cpython-310.pyc new file mode 100644 index 0000000..466e210 Binary files /dev/null and b/__pycache__/player.cpython-310.pyc differ diff --git a/game.py b/game.py new file mode 100644 index 0000000..b89dfcc --- /dev/null +++ b/game.py @@ -0,0 +1,29 @@ +from player import Player + +class Game: + def __init__(self, map_name, game_info): + self.players = [] + self.map_name = map_name + self.round = 0 + self.tick = 0 + self.max_tick = game_info.index[-1] + self.game_info = game_info # pd dataframe sorted by tick + + def add_player(self, player: Player) -> None: + self.players.append(player) + + def next_tick(self) -> None: + self.tick += 1 + self._update_player_positions() + + def _update_player_positions(self) -> None: + # inefficient, might need to change + current_tick = self.game_info[self.game_info["tick"] == self.tick] + for player in self.players: + print("Updated player position of ", player.name) + 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 diff --git a/parser.py b/parser.py new file mode 100644 index 0000000..68efc90 --- /dev/null +++ b/parser.py @@ -0,0 +1,29 @@ +import demoparser2 +from game import Game +from player import Player + +demo_parser = demoparser2.DemoParser("demo.dem") +demo_info = demo_parser.parse_ticks(["X", "Y", "Z"]) + +class Parser: + def __init__(self, demo_path): + self.demo_parser = demoparser2.DemoParser(demo_path) + self.demo_info = self.demo_parser.parse_ticks(["X", "Y", "Z", "pitch", "yaw", "is_alive", "team", "player_steamid"]) + + self.players = self.demo_parser.parse_player_info() + +if __name__ == "__main__": + parser = Parser("demo.dem") + game = Game("de_dust2", parser.demo_info) + + for index, row in parser.players.iterrows(): + game.add_player(Player(row["name"], row["steamid"])) + + while game.tick < game.max_tick: + game.next_tick() + + + + + + diff --git a/player.py b/player.py new file mode 100644 index 0000000..dad69c4 --- /dev/null +++ b/player.py @@ -0,0 +1,13 @@ +class Player: + def __init__(self, name, steam_id, x=0, y=0, z=0, pitch=0, yaw=0): + self.name = name + self.steam_id = steam_id + self.x = x + self.y = y + self.z = z + + self.pitch = pitch + self.yaw = yaw # Probably only need this if top-down + self.dead = False + + \ No newline at end of file