initial commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
demo.dem
|
||||
BIN
__pycache__/game.cpython-310.pyc
Normal file
BIN
__pycache__/game.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/player.cpython-310.pyc
Normal file
BIN
__pycache__/player.cpython-310.pyc
Normal file
Binary file not shown.
29
game.py
Normal file
29
game.py
Normal file
@@ -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
|
||||
29
parser.py
Normal file
29
parser.py
Normal file
@@ -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()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user