@window.event
def on_mouse_press(x,y,button,modifiers):
if mouse.LEFT and Objects.game_obj.game_state == 'Map Editor':
Terrain.terrain_obj.map_editor_function(x,y)
#Run Dijskstra search
if mouse.LEFT and Objects.game_obj.game_state == 'Main':
print('left selected')
#if player is selected player, run djikstra
for player in [obj for obj in Objects.game_obj.game_objects if obj.__class__ == Players.Player]:
if player.selected == True:
player_cell = Terrain.terrain_obj.return_player_cell(player)
destination_cell = Terrain.terrain_obj.return_sprite_index(x,y)
print('left click, player cell',player_cell)
print('left click, destination cell',destination_cell)
nav_list = Terrain.terrain_obj.Dijkstra_algorithm(player_cell,destination_cell)
nav_path = Terrain.terrain_obj.return_list_cell_positions(nav_list)
player.nav_path = nav_path
player.navigation = True
#Select player
if mouse.RIGHT and Objects.game_obj.game_state == 'Main':
print('right selected')
#Runs through players and makes player.selected = True if within mouse coordinates
for player in [obj for obj in Objects.game_obj.game_objects if obj.__class__ == Players.Player]:
player_coord = player.sprite.position
half_width = player.sprite.width//2
half_height = player.sprite.height//2
if (x >= player_coord[0] - half_width and x <= player_coord[0] + half_width) and \
(y >= player_coord[1] - half_height and y <= player_coord[1] + half_height):
player.selected = True
print(
'right click player name',
player.name,
' selected')
#highlights which cells the selected player can move to
available_cells = Terrain.terrain_obj.move_distance_calc(player)
for cell in available_cells:
Terrain.terrain_obj.terrain_dict[cell].terrain_type == 'Black'
#print('reached init cell loop')
Terrain.terrain_obj.terrain_dict[cell].sprite=Terrain.terrain_obj.terrain_dict[cell].init_cell()
else:
player.selected = False
--###More code