-
Notifications
You must be signed in to change notification settings - Fork 15
/
scorescreen.py
executable file
·216 lines (155 loc) · 6.54 KB
/
scorescreen.py
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
211
212
213
214
215
216
# -*- coding: utf-8 -*-
#
# Stick Hero
# Copyright (C) 2015 Utkarsh Tiwari
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Contact information:
# Utkarsh Tiwari iamutkarshtiwari@gmail.com
import os
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import pickle
import pygame
from gettext import gettext as _
from math import *
from random import *
from rules import sx, sy, display_init
from score_path import score_path
class scorescreen:
def make(self, gameDisplay, back, score, fruitscore):
sound = True
gameDisplay = display_init()
black = (0, 0, 0)
white = (255, 255, 255)
clock = pygame.time.Clock()
timer = pygame.time.Clock()
crashed = False
disp_width = 600
disp_height = 600
press = 0
info = pygame.display.Info()
if not(gameDisplay):
gameDisplay = pygame.display.set_mode(
(info.current_w, info.current_h))
replay = pygame.image.load("images/scorescreen/replay.png")
replay = pygame.transform.scale(replay, (int(sx(104)), int(sy(102))))
scoreplate = pygame.image.load("images/scorescreen/scoreplate.png")
scoreplate = pygame.transform.scale(scoreplate, (int(sx(230 + 130)), int(sy(140 + 80))))
plate = pygame.image.load("images/scoreplate.png").convert()
plate = pygame.transform.scale(plate, (int(sx(340)), int(sy(90))))
plate.set_alpha(220)
home = pygame.image.load("images/scorescreen/home.png")
home = pygame.transform.scale(
home, (int(sx(108)), int(sy(106))))
# back=pygame.image.load("screenshot/screenshot.png")
back.convert()
back.set_alpha(225)
font_path = "fonts/Arimo.ttf"
font_size = int(sx(50))
font1 = pygame.font.Font(font_path, font_size)
font2 = pygame.font.Font("fonts/Arimo.ttf", int(sx(30)))
font3 = pygame.font.Font("fonts/Arimo.ttf", int(sx(40)))
font4 = pygame.font.Font("fonts/Arimo.ttf", int(sx(20)))
down = 1
bounce = 0
i = 0
keypressflag = 0
maxscore = 0
fruitmaxscore = 0
self.score_path = score_path()
with open(self.score_path, 'rb') as input: # REading
maxscore = pickle.load(input)
fruitmaxscore = pickle.load(input)
if(fruitscore > fruitmaxscore):
fruitmaxscore = fruitscore
with open(self.score_path, 'wb') as output:
pickle.dump(maxscore, output, pickle.HIGHEST_PROTOCOL)
pickle.dump(fruitmaxscore, output, pickle.HIGHEST_PROTOCOL)
if(score > maxscore):
maxscore = score
with open(self.score_path, 'wb') as output:
pickle.dump(maxscore, output, pickle.HIGHEST_PROTOCOL)
pickle.dump(fruitmaxscore, output, pickle.HIGHEST_PROTOCOL)
# GAME LOOP BEGINS !!!
while not crashed:
# Gtk events
mouse_button_up = False
while Gtk.events_pending():
Gtk.main_iteration()
for event in pygame.event.get():
# totaltime+=timer.tick()
if event.type == pygame.QUIT:
crashed = True
elif event.type == pygame.MOUSEBUTTONUP:
mouse_button_up = True
elif event.type == pygame.KEYDOWN:
# jump.play(0)
return 1
# event=pygame.event.poll()
mos_x, mos_y = pygame.mouse.get_pos()
# print event
i += 1
if(i > 20):
i = 0
if(i % 3 == 0):
if(down == 1):
bounce += 1
if(bounce > 8):
down = 0
if(down == 0):
bounce -= 1
if(bounce < 0):
down = 1
gameDisplay.fill(white)
gameDisplay.blit(back, (sx(350, 1), 0))
gameDisplay.blit(plate, (sx(430, 1), sy(40)))
head1 = font1.render(_("GAME OVER!"), 1, (white))
gameDisplay.blit(head1, (sx(440, 1), sy(50)))
gameDisplay.blit(scoreplate, (sx(420, 1), sy(200)))
gameDisplay.blit(home, (sx(380 + 60 + 25, 1), sy(400 + 50)))
gameDisplay.blit(replay, (sx(600 + 60 - 25, 1), sy(400 + 50)))
# score check
scores = font2.render(str(score), 1, black)
gameDisplay.blit(scores, (sx(575, 1), sy(250)))
maxscores = font2.render(str(maxscore), 1, black)
gameDisplay.blit(maxscores, (sx(575, 1), sy(350)))
# GAME START
if home.get_rect(center=(sx(380 + 60 + 52 + 25, 1), sy(400 + 50 + 51))).collidepoint(mos_x, mos_y):
gameDisplay.blit(home, (sx(380 + 60 + 25 - 2, 1), sy(400 + 50 - 2)))
if(pygame.mouse.get_pressed())[0] == 1 and press == 0:
return 0
if mouse_button_up:
press = 0
# Help menu
if replay.get_rect(center=(sx(600 + 60 + 52 - 25, 1), sy(400 + 50 + 51))).collidepoint(mos_x, mos_y):
gameDisplay.blit(replay, (sx(600 + 60 - 25 - 2, 1), sy(400 + 50 - 2)))
if(pygame.mouse.get_pressed())[0] == 1 and press == 0:
return 1
pygame.draw.rect(gameDisplay, black, (0, 0, sx(350, 1), sy(768)))
pygame.draw.rect(gameDisplay, black, (sx(840, 1), 0, sx(693, 1), sy(768)))
pygame.display.update()
clock.tick(60)
if crashed == True: # Game crash or Close check
pygame.quit()
return crashed
# Just a window exception check condition
event1 = pygame.event.get()
if event1.type == pygame.QUIT:
crashed = True
if crashed == True:
pygame.quit()
return crashed