Skip to content

Commit e3f61b9

Browse files
committed
Creating Bullets for Shooting - Python #PyGame Lesson 4
Creating Bullets for Shooting - Python #PyGame Lesson 4
1 parent 677d45a commit e3f61b9

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

Python PyGame/main.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,37 @@
3131

3232
clock = pygame.time.Clock()
3333

34-
3534
class player(object):
3635
def __init__(self, x, y, width, height):
3736
self.x = x
3837
self.y = y
3938
self.width = width
4039
self.height = height
41-
self.vel = 5
40+
self.mov = 5
4241
self.isJump = False
4342
self.left = False
4443
self.right = False
4544
self.walkCount = 0
4645
self.jumpCount = 10
4746
self.standing = True
4847

49-
def draw(self, win):
48+
def draw(self, window):
5049
if self.walkCount + 1 >= 27:
5150
self.walkCount = 0
5251

5352
if not (self.standing):
53+
5454
if self.left:
55-
win.blit(walkLeft[self.walkCount // 3], (self.x, self.y))
55+
window.blit(walkLeft[self.walkCount // 3], (self.x, self.y))
5656
self.walkCount += 1
5757
elif self.right:
58-
win.blit(walkRight[self.walkCount // 3], (self.x, self.y))
58+
window.blit(walkRight[self.walkCount // 3], (self.x, self.y))
5959
self.walkCount += 1
6060
else:
6161
if self.right:
62-
win.blit(walkRight[0], (self.x, self.y))
62+
window.blit(walkRight[0], (self.x, self.y))
6363
else:
64-
win.blit(walkLeft[0], (self.x, self.y))
65-
64+
window.blit(walkLeft[0], (self.x, self.y))
6665

6766
class projectile(object):
6867
def __init__(self, x, y, radius, color, facing):
@@ -73,23 +72,22 @@ def __init__(self, x, y, radius, color, facing):
7372
self.facing = facing
7473
self.vel = 8 * facing
7574

76-
def draw(self, win):
77-
pygame.draw.circle(win, self.color, (self.x, self.y), self.radius)
75+
def draw(self, window):
76+
pygame.draw.circle(window, self.color, (self.x, self.y), self.radius)
7877

7978

8079
def redrawGameWindow():
8180
window.blit(bg, (0, 0))
8281
man.draw(window)
8382
for bullet in bullets:
8483
bullet.draw(window)
85-
8684
pygame.display.update()
8785

8886

89-
# mainloop
87+
9088
man = player(200, 410, 64, 64)
91-
bullets = []
9289
run = True
90+
bullets = []
9391
while run:
9492
clock.tick(27)
9593

@@ -115,28 +113,31 @@ def redrawGameWindow():
115113
bullets.append(
116114
projectile(round(man.x + man.width // 2),
117115
round(man.y + man.height // 2),
118-
6, (0, 0, 0), facing))
116+
6, (0,0,0), facing))
119117

120-
if keys[pygame.K_LEFT] and man.x > man.vel:
121-
man.x -= man.vel
118+
if keys[pygame.K_LEFT] and man.x > man.mov:
119+
man.x -= man.mov
122120
man.left = True
123121
man.right = False
124122
man.standing = False
125-
elif keys[pygame.K_RIGHT] and man.x < 500 - man.width - man.vel:
126-
man.x += man.vel
127-
man.right = True
123+
124+
elif keys[pygame.K_RIGHT] and man.x < 500 - man.mov - man.width:
125+
man.x +=man.mov
128126
man.left = False
127+
man.right = True
129128
man.standing = False
129+
130130
else:
131131
man.standing = True
132132
man.walkCount = 0
133133

134-
if not (man.isJump):
134+
if not(man.isJump):
135135
if keys[pygame.K_UP]:
136136
man.isJump = True
137-
man.right = False
138137
man.left = False
138+
man.right = False
139139
man.walkCount = 0
140+
140141
else:
141142
if man.jumpCount >= -10:
142143
neg = 1

0 commit comments

Comments
 (0)