Skip to content

Commit 46a4e75

Browse files
committed
Fix flake8 errors
1 parent e693fd3 commit 46a4e75

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

top-python-game-engines/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ Alternately, you can use `pgzrun` to run both games:
8484
(venv) $ pgzrun pygame_zero_game.py
8585
```
8686

87+
### Note
88+
Checkers like [flake8 are unaware](https://pygame-zero.readthedocs.io/en/latest/installation.html#for-flake8-pyflakes) of Pygame Zero's extra builtins.
89+
That's why xou'll find `# noqa: F821` inline comments in `pygame_zero_basic.py` and `pygame_zero_game.py`.
90+
With the `# noqa` inline comments [flake8](https://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html#in-line-ignoring-errors) ignores the errors that these lines would cause.
91+
8792
## Arcade
8893

8994
To run the Arcade sample code, first activate the virtual environment:

top-python-game-engines/adventurelib/adventurelib_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,5 @@ def use(item: str):
188188
if __name__ == "__main__":
189189
# Look at out starting room
190190
look()
191-
191+
192192
adv.start()

top-python-game-engines/pygame_zero/pygame_zero_basic.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ def draw():
2323
"""Draw is called once per frame to render everything on the screen"""
2424

2525
# Clear the screen first
26-
screen.clear()
26+
screen.clear() # noqa: F821
2727

2828
# Set the background color to white
29-
screen.fill("white")
29+
screen.fill("white") # noqa: F821
3030

3131
# Draw a blue circle with a radius of 50 in the center of the screen
32-
screen.draw.filled_circle(
32+
screen.draw.filled_circle( # noqa: F821
3333
(WIDTH // 2, HEIGHT // 2), 50, "blue"
3434
)
3535

3636
# Draw a red outlined square in the top left corner of the screen
37-
red_square = Rect((50, 50), (100, 100))
38-
screen.draw.rect(red_square, (200, 0, 0))
37+
red_square = Rect((50, 50), (100, 100)) # noqa: F821
38+
screen.draw.rect(red_square, (200, 0, 0)) # noqa: F821
3939

4040
# Draw an orange caption along the bottom in 60 point font
41-
screen.draw.text(
41+
screen.draw.text( # noqa: F821
4242
"Hello, World! From Pygame Zero!",
4343
(100, HEIGHT - 50),
4444
fontsize=60,

top-python-game-engines/pygame_zero/pygame_zero_game.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
HEIGHT = 600
2626

2727
# Setup the player
28-
player = Actor("alien_green_stand")
28+
player = Actor("alien_green_stand") # noqa: F821
2929
player_position = WIDTH // 2, HEIGHT // 2
3030
player.center = player_position
3131

@@ -48,7 +48,7 @@ def add_coin():
4848
global coin_list, coin_countdown
4949

5050
# Create a new coin Actor at a random location
51-
new_coin = Actor(
51+
new_coin = Actor( # noqa: F821
5252
"coin_gold", (randint(10, WIDTH - 10), randint(10, HEIGHT - 10))
5353
)
5454

@@ -65,7 +65,7 @@ def add_coin():
6565
coin_countdown = 0.1
6666

6767
# Schedule the next coin addition
68-
clock.schedule(add_coin, coin_countdown)
68+
clock.schedule(add_coin, coin_countdown) # noqa: F821
6969

7070

7171
def on_mouse_move(pos: Tuple):
@@ -109,7 +109,7 @@ def update(delta_time: float):
109109
# Check each coin in the list for a collision
110110
for coin in coin_list:
111111
if player.colliderect(coin):
112-
sounds.coin_pickup.play()
112+
sounds.coin_pickup.play() # noqa: F821
113113
coin_remove_list.append(coin)
114114
score += 10
115115

@@ -120,7 +120,7 @@ def update(delta_time: float):
120120
# The game is over when there are too many coins on the screen
121121
if len(coin_list) >= COIN_COUNT:
122122
# Stop making new coins
123-
clock.unschedule(add_coin)
123+
clock.unschedule(add_coin) # noqa: F821
124124

125125
# Print the final score and exit the game
126126
print(f"Game over! Final score: {score}")
@@ -131,10 +131,10 @@ def draw():
131131
"""Render everything on the screen once per frame"""
132132

133133
# Clear the screen first
134-
screen.clear()
134+
screen.clear() # noqa: F821
135135

136136
# Set the background color to pink
137-
screen.fill("pink")
137+
screen.fill("pink") # noqa: F821
138138

139139
# Draw the player
140140
player.draw()
@@ -144,7 +144,7 @@ def draw():
144144
coin.draw()
145145

146146
# Draw the current score at the bottom
147-
screen.draw.text(
147+
screen.draw.text( # noqa: F821
148148
f"Score: {score}",
149149
(50, HEIGHT - 50),
150150
fontsize=48,
@@ -153,7 +153,7 @@ def draw():
153153

154154

155155
# Schedule the first coin to appear
156-
clock.schedule(add_coin, coin_countdown)
156+
clock.schedule(add_coin, coin_countdown) # noqa: F821
157157

158158
# Run the program
159159
pgzrun.go()

0 commit comments

Comments
 (0)