-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·117 lines (92 loc) · 2.57 KB
/
main.py
File metadata and controls
executable file
·117 lines (92 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import pygame
import playerclass
import enemy
from random import randint
# Window setup
pygame.init()
window_height = 900
window_width = 1600
window = pygame.display.set_mode((window_width, window_height))
clock = pygame.time.Clock()
framerate = 60
# Objects
player = playerclass.Player(window)
targets = []
# Other global variables
run = True
score = 0
game_over = False
countdown_len = randint(50, 70)
target_countdown = countdown_len
max_fires = 10
# Fonts
water_font = pygame.font.Font("Righteous-Regular.ttf", 48)
score_font = pygame.font.Font("Righteous-Regular.ttf", 100)
def render_targets():
global score, player
for target in targets:
target.show()
target.check_hit(player.bullets)
if target.hp == 0:
targets.remove(target)
score += 10
player.ammo += 10
def generate_targets():
global target_countdown
if target_countdown == 0:
targets.append(enemy.Enemy(
window,
50,
50,
randint(0, window_width - 50),
randint(0, window_height - 50)
))
target_countdown = countdown_len
target_countdown -= 1
def player_update(player):
player.move(inputs)
player.show()
player.shoot(inputs)
player.shot_vel = randint(10,20)
player.bullets_update()
def draw_UI():
water_text = water_font.render(
f"Water: {player.ammo}",
False,
(255, 255, 255)
)
window.blit(water_text, (10, 10))
def check_game_over():
global run, game_over
if not player.ammo or len(targets) > max_fires:
run = False
game_over = True
# font = pygame.font.Font("Righteous-Regular.ttf", 54)
score_text = score_font.render(
f"YOUR SCORE: {score}",
False,
(255, 255, 255)
)
window.fill((0, 0, 0))
window.blit(score_text, (window_width/2 - 100, window_height/2))
pygame.display.flip()
# Main Loop
while run:
window.fill((0, 15, 0))
clock.tick(framerate)
inputs = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
player_update(player)
draw_UI()
generate_targets()
render_targets()
pygame.display.flip()
check_game_over()
# Game Over screen
while game_over:
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = False
pygame.quit()