Skip to content

Commit 0e06dc0

Browse files
dodany finished popup
1 parent df71ba4 commit 0e06dc0

File tree

4 files changed

+68
-20
lines changed

4 files changed

+68
-20
lines changed

car.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,4 @@ def handle_collision_facilitator(self):
140140
self.collision_facilitator[1] -= pg.time.get_ticks()
141141
if self.collision_facilitator[1] <= 0:
142142
self.collision_facilitator[0] = False
143-
self.collision_facilitator[1] = 0
143+
self.collision_facilitator[1] = 0

data/Records.csv

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,4 +977,21 @@ supra_new,map1,7983,Player 1
977977
supra_new,map1,7308,Player 1
978978
supra_new,map1,8085,Player 1
979979
supra_new,map1,36237,Player 1
980-
supra_new,map1,10925,Player 1
980+
supra_new,map1,10925,Player 1
981+
supra_new,map1,9085,Player 1
982+
supra_new,map1,9679,Player 1
983+
supra_new,map1,39868,Player 1
984+
supra_new,map1,9856,Player 1
985+
supra_new,map1,50930,Player 1
986+
supra_new,map1,13588,Player 1
987+
supra_new,map1,10635,Player 1
988+
supra_new,map1,11970,Player 1
989+
supra_new,map1,11091,Player 1
990+
supra_new,map1,13669,Player 1
991+
supra_new,map1,10101,Player 1
992+
supra_new,map1,15133,Player 1
993+
supra_new,map1,4839,Player 1
994+
supra_new,map1,17663,Player 1
995+
supra_new,map1,12519,Player 1
996+
supra_new,map1,11388,Player 1
997+
supra_new,map1,8712,Player 1

engine.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@
1212
from boosterType import BoosterType
1313
from CSVParser import CSVParser
1414

15+
class Results:
16+
def __init__(self, x, y, w, h, bg_color, color, font):
17+
self.x = x
18+
self.y = y
19+
self.w = w
20+
self.h = h
21+
self.bg_color = bg_color
22+
self.color = color
23+
self.font = font
24+
self.bg_rect = pg.Rect(x,y,w,h)
25+
self.finished_rect = pg.Rect(x + 10, y + 10, w - 20, 40)
26+
def draw(self, surf, times):
27+
pg.draw.rect(surf, self.bg_color, self.bg_rect)
28+
pg.draw.rect(surf, self.color, self.finished_rect)
29+
finished = self.font.render("FINISHED!", 1, (0,0,0))
30+
surf.blit(finished, finished.get_rect(center=self.finished_rect.center))
31+
results = [pg.Rect(self.x + 10, self.y + 80 + 50 * i, self.w - 20, 40) for i in range(6)]
32+
for i in range(6):
33+
t = self.font.render(times[i], 1, (0,0,0))
34+
surf.blit(t, t.get_rect(center=results[i].center))
1535

1636
class NitroBar():
1737
def __init__(self, x, y, w, h, bg_color, color, font):
@@ -31,7 +51,6 @@ def draw(self, surf, val, cap):
3151
nitro_text = self.font.render("NITRO", 1, (0, 0, 0))
3252
surf.blit(nitro_text, nitro_text.get_rect(center=self.bg_rect.center))
3353

34-
3554
class Engine:
3655
def __init__(self, refresh_rate, name, car, map):
3756
self.refresh = refresh_rate
@@ -44,7 +63,8 @@ def __init__(self, refresh_rate, name, car, map):
4463
self.car = car
4564
self.map = map
4665
self.nitro_bar = NitroBar(5, 5, 250, 40, (240, 230, 140), (100, 100, 255), pg.font.SysFont('Calibri', 35))
47-
66+
self.results_popup = Results(1480//2-300//2, 780//2-400//2, 300, 400, (240, 230, 140), (100, 100, 255), pg.font.SysFont('Calibri', 35))
67+
4868
def spawn_booster(self, map: Map, dt):
4969
if random.randrange(0, 256) != 8:
5070
return
@@ -137,5 +157,8 @@ def run(self):
137157

138158
ticks = pg.time.get_ticks()
139159
stopwatch.display_timer(ticks)
160+
161+
if curr_map.won == 1:
162+
self.results_popup.draw(self.screen, curr_map.times)
140163

141164
pg.display.flip()

map.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from math import sin, cos, radians
99

10-
1110
class Map:
1211
def __init__(self, id, width, height, stopwatch, player_name):
1312
self.id = id
@@ -26,6 +25,9 @@ def __init__(self, id, width, height, stopwatch, player_name):
2625
self.font = pg.freetype.SysFont(None, 34)
2726
self.font.origin = True
2827
self.laps_completed = 0
28+
29+
self.times = []
30+
self.won = 0
2931

3032
def place_objects(self):
3133
parser = CSVParser("./data/" + self.name + ".csv", "./data/Leaderboard.csv", None)
@@ -152,21 +154,27 @@ def handle_collision_with_sufraces(self, car):
152154
for slide in slides:
153155
if slide.type == "FINISHLINE":
154156
if False not in self.checkpoints: # int(self.stopwatch.get_time(pg.time.get_ticks()) / 1000 % 60) > 5: #placeholder: if at least 5 secs
155-
with open("./data/Records.csv", "a") as f:
156-
f.write("\n{},{},{},{}".format(car.name, self.name,
157-
self.stopwatch.get_time(pg.time.get_ticks()),
158-
self.player_name))
159-
self.stopwatch.restart_timer(pg.time.get_ticks())
160-
self.placement = 0
161-
162-
for i in range(0, len(self.checkpoints)):
163-
self.checkpoints[i] = False
164-
165-
for slide in self.all_surfaces:
166-
slide.checked = False
167-
168-
self.increment_laps()
169-
157+
if self.won == 0:
158+
self.times.append(self.stopwatch.get_time(pg.time.get_ticks()))
159+
160+
with open("./data/Records.csv", "a") as f:
161+
f.write("\n{},{},{},{}".format(car.name, self.name,
162+
self.stopwatch.get_time(pg.time.get_ticks()),
163+
self.player_name))
164+
self.stopwatch.restart_timer(pg.time.get_ticks())
165+
self.placement = 0
166+
167+
for i in range(0, len(self.checkpoints)):
168+
self.checkpoints[i] = False
169+
170+
for slide in self.all_surfaces:
171+
slide.checked = False
172+
173+
self.increment_laps()
174+
if self.laps_completed == 1:
175+
self.won = 1
176+
self.times = ["{minutes:02d}.{seconds:02d}.{millis}".format(minutes=int(self.times[0] / 60000 % 24), millis=self.times[0] % 1000, seconds=int(self.times[0] / 1000 % 60)) for i in range(6)]
177+
170178
if slide.type == "CHECKPOINT":
171179
if self.placement <= len(self.checkpoints) - 1 and self.checkpoints[
172180
self.placement] == False and slide.checked == False:

0 commit comments

Comments
 (0)