Skip to content
Snippets Groups Projects
Commit 226c3337 authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

Sizes in configs (kitchen, players and viz) relative to counter size. Doc missing

parent 712f049a
No related branches found
No related tags found
1 merge request!17Resolve "Sizes relative to world grid size instead of absolute pixels"
Pipeline #42278 failed
kitchen:
layout_path: layouts/basic.layout
counter_side_length: 40
\ No newline at end of file
layout_path: layouts/basic.layout
counter_side_length: 15
world_width: 800
world_height: 600
radius: 0.4
move_dist: 5
interaction_range: 1.5
\ No newline at end of file
......@@ -67,9 +67,9 @@ class Environment:
with open(env_config_path, "r") as file:
environment_config = yaml.safe_load(file)
self.layout_path: Path = Path(
ROOT_DIR / "game_content" / environment_config["kitchen"]["layout_path"]
ROOT_DIR / "game_content" / environment_config["layout_path"]
)
self.counter_side_length = environment_config["kitchen"]["counter_side_length"]
self.counter_side_length = environment_config["counter_side_length"]
self.item_info_path: Path = item_info_path
self.item_info = self.load_item_info()
......@@ -83,7 +83,7 @@ class Environment:
"T": lambda pos: Dispenser(pos, self.item_info["Tomato"]),
"L": lambda pos: Dispenser(pos, self.item_info["Lettuce"]),
"P": lambda pos: Dispenser(pos, self.item_info["Plate"]),
"N": lambda pos: Dispenser(pos, self.item_info["Onion"]),
"N": lambda pos: Dispenser(pos, self.item_info["Onion"]), # N for oNioN
"_": "Free",
"A": "Agent",
"U": lambda pos: Stove(
......@@ -97,9 +97,11 @@ class Environment:
self.designated_player_positions,
self.free_positions,
) = self.parse_layout_file(self.layout_path)
self.score: int = 0
self.world_width: int = 800
self.world_height: int = 600
self.world_width: int = environment_config["world_width"]
self.world_height: int = environment_config["world_height"]
def load_item_info(self) -> dict[str, ItemInfo]:
with open(self.item_info_path, "r") as file:
......@@ -205,7 +207,11 @@ class Environment:
Returns:
"""
facing_point = player.pos + (player.facing_direction * player.interaction_range)
facing_point = player.pos + (
player.facing_direction
* player.interaction_range
* self.counter_side_length
)
facing_counter = self.get_closest_counter(facing_point)
return facing_counter
......@@ -291,7 +297,9 @@ class Environment:
other_players = filter(lambda p: p.name != player.name, self.players.values())
def collide(p):
return np.linalg.norm(player.pos - p.pos) <= (player.radius + p.radius)
return np.linalg.norm(player.pos - p.pos) <= (
player.radius * self.counter_side_length
) + (p.radius * self.counter_side_length)
return list(filter(collide, other_players))
......@@ -309,7 +317,10 @@ class Environment:
other_players = filter(lambda p: p.name != player.name, self.players.values())
def collide(p):
return np.linalg.norm(player.pos - p.pos) <= (player.radius + p.radius)
return np.linalg.norm(player.pos - p.pos) <= (
(player.radius * self.counter_side_length)
+ (p.radius * self.counter_side_length)
)
return any(map(collide, other_players))
......@@ -348,7 +359,7 @@ class Environment:
dx = max(np.abs(cx - counter.pos[0]) - size / 2, 0)
dy = max(np.abs(cy - counter.pos[1]) - size / 2, 0)
distance = np.linalg.norm([dx, dy])
return distance < player.radius
return distance < (player.radius * self.counter_side_length)
def add_player(self, player: Player):
# print(f"Added player {player.name} to the game.")
......@@ -374,9 +385,12 @@ class Environment:
Returns: True if the player touches the world bounds, False if not.
"""
collisions_lower = any((player.pos - player.radius) < 0)
collisions_lower = any(
(player.pos - (player.radius * self.counter_side_length)) < 0
)
collisions_upper = any(
(player.pos + player.radius) > [self.world_width, self.world_height]
(player.pos + (player.radius * self.counter_side_length))
> [self.world_width, self.world_height]
)
return collisions_lower or collisions_upper
......
from pathlib import Path
from typing import Optional
import numpy as np
import numpy.typing as npt
import yaml
from overcooked_simulator import ROOT_DIR
from overcooked_simulator.counters import Counter
from overcooked_simulator.game_items import Item
......@@ -14,7 +17,11 @@ class Player:
"""
def __init__(self, name: str, pos: Optional[npt.NDArray[float]] = None):
def __init__(
self,
name: str,
pos: Optional[npt.NDArray[float]] = None,
):
self.name: str = name
if pos is not None:
self.pos: npt.NDArray[float] = np.array(pos, dtype=float)
......@@ -23,9 +30,15 @@ class Player:
self.holding: Optional[Item] = None
self.radius: int = 18
self.move_dist: int = 5
self.interaction_range: int = 60
self.player_config_path: Path = Path(
ROOT_DIR / "game_content" / "player_config.yaml"
)
with open(self.player_config_path, "r") as file:
self.player_config = yaml.safe_load(file)
self.radius: float = self.player_config["radius"]
self.move_dist: int = self.player_config["move_dist"]
self.interaction_range: int = self.player_config["interaction_range"]
self.facing_direction: npt.NDArray[float] = np.array([0, 1])
self.last_interacted_counter: Optional[
Counter
......
......@@ -212,6 +212,16 @@ class PyGameGUI:
"""
for p_idx, player in enumerate(state["players"].values()):
if USE_PLAYER_COOK_SPRITES:
img_path = self.visualization_config["Cook"]["parts"][0]["path"]
rel_x, rel_y = player.facing_direction
angle = -np.rad2deg(math.atan2(rel_y, rel_x)) + 90
size = (
self.visualization_config["Cook"]["parts"][0]["size"]
* self.counter_size
)
self.draw_image(img_path, size, player.pos, angle)
else:
pos = player.pos
size = player.radius * self.counter_size
color1 = self.player_colors[p_idx]
......@@ -227,20 +237,17 @@ class PyGameGUI:
self.screen,
BLUE,
(
(pos[0] + (facing[1] * 5), pos[1] - (facing[0] * 5)),
(pos[0] - (facing[1] * 5), pos[1] + (facing[0] * 5)),
player.pos + (facing * 25),
(
pos[0] + (facing[1] * 0.1 * self.counter_size),
pos[1] - (facing[0] * 0.1 * self.counter_size),
),
(
pos[0] - (facing[1] * 0.1 * self.counter_size),
pos[1] + (facing[0] * 0.1 * self.counter_size),
),
player.pos + (facing * 0.5 * self.counter_size),
),
)
else:
img_path = self.visualization_config["Cook"]["parts"][0]["path"]
rel_x, rel_y = player.facing_direction
angle = -np.rad2deg(math.atan2(rel_y, rel_x)) + 90
size = (
self.visualization_config["Cook"]["parts"][0]["size"]
* self.counter_size
)
self.draw_image(img_path, size, player.pos, angle)
if SHOW_INTERACTION_RANGE:
pygame.draw.circle(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment