-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
035b6f5
commit 4f5fd96
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Build off of your previous code (the code from QuitPygameProblem.py) | ||
# Draw the provided rectangle onto the screen. | ||
# Move the object up when either the W or up arrow key is pressed; | ||
# right when either the D or right arrow is pressed; etc. | ||
|
||
import pygame | ||
|
||
pygame.init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Create a program that increments a counter every time the space bar is | ||
# pressed. This counter should be displayed as text on the pygame window. | ||
|
||
import pygame | ||
|
||
pygame.init() | ||
screen = pygame.display.set_mode((400, 400)) | ||
|
||
font = pygame.font.SysFont("arial", 70) | ||
|
||
display_counter = 0 | ||
|
||
run = True | ||
|
||
while run: | ||
|
||
# Render the "display_counter" to the screen | ||
show_counter = font.render(str(display_counter), True, (255, 192, 203)) | ||
|
||
# Makes Screen Black | ||
screen.fill((0, 0, 0)) | ||
|
||
# Prints Data on Screen | ||
screen.blit(show_counter, (30, 30)) | ||
|
||
for event in pygame.event.get(): | ||
if event.type == pygame.QUIT: | ||
run = False | ||
|
||
# Checks to see if key is pressed | ||
if event.type == pygame.KEYDOWN: | ||
|
||
# Checks to see if the space is pressed | ||
if event.key == pygame.K_SPACE: | ||
|
||
# Adds one to the counter | ||
display_counter += 1 | ||
|
||
# Updates the data | ||
pygame.display.update() | ||
|
||
pygame.quit() |