-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlemon_clicker.pyw
124 lines (114 loc) · 4.05 KB
/
lemon_clicker.pyw
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
import pygame
from image_button import Button
import bg
#Setup Stuff
pygame.init()
pygame.font.init()
pygame.mixer.init()
pygame.mixer.music.load("Assets/sound/bg-music.mp3")
window = pygame.display.set_mode((600, 450)) #Original resolution 450 x 450
pygame.display.set_caption("Lemon Clicker") #Alpha 0.40
pygame.display.set_icon(pygame.transform.scale(pygame.image.load("Assets/fruits/lemon.png").convert_alpha(), (32, 32)))
#Variables
clock = pygame.time.Clock()
PLAYERSCORE = 0
extra_clicks = 0
global_timer = 0
minute_timer = 60
click_power = 1
click_power_timer = 0
timer_ready = False
#Class Variables
backg = bg.Background(window, "Assets/fruits/lemon.png")
lemon = Button(window, 25, 75, "Assets/fruits/Lemon.png", 400, 300)
AutoClick = Button(window, 450, 0, "Assets/buttons/Auto_Clicker_Button.png", 150, 150)
Lemonade = Button(window, 450, 150, "Assets/buttons/Lemonade_Button.png", 150, 150)
Double = Button(window, 450, 300, "Assets/buttons/Double_Button.png", 150, 150)
#Get Save Data
try:
save_file = open("Assets/save_data.lemon", "r").read()
save_file = save_file.split(" ")
PLAYERSCORE = int(save_file[0])
extra_clicks = int(save_file[1])
except Exception as e:
open("Assets/save_data.lemon", "w").truncate(0)
open("Assets/save_data.lemon", "w").write("0 0")
#Functions
def disp_text(window, x, y, text):
font = pygame.font.SysFont("Comic Sans MS", 20)
surface = font.render(text, False, (0, 0, 0))
window.blit(surface, (x, y))
#Main Pygame Loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
#Debug Keys: Up arrow sets the minute timer to 1, Down arrow resets scores to zero
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
minute_timer = 1
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
PLAYERSCORE = 0
extra_clicks = 0
''' Scripts that run every frame '''
#Background Script
backg.update()
#Music Script
if global_timer % 900 == 0:
pygame.mixer.music.play()
#Auto Click Script
if global_timer % 30 == 0:
PLAYERSCORE += (extra_clicks * click_power)
#Click Power Script
if click_power_timer > 0:
if global_timer % 30 == 0:
click_power_timer -= 1
elif click_power_timer <= 0:
click_power = 1
#Minute timer script
if global_timer % 30 == 0 and minute_timer > 0:
minute_timer -= 1
timer_ready = False
if minute_timer <= 0:
timer_ready = True
#Class Updates
#Buttons
#Lemon
lemon.update()
if lemon.clicked:
print(f"Lemon Clicked! Score = {PLAYERSCORE + 1}")
PLAYERSCORE += (1 * click_power)
#Auto Clicker Button
AutoClick.update()
if AutoClick.clicked:
if PLAYERSCORE >= 100:
PLAYERSCORE -= 100
extra_clicks += 1
#Lemonade Button
Lemonade.update(disp_img = timer_ready)
if Lemonade.clicked and timer_ready:
minute_timer = 60
timer_ready = False
PLAYERSCORE += (200 * click_power)
#Double Score Button
Double.update(disp_img = timer_ready)
if Double.clicked and timer_ready:
minute_timer = 60
timer_ready = False
click_power = 2
click_power_timer = 20
disp_text(window, 0, 0, f"Score: {PLAYERSCORE} | AutoClicks: {extra_clicks} | Timer: {minute_timer} {'| READY' if minute_timer <=0 else ''}")
disp_text(window, 0, 22, 'Double Points Time Left: '+str(click_power_timer) if click_power_timer > 0 else '')
global_timer += 1
pygame.display.update()
clock.tick(30)
window.fill((255, 255, 0))
#End of Pygame Loop, final save function before program exit
with open("Assets/save_data.lemon", "w") as savedata:
savedata.truncate(0)
savedata.write(f"{str(PLAYERSCORE)} {str(extra_clicks)}")
savedata.close()
pygame.quit()
quit(0)