-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
210 lines (170 loc) · 6.47 KB
/
game.py
File metadata and controls
210 lines (170 loc) · 6.47 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import pygame
# import sys
# import time
# import random
# from pygame.sprite import Sprite
"""INIT"""
pygame.init()
pygame.mixer.init()
"""VARIABLES"""
display_width = 1067
display_height = 706
gameDisplay = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption('Cow Clicker')
clock = pygame.time.Clock()
FPS = 60
running = True
smallfont = pygame.font.SysFont('impact', 125)
medfont = pygame.font.SysFont('impact', 35)
bigfont = pygame.font.SysFont('impact', 50)
score = 999
score_text = 'Clicks: {0}'.format(score)
red = (237, 4, 4)
orange = (237, 113, 4)
yellow = (237, 186, 4)
green = (122, 206, 4)
blue = (4, 189, 206)
purple = (145, 4, 206)
pink = (242, 150, 236)
black = (0, 0, 0)
brown = (96, 78, 55)
white = (255, 255, 255)
cow = pygame.image.load_extended('cow.png')
cow_small = pygame.transform.scale(cow, (100, 100))
cow_super_small = pygame.transform.scale(cow, (32, 32))
pygame.display.set_icon(cow_super_small)
"""FUNCTIONS"""
def music():
pygame.mixer.music.load('Silly Fun.mp3')
pygame.mixer.music.play(-1)
def oof():
effect = pygame.mixer.Sound('moo.wav')
effect.play()
def end_music():
pygame.mixer.music.load('boom_9.mp3')
pygame.mixer.music.play(0)
def text_objects(text, color, font):
text_surface = font.render(text, True, color)
return text_surface, text_surface.get_rect()
def msg_print(msg, color, y_displace, size):
text_surf, text_rect = text_objects(msg, color, size)
text_rect.center = (display_width/2), (display_height/2) + y_displace
gameDisplay.blit(text_surf, text_rect)
def bg_red():
gameDisplay.fill(red)
def bg_orange():
gameDisplay.fill(orange)
def bg_yellow():
gameDisplay.fill(yellow)
def bg_green():
gameDisplay.fill(green)
def bg_blue():
gameDisplay.fill(blue)
def bg_purple():
gameDisplay.fill(purple)
def bg_pink():
gameDisplay.fill(pink)
def bg_colors():
bg_red()
# time.sleep(0.05)
pygame.display.flip()
bg_orange()
clock.tick(FPS)
pygame.display.flip()
bg_yellow()
clock.tick(FPS)
pygame.display.flip()
bg_green()
clock.tick(FPS)
pygame.display.flip()
bg_blue()
clock.tick(FPS)
pygame.display.flip()
bg_purple()
clock.tick(FPS)
pygame.display.flip()
bg_pink()
clock.tick(FPS)
pygame.display.flip()
y_displace = 0
text_surf = smallfont.render(score_text, True, white)
text_rect = text_surf.get_rect()
text_rect.center = (display_width / 2), (display_height / 2) + y_displace
gameDisplay.blit(text_surf, text_rect)
pygame.display.flip()
def color_update():
# gameDisplay.fill(blue)
bg_colors()
# pygame.display.flip()
"""time.sleep(0.01)
gameDisplay.fill(red)
pygame.display.flip()"""
def main_loop():
global running
global cow
music()
if score >= 1000:
end_music()
while running:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_e:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_p:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_i:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_l:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_e:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_p:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_s:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_y:
print('done')
while 1 == 1:
bg_colors()
if event.type == pygame.QUIT:
running = False
pygame.quit()
quit()
if event.type == pygame.MOUSEBUTTONDOWN:
x, y = event.pos
pas = pygame.mouse.get_pos()
if cow.get_rect().collidepoint(x, y):
gameDisplay.blit(cow_small, (pas[0] - 40, pas[1] - 40))
score = score + 1
bg_colors()
oof()
game()
global score
global score_text
score_text = 'Clicks: {0}'.format(score)
pygame.display.flip()
# text = smallfont.render(score_text, True, black)
clock.tick(FPS)
gameDisplay.fill(black)
gameDisplay.blit(cow, [0, 0])
y_displace = 0
text_surf = smallfont.render(score_text, True, white)
text_rect = text_surf.get_rect()
text_rect.center = (display_width / 2), (display_height / 2) + y_displace
gameDisplay.blit(text_surf, text_rect)
"""GAME LOOP"""
def game():
global running
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit()
quit()
main_loop()