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

Added pure player movement (without collisions)

parent 3f59cb2c
No related branches found
No related tags found
1 merge request!2Resolve "2D movement continuous"
import numpy as np
class Counter:
"""Simple class for a counter at a specified position (center of counter). Can hold things on top.
"""
def __init__(self, pos: np.array):
self.pos = pos
self.occupied_by = None
def __repr__(self):
return f"Counter(pos:{str(self.pos)},holds:{self.occupied_by})"
\ No newline at end of file
...@@ -5,17 +5,8 @@ if TYPE_CHECKING: ...@@ -5,17 +5,8 @@ if TYPE_CHECKING:
from overcooked_simulator.player import Player from overcooked_simulator.player import Player
from pathlib import Path from pathlib import Path
import numpy as np import numpy as np
from scipy.spatial import distance_matrix
from counters import Counter
class Counter:
"""Simple class for a counter at a specified position (center of counter). Can hold things on top.
"""
def __init__(self, pos: np.array):
self.pos = pos
self.occupied_by = None
def __repr__(self):
return f"Counter(pos:{str(self.pos)},holds:{self.occupied_by})"
class Action: class Action:
......
import numpy as np import numpy as np
from overcooked_simulator.overcooked_environment import Counter from counters import Counter
class Player: class Player:
...@@ -14,6 +14,7 @@ class Player: ...@@ -14,6 +14,7 @@ class Player:
self.holding = None self.holding = None
self.move_dist = 5 self.move_dist = 5
self.interaction_range = 50
self.facing_direction = np.array([0, 1]) self.facing_direction = np.array([0, 1])
def move(self, movement: np.array): def move(self, movement: np.array):
...@@ -23,7 +24,9 @@ class Player: ...@@ -23,7 +24,9 @@ class Player:
Args: Args:
movement: 2D-Vector of length 1 movement: 2D-Vector of length 1
""" """
pass self.pos += movement
if np.linalg.norm(movement) != 0:
self.turn(movement)
def move_abs(self, new_pos: np.array): def move_abs(self, new_pos: np.array):
"""Overwrites the player location by the new_pos 2d-vector. Absolute movement. """Overwrites the player location by the new_pos 2d-vector. Absolute movement.
...@@ -32,7 +35,7 @@ class Player: ...@@ -32,7 +35,7 @@ class Player:
Args: Args:
new_pos: 2D-Vector of the new player position. new_pos: 2D-Vector of the new player position.
""" """
pass self.pos = new_pos
def turn(self, direction: np.array): def turn(self, direction: np.array):
"""Turns the player in the given direction. Overwrites the facing_direction by a given 2d-vector. """Turns the player in the given direction. Overwrites the facing_direction by a given 2d-vector.
...@@ -41,7 +44,8 @@ class Player: ...@@ -41,7 +44,8 @@ class Player:
Args: Args:
direction: 2D-Vector of the direction for the player to face. direction: 2D-Vector of the direction for the player to face.
""" """
pass if np.linalg.norm(direction) != 0:
self.facing_direction = direction / np.linalg.norm(direction)
def pick_action(self, counter: Counter): def pick_action(self, counter: Counter):
"""Performs the pickup-action with the counter. Handles the logic of what the player is currently holding, """Performs the pickup-action with the counter. Handles the logic of what the player is currently holding,
......
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