def init_settings_menu(self): """Initializes the settings menu.""" self.settings_menu_surface = pygame.Surface(self.screen_dimensions) self.main_menu_surface = None self.pause_menu_surface = None self.buttons = [] self.settings_buttons = [] style_button = TextButton((0, 450), get_style_name(self.game_data.get_style()), menu_fonts, 30, white, red, self.switch_style) style_button.center_horizontally(self.screen_dimensions) self.settings_buttons.append(style_button) self.buttons.append(style_button) x_center = center_horizontally(pygame.Surface((0, 0)), self.screen_dimensions) music_button = ImageButton((x_center - 50, 510), self.get_music_button_img(), self.get_music_button_img_h(), self.toggle_music) self.settings_buttons.append(music_button) self.buttons.append(music_button) sound_button = ImageButton((x_center + 20, 510), self.get_sound_button_img(), self.get_sound_button_img_h(), self.toggle_sound) self.settings_buttons.append(sound_button) self.buttons.append(sound_button) main_menu_button = TextButton( (0, 550), "Back to main menu", menu_fonts, 30, white, red, lambda: pygame.event.post( pygame.event.Event(events.BACK_TO_MAIN_MENU, {}))) main_menu_button.center_horizontally(self.screen_dimensions) self.buttons.append(main_menu_button)
def init_main_menu_surface(self): """Initializes the surface for the main menu, drawing the title and creating the buttons.""" if self.level == 0: self.level = self.max_level = self.game_data.get_max_level() self.main_menu_surface = pygame.Surface(self.screen_dimensions) self.pause_menu_surface = None self.settings_menu_surface = None self.main_menu_surface.fill(black) self.buttons = [] self.level_buttons = [] level_button = TextButton((0, 450), "Level " + str(self.level), menu_fonts, 30, white, white, lambda: None) level_button.center_horizontally(self.screen_dimensions) self.level_buttons.append(level_button) self.buttons.append(level_button) level_down_button = ImageButton( left_of(img_arrow_left, level_button, 20), img_arrow_left, img_arrow_left_hover, self.level_down, False) self.level_buttons.append(level_down_button) self.buttons.append(level_down_button) level_up_button = ImageButton( right_of(img_arrow_right, level_button, 20), img_arrow_right, img_arrow_right_hover, self.level_up, False) self.level_buttons.append(level_up_button) self.update_level_buttons() self.buttons.append(level_up_button) # the line of code below creates a MenuButton that contains white text that gets red when hovered, # and sends an event to start game mode 0 for the control unit if clicked. start_button = TextButton((0, 500), "Start game", menu_fonts, 30, white, red, self.start_game_mode_0) start_button.center_horizontally(self.screen_dimensions) self.buttons.append(start_button) settings_button = TextButton( (0, 550), "Settings", menu_fonts, 30, white, red, lambda: pygame.event.post( pygame.event.Event(events.OPEN_SETTINGS, {}))) settings_button.center_horizontally(self.screen_dimensions) self.buttons.append(settings_button) how_to_button = TextButton( (0, 600), "How to play", menu_fonts, 30, white, red, lambda: pygame.event.post( pygame.event.Event(events.OPEN_HOW_TO, {}))) how_to_button.center_horizontally(self.screen_dimensions) self.buttons.append(how_to_button) quit_button = self.create_quit_button(650) self.buttons.append(quit_button)
def __init__(self): self.system = platform.system() pygame.init() pygame.display.set_caption('Flappy Bird') self.FPS = 55 self.SCREEN_WIDTH = 1000 self.SCREEN_HEIGHT = 563 self.screen = pygame.display.set_mode((self.SCREEN_WIDTH, self.SCREEN_HEIGHT)) self.sliding_background = SlidingBackground(self.screen) if self.system == 'Linux': self.flappy_bird_title = Title(self.screen, r'images/title2.0.png', 466, 137, 50) else: self.flappy_bird_title = Title(self.screen, r'images\title2.0.png', 466, 137, 50) if self.system == 'Linux': self.game_over_title = Title(self.screen, r'images/game_over2.0.png', 383, 90, 50) else: self.game_over_title = Title(self.screen, r'images\game_over2.0.png', 383, 90, 50) if self.system == 'Linux': self.start_image_button = ImageButton(self.screen, r'images/start_button3.0.png', 183, 109, 400) else: self.start_image_button = ImageButton(self.screen, r'images\start_button3.0.png', 183, 109, 400) self.scoreboard = ScoreBoard(self.screen) self.retry_button = Button(self.screen, 425, 'Retry') self.bird = Bird(self.screen) # True until reset in pressed self.game_active = False # True until obstacle was hit self.game_lost = False self.score = 0 self.create_best_score_file() self.get_best_score()
def createButtons(self): _list = self.game.assets["ICONS"] self.buttons = list() OFFSET = [50, 90] SPASE = 8 for idx, item, in enumerate(_list): _gen = [item['img'].format(_suff) for _suff in [ 'n', 'a', 'd'] if os.path.isfile(item['img'].format(_suff))] _imgs = [pygame.image.load(img) for img in _gen] _btn = ImageButton(_imgs) _btn.pos = [OFFSET[0], OFFSET[1] + (_btn.rect.height + SPASE) * idx] self.buttons.append(_btn) self.target_selector_pos = self.selector.pos = [ self.buttons[0].pos[0] - 5, self.buttons[0].pos[1] - 5]
def __init__(self): super(IconEditArea, self).__init__() self.edit_area = gtk.EventBox() self.camera_area_vbox = gtk.VBox(False) self.camera_area = Webcam() self.camera_area_up = gtk.EventBox() self.camera_area_down = gtk.EventBox() self.camera_area_init_flag = False self.button_hbox = gtk.HBox(False) self.button_hbox_height = 40 self.__widget_y = 92 self.edit_area.set_size_request(self.AREA_WIDTH, self.AREA_HEIGHT) #self.camera_area.set_size_request(self.AREA_WIDTH, self.AREA_HEIGHT) self.camera_area_vbox.set_size_request(self.AREA_WIDTH, self.AREA_HEIGHT) self.camera_area.set_size_request(self.AREA_WIDTH, 225) #self.camera_area_up.set_size_request(self.AREA_WIDTH, 37) #self.camera_area_down.set_size_request(self.AREA_WIDTH, 37) self.button_hbox.set_size_request(self.AREA_WIDTH, self.button_hbox_height) self.button_zoom_in = ImageButton( app_theme.get_pixbuf("account/zoom_in.png"), app_theme.get_pixbuf("account/zoom_in.png"), app_theme.get_pixbuf("account/zoom_in.png"), _("zoom in")) self.button_zoom_out = ImageButton( app_theme.get_pixbuf("account/zoom_out.png"), app_theme.get_pixbuf("account/zoom_out.png"), app_theme.get_pixbuf("account/zoom_out.png"), _("zoom out")) self.button_camera = ImageButton( app_theme.get_pixbuf("account/camera.png"), app_theme.get_pixbuf("account/camera.png"), app_theme.get_pixbuf("account/camera.png"), _("Take a photo")) self.button_camera_again = ImageButton( app_theme.get_pixbuf("account/camera_again.png"), app_theme.get_pixbuf("account/camera_again.png"), app_theme.get_pixbuf("account/camera_again.png"), _("Try again")) self.button_zoom_in_align = tools.make_align(self.button_zoom_in, xalign=0.5, yalign=0.5) self.button_zoom_out_align = tools.make_align(self.button_zoom_out, xalign=0.5, yalign=0.5) self.button_camera_align = tools.make_align(self.button_camera, xalign=0.5, yalign=0.5) self.button_camera_again_align = tools.make_align( self.button_camera_again, xalign=0.5, yalign=0.5) self.button_zoom_in.connect("clicked", self.on_zoom_in_clicked_cb) self.button_zoom_out.connect("clicked", self.on_zoom_out_clicked_cb) self.button_camera.connect("clicked", self.on_camera_clicked_cb) self.button_camera_again.connect("clicked", self.on_camera_again_clicked_cb) self.box = gtk.VBox(False) self.box.pack_start(self.edit_area, False, False) #self.box.pack_start(self.button_hbox, False, False) #self.box.pack_start(tools.make_align(yalign=0.0, yscale=1.0)) self.set_size(self.AREA_WIDTH, self.AREA_HEIGHT) self.set_size_request(self.AREA_WIDTH, self.AREA_HEIGHT) self.connect("expose-event", self.draw_frame_border) self.put(self.box, 0, 0) #self.put(self.button_hbox, 0, self.AREA_HEIGHT-self.button_hbox_height) self.edit_area.set_can_focus(True) self.edit_area.set_visible_window(False) self.edit_area.add_events(gtk.gdk.ALL_EVENTS_MASK) self.edit_area.connect("button-press-event", self.__on_button_press_cb) self.edit_area.connect("button-release-event", self.__on_button_release_cb) self.edit_area.connect("motion-notify-event", self.__on_motion_notify_cb) #self.edit_area.connect("leave-notify-event", self.__on_leave_notify_cb) self.edit_area.connect("expose-event", self.__expose_edit) self.camera_area_down.add_events(gtk.gdk.POINTER_MOTION_MASK) #self.camera_area.connect("motion-notify-event", self.__on_camera_motion_notify_cb) self.camera_area_down.connect("motion-notify-event", self.__on_camera_motion_notify_cb) self.camera_area_up.connect("expose-event", self.__on_camera_expose_cb) self.camera_area_down.connect("expose-event", self.__on_camera_expose_cb) self.camera_area_vbox.pack_start(self.camera_area_up) self.camera_area_vbox.pack_start(self.camera_area, False, False) self.camera_area_vbox.pack_start(self.camera_area_down) #panel_size = self.button_camera.get_size_request() #self.panel = Panel(panel_size[0], panel_size[1], gtk.WINDOW_POPUP) self.panel = Panel(self.AREA_WIDTH, self.button_hbox_height, gtk.WINDOW_POPUP) self.panel_layout = gtk.Fixed() #self.panel_layout.put(self.button_camera_align, (self.AREA_WIDTH-panel_size[0])/2, 0) self.panel_layout.put(self.button_hbox, 0, 0) self.panel.add(self.panel_layout) self.panel.hide_panel() self.panel.connect("expose-event", self.__draw_panel_background) self.panel.connect("size-allocate", lambda w, e: w.queue_draw()) #self.panel.connect("enter-notify-event", self.__on_camera_enter_notify_cb) self.panel.connect("leave-notify-event", self.__on_camera_leave_notify_cb) self.camera_focus_flag = True self.__refresh_time_id = None self.__button_time_id = None self.current_mode = self.MODE_EDIT self.origin_pixbuf = None self.origin_pixbuf_width = 0 self.origin_pixbuf_height = 0 self.cache_pixbuf = CachePixbuf() self.border_color = "#000000" # cursor self.cursor = { self.POS_IN_DRAG: gtk.gdk.Cursor(gtk.gdk.BOTTOM_RIGHT_CORNER), self.POS_IN_MOVE: gtk.gdk.Cursor(gtk.gdk.FLEUR), self.POS_OUT: None } self.cursor_current = None self.press_point_coord = (0, 0) self.position = self.POS_OUT self.drag_flag = False self.move_flag = False # self.__show_button_flag = True self.__button_moving_flag = False #self.__refresh_flag = False # the pixbuf shown area self.pixbuf_offset_x = 0 self.pixbuf_offset_y = 0 self.pixbuf_offset_cmp_x = 0 self.pixbuf_offset_cmp_y = 0 self.pixbuf_x = 0 self.pixbuf_y = 0 self.pixbuf_w = self.AREA_WIDTH self.pixbuf_h = self.AREA_HEIGHT # the select box area self.edit_coord_x = 0 self.edit_coord_y = 0 self.edit_coord_w = self.AREA_WIDTH self.edit_coord_h = self.AREA_HEIGHT self.edit_coord_backup_x = 0 self.edit_coord_backup_y = 0 self.edit_coord_backup_w = self.AREA_WIDTH self.edit_coord_backup_h = self.AREA_HEIGHT self.drag_point_x = 0 self.drag_point_y = 0 self.__update_drag_point_coord()