/
context_handlers.py
691 lines (573 loc) · 27.2 KB
/
context_handlers.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
import libtcodpy as tcod
import circuits
from context import Context
import global_data as g
from input_handlers import handle_keys
from interval_stat import Interval_Stat
import lexicons as lex
from physics import *
from race import Race
import random
from render import *
from song_generator import build_song
from team import Team
import teams as t
import time
from vehicle import Vehicle
import vehicle_bodies
###############################################################################
# Context handlers
###############################################################################
# These are the major functions of the game (and their helper functions) that
# cause the game to run.
###############################################################################
# Helper functions
###############################################################################
# build_race_stats
#
# returns list of Interval_Stat objects in proper order
def build_race_stats(race):
ordered_race_stats = []
# Teams that have finished are locked in place based on finishing info
already_finished = [] # This will make things simpler later in the function
for place_team in race.finished_teams:
place = place_team[0]
team = place_team[1]
time = str(format(round((race.finish_times[team]), 2), '.2f'))
ordered_race_stats.append(Interval_Stat(place_team[0], place_team[1], time))
already_finished.append(team)
sorted_teams = sorted(race.teams, key=get_distance_traveled, reverse=True)
# Now list non-finished teams
counter = 1
for team in sorted_teams:
place = counter
if team not in already_finished:
dist_to_first = sorted_teams[0].vehicle.distance_traveled - team.vehicle.distance_traveled
# Check for tie with most recently checked vehicle
if len(ordered_race_stats) > 0:
if team.vehicle.distance_traveled == ordered_race_stats[len(ordered_race_stats) - 1].team.vehicle.distance_traveled:
place = ordered_race_stats[len(ordered_race_stats) - 1].place
interval = '----'
if (team.vehicle.speed >= 1):
interval = '+' + str(format(round((dist_to_first / team.vehicle.speed), 2), '.2f'))
ordered_race_stats.append(Interval_Stat(place, team, interval))
counter += 1
return ordered_race_stats
def check_key_char_input(pressed_key_char, lyrics, active_lyrics_character):
target_char = lyrics[active_lyrics_character].lower()
correct = pressed_key_char.lower() == target_char
if correct:
return True
else:
return False
def finish_race(race, team, time):
# Update race finishing places and times ####################################
finished_teams_count = len(race.finished_teams)
# First check and see if this team ties with another
tie_occurred = False
if finished_teams_count > 0:
latest_place = race.finished_teams[finished_teams_count - 1][0]
latest_team = race.finished_teams[finished_teams_count - 1][1]
latest_time = race.finish_times[latest_team]
# If this team ties with the previously finished team
if latest_time == time:
tie_occurred = True
# Update pertinent info
race.finished_teams.append((latest_place, team))
if not tie_occurred:
finishing_place = finished_teams_count + 1
race.finished_teams.append((finishing_place, team))
# This happens the same way regardless of a tie
race.finish_times[team] = time
# Misc other things to take care of #########################################
team.finished_current_race = True
team.vehicle.acceleration = 0
def get_distance_traveled(team):
return team.vehicle.distance_traveled
# get_race_intro
#
# Returns list of tuples containing the line of text that should be displayed,
# coupled with the time (in seconds) to display each.
def get_race_intro(song_title, lexicon, circuit):
announcement = [
('Welcome to the {}!'.format(circuit.name), 1.5),
('Today you will be playing the hit {} song'.format(lexicon.name), 1.5),
('Today you will be playing the hit {} song'.format(lexicon.name) + '\n' + '\n' + '\n' + '"{}"'.format(song_title), 2.5),
('Get ready!', 1.5),
('Get ready!' + '\n' + '\n' + '\n' + '\n' + '%c%c%c%c*%c'%(tcod.COLCTRL_FORE_RGB, tcod.red.r + 256, tcod.red.g + 256, tcod.red.b + 256, tcod.COLCTRL_STOP), 1),
('Get ready!' + '\n' + '\n' + '\n' + '\n' + '%c%c%c%c* * *%c'%(tcod.COLCTRL_FORE_RGB, tcod.red.r + 256, tcod.red.g + 256, tcod.red.b + 256, tcod.COLCTRL_STOP), 1),
('Get ready!' + '\n' + '\n' + '\n' + '\n' + '%c%c%c%c* * * * *%c'%(tcod.COLCTRL_FORE_RGB, tcod.red.r + 256, tcod.red.g + 256, tcod.red.b + 256, tcod.COLCTRL_STOP), 1),
]
return announcement
# Returns dictionary in following format:
# {
# 'value': program-usable value of response,
# 'string': string representation of response,
# 'confirmed': bool describing whether input is complete
# }
def handle_option_selection(key, options):
confirmed = False
action = handle_keys(key)
pressed_key_char = action.get('key_char')
if pressed_key_char != None:
pressed_key_char = pressed_key_char.lower()
response = None
response_text = ''
if pressed_key_char in g.ALPHABET:
index = g.ALPHABET.index(pressed_key_char)
if index < len(options):
response = options[index][0]
response_text = options[index][1]
confirmed = True
return {
'value': response,
'string' : response_text,
'confirmed': confirmed
}
# handle_questions
#
# Takes a dict of questions:options, prints them to the screen, and returns
# the responses in list form. Options should be provided as lists of
# value:string tuples. If the question requires a text-input response,
# provide an empty list argument for the options.
def handle_questions(con, key, mouse, questions_options, con_y_pos=0):
static_text_to_print = []
responses = []
for question, options in questions_options.items():
response = ''
confirmed = False
static_text_to_print.append(question)
while not confirmed:
tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse)
tcod.console_clear(con)
tcod.console_set_default_foreground(con, tcod.sea)
tcod.console_set_default_background(con, tcod.black)
# For open text input
if len(options) == 0:
response_data = handle_text_input(key, response)
response = response_data['value']
response_line = '> ' + response_data['string']
confirmed = response_data['confirmed']
tcod.console_print_rect_ex(con, 0, len(static_text_to_print), g.screen_width, g.screen_height, tcod.BKGND_SET, tcod.LEFT, response_line)
# For input with discreet options
else:
response_data = handle_option_selection(key, options)
response = response_data['value']
response_text = response_data['string']
response_line = '> ' + response_text
confirmed = response_data['confirmed']
# Display options
for x in range(0, len(options)):
option_text = g.ALPHABET[x] + '. ' + options[x][1]
tcod.console_print_rect_ex(con, 0, len(static_text_to_print) + x, g.screen_width, g.screen_height, tcod.BKGND_SET, tcod.LEFT, option_text)
# Once we get a response, do this stuff:
if confirmed:
if len(options) > 0:
# Clear to remove list of options
tcod.console_clear(con)
static_text_to_print.append(response_line)
responses.append(response)
# Do this stuff every time no matter what
for x in range(0, len(static_text_to_print)):
tcod.console_print_rect_ex(con, 0, x, g.screen_width, g.screen_height, tcod.BKGND_SET, tcod.LEFT, static_text_to_print[x])
tcod.console_blit(con, 0, 0, g.screen_height, g.screen_height, 0, 0, con_y_pos)
tcod.console_flush()
time.sleep(0.2)
return responses
# Returns dictionary in following format:
# {
# 'value': program-usable value of response,
# 'string': string representation of response,
# 'confirmed': bool describing whether input is complete
# }
def handle_text_input(key, response):
confirmed = False
action = handle_keys(key)
pressed_key_char = action.get('key_char')
pressed_backspace = action.get('backspace')
pressed_enter = action.get('confirm')
RESPONSE_MAX = 30
if pressed_key_char and len(response) < RESPONSE_MAX:
response += pressed_key_char
elif pressed_backspace:
response = response[:-1]
elif pressed_enter:
confirmed = True
return {
'value': response,
'string': response,
'confirmed': confirmed
}
# Handler functions
###############################################################################
def do_main_menu(key, mouse):
title_panel_h = 28
title_panel = tcod.console_new(g.screen_width, title_panel_h)
tcod.console_set_alignment(title_panel, tcod.LEFT)
tcod.console_set_default_foreground(title_panel, tcod.blue)
for x in range(0, len(g.TITLE_GRAPHIC_TOP)):
tcod.console_print_ex(title_panel, 1, x + 1, tcod.BKGND_SET, tcod.LEFT, g.TITLE_GRAPHIC_TOP[x][0])
for x in range(0, len(g.TITLE_GRAPHIC_BOTTOM)):
tcod.console_print_ex(title_panel, 1, x + 4 + len(g.TITLE_GRAPHIC_TOP), tcod.BKGND_SET, tcod.LEFT, g.TITLE_GRAPHIC_BOTTOM[x][0])
selection_panel = tcod.console_new(g.screen_width, g.screen_height - title_panel_h)
tcod.console_set_alignment(selection_panel, tcod.LEFT)
tcod.console_set_default_foreground(selection_panel, tcod.sea)
title_colors = [
tcod.azure,
tcod.cyan,
tcod.dark_purple,
tcod.dark_violet,
tcod.fuchsia,
tcod.light_gray,
tcod.purple,
tcod.sea,
tcod.turquoise,
]
g.lexicon_counter = 0
questions_options = {
'': [
('start', 'Start'),
('exit', 'Exit game')
]
}
waiting_for_response = True
while waiting_for_response:
for y in range(1, 1 + len(g.TITLE_GRAPHIC_TOP)):
color_index = random.randint(0, len(title_colors) - 1)
for x in range(0, g.screen_width):
tcod.console_set_char_foreground(title_panel, x, y, title_colors[color_index])
tcod.console_blit(title_panel, 0, 0, g.screen_width, title_panel_h, 0, 0, 0)
tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse)
selection = handle_questions(selection_panel, key, mouse, questions_options, 24)
if len(selection) > 0:
if selection[0] == 'start':
g.context = Context.TEAM_CREATION
waiting_for_response = False
elif selection[0] == 'exit':
g.context = Context.EXIT
waiting_for_response = False
tcod.console_clear(title_panel)
tcod.console_blit(title_panel, 0, 0, g.screen_width, title_panel_h, 0, 0, 0)
tcod.console_clear(selection_panel)
tcod.console_blit(selection_panel, 0, 0, g.screen_width, title_panel_h, 0, 0, 0)
tcod.console_flush()
# do_post_race
#
# Store points for this race in the season data, and print post-race display
def do_post_race(key, mouse):
finished_race = g.season.races[g.season.current_race]
full_panel = tcod.console_new(g.screen_width, g.screen_height)
tcod.console_set_alignment(full_panel, tcod.CENTER)
tcod.console_set_default_foreground(full_panel, tcod.sea)
tcod.console_clear(full_panel)
title = finished_race.circuit.name + ' Results'
tcod.console_print_frame(full_panel, 1, 1, g.screen_width - 2, g.screen_height - 2, False, tcod.BKGND_DEFAULT, title)
LINE_LENGTH = 50
header = 'Team' + (' ' * (LINE_LENGTH - 10)) + 'Points'
underline = '=' * LINE_LENGTH
tcod.console_print_ex(full_panel, 30, 20, tcod.BKGND_SET, tcod.LEFT, header)
tcod.console_print_ex(full_panel, 30, 21, tcod.BKGND_SET, tcod.LEFT, underline)
for place, team in finished_race.places.items():
# Record point data
points = g.POINTS[place]
g.season.standings[team] += points
# Print info
place_name = str(place) + '. ' + team.name
point_string = str(points)
space_count = LINE_LENGTH - (len(place_name) + len(point_string))
line = place_name + (' ' * space_count) + point_string
tcod.console_print_ex(full_panel, 30, 21 + place, tcod.BKGND_SET, tcod.LEFT, line)
tcod.console_blit(full_panel, 0, 0, g.screen_width, g.screen_height, 0, 0, 0)
tcod.console_flush()
# Wait for `tcod.Enter` to continue
confirm = False
while not confirm:
tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse)
action = handle_keys(key)
confirm = action.get('confirm')
if confirm:
g.season.current_race += 1
g.context = Context.SEASON_OVERVIEW
def do_race(key, mouse):
bottom_viewport_height = 7
main_viewport_height = g.screen_height - bottom_viewport_height
main_viewport_width = g.MAIN_VIEWPORT_WIDTH
side_viewport_width = g.screen_width - main_viewport_width
main_viewport = tcod.console_new(main_viewport_width, main_viewport_height)
bottom_viewport_y = g.screen_height - bottom_viewport_height
bottom_viewport = tcod.console_new(main_viewport_width, bottom_viewport_height)
tcod.console_set_alignment(bottom_viewport, tcod.LEFT)
side_viewport_x = g.screen_width - side_viewport_width
side_viewport = tcod.console_new(side_viewport_width, g.screen_height)
intro_w = int(g.screen_width * .35)
intro_h = int(g.screen_height * .20)
intro_x = int(g.screen_width * 0.5 - intro_w * 0.5)
intro_y = int(g.screen_height * 0.5 - intro_h * 0.5)
intro_window = tcod.console_new(intro_w, intro_h)
tcod.console_set_alignment(intro_window, tcod.CENTER)
tcod.console_set_default_foreground(intro_window, tcod.sea)
lexicon = lex.genres_lexicons[g.lexicon_counter][0]
title_and_song = build_song(lexicon)
race = Race(g.season.teams, g.season.circuits[g.season.current_race], title_and_song[1], title_and_song[0])
# Reset stuff
for x in range(0, len(race.teams)):
race.teams[x].reset()
teams = race.teams
player_team_index = 0
lane_count = len(race.teams)
track_width = ((race.lane_size + 1) * lane_count) + 1
BASE_OFFSET_TO_CENTER = int((g.MAIN_VIEWPORT_WIDTH - track_width) / 2)
for x in range(0, len(teams)):
if (teams[x].isPlayer):
player_team_index = x
teams[x].vehicle.x = BASE_OFFSET_TO_CENTER + (x * (race.lane_size + 1)) + 2
exit_game = False
lyrics = race.lyrics
vehicles_collided = set([])
active_lyrics_character = 0
keypress_timer = 99999
race_finished = False
race_started = False
verse = 0
song_completed = False
barricade_locations = [] # holds tuples of x, y barricade locations
intro_lines = get_race_intro(title_and_song[0], lexicon, race.circuit)
current_intro_line = 0
first_frame = True
time_elapsed_last_frame = 0
race_start_time = tcod.sys_elapsed_seconds()
while not race_finished and not exit_game:
tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse)
keypress_timer += tcod.sys_get_last_frame_length()
total_time_elapsed = tcod.sys_elapsed_seconds()
if race_started:
if not first_frame:
time_elapsed_last_frame = tcod.sys_get_last_frame_length()
for team in teams:
team.ai_run_counters()
# Apply collision physics if needed
if team.vehicle in vehicles_collided:
handle_post_collision(team)
else:
if team.vehicle.distance_traveled >= len(race.circuit.track_shape) and not team.finished_current_race:
finish_race(race, team, total_time_elapsed - race_start_time)
# Control player vehicle
if team.isPlayer and not team.finished_current_race:
action = handle_keys(key)
pressed_key_char = action.get('key_char')
steer = action.get('steer')
exit = action.get('exit')
if not song_completed:
powerpct = g.get_powerpct_from_keyspeed(keypress_timer)
else:
powerpct = 1
team.vehicle.apply_power(powerpct)
if pressed_key_char and not song_completed:
correct = check_key_char_input(pressed_key_char, race.lyrics[verse], active_lyrics_character)
if correct:
keypress_timer = 0.0
active_lyrics_character += 1
if (active_lyrics_character >= len(lyrics[verse])):
active_lyrics_character = 0
verse += 1
if verse >= len(lyrics):
song_completed = True
else:
# TODO: mis-steer
pass
if steer and team.vehicle.speed > 0: # Can only steer if moving
teams[player_team_index].vehicle.x += steer
if exit:
exit_game = True
# If team is not player
elif not team.finished_current_race:
direction = team.ai_determine_direction()
if direction == td.LEFT:
team.vehicle.x += -1
elif direction == td.RIGHT:
team.vehicle.x += 1
team.ai_apply_power()
# If team has reached the finish line
else:
team.vehicle.apply_power(0)
# Don't have time to do proper checks to wait for all teams to
# finsh race. For now, just wait until the player team's vehicle
# has coasted to a stop, and then take everyone's place from that
# moment.
if team.isPlayer and team.vehicle.speed == 0:
race_finished = True
# Apply acceleration, determine speed
speed_to_add = time_elapsed_last_frame * team.vehicle.acceleration
team.vehicle.speed += speed_to_add
if team.vehicle.speed > team.vehicle.current_max_speed_from_power:
team.vehicle.speed -= 0.1
if team.vehicle.speed > team.vehicle.max_speed:
team.vehicle.speed = team.vehicle.max_speed
elif team.vehicle.speed < 0:
team.vehicle.speed = 0
distance_traveled_this_frame = time_elapsed_last_frame * team.vehicle.speed
team.ai_observe_curves(race.circuit.track_layout, int(team.vehicle.distance_traveled + distance_traveled_this_frame) - int(team.vehicle.distance_traveled)) # This HAS to come first
team.vehicle.distance_traveled += distance_traveled_this_frame
# Check for collisions
vehicles_collided.clear()
handle_collisions(race, vehicles_collided, barricade_locations)
first_frame = False
# Render
tcod.console_clear(main_viewport)
print_race(main_viewport, race, int(teams[player_team_index].vehicle.y), int(teams[player_team_index].vehicle.distance_traveled), barricade_locations)
tcod.console_blit(main_viewport, 0, 0, g.screen_width, g.screen_height, 0, 0, 0,)
tcod.console_clear(bottom_viewport)
if not song_completed:
print_lyrics(bottom_viewport, race.lyrics[verse], active_lyrics_character)
tcod.console_blit(bottom_viewport, 0, 0, main_viewport_width, bottom_viewport_height, 0, 0, bottom_viewport_y)
tcod.console_clear(side_viewport)
print_panel_side(side_viewport, build_race_stats(race), side_viewport_width)
tcod.console_blit(side_viewport, 0, 0, side_viewport_width, g.screen_height - bottom_viewport_height, 0, side_viewport_x, 0)
if not race_started:
# This structure is pretty ugly, but no time to clean it up
if current_intro_line == len(intro_lines):
time.sleep(intro_lines[current_intro_line - 1][1])
elif current_intro_line >= len(intro_lines):
race_started = True
else:
tcod.console_clear(intro_window)
tcod.console_hline(intro_window, 0, 0, intro_w)
tcod.console_hline(intro_window, 0, intro_h - 1, intro_w)
tcod.console_vline(intro_window, 0, 0, intro_h)
tcod.console_vline(intro_window, intro_w - 1, 0, intro_h)
tcod.console_print_rect_ex(intro_window, int(intro_w/2), 1, intro_w - 3, intro_h - 2, tcod.BKGND_SET, tcod.CENTER, intro_lines[current_intro_line][0])
tcod.console_blit(intro_window, 0, 0, intro_w, intro_h, 0, intro_x, intro_y)
if current_intro_line > 0:
time.sleep(intro_lines[current_intro_line - 1][1])
current_intro_line += 1
tcod.console_flush()
# Race is finished
if exit_game:
tcod.console_clear(main_viewport)
tcod.console_blit(main_viewport, 0, 0, g.screen_width, g.screen_height, 0, 0, 0,)
tcod.console_clear(bottom_viewport)
tcod.console_blit(bottom_viewport, 0, 0, main_viewport_width, bottom_viewport_height, 0, 0, bottom_viewport_y)
tcod.console_flush()
g.context = Context.MAIN_MENU
else:
final_stats = build_race_stats(race)
place = 1
for stat in final_stats:
race.places[place] = stat.team
place += 1
g.season.races.append(race)
g.lexicon_counter += 1
if g.lexicon_counter >= len(lex.genres_lexicons):
g.lexicon_counter = 0
g.context = Context.POST_RACE
def do_season_overview(key, mouse):
bottom_selector_panel_h = 9
bottom_selector_panel = tcod.console_new(g.screen_width, bottom_selector_panel_h)
tcod.console_set_alignment(bottom_selector_panel, tcod.CENTER)
tcod.console_set_default_foreground(bottom_selector_panel, tcod.lightest_magenta)
nearly_full_panel = tcod.console_new(g.screen_width, g.screen_height - bottom_selector_panel_h)
tcod.console_set_alignment(nearly_full_panel, tcod.LEFT)
tcod.console_set_default_foreground(nearly_full_panel, tcod.sea)
print_season_overview(nearly_full_panel, g.screen_width, g.season)
tcod.console_blit(nearly_full_panel, 0, 0, g.screen_width, g.screen_height - bottom_selector_panel_h, 0, 0, 0)
confirm = False
selected_option = 1
while not confirm:
tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse)
spacing = 6
options = []
if g.season.current_race >= len(g.season.circuits):
options = [
('exit', 'Retire!'),
('start over', 'Play again')
]
else:
options = [
('exit', 'I quit'),
('go forward', 'Let\'s rock')
]
selection = options[0][0]
tcod.console_clear(bottom_selector_panel)
option0_text = options[0][1]
option1_text = options[1][1]
# Currently only supports exactly 2 options
xy0 = (int(g.screen_width / 2) - len(option0_text) - int(spacing / 2), int(bottom_selector_panel_h / 2))
xy1 = (int(g.screen_width / 2) + int(spacing / 2), int(bottom_selector_panel_h / 2))
tcod.console_print_ex(bottom_selector_panel, xy0[0], xy0[1], tcod.BKGND_SET, tcod.LEFT, option0_text)
tcod.console_print_ex(bottom_selector_panel, xy1[0], xy1[1], tcod.BKGND_SET, tcod.LEFT, option1_text)
if selected_option == 0:
tcod.console_hline(bottom_selector_panel, xy0[0] - 2, xy0[1] - 1, len(option0_text) + 4)
tcod.console_hline(bottom_selector_panel, xy0[0] - 2, xy0[1] + 1, len(option0_text) + 4)
elif selected_option == 1:
tcod.console_hline(bottom_selector_panel, xy1[0] - 2, xy1[1] - 1, len(option1_text) + 4)
tcod.console_hline(bottom_selector_panel, xy1[0] - 2, xy1[1] + 1, len(option1_text) + 4)
action = handle_keys(key, 'simple selection')
select = action.get('select')
enter = action.get('enter')
if select:
selected_option += select
if selected_option > len(options) - 1:
selected_option = 0
elif selected_option < 0:
selected_option = len(options) - 1
if enter:
selection = options[selected_option][0]
confirm = True
tcod.console_blit(bottom_selector_panel, 0, 0, g.screen_width, bottom_selector_panel_h, 0, 0, g.screen_height - bottom_selector_panel_h)
tcod.console_flush()
if selection == 'exit':
g.context = Context.MAIN_MENU
tcod.console_clear(bottom_selector_panel)
tcod.console_clear(nearly_full_panel)
tcod.console_blit(bottom_selector_panel, 0, 0, g.screen_width, bottom_selector_panel_h, 0, 0, g.screen_height - bottom_selector_panel_h)
tcod.console_blit(nearly_full_panel, 0, 0, g.screen_width, g.screen_height - bottom_selector_panel_h, 0, 0, 0)
tcod.console_flush()
elif selection == 'go forward':
g.context = Context.RACE
tcod.console_clear(bottom_selector_panel)
tcod.console_clear(nearly_full_panel)
tcod.console_blit(bottom_selector_panel, 0, 0, g.screen_width, bottom_selector_panel_h, 0, 0, g.screen_height - bottom_selector_panel_h)
tcod.console_blit(nearly_full_panel, 0, 0, g.screen_width, g.screen_height - bottom_selector_panel_h, 0, 0, 0)
tcod.console_flush()
elif selection == 'start over':
g.context = Context.TEAM_CREATION
tcod.console_clear(bottom_selector_panel)
tcod.console_clear(nearly_full_panel)
tcod.console_blit(bottom_selector_panel, 0, 0, g.screen_width, bottom_selector_panel_h, 0, 0, g.screen_height - bottom_selector_panel_h)
tcod.console_blit(nearly_full_panel, 0, 0, g.screen_width, g.screen_height - bottom_selector_panel_h, 0, 0, 0)
tcod.console_flush()
def do_team_creation(key, mouse):
tcod.console_flush()
full_panel = tcod.console_new(g.screen_width * 2, g.screen_height)
tcod.console_set_alignment(full_panel, tcod.LEFT)
tcod.console_set_default_foreground(full_panel, tcod.sea)
questions_options = {
'What is the name of your team?': [],
'What color is your team?': [
(tcod.red, '%c%c%c%cRed%c'%(tcod.COLCTRL_FORE_RGB, tcod.red.r + 256, tcod.red.g + 256, tcod.red.b + 256, tcod.COLCTRL_STOP)),
(tcod.orange, '%c%c%c%cOrange%c'%(tcod.COLCTRL_FORE_RGB, tcod.orange.r + 256, tcod.orange.g + 256, tcod.orange.b + 256, tcod.COLCTRL_STOP)),
(tcod.yellow, '%c%c%c%cYellow%c'%(tcod.COLCTRL_FORE_RGB, tcod.yellow.r + 256, tcod.yellow.g + 256, tcod.yellow.b + 256, tcod.COLCTRL_STOP)),
(tcod.green, '%c%c%c%cGreen%c'%(tcod.COLCTRL_FORE_RGB, tcod.green.r + 256, tcod.green.g + 256, tcod.green.b + 256, tcod.COLCTRL_STOP)),
(tcod.sea, '%c%c%c%cSea%c'%(tcod.COLCTRL_FORE_RGB, tcod.sea.r + 256, tcod.sea.g + 256, tcod.sea.b + 256, tcod.COLCTRL_STOP)),
(tcod.turquoise, '%c%c%c%cTurquoise%c'%(tcod.COLCTRL_FORE_RGB, tcod.turquoise.r + 256, tcod.turquoise.g + 256, tcod.turquoise.b + 256, tcod.COLCTRL_STOP)),
(tcod.light_cyan, '%c%c%c%cLight cyan%c'%(tcod.COLCTRL_FORE_RGB, tcod.light_cyan.r + 256, tcod.light_cyan.g + 256, tcod.light_cyan.b + 256, tcod.COLCTRL_STOP)),
(tcod.azure, '%c%c%c%cAzure%c'%(tcod.COLCTRL_FORE_RGB, tcod.azure.r + 256, tcod.azure.g + 256, tcod.azure.b + 256, tcod.COLCTRL_STOP)),
(tcod.blue, '%c%c%c%cBlue%c'%(tcod.COLCTRL_FORE_RGB, tcod.blue.r + 256, tcod.blue.g + 256, tcod.blue.b + 256, tcod.COLCTRL_STOP)),
(tcod.purple, '%c%c%c%cPurple%c'%(tcod.COLCTRL_FORE_RGB, tcod.purple.r + 256, tcod.purple.g + 256, tcod.purple.b + 256, tcod.COLCTRL_STOP)),
(tcod.light_purple, '%c%c%c%cLight purple%c'%(tcod.COLCTRL_FORE_RGB, tcod.light_purple.r + 256, tcod.light_purple.g + 256, tcod.light_purple.b + 256, tcod.COLCTRL_STOP)),
(tcod.pink, '%c%c%c%cPink%c'%(tcod.COLCTRL_FORE_RGB, tcod.pink.r + 256, tcod.pink.g + 256, tcod.pink.b + 256, tcod.COLCTRL_STOP)),
(tcod.sepia, '%c%c%c%cSepia%c'%(tcod.COLCTRL_FORE_RGB, tcod.sepia.r + 256, tcod.sepia.g + 256, tcod.sepia.b + 256, tcod.COLCTRL_STOP)),
(tcod.gray, '%c%c%c%cGray%c'%(tcod.COLCTRL_FORE_RGB, tcod.gray.r + 256, tcod.gray.g + 256, tcod.gray.b + 256, tcod.COLCTRL_STOP)),
(tcod.white, '%c%c%c%cWhite%c'%(tcod.COLCTRL_FORE_RGB, tcod.white.r + 256, tcod.white.g + 256, tcod.white.b + 256, tcod.COLCTRL_STOP))
]
}
responses = handle_questions(full_panel, key, mouse, questions_options)
player_team = Team(responses[0], responses[1], Vehicle(vehicle_bodies.v_bod_1), True)
teams = t.pick_season_teams(player_team)
# Build season
season_circuits = []
for circuit in circuits.ALL:
season_circuits.append(circuit)
g.season = Season(2094, season_circuits, teams)
# Move on
g.context = Context.SEASON_OVERVIEW