FEAT: Added map image (though inaccurate), and added round attr to match
This commit is contained in:
23
game.py
23
game.py
@@ -1,9 +1,10 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from match import Match
|
from match import Match
|
||||||
from player import Player
|
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
|
FPS = 60
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
@@ -19,6 +20,7 @@ class Game:
|
|||||||
self.running = True
|
self.running = True
|
||||||
|
|
||||||
self.match = match
|
self.match = match
|
||||||
|
self.coordinate_manager = CoordinateManager(WIDTH, HEIGHT)
|
||||||
|
|
||||||
def handle_events(self):
|
def handle_events(self):
|
||||||
"""Handles user inputs."""
|
"""Handles user inputs."""
|
||||||
@@ -33,16 +35,27 @@ class Game:
|
|||||||
def draw(self):
|
def draw(self):
|
||||||
"""Draws everything on screen."""
|
"""Draws everything on screen."""
|
||||||
self.screen.fill((30, 30, 30)) # Clear 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
|
# Draw current tick
|
||||||
text = self.font.render(f"Tick: {self.match.tick}/{self.match.max_tick}", True, (255, 255, 255))
|
text = self.font.render(f"Tick: {self.match.tick}/{self.match.max_tick}", True, (255, 255, 255))
|
||||||
self.screen.blit(text, (10, 10))
|
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:
|
for player in self.match.players:
|
||||||
if player.dead:
|
if player.dead:
|
||||||
continue
|
continue
|
||||||
mapped_x = mapped_value(player.x, -4000, 4000, 0, WIDTH)
|
mapped_x, mapped_y = self.coordinate_manager.coord_to_pixel(player.x, player.y)
|
||||||
mapped_y = mapped_value(player.y, -4000, 4000, 0, HEIGHT)
|
|
||||||
pygame.draw.circle(self.screen, (255, 255, 255), (mapped_x, mapped_y), 5)
|
pygame.draw.circle(self.screen, (255, 255, 255), (mapped_x, mapped_y), 5)
|
||||||
|
|
||||||
# Draw player name
|
# Draw player name
|
||||||
@@ -65,7 +78,7 @@ if __name__ == "__main__":
|
|||||||
import demoparser2
|
import demoparser2
|
||||||
|
|
||||||
demo_parser = demoparser2.DemoParser("demo.dem")
|
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()
|
header_info = demo_parser.parse_header()
|
||||||
map_name = header_info['map_name']
|
map_name = header_info['map_name']
|
||||||
players = demo_parser.parse_player_info()
|
players = demo_parser.parse_player_info()
|
||||||
|
|||||||
30
match.py
30
match.py
@@ -4,8 +4,12 @@ class Match:
|
|||||||
def __init__(self, map_name, game_info, tick_rate=64):
|
def __init__(self, map_name, game_info, tick_rate=64):
|
||||||
self.players = []
|
self.players = []
|
||||||
self.map_name = map_name
|
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.max_tick = game_info.index[-1]
|
||||||
self.game_info = game_info # pd dataframe sorted by tick
|
self.game_info = game_info # pd dataframe sorted by tick
|
||||||
self.tick_rate = tick_rate
|
self.tick_rate = tick_rate
|
||||||
@@ -15,20 +19,26 @@ class Match:
|
|||||||
|
|
||||||
def next_tick(self) -> None:
|
def next_tick(self) -> None:
|
||||||
self.tick += 1
|
self.tick += 1
|
||||||
|
self.current_tick = self.game_info[self.game_info["tick"] == self.tick]
|
||||||
self._update_player_positions()
|
self._update_player_positions()
|
||||||
|
self._update_round()
|
||||||
|
|
||||||
def _update_player_positions(self) -> None:
|
def _update_player_positions(self) -> None:
|
||||||
# inefficient, might need to change
|
# inefficient, might need to change
|
||||||
current_tick = self.game_info[self.game_info["tick"] == self.tick]
|
|
||||||
|
|
||||||
# empty tick
|
# empty tick
|
||||||
if current_tick.empty:
|
if self.current_tick.empty:
|
||||||
return
|
return
|
||||||
|
|
||||||
for player in self.players:
|
for player in self.players:
|
||||||
player.x = current_tick[current_tick["player_steamid"] == player.steam_id]["X"].values[0]
|
player.x = self.current_tick[self.current_tick["player_steamid"] == player.steam_id]["Y"].values[0]
|
||||||
player.y = current_tick[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 = current_tick[current_tick["player_steamid"] == player.steam_id]["Z"].values[0]
|
player.z = self.current_tick[self.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.pitch = self.current_tick[self.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.yaw = self.current_tick[self.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.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]
|
||||||
Reference in New Issue
Block a user