Skip to content

Commit 6cb5c63

Browse files
committed
variable name clarifications
1 parent f3dc016 commit 6cb5c63

File tree

4 files changed

+57
-57
lines changed

4 files changed

+57
-57
lines changed

main.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414

1515
player_spritesheet = pygame.image.load("player.png").convert_alpha()
1616
player_imgs = []
17-
for x in range(4):
18-
player_img = player_spritesheet.subsurface(x * 9, 0, 9, 14)
17+
for frame in range(4):
18+
player_img = player_spritesheet.subsurface(frame * 9, 0, 9, 14)
1919
player_img = pygame.transform.scale(player_img, (36, 56))
2020
player_imgs.append(player_img)
2121

2222
cookie_img = pygame.image.load("cookie.png").convert_alpha()
2323

2424
bullet_spritesheet = pygame.image.load("bullet.png").convert_alpha()
2525
bullet_imgs = []
26-
for x in range(4):
27-
bullet_img = bullet_spritesheet.subsurface(x * 3, 0, 3, 7)
26+
for frame in range(4):
27+
bullet_img = bullet_spritesheet.subsurface(frame * 3, 0, 3, 7)
2828
bullet_img = pygame.transform.scale(bullet_img, (12, 28))
2929
bullet_imgs.append(bullet_img)
3030

@@ -35,20 +35,20 @@ def __init__(self):
3535
super().__init__()
3636

3737
self.image = player_imgs[0]
38-
self.index = 0
39-
self.animation_time = time.time()
38+
self.frame = 0
39+
self.frame_time = time.time()
4040
self.rect = player_img.get_rect()
4141

4242
self.x = 180
4343
self.y = 340
4444

4545
def update(self):
46-
self.image = player_imgs[self.index]
47-
if time.time() - self.animation_time > 0.1:
48-
self.animation_time = time.time()
49-
self.index += 1
50-
if self.index == 4:
51-
self.index = 0
46+
self.image = player_imgs[self.frame]
47+
if time.time() - self.frame_time > 0.1:
48+
self.frame_time = time.time()
49+
self.frame += 1
50+
if self.frame == 4:
51+
self.frame = 0
5252

5353
keys = pygame.key.get_pressed()
5454
if keys[K_LEFT]:
@@ -101,20 +101,20 @@ def __init__(self, x, y):
101101
super().__init__(bullets)
102102

103103
self.image = bullet_imgs[0]
104-
self.index = 0
105-
self.animation_time = time.time()
104+
self.frame = 0
105+
self.frame_time = time.time()
106106
self.rect = self.image.get_rect()
107107

108108
self.x = x
109109
self.y = y
110110

111111
def update(self):
112-
self.image = bullet_imgs[self.index]
113-
if time.time() - self.animation_time > 0.1:
114-
self.animation_time = time.time()
115-
self.index += 1
116-
if self.index == 4:
117-
self.index = 0
112+
self.image = bullet_imgs[self.frame]
113+
if time.time() - self.frame_time > 0.1:
114+
self.frame_time = time.time()
115+
self.frame += 1
116+
if self.frame == 4:
117+
self.frame = 0
118118

119119
self.y -= 10
120120

part_3_steps/step-2.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
cookie_img = pygame.image.load("cookie.png").convert_alpha()
1919
bullet_spritesheet = pygame.image.load("bullet.png").convert_alpha()
2020
bullet_imgs = []
21-
for x in range(4):
22-
bullet_img = bullet_spritesheet.subsurface(x * 3, 0, 3, 7)
21+
for frame in range(4):
22+
bullet_img = bullet_spritesheet.subsurface(frame * 3, 0, 3, 7)
2323
bullet_img = pygame.transform.scale(bullet_img, (12, 28))
2424
bullet_imgs.append(bullet_img)
2525
bg_img = pygame.image.load("background.png").convert()
@@ -87,17 +87,17 @@ def __init__(self, x, y):
8787
super().__init__(bullets)
8888

8989
self.image = bullet_imgs[0]
90-
self.index = 0
90+
self.frame = 0
9191
self.rect = self.image.get_rect()
9292

9393
self.x = x
9494
self.y = y
9595

9696
def update(self):
97-
self.image = bullet_imgs[self.index]
98-
self.index += 1
99-
if self.index == 4:
100-
self.index = 0
97+
self.image = bullet_imgs[self.frame]
98+
self.frame += 1
99+
if self.frame == 4:
100+
self.frame = 0
101101

102102
self.y -= 10
103103

part_3_steps/step-3.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
cookie_img = pygame.image.load("cookie.png").convert_alpha()
2020
bullet_spritesheet = pygame.image.load("bullet.png").convert_alpha()
2121
bullet_imgs = []
22-
for x in range(4):
23-
bullet_img = bullet_spritesheet.subsurface(x * 3, 0, 3, 7)
22+
for frame in range(4):
23+
bullet_img = bullet_spritesheet.subsurface(frame * 3, 0, 3, 7)
2424
bullet_img = pygame.transform.scale(bullet_img, (12, 28))
2525
bullet_imgs.append(bullet_img)
2626
bg_img = pygame.image.load("background.png").convert()
@@ -87,20 +87,20 @@ def __init__(self, x, y):
8787
super().__init__(bullets)
8888

8989
self.image = bullet_imgs[0]
90-
self.index = 0
91-
self.animation_time = time.time()
90+
self.frame = 0
91+
self.frame_time = time.time()
9292
self.rect = self.image.get_rect()
9393

9494
self.x = x
9595
self.y = y
9696

9797
def update(self):
98-
self.image = bullet_imgs[self.index]
99-
if time.time() - self.animation_time > 0.1:
100-
self.animation_time = time.time()
101-
self.index += 1
102-
if self.index == 4:
103-
self.index = 0
98+
self.image = bullet_imgs[self.frame]
99+
if time.time() - self.frame_time > 0.1:
100+
self.frame_time = time.time()
101+
self.frame += 1
102+
if self.frame == 4:
103+
self.frame = 0
104104

105105
self.y -= 10
106106

part_3_steps/step-4.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616

1717
player_spritesheet = pygame.image.load("player.png").convert_alpha()
1818
player_imgs = []
19-
for x in range(4):
20-
player_img = player_spritesheet.subsurface(x * 9, 0, 9, 14)
19+
for frame in range(4):
20+
player_img = player_spritesheet.subsurface(frame * 9, 0, 9, 14)
2121
player_img = pygame.transform.scale(player_img, (36, 56))
2222
player_imgs.append(player_img)
2323

2424
cookie_img = pygame.image.load("cookie.png").convert_alpha()
2525

2626
bullet_spritesheet = pygame.image.load("bullet.png").convert_alpha()
2727
bullet_imgs = []
28-
for x in range(4):
29-
bullet_img = bullet_spritesheet.subsurface(x * 3, 0, 3, 7)
28+
for frame in range(4):
29+
bullet_img = bullet_spritesheet.subsurface(frame * 3, 0, 3, 7)
3030
bullet_img = pygame.transform.scale(bullet_img, (12, 28))
3131
bullet_imgs.append(bullet_img)
3232

@@ -37,20 +37,20 @@ def __init__(self):
3737
super().__init__()
3838

3939
self.image = player_imgs[0]
40-
self.index = 0
41-
self.animation_time = time.time()
40+
self.frame = 0
41+
self.frame_time = time.time()
4242
self.rect = player_img.get_rect()
4343

4444
self.x = 180
4545
self.y = 340
4646

4747
def update(self):
48-
self.image = player_imgs[self.index]
49-
if time.time() - self.animation_time > 0.1:
50-
self.animation_time = time.time()
51-
self.index += 1
52-
if self.index == 4:
53-
self.index = 0
48+
self.image = player_imgs[self.frame]
49+
if time.time() - self.frame_time > 0.1:
50+
self.frame_time = time.time()
51+
self.frame += 1
52+
if self.frame == 4:
53+
self.frame = 0
5454

5555
keys = pygame.key.get_pressed()
5656
if keys[K_LEFT]:
@@ -103,20 +103,20 @@ def __init__(self, x, y):
103103
super().__init__(bullets)
104104

105105
self.image = bullet_imgs[0]
106-
self.index = 0
107-
self.animation_time = time.time()
106+
self.frame = 0
107+
self.frame_time = time.time()
108108
self.rect = self.image.get_rect()
109109

110110
self.x = x
111111
self.y = y
112112

113113
def update(self):
114-
self.image = bullet_imgs[self.index]
115-
if time.time() - self.animation_time > 0.1:
116-
self.animation_time = time.time()
117-
self.index += 1
118-
if self.index == 4:
119-
self.index = 0
114+
self.image = bullet_imgs[self.frame]
115+
if time.time() - self.frame_time > 0.1:
116+
self.frame_time = time.time()
117+
self.frame += 1
118+
if self.frame == 4:
119+
self.frame = 0
120120

121121
self.y -= 10
122122

0 commit comments

Comments
 (0)