def intel_menu(screen, my_nation, all_nations): insert_dem = [0, 32, 300, 704] # Should change based on player count co_splash = [255, 255, 153] # Button info: button_color = cncc.get_color("inactive_button") text_color = cncc.get_color("inactive_text") button_prompt_color = cncc.get_color("active_button") text_prompt_color = cncc.get_color("active_text") # Draw outside rectangle pygame.draw.rect(screen, co_splash, insert_dem) menu_buttons = [] # Draw tile name title_font = pygame.font.Font('./fonts/steam_punk_flyer.ttf', 24) detail_font = pygame.font.Font('./fonts/steam_punk_flyer.ttf', 12) cncc.draw_notice(screen, "Intelligence Report", title_font, [0, 64, 300, 30], co_splash, [0, 0, 0]) # Your nations status cncc.draw_notice(screen, "My Components:" + str(my_nation.score), detail_font, [0, 128, 300, 30], co_splash, [0, 0, 0]) cncc.draw_notice(screen, "Spies Available", detail_font, [0, 160, 300, 30], co_splash, [0, 0, 0]) cursor_x = 192 # All other nations for this_nation in all_nations: # No need to draw your own nation if this_nation.playername == my_nation.playername: continue cncc.draw_notice( screen, this_nation.playername + " Components:" + str(this_nation.score), detail_font, [0, cursor_x, 300, 30], co_splash, [0, 0, 0]) cursor_x = cursor_x + 32 menu_buttons.append( cncc.a_button("Coup", "coup", this_nation, detail_font, [0, cursor_x, 99, 30], button_color, text_color, button_prompt_color, text_prompt_color)) menu_buttons.append( cncc.a_button("Observe", "observe", this_nation, detail_font, [100, cursor_x, 99, 30], button_color, text_color, button_prompt_color, text_prompt_color)) menu_buttons.append( cncc.a_button("Counter", "counter", this_nation, detail_font, [200, cursor_x, 99, 30], button_color, text_color, button_prompt_color, text_prompt_color)) cursor_x = cursor_x + 32 # print(cursor_x) # cncc.draw_notice(screen,"Reset Spies",detail_font,[0,cursor_x,300,30],co_splash,[0,0,0]) menu_buttons.append( cncc.a_button("Reset Spies", "spy_reset", None, detail_font, [0, cursor_x, 300, 30], button_color, text_color, button_prompt_color, text_prompt_color)) return menu_buttons
def make_mainmenu_buttons(): button_font = pygame.font.Font('./fonts/steam_punk_flyer.ttf', 24) mainmenu_buttons = [] button_color = cncc.get_color("inactive_button") text_color = cncc.get_color("inactive_text") button_prompt_color = cncc.get_color("active_button") text_prompt_color = cncc.get_color("active_text") mainmenu_buttons.append( cncc.a_button("Test", "test", None, button_font, [500, 372, 240, 64], button_color, text_color, button_prompt_color, text_prompt_color)) mainmenu_buttons.append( cncc.a_button("New Game", "new", None, button_font, [500, 436, 240, 64], button_color, text_color, button_prompt_color, text_prompt_color)) mainmenu_buttons.append( cncc.a_button("Join Game", "join", None, button_font, [500, 500, 240, 64], button_color, text_color, button_prompt_color, text_prompt_color)) mainmenu_buttons.append( cncc.a_button("Load Game", "load", None, button_font, [500, 564, 240, 64], button_color, text_color, button_prompt_color, text_prompt_color)) mainmenu_buttons.append( cncc.a_button("Options", "opt", None, button_font, [500, 628, 240, 64], button_color, text_color, button_prompt_color, text_prompt_color)) mainmenu_buttons.append( cncc.a_button("Credits", "credits", None, button_font, [500, 692, 240, 64], button_color, text_color, button_prompt_color, text_prompt_color)) return mainmenu_buttons
def main_menu(screen): insert_dem = [0, 32, 128, 160] co_splash = [255, 255, 153] button_font = pygame.font.Font('./fonts/steam_punk_flyer.ttf', 16) mainmenu_buttons = [] button_color = cncc.get_color("inactive_button") text_color = cncc.get_color("inactive_text") button_prompt_color = cncc.get_color("active_button") text_prompt_color = cncc.get_color("active_text") # Draw outside rectangle pygame.draw.rect(screen, co_splash, insert_dem) # Draw tile name mainmenu_buttons.append( cncc.a_button("Change Game", "load", None, button_font, [0, 64, 128, 32], button_color, text_color, button_prompt_color, text_prompt_color)) mainmenu_buttons.append( cncc.a_button("Options", "opt", None, button_font, [0, 96, 128, 32], button_color, text_color, button_prompt_color, text_prompt_color)) mainmenu_buttons.append( cncc.a_button("Quit", "quit", None, button_font, [0, 128, 128, 32], button_color, text_color, button_prompt_color, text_prompt_color)) return mainmenu_buttons
def draw_main(mm_buttons, gameDisplay): intro = True click_select = None # Draw title title_font = pygame.font.Font('./fonts/steam_punk_flyer.ttf', 64) title_text = "Copper and Coal" TitleSurf, TitleRect = cncc.text_objects(title_text, title_font, [153, 102, 51]) TitleRect.center = ((display_width / 2), 100) # Subtitle subtitle_font = pygame.font.Font('./fonts/steam_punk_flyer.ttf', 32) subtitle_text = "By Scott Wambold" subTitleSurf, subTitleRect = cncc.text_objects(subtitle_text, subtitle_font, [153, 102, 51]) subTitleRect.center = ((display_width / 2), 200) while intro: for event in pygame.event.get(): if event.type == pygame.QUIT: intro = False cncc.game_quit() # Only looking for a click if event.type == pygame.MOUSEBUTTONUP: x, y = event.pos if event.button == 1: nada = True # Check if it was a hex for my_button in mm_buttons: if my_button.but_rect.collidepoint(x, y): # print(my_button.button_id) click_select = my_button nada = False if nada: click_select = None # Do something with the button presss if click_select: if click_select.button_id == "test": cncp.test_map() if click_select.button_id == "new": make_game(gameDisplay, clock_1, mm_buttons) print(click_select.button_id) # Draw Display gameDisplay.fill(cncc.get_color("bg")) gameDisplay.blit(TitleSurf, TitleRect) gameDisplay.blit(subTitleSurf, subTitleRect) # Draw Buttons for this_button in mm_buttons: this_button.draw(gameDisplay) pygame.display.update() clock_1.tick(90)
def hex_buttons(): button_font = pygame.font.Font('./fonts/steam_punk_flyer.ttf', 18) button_color = cncc.get_color("inactive_button") text_color = cncc.get_color("inactive_text") button_prompt_color = cncc.get_color("active_button") text_prompt_color = cncc.get_color("active_text") unit_buttons = [] unit_buttons.append( cncc.a_button("Support", "support", None, button_font, [0, 160, 128, 32], button_color, text_color, button_prompt_color, text_prompt_color)) unit_buttons.append( cncc.a_button("Disband", "disband", None, button_font, [128, 160, 128, 32], button_color, text_color, button_prompt_color, text_prompt_color)) return unit_buttons
def draw_gamebar(gamebar_buttons, screen, my_nation, my_world, display_width): # Draw toolbar # Get gamebar color gb_color = cncc.get_color("gamebar") gb_font = pygame.font.Font('./fonts/steam_punk_flyer.ttf', 12) # Background pygame.draw.rect(screen, gb_color, [0, 0, display_width, 32]) # Draw buttons for button in gamebar_buttons: button.draw(screen) # Draw World Info # Start from the far right # Time to next orders current_time = datetime.now() dueby_raw = my_world.due_date - current_time hours = dueby_raw.seconds // 3600 minutes = dueby_raw.seconds // 60 seconds = dueby_raw.seconds % 60 due_by_readable = "%s:%s.%s" % (hours, minutes, seconds) # Draw date time cncc.draw_notice(screen, str(due_by_readable), gb_font, [display_width - 128, 0, 128, 32], gb_color, [0, 0, 0]) # Draw season info # TODO: setup up weather icon # TODO: change to a previous season # TODO: prisoner menu # TODO: Rulebook menu # Just an empty 32 right now # Draw Year number, just a 32x32 square cncc.draw_notice(screen, str(my_world.year), gb_font, [display_width - 192, 0, 32, 32], gb_color, [0, 0, 0]) # Season is a 64x32 - maybe needs to be made a 96? cncc.draw_notice(screen, str(my_world.season), gb_font, [display_width - 256, 0, 64, 32], gb_color, [0, 0, 0])
def make_game(gameDisplay, clock_1, mm_buttons): custom_menu = [] frequency_menu = [] button_font = pygame.font.Font('./fonts/steam_punk_flyer.ttf', 18) mainmenu_buttons = [] button_color = cncc.get_color("inactive_button") text_color = cncc.get_color("inactive_text") button_prompt_color = cncc.get_color("active_button") text_prompt_color = cncc.get_color("active_text") button_select_color = cncc.get_color("selected_button") text_select_color = cncc.get_color("selected_text") # Game Options # Game Name # Game Password # Player Count # 6 or 8 custom_menu.append( cncc.a_button("6", "pc_6", None, button_font, [608, 256, 64, 48], button_color, text_color, button_prompt_color, text_prompt_color)) custom_menu.append( cncc.a_button("8", "pc_8", None, button_font, [672, 256, 64, 48], button_color, text_color, button_prompt_color, text_prompt_color)) # Messaging # Standard # Airwaves (Broadcast All) # Grey # Radio Silence custom_menu.append( cncc.a_button("Standard", "comm_standard", None, button_font, [400, 352, 128, 48], button_color, text_color, button_prompt_color, text_prompt_color)) custom_menu.append( cncc.a_button("Open Airwaves", "comm_airwaves", None, button_font, [528, 352, 128, 48], button_color, text_color, button_prompt_color, text_prompt_color)) custom_menu.append( cncc.a_button("Grey Comms", "comm_grey", None, button_font, [656, 352, 128, 48], button_color, text_color, button_prompt_color, text_prompt_color)) custom_menu.append( cncc.a_button("Radio Silence", "comm_silence", None, button_font, [784, 352, 128, 48], button_color, text_color, button_prompt_color, text_prompt_color)) # Game Length # Short - 2 components # Medium - 3 components # Long - 5 Components custom_menu.append( cncc.a_button("Short", "cp_2", None, button_font, [512, 448, 128, 48], button_color, text_color, button_prompt_color, text_prompt_color)) custom_menu.append( cncc.a_button("Medium", "cp_3", None, button_font, [640, 448, 128, 48], button_color, text_color, button_prompt_color, text_prompt_color)) custom_menu.append( cncc.a_button("Long", "cp_5", None, button_font, [768, 448, 128, 48], button_color, text_color, button_prompt_color, text_prompt_color)) # Turn Length # Quick # Marathon custom_menu.append( cncc.a_button("Quick", "clock_quick", None, button_font, [528, 544, 128, 48], button_color, text_color, button_prompt_color, text_prompt_color)) custom_menu.append( cncc.a_button("Marathon", "clock_long", None, button_font, [656, 544, 128, 48], button_color, text_color, button_prompt_color, text_prompt_color)) # If marathon - turn pauses frequency_menu.append( cncc.a_button("Mn", "sd_mn", None, button_font, [416, 640, 64, 48], button_color, text_color, button_prompt_color, text_prompt_color)) frequency_menu.append( cncc.a_button("Tu", "sd_tu", None, button_font, [480, 640, 64, 48], button_color, text_color, button_prompt_color, text_prompt_color)) frequency_menu.append( cncc.a_button("Wd", "sd_wd", None, button_font, [544, 640, 64, 48], button_color, text_color, button_prompt_color, text_prompt_color)) frequency_menu.append( cncc.a_button("Th", "sd_th", None, button_font, [608, 640, 64, 48], button_color, text_color, button_prompt_color, text_prompt_color)) frequency_menu.append( cncc.a_button("Fr", "sd_fr", None, button_font, [672, 640, 64, 48], button_color, text_color, button_prompt_color, text_prompt_color)) frequency_menu.append( cncc.a_button("Sa", "sd_sa", None, button_font, [736, 640, 64, 48], button_color, text_color, button_prompt_color, text_prompt_color)) frequency_menu.append( cncc.a_button("Su", "sd_su", None, button_font, [800, 640, 64, 48], button_color, text_color, button_prompt_color, text_prompt_color)) # Launch game button custom_menu.append( cncc.a_button("Launch Game!", "launch", None, button_font, [480, 688, 256, 64], button_color, text_color, button_prompt_color, text_prompt_color)) # TODO: Add back button custom_menu.append( cncc.a_button("Back", "back", None, button_font, [64, 64, 128, 64], button_color, text_color, button_prompt_color, text_prompt_color)) title_font = pygame.font.Font('./fonts/steam_punk_flyer.ttf', 32) title_text = "New Custom Game" TitleSurf, TitleRect = cncc.text_objects(title_text, title_font, [153, 102, 51]) # TODO: Pass along display info TitleRect.center = ((1280 / 2), 50) playing = True click_select = None # Game parameters is the returned value to the map maker # [name,passowrd,player_count,communication,score,clock,turn_frequency] game_params = ["", "", "", "", "", "", "", []] while playing: gameDisplay.blit(TitleSurf, TitleRect) for event in pygame.event.get(): if event.type == pygame.QUIT: intro = False cncc.game_quit() # Only looking for a click if event.type == pygame.MOUSEBUTTONUP: x, y = event.pos if event.button == 1: nada = True # Check if it was a hex for my_button in custom_menu: if my_button.but_rect.collidepoint(x, y): # Find out what type of button was clicked and put the correct id in the game params if my_button.button_id.startswith("pc_"): game_params[2] = my_button.button_id elif my_button.button_id.startswith("comm_"): game_params[3] = my_button.button_id elif my_button.button_id.startswith("cp_"): game_params[4] = my_button.button_id elif my_button.button_id.startswith("clock_"): game_params[5] = my_button.button_id elif my_button.button_id == "launch": print(game_params) elif my_button.button_id == "back": draw_main(mm_buttons, gameDisplay) click_select = my_button nada = False if nada: click_select = None # Do something with the button presss if click_select: pass # Draw Display gameDisplay.fill(cncc.get_color("bg")) gameDisplay.blit(TitleSurf, TitleRect) # Draw lables cncc.draw_notice(gameDisplay, "Player Count", button_font, [640, 208, 128, 48], [30, 30, 30], [200, 200, 200], None) cncc.draw_notice(gameDisplay, "Comms Style", button_font, [640, 304, 128, 48], [30, 30, 30], [200, 200, 200], None) cncc.draw_notice(gameDisplay, "Game Length", button_font, [640, 400, 128, 48], [30, 30, 30], [200, 200, 200], None) cncc.draw_notice(gameDisplay, "Turn Length", button_font, [640, 496, 128, 48], [30, 30, 30], [200, 200, 200], None) # Draw Buttons for this_button in custom_menu: # Skip selected button if this_button.button_id in game_params: cncc.draw_notice(gameDisplay, this_button.message, button_font, this_button.button_dem, button_select_color, text_select_color) continue this_button.draw(gameDisplay) # def __init__(self,message,button_id,data,font,button_dem,sq_co=[255,255,255],tx_co=[0,0,0],sq_p_co=[255,255,255],tx_p_co=[0,0,0],img_file=None): # If a marathon game is selected, draw the frequency buttons to record their responses pygame.display.update() clock_1.tick(90)
def test_map(): # A test of running the map pygame.init() # Display size should be the option display_width = 1280 display_height = 800 gameDisplay = pygame.display.set_mode([display_width, display_height]) nations, this_map, my_world, row_d = cnc_mm.quick_map() my_nation = nations[0] # Create Images So we don't have to worry about it later hilight = pygame.image.load('./images/hexes/hex_select.png') shadow = pygame.image.load('./images/hexes/shadow.png') target = pygame.image.load('./images/hexes/hex_target.png') # Toolbar Icons # TODO - grab the actual number of columns, will need to figure out how to grab from the map # TODO - Load buttons # Define FPS Clock clock_1 = pygame.time.Clock() # Get buttons for the icons for game bar gb_buttons = gamebar_buttons() hex_buttons = make_hex_icons() # Set initial click variable click_select = None insta_select = None context_menu = [] local_order_queue = [] # TODO: Figure out a way to load your orders # first_draw_map first_draw_map(this_map, 0, 0, display_width, display_height) # Get fog or war # Will need to run this when the map updates this_map = cncc.fog_o_war(this_map, my_nation, row_d) # Begin the loop! playing = True while playing: # Check if map needs updating for event in pygame.event.get(): # Exit Event if event.type == pygame.QUIT: # Prompt to submit orders if you have none cncc.game_quit() exited = True if event.type == pygame.MOUSEBUTTONUP: # Check what was clicked - first, through the hexes x, y = event.pos print(event.button) if event.button == 1: # Left Click - only click nada = True # Toolbar Button for my_button in gb_buttons: if my_button.but_rect.collidepoint(x, y): # print(my_button.button_id) if my_button.button_id == "submit": print(local_order_queue) click_select = my_button nada = False # my_button.function if nada == False: break # Context button for my_button in context_menu: if my_button.but_rect.collidepoint(x, y): # This should almost always be an instant change instead of a selection change you can't #print(my_button.button_id) # Buttons for this hex (assume click_select == map_hex), may want to confirm this if my_button.button_id == "conserve": click_select.command == "Conservation Initiative" queue_order(local_order_queue, [click_select, "conserve"]) elif my_button.button_id == "defend": click_select.command == "Defense Initative" queue_order(local_order_queue, [click_select, "defend"]) elif my_button.button_id == "extract": click_select.command == "Extract Coal" queue_order(local_order_queue, [click_select, "extract"]) elif my_button.button_id == "build_autos": click_select.command == "Build Automatons" queue_order(local_order_queue, [click_select, "build_autos"]) elif my_button.button_id == "build_airship": click_select.command == "Build Airship" queue_order(local_order_queue, [click_select, "build_airship"]) elif my_button.button_id == "build_landship": click_select.command == "Build Landship" queue_order(local_order_queue, [click_select, "build_landship"]) elif my_button.button_id == "build_extractor": click_select.command == "Build Extractor" queue_order(local_order_queue, [click_select, "build_extractor"]) elif my_button.button_id == "build_device": click_select.command == "Build Doomsday Device" queue_order(local_order_queue, [click_select, "build_device"]) elif my_button.button_id == "build_component": click_select.command == "Build City Component" queue_order(local_order_queue, [click_select, "build_component"]) elif my_button.button_id == "launch": click_select.command == "Launching City" queue_order(local_order_queue, [click_select, "Launch"]) # Agent Actions # Generally shouldn't change the click select nada = False # my_button.function if nada == False: break for my_hex in this_map: # Bange together an actual rect becasuse f**k it if my_hex.hex_rect.collidepoint(x, y): my_hex.selected = True click_select = my_hex nada = False else: my_hex.selected = False if nada == False: break # If a hex was selected, check if there is a unit to select too? # If nothing was selected, back up? if nada: click_select = None context_menu = [] # If you didn't click a hex, you clicked a button? # If you clicked nothing elif event.button == 3 and isinstance(click_select, cncc.my_hex): print("Move!") # Left - select a hex/option # Right - start a move # Every so often, will need to go new map state? #Check if Scrolling left/right - no need for up/down if pygame.mouse.get_pos()[0] < 30: push_map(this_map, "r") elif pygame.mouse.get_pos()[0] > display_width - 30: push_map(this_map, "l") # Push up and down if 30 < pygame.mouse.get_pos()[1] < 60: push_map(this_map, "u") elif pygame.mouse.get_pos()[1] > display_height - 30: push_map(this_map, "d") # Draw # 1 - Background - Orange gameDisplay.fill(cncc.get_color("bg")) # 2 - Map and Units draw_map(this_map, row_d, display_width, hilight, gameDisplay, shadow) # Hilight the appropriate hex # Done in a different hex in order to not draw over other hexes if click_select: if isinstance(click_select, cncc.map_hex): # Hilight selected hex gameDisplay.blit(hilight, [click_select.pos_x, click_select.pos_y]) # If this is your hex, show range if click_select.controller == my_nation: if "airship" in click_select.wm: # If you have an airship can target up to 2 spaces away for my_hex in this_map: if cncc.range_two(click_select, my_hex, row_d): gameDisplay.blit(target, [my_hex.pos_x, my_hex.pos_y]) else: # Just adjaceny for my_hex in this_map: if cncc.is_adjacent(click_select, my_hex, row_d): gameDisplay.blit(target, [my_hex.pos_x, my_hex.pos_y]) # 4 - If you have a that has potential targets? # 4 - Toolbar # May need to define an array of buttons out here so that they can be clicked draw_gamebar(gb_buttons, gameDisplay, my_nation, my_world, display_width) # 4 - Queued Orders # 5 - Popups # Draw popup of the selected hex # Maybe have a selector that changes based on the last click? if click_select: if isinstance(click_select, cncc.map_hex): # OR IF A BUTTON WITHIN THE HEX POPUP IS CLICKED! context_menu = draw_hex_popup(gameDisplay, click_select, hex_buttons, my_nation) # Hilight selected hex gameDisplay.blit(hilight, [click_select.pos_x, click_select.pos_y]) elif isinstance(click_select, cncc.a_button): if click_select.button_id == "menu": context_menu = main_menu(gameDisplay) elif click_select.button_id == "intel": context_menu = intel_menu(gameDisplay, my_nation, nations) elif click_select.button_id == "mssg": pass # Button Functions go here? # 6 - Draw buttons from click select for button in context_menu: button.draw(gameDisplay) # 7 - Update pygame.display.update() clock_1.tick(90) # Cleanup tasks pygame.quit() quit()