So I have my code do something different based on whether the user clicks
with the left or right mouse button. However, I noticed that for some
reason both print statements are running when I click on any mouse button.
Any idea as to what might be causing this?
Code snip:
window.push_handlers(Objects.global_mouse_handler)
... #more code
@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
print('right click',player.name,' unselected')
--###More code
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyglet-users/a8be0640-ebd7-4f13-80a5-04678a0fc7b6o%40googlegroups.com.