def __menu(self): print("entering __menu") menu = Menu(self.graphics, ("play", "how to play", "exit")) state_to_return = "EXIT" goon = True while goon: # events for event in pygame.event.get(): if event.type == QUIT: goon = False menu.event(event) # updates menu.update() choice = menu.get_clicked_button_txt() if choice == "play": state_to_return = "GAME" goon = False if choice == "how to play": state_to_return = "HOWTOPLAY" goon = False #if choice == "credits": # state_to_return = "CREDITS" # goon = False if choice == "exit": state_to_return = "EXIT" goon = False # draws finalrender = pygame.Surface((c.WINDOW_WIDTH, c.WINDOW_HEIGHT)) finalrender.blit(menu.draw(), (0, 0)) self.screen.blit( pygame.transform.scale(finalrender, (c.WINDOW_WIDTH, c.WINDOW_HEIGHT)), (0, 0)) pygame.display.flip() self.clock.tick(30) print("exiting __menu") return state_to_return
SCREEN_SIZE = (1080, 720) SCREEN_COLOR = (255, 255, 255) screen = pygame.display.set_mode(SCREEN_SIZE) # screen = pygame.display.set_mode(SCREEN_SIZE, pygame.FULLSCREEN, pygame.RESIZABLE) # 60 frames per second clock = pygame.time.Clock() FPS = 60 # Debug mode on DEBUG = True DEBUG_FONT = pygame.font.SysFont("arial", 16) menu = Menu() # player pl = Player((540, 500)) keydict = [ pygame.K_LEFT, pygame.K_RIGHT, pygame.K_UP, pygame.K_DOWN, pygame.K_LSHIFT ] player_group = pygame.sprite.Group() player_group.add(pl) level = "hometown" bg = level_list[level] music = bg.music_path save_data = {"level": level, "pos": pl.get_rect(), "save_iteration": 0}
def populate_menu(self): item_list = [] for item in self.menu_items: item_list.append(item) self.main_menu = Menu(self.screen, self) self.main_menu.post_init(item_list)
def __init__(self): """ initialize game window """ pg.init() pg.mixer.init() self.clock = pg.time.Clock() if FULLSCREEN: self.screen = pg.display.set_mode((WIDTH, HEIGHT), pg.FULLSCREEN) else: self.screen = pg.display.set_mode((WIDTH, HEIGHT)) pg.display.set_caption(TITLE) self.font_name = pg.font.match_font(FONT_NAME) self.running = True self.playing = True self.has_won = False self.lives = PLAYER_LIVES self.coin_counter = 0 self.dead = True self.frame_count = 0 self.total_seconds = 0 self.dir = path.dirname(__file__) # init sprite Groups self.all_sprites = pg.sprite.Group() self.platforms = pg.sprite.Group() self.death_tiles = pg.sprite.Group() self.checkpoints = pg.sprite.Group() self.ai_borders = pg.sprite.Group() self.coins = pg.sprite.Group() self.sprites_on_screen = pg.sprite.Group() self.jump_pads = pg.sprite.Group() self.enemies = pg.sprite.Group() self.sprites_on_screen = pg.sprite.Group() self.finishes = pg.sprite.Group() # map self.player = None self.map = None self.player_start = None self.player_spawn = None self.total_world_shift = 0 self.checkpoint_shift = 0 self.checkpoint_coin_counter = 0 self.shift_factor = 999 self.last_checkpoint_rect = None self.map_quick_load = False # menu self.menu = Menu(self.screen) # sounds self.sound_counter = 0 self.coin_sound = rM.getSound("coin.wav") self.checkpoint_sound = rM.getSound("Checkpoint.wav") self.die_sound = rM.getSound("steve_hurt.wav") self.win_sound = rM.getSound("finish.wav") self.lose_sound = rM.getSound("game-over.wav") # overlayed text info self.overlay_seconds = 0 self.overlay_coins = 0 self.overlay_lives = 0 self.overlay_map_name = None # rendered text info self.rendered_seconds = None self.rendered_coins = None self.rendered_lives = None self.rendered_map_name = None
from game.menu import Menu import pygame as pg from game import settings import time pg.init() pg.mixer.init() screen = pg.display.set_mode( (settings.WIDTH, settings.HEIGHT)) # (0, pg.FULLSCREEN)[FULLSCREEN] pg.display.set_caption(settings.TITLE) m = Menu(screen) m.finish(True, "test playlist", 50, 1)