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

Fixed determining closest counter and if the player can reach it. Added flags...

Fixed determining closest counter and if the player can reach it. Added flags in gui to show ranges and interaction points
parent ba5eec9c
No related branches found
No related tags found
1 merge request!21Resolve "Mark counter to interact with"
Pipeline #42411 passed
radius: 0.4
move_dist: 5
interaction_range: 1.5
\ No newline at end of file
interaction_range: 1.6
\ No newline at end of file
......@@ -167,7 +167,7 @@ class Environment:
else:
counter = self.get_facing_counter(player)
if player.can_reach(counter):
if player.can_reach(counter): # TODO: this
if action.act_type == "pickup":
player.pick_action(counter)
......@@ -205,14 +205,7 @@ class Environment:
Returns:
"""
# TODO: Decide on one variant of getting the interacting counter
# facing_point = player.pos + (
# player.facing_direction
# * player.interaction_range
# * self.counter_side_length
# )
# facing_counter = self.get_closest_counter(facing_point)
facing_counter = self.get_closest_counter(player.pos)
facing_counter = self.get_closest_counter(player.facing_point)
return facing_counter
def perform_movement(self, player: Player, move_vector: np.array):
......
......@@ -50,6 +50,7 @@ class Player:
] = None # needed to stop progress when moved away
self.current_nearest_counter: Optional[Counter] = None
self.facing_point: npt.NDArray[float] = np.array([0, 0], float)
def move(self, movement: npt.NDArray[float]):
"""Moves the player position by the given movement vector.
......@@ -80,6 +81,9 @@ class Player:
"""
if np.linalg.norm(direction) != 0:
self.facing_direction = direction / np.linalg.norm(direction)
self.facing_point = self.pos + (
self.facing_direction * self.radius * self.grid_size * 0.5
)
def can_reach(self, counter: Counter):
"""Checks whether the player can reach the counter in question. Simple check if the distance is not larger
......@@ -91,7 +95,7 @@ class Player:
Returns: True if the counter is in range of the player, False if not.
"""
return np.linalg.norm(counter.pos - self.pos) <= (
return np.linalg.norm(counter.pos - self.facing_point) <= (
self.interaction_range * self.grid_size
)
......
......@@ -22,8 +22,9 @@ from overcooked_simulator.pygame_gui.game_colors import BLUE
from overcooked_simulator.pygame_gui.game_colors import colors, Color
from overcooked_simulator.simulation_runner import Simulator
USE_PLAYER_COOK_SPRITES = False
USE_PLAYER_COOK_SPRITES = True
SHOW_INTERACTION_RANGE = False
SHOW_COUNTER_CENTERS = False
def create_polygon(n, length):
......@@ -256,8 +257,13 @@ class PyGameGUI:
if SHOW_INTERACTION_RANGE:
pygame.draw.circle(
self.screen, BLUE, player.pos, player.interaction_range, width=1
self.screen,
BLUE,
player.facing_point,
player.interaction_range * self.counter_size,
width=1,
)
pygame.draw.circle(self.screen, colors["red1"], player.facing_point, 4)
if player.holding is not None:
holding_item_pos = player.pos + (20 * player.facing_direction)
......@@ -406,6 +412,8 @@ class PyGameGUI:
"""
for counter in state["counters"]:
self.draw_counter(counter)
if SHOW_COUNTER_CENTERS:
pygame.draw.circle(self.screen, colors["green1"], counter.pos, 3)
def draw(self, state):
"""Main visualization function.
......
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