@@ -246,9 +246,9 @@ def __init__(
246
246
self .defeat : bool = False
247
247
248
248
# Data structures for possible actions
249
- self .possible_moves : dict [tuple [ int , int ] , int ] = {}
250
- self .possible_attacks : list [tuple [ int , int ] ] = []
251
- self .possible_interactions : list [tuple [ int , int ] ] = []
249
+ self .possible_moves : dict [Position , int ] = {}
250
+ self .possible_attacks : list [Position ] = []
251
+ self .possible_interactions : list [Position ] = []
252
252
253
253
# Storage of current selected entity
254
254
self .selected_player : Optional [Player ] = None
@@ -381,7 +381,7 @@ def load_level_content(self) -> None:
381
381
382
382
self .sidebar = Sidebar (
383
383
(MENU_WIDTH , MENU_HEIGHT ),
384
- pygame . Vector2 (0 , MAX_MAP_HEIGHT ),
384
+ Position (0 , MAX_MAP_HEIGHT ),
385
385
self .missions ,
386
386
self .number ,
387
387
)
@@ -731,7 +731,7 @@ def get_next_cases(self, position: Position) -> list[Optional[Entity]]:
731
731
for y_coordinate in (1 - abs (x_coordinate ), - 1 + abs (x_coordinate )):
732
732
tile_x : int = position [0 ] + (x_coordinate * TILE_SIZE )
733
733
tile_y : int = position [1 ] + (y_coordinate * TILE_SIZE )
734
- tile_position = tile_x , tile_y
734
+ tile_position : Position = Position ( tile_x , tile_y )
735
735
tile_content : Optional [Entity ] = self .get_entity_on_tile (tile_position )
736
736
tiles_content .append (tile_content )
737
737
return tiles_content
@@ -746,7 +746,8 @@ def get_possible_moves(
746
746
position -- the starting position
747
747
max_moves -- the maximum number of tiles that could be traveled
748
748
"""
749
- tiles : dict [Position , int ] = {position : 0 }
749
+ new_position = Position (position .x , position .y )
750
+ tiles : dict [Position , int ] = {new_position : 0 }
750
751
previously_computed_tiles : dict [Position , int ] = tiles
751
752
for i in range (1 , max_moves + 1 ):
752
753
tiles_current_level : dict [Position , int ] = {}
@@ -755,7 +756,7 @@ def get_possible_moves(
755
756
for y_coordinate in (1 - abs (x_coordinate ), - 1 + abs (x_coordinate )):
756
757
tile_x : int = tile [0 ] + (x_coordinate * TILE_SIZE )
757
758
tile_y : int = tile [1 ] + (y_coordinate * TILE_SIZE )
758
- tile_position = (tile_x , tile_y )
759
+ tile_position = Position (tile_x , tile_y )
759
760
if (
760
761
self .is_tile_available (tile_position )
761
762
and tile_position not in tiles
@@ -768,10 +769,10 @@ def get_possible_moves(
768
769
769
770
def get_possible_attacks (
770
771
self ,
771
- possible_moves : Sequence [tuple [ int , int ] ],
772
+ possible_moves : Sequence [Position ],
772
773
reach : Sequence [int ],
773
774
from_ally_side : bool ,
774
- ) -> set [tuple [ float , float ] ]:
775
+ ) -> set [Position ]:
775
776
"""
776
777
Return all the tiles that could be targeted for an attack from a specific entity
777
778
@@ -780,7 +781,7 @@ def get_possible_attacks(
780
781
reach -- the reach of the attacking entity
781
782
from_ally_side -- a boolean indicating whether this is a friendly attack or not
782
783
"""
783
- tiles : list [tuple [ float , float ] ] = []
784
+ tiles : list [Position ] = []
784
785
785
786
entities = list (self .entities .breakables )
786
787
if from_ally_side :
@@ -794,11 +795,11 @@ def get_possible_attacks(
794
795
for y_coordinate in (i - abs (x_coordinate ), - i + abs (x_coordinate )):
795
796
tile_x : int = entity .position [0 ] + (x_coordinate * TILE_SIZE )
796
797
tile_y : int = entity .position [1 ] + (y_coordinate * TILE_SIZE )
797
- tile_position = (tile_x , tile_y )
798
+ tile_position = Position (tile_x , tile_y )
798
799
if tile_position in possible_moves :
799
- tiles .append (tuple ( entity .position ) )
800
+ tiles .append (entity .position )
800
801
801
- return set (tiles )
802
+ return set ([ Position ( i . x , i . y ) for i in tiles ] )
802
803
803
804
def is_tile_available (self , tile : Position ) -> bool :
804
805
"""
@@ -807,8 +808,8 @@ def is_tile_available(self, tile: Position) -> bool:
807
808
Keyword arguments:
808
809
tile -- the position of the tile
809
810
"""
810
- min_case : Position = pygame . Vector2 (self .map ["x" ], self .map ["y" ])
811
- max_case : Position = pygame . Vector2 (
811
+ min_case : Position = Position (self .map ["x" ], self .map ["y" ])
812
+ max_case : Position = Position (
812
813
self .map ["x" ] + self .map ["width" ],
813
814
self .map ["y" ] + self .map ["height" ],
814
815
)
@@ -842,7 +843,7 @@ def get_entity_on_tile(self, tile: Position) -> Optional[Entity]:
842
843
return None
843
844
844
845
def determine_path_to (
845
- self , destination_tile : Position , distance_for_tile : dict [tuple [ int , int ] , int ]
846
+ self , destination_tile : Position , distance_for_tile : dict [Position , int ]
846
847
) -> list [Position ]:
847
848
"""
848
849
Return an ordered list of position that represent the path from one tile to another
@@ -852,18 +853,16 @@ def determine_path_to(
852
853
distance -- the distance between the starting tile and the destination
853
854
"""
854
855
path : list [Position ] = [destination_tile ]
855
- current_tile : tuple [ int , int ] = tuple ( destination_tile )
856
+ current_tile : Position = destination_tile
856
857
while distance_for_tile [current_tile ] > 1 :
857
858
# Check for neighbour cases
858
- available_tiles : dict [tuple [int , int ], int ] = self .get_possible_moves (
859
- tuple (current_tile ), 1
860
- )
859
+ available_tiles : dict [Position , int ] = self .get_possible_moves (current_tile , 1 )
861
860
for tile in available_tiles :
862
861
if tile in distance_for_tile :
863
862
distance = distance_for_tile [tile ]
864
863
if distance < distance_for_tile [current_tile ]:
865
864
current_tile = tile
866
- path .insert (0 , pygame . Vector2 ( current_tile ) )
865
+ path .insert (0 , current_tile )
867
866
return path
868
867
869
868
def distance_between_all (
@@ -876,8 +875,8 @@ def distance_between_all(
876
875
entity -- the entity for which the distance from all other entities should be computed
877
876
all_other_entities -- all other entities for which the distance should be computed
878
877
"""
879
- free_tiles_distance : dict [tuple [ int , int ] , int ] = self .get_possible_moves (
880
- tuple ( entity .position ) ,
878
+ free_tiles_distance : dict [Position , int ] = self .get_possible_moves (
879
+ entity .position ,
881
880
(self .map ["width" ] * self .map ["height" ]) // (TILE_SIZE * TILE_SIZE ),
882
881
)
883
882
entities_distance : dict [Entity , int ] = {
@@ -1099,7 +1098,7 @@ def interact(
1099
1098
new_based_position : Position = target .linked_to .position
1100
1099
possible_positions_with_distance : dict [
1101
1100
Position , int
1102
- ] = self .get_possible_moves (tuple ( new_based_position ) , 1 )
1101
+ ] = self .get_possible_moves (new_based_position , 1 )
1103
1102
# Remove portal pos since player cannot be on the portal
1104
1103
del possible_positions_with_distance [new_based_position ]
1105
1104
if possible_positions_with_distance :
@@ -1326,8 +1325,8 @@ def process_entity_action(self, entity: Movable, is_ally: bool) -> None:
1326
1325
entity -- the entity for which the action should be computed
1327
1326
is_ally -- a boolean indicating if the entity is an ally or not
1328
1327
"""
1329
- possible_moves : dict [tuple [ int , int ] , int ] = self .get_possible_moves (
1330
- tuple ( entity .position ) , entity .max_moves
1328
+ possible_moves : dict [Position , int ] = self .get_possible_moves (
1329
+ entity .position , entity .max_moves
1331
1330
)
1332
1331
targets : Sequence [Movable ] = (
1333
1332
self .entities .foes if is_ally else self .players + self .entities .allies
@@ -2128,7 +2127,7 @@ def left_click(self, position: Position) -> None:
2128
2127
player .selected = True
2129
2128
self .selected_player = player
2130
2129
self .possible_moves = self .get_possible_moves (
2131
- tuple ( player .position ) ,
2130
+ player .position ,
2132
2131
player .max_moves + player .get_stat_change ("speed" ),
2133
2132
)
2134
2133
self .possible_attacks = (
@@ -2272,7 +2271,7 @@ def button_down(self, button: int, position: Position) -> None:
2272
2271
) and entity .get_rect ().collidepoint (position_inside_level ):
2273
2272
self .watched_entity = entity
2274
2273
self .possible_moves = self .get_possible_moves (
2275
- tuple ( entity .position ) , entity .max_moves
2274
+ entity .position , entity .max_moves
2276
2275
)
2277
2276
reach : Sequence [int ] = self .watched_entity .reach
2278
2277
self .possible_attacks = {}
@@ -2340,7 +2339,7 @@ def _compute_relative_position(self, position: Position) -> Position:
2340
2339
Keyword arguments:
2341
2340
position -- the absolute position to be converted
2342
2341
"""
2343
- return position - pygame . Vector2 (
2342
+ return position - Position (
2344
2343
self .screen .get_width () // 2 - self .active_screen_part .get_width () // 2 ,
2345
2344
self .screen .get_height () // 2 - self .active_screen_part .get_height () // 2 ,
2346
2345
)
0 commit comments