44import board
55import displayio
66import adafruit_imageload
7- from displayio import Palette
87import ugame
98import terminalio
109from adafruit_display_text import label
1110from tilegame_assets .tiles import TILES
12- from tilegame_assets .tiles import take_item
1311from tilegame_assets .states import (
1412 STATE_PLAYING ,
1513 STATE_MAPWIN ,
2018from tilegame_assets .fun_facts import FACTS
2119from tilegame_assets .text_helper import wrap_nicely
2220
21+ # pylint: disable=bad-continuation
22+
2323# Direction constants for comparison
2424UP = 0
2525DOWN = 1
7878NEED_TO_DRAW_ENTITIES = []
7979
8080
81- # return from GAME_STATE['CURRENT_MAP'] the tile name of the tile of the given coords
8281def get_tile (coords ):
82+ """
83+ :param coords: (x, y) tuple
84+ :return: tile name of the tile at the given coords from GAME_STATE['CURRENT_MAP']
85+ """
8386 return GAME_STATE ["CURRENT_MAP" ][coords [0 ], coords [1 ]]
8487
8588
86- # return from TILES dict the tile object with stats and behavior for the tile at the given coords.
8789def get_tile_obj (coords ):
90+ """
91+ :param coords: (x, y) tuple
92+ :return: tile object with stats and behavior for the tile at the given coords.
93+ """
8894 return TILES [GAME_STATE ["CURRENT_MAP" ][coords [0 ], coords [1 ]]]
8995
9096
91- # check the can_walk property of the tile at the given coordinates
97+ #
9298def is_tile_moveable (tile_coords ):
99+ """
100+ Check the can_walk property of the tile at the given coordinates
101+ :param tile_coords: (x, y) tuple
102+ :return: True if the player can walk on this tile. False otherwise.
103+ """
93104 return TILES [GAME_STATE ["CURRENT_MAP" ][tile_coords [0 ], tile_coords [1 ]]]["can_walk" ]
94105
95106
@@ -134,6 +145,7 @@ def is_tile_moveable(tile_coords):
134145
135146
136147def load_map (file_name ):
148+ # pylint: disable=global-statement,too-many-statements,too-many-nested-blocks,too-many-branches
137149 global ENTITY_SPRITES , CAMERA_VIEW
138150
139151 # empty the sprite_group
@@ -142,7 +154,7 @@ def load_map(file_name):
142154 # remove player sprite
143155 try :
144156 sprite_group .remove (GAME_STATE ["PLAYER_SPRITE" ])
145- except :
157+ except ValueError :
146158 pass
147159
148160 # reset map and other game state objects
@@ -233,19 +245,19 @@ def load_map(file_name):
233245 # print("setting GAME_STATE['ENTITY_SPRITES_DICT'][%s,%s]" % (x,y))
234246
235247 # create an entity obj
236- entity_obj = {
248+ _entity_obj = {
237249 "entity_sprite_index" : len (ENTITY_SPRITES ) - 1 ,
238250 "map_tile_name" : tile_name ,
239251 }
240252
241253 # if there are no entities at this location yet
242254 if (x , y ) not in GAME_STATE ["ENTITY_SPRITES_DICT" ]:
243255 # create a list and add it to the dictionary at the x,y location
244- GAME_STATE ["ENTITY_SPRITES_DICT" ][x , y ] = [entity_obj ]
256+ GAME_STATE ["ENTITY_SPRITES_DICT" ][x , y ] = [_entity_obj ]
245257 else :
246258 # append the entity to the existing list in the dictionary
247259 GAME_STATE ["ENTITY_SPRITES_DICT" ][x , y ].append (
248- entity_obj
260+ _entity_obj
249261 )
250262
251263 else : # tile is not entity
@@ -313,10 +325,13 @@ def can_player_move(direction):
313325 GAME_STATE ["CURRENT_MAP" ][tile_right_of_coords [0 ], tile_right_of_coords [1 ]]
314326 ]["can_walk" ]
315327
328+ return None
329+
316330
317331# set the appropriate tiles into the CAMERA_VIEW dictionary
318332# based on given starting coords and size
319333def set_camera_view (startX , startY , width , height ):
334+ # pylint: disable=global-statement
320335 global CAMERA_OFFSET_X
321336 global CAMERA_OFFSET_Y
322337 # set the offset variables for use in other parts of the code
@@ -342,6 +357,7 @@ def draw_camera_view():
342357 # any entities not in this list should get moved off the screen
343358 drew_entities = []
344359 # print(CAMERA_VIEW)
360+ # pylint: disable=too-many-nested-blocks
345361
346362 # loop over y tile coordinates
347363 for y in range (0 , SCREEN_HEIGHT_TILES ):
@@ -597,7 +613,10 @@ def show_splash(new_text, color, vertical_offset=18):
597613 elif GAME_STATE ["STATE" ] == STATE_LOST_SPARKY :
598614 GAME_STATE ["MAP_INDEX" ] = 0
599615 GAME_STATE ["STATE" ] = STATE_WAITING
600- game_over_text = "Be careful not to \n touch Sparky unless \n you've collected \n enough Mho's.\n Starting Over"
616+ game_over_text = (
617+ "Be careful not to \n touch Sparky unless \n "
618+ "you've collected \n enough Mho's.\n Starting Over"
619+ )
601620 show_splash (game_over_text , 0x25AFBB )
602621 load_map (MAPS [GAME_STATE ["MAP_INDEX" ]])
603622 # talking to minerva
0 commit comments