Skip to content

Commit 1444b3e

Browse files
committed
Fix error with flickering ball2
1 parent ac2d13a commit 1444b3e

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

bouncing_ball/bounceball.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pygame.init()
44

55
size = width, height = 620, 540
6-
speed1 = [2, 2]
6+
speed1 = [1.5, 1.5]
77
speed2 = [1, 1]
88
black = 0, 0, 0
99

@@ -13,9 +13,9 @@
1313
img1 = pygame.image.load("ball1.png")
1414
img2 = pygame.image.load("ball2.png")
1515
ball1 = pygame.transform.scale(img1, (65, 65))
16-
ball2 = pygame.transform.scale(img2, (65, 65))
16+
ball2 = pygame.transform.scale(img2, (63, 63))
1717
ballrect1 = ball1.get_rect()
18-
ballrect2 = ball2.get_rect()
18+
ballrect2 = ball2.get_rect(topleft=(100, 300))
1919

2020
while 1:
2121
for event in pygame.event.get():
@@ -34,11 +34,11 @@
3434
speed2[0] = -speed2[0]
3535
if ballrect2.top < 0 or ballrect2.bottom > height:
3636
speed2[1] = -speed2[1]
37-
37+
3838
screen.fill(black)
3939

4040
screen.blit(ball1, ballrect1)
41-
pygame.display.flip()
41+
# pygame.display.flip()
4242

4343
screen.blit(ball2, ballrect2)
4444
pygame.display.flip()

notes.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,12 @@ Variables needed with example code:
9191
font = `pygame.font.SysFont("comicsans", 30, True, True)` (True stands for bold and italic)
9292
text = `font.render("myText")` => this creates a surface that can be blit onto the screen (same as blitting an imange)
9393

94+
**Keys**
95+
To use key press for jumping, increasing speed, shooting bullets etc. write:
96+
`keys = pygame.key.get_pressed()`
97+
and use the key constants (K_xxx) as follows:
98+
K_SPACE space
99+
K_UP up arrow
100+
K_DOWN down arrow
101+
K_RIGHT right arrow
102+
K_LEFT left arrow

0 commit comments

Comments
 (0)