MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / play

Function play

projects/space_battle/main.py:13–196  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11
12
13def play():
14 screen = pygame.display.set_mode((800, 600))
15 running = True
16 pygame.display.set_caption("Space invaders")
17 icon = pygame.image.load("ufo.png")
18 pygame.display.set_icon(icon)
19 player_image = pygame.image.load("resize-16681994301185496102ufo1.png")
20 playerX = 200
21 playerY = 400
22 player_change = 0
23 player_changeY = 0
24 enemy_img = pygame.image.load("icons8-ufo-64.png")
25 enemyN = 10
26 img_list = []
27 enemyX = []
28 enemyY = []
29 touch8 = []
30 temp = []
31 d = []
32 d2 = []
33 bullet = pygame.image.load("yellow_ball.png")
34 bg = pygame.image.load("2352.jpg")
35 Release = False
36 bulletX = playerX + 8
37 count = 0
38
39 font = pygame.font.Font("freesansbold.ttf", 32)
40 textX = 10
41 textY = 10
42 xchange = 0.3
43 ychange = 25
44
45 def bg_image(bg):
46 screen.blit(bg, (0, 0))
47
48 for t in range(enemyN):
49 img_list.append(enemy_img)
50 enemyX.append(random.randint(0, 700))
51 enemyY.append(random.randint(0, 150))
52 touch8.append(True)
53 temp.append(True)
54 d.append(100)
55 d2.append(100)
56 impact = False
57
58 def show_score(x, y):
59 count1 = font.render(("score:" + str(count)), True, (220, 34, 120))
60 screen.blit(count1, (x, y))
61
62 def game_over(x, y):
63 over = font.render(
64 "Game-Over\nYour Final Score is:" + str(count), True, (240, 140, 220)
65 )
66 screen.blit(over, (x, y))
67
68 m1 = mixer.Sound("space-120280.mp3")
69
70 m1.play(-1)

Callers 1

main.pyFile · 0.70

Calls 8

bg_imageFunction · 0.85
game_overFunction · 0.85
restartFunction · 0.85
bulletPFunction · 0.85
enemyFunction · 0.85
playerFunction · 0.70
show_scoreFunction · 0.70
updateMethod · 0.45

Tested by

no test coverage detected