def __init__(self, options, initial_selected=0): self.options = options selected_font = utils.load_font("FreeSans.ttf", 30) selected_color = (255, 255, 255) font = utils.load_font("FreeSans.ttf", 30) color = (0, 0, 0) self.normal_font = font self.normal_color = color self.selected_font = selected_font self.selected_color = selected_color self.start_y = 200 self.item_height = 50 self.cursor = Cursor(self.start_y, self.item_height, initial_selected) self.selected = initial_selected self.imgs_normal = [] self.imgs_selected = [] self._create_option_images() self.last_mouse_position = pygame.mouse.get_pos() # espera unos segundos antes de que el usuario pueda seleccionar algo self.delay = 50
def __init__(self, app, lobby_type): logging.info('Initializing lobby') self.app = app self.lobby_type = lobby_type self.games_list = {} logging.info('Type: {}'.format(self.lobby_type)) logging.info('Loading fonts') self.title_font = utils.load_font('monofur.ttf', 24) self.normal_font = utils.load_font('monofur.ttf', 18) gui.init() self.gui_container = pygame.sprite.Group() if self.lobby_type == settings.LobbyStates.HOST_ONLINE_GAME: self.create_online_game() elif self.lobby_type == settings.LobbyStates.JOIN_ONLINE_GAME: self.get_online_games() pygame.time.set_timer(settings.Events.GET_ONLINE_GAMES.value, 5000) elif self.lobby_type == settings.LobbyStates.HOST_LAN_GAME: self.lan_announcer = networking.lan.Announcer( game_name=self.app.config.get('connectfour', 'game_name')) self.lan_announcer.start() networking.engine.Engine(settings.NetworkEngineMode.HOST, '') elif self.lobby_type == settings.LobbyStates.JOIN_LAN_GAME: self.lan_discoverer = networking.lan.Discoverer( self, self.games_list) self.lan_discoverer.start() pygame.time.set_timer(settings.Events.CLEAN_LAN_GAMES.value, 3000)
def __init__(self, screen, bartending): Abstract_Menu.__init__(self, screen) self.font = utils.load_font('chitown.ttf', 24) self.font_name = utils.load_font('chitown.ttf', 30) self.player_name = 'AAA' self.bartending = bartending self.any_key_pressed = False self.age_2 = 0 #No options in this menu self.options = [ 'New High score', 'You made {0} points'.format(self.bartending.score)]
def __init__(self, screen, bartending): Abstract_Menu.__init__(self, screen) self.font = utils.load_font('saloon.ttf', 16) self.font_name = utils.load_font('saloon.ttf', 22) self.player_name = 'AAA' self.bartending = bartending self.any_key_pressed = False self.age_2 = 0 #No options in this menu self.options = [ 'New High score', 'You made {0} points'.format(self.bartending.score) ]
def __init__(self, allsprites, game_state, song, background_handler): sprite.Sprite.__init__(self, allsprites) self.game_state = game_state self.background_handler = background_handler self.font = load_font(song.get_font_filename(), 36) self.score = 0 self.show_highscore = False self.enabled = True # Feel free to play around with these variables # Currently they are not used anywhere in the code self.score_streak = 0 self.score_multiplier = 1 # Required to make sure the first note hits correctly self.played_once = False # Flag to see when a score should be saved after an update self.score_is_saved = True self.image = self.font.render('Score: ' + str(self.score), 1, (255, 255, 255)) self.pos = (1050, 650) # Set the location of the text self.score_text = None self.rect = (self.pos, self.image.get_size()) self.streak_label = Label(f"Streak: 0", 1050, 600, False, 36, song.get_font_filename(), (255, 255, 255), "playing", allsprites, game_state)
def __init__(self, screen, text, pos, duration=1000, size=12, flashy=True, initialdelay=200, color=(130, 40, 0)): self.screen = screen self.pos = pos self.size = size self.color = color self.font = load_font("audiowide.ttf", self.size) self.font.set_bold(True) self.textstring = text self.text = self.font.render(text, True, color) self.duration = duration self.initialdelay = initialdelay self.flashy = flashy self.timealive = 0 #ms self.lastactiontime = 0 #ms if duration > 0: self.sizereductionperaction = ((size / 1.9) / duration) * 50. if self.sizereductionperaction >= 0.5 or self.sizereductionperaction <= 1: self.sizereductionperaction = 1 else: self.sizereductionperaction = round( self.sizereductionperaction) self.xdirection = random.choice([-1, 1])
def __init__(self, x, y, width, height, text, function, font_filename, allsprites, game_state): pygame.sprite.Sprite.__init__(self, allsprites) self.game_state = game_state self.allsprites = allsprites self.x = x self.y = y self.width = width self.height = height self.onclick_function = function self.color_text = (255, 255, 255) self.dark_bg_rgb = (140, 140, 140) self.light_bg_rgb = (170, 170, 170) self.font = load_font(font_filename, 30) self.text = self.font.render(text, True, self.color_text) dark_button = pygame.Surface((self.width, self.height)) dark_button.fill(self.dark_bg_rgb) dark_button.blit(self.text, (8, 8)) self.dark_button = dark_button light_button = pygame.Surface((self.width, self.height)) light_button.fill(self.light_bg_rgb) light_button.blit(self.text, (8, 8)) self.light_button = light_button self.image = self.dark_button self.pos = (self.x, self.y) self.rect = (self.pos, (self.width, self.height))
def __init__(self, text, x, y, center, font_size, font_name, color, type, allsprites, game_state): pygame.sprite.Sprite.__init__(self, allsprites) self.game_state = game_state self.allsprites = allsprites self.background_handler = game_state.background_handler self.center = center self.x = x self.y = y self.type = type self.enabled = False self.type = type self.color = color self.text = text self.font = load_font(font_name, font_size) self.image = self.font.render('', 1, color) if center: self.pos = (self.background_handler.background.get_width() / 2 - self.image.get_width() / 2, self.y) else: self.pos = (x, y) self.rect = (self.pos, self.image.get_size()) self.hide()
def __init__(self, allsprites, song): self.state = 'prestart' self.allsprites = allsprites self.keyboard_button = [] self.song = song self.font = load_font(song.get_font_filename(), 36) self.notes_are_dropping = False self.song_is_finished = False # Reads and plays audio from notes files self.music_player = MusicPlayer(song, self) # Responsible for loading and animating the background self.background_handler = BackgroundHandler(song) # Assigns falling notes to correct hitbox self.note_dropper = NoteDropper(self.music_player) # Responsible for managing (high) scores self.scoreHandler = ScoreHandler(self.allsprites,self, self.song) # Load sound which plays when a note is missed self.sounds_miss = load_sound(song.get_sound_miss()) # Define Hitboxes input_keys = ['a', 's', 'd', 'f'] self.hitboxes = [ Hitbox('hitbox-example.png', 0, input_keys[0], self.allsprites), Hitbox('hitbox-example.png', 1, input_keys[1], self.allsprites), Hitbox('hitbox-example.png', 2, input_keys[2], self.allsprites), Hitbox('hitbox-example.png', 3, input_keys[3], self.allsprites), ]
def initialise(self): # Initialize Everything pygame.display.flip() self.game_paused = False # sounds self.sounds = {} self.sounds["plop"] = utils.load_sound("plop.wav") # Create The Backgound self.background, foo = utils.load_image("background.png") # Display The Background self.screen.blit(self.background, (0, 0)) pygame.display.flip() # group that stores all bubbles self.bubbles = pygame.sprite.Group() self.flying_scores = pygame.sprite.Group() # game variables self.score = Score_Meter((10, 10, 10, 10)) self.flying_scores.add(self.score) self.bubble_grid = Bubblegrid(13, 20, self.bubbles) # group for information sprites in the screen, should be rendered the last one self.font = utils.load_font("chitown.ttf", 20) self.game_started = False self.game_finished = False self.level_finished = False
def __init__(self, topleft, caption): Sprite.__init__(self) self.caption = caption self.font = utils.load_font('GenghisKhan.otf', 20) self.image = self._render_text() image_rect = self.image.get_rect() self.rect = Rect(topleft, (image_rect.width, image_rect.height))
def update_image(self): font = utils.load_font("FreeSans.ttf", 30) text = "Lines: %d" % (self.lines) self.image, self.image_rect = utils.render_text(text, font) self.image_rect.move_ip( self.rect.x + ((self.rect.w - self.image_rect.w) / 2), self.rect.y + 10)
def __init__(self, position): pygame.sprite.Sprite.__init__(self) self.score = 0 self.target_score = 0 self.rect = position self.font = utils.load_font('chitown.ttf', 36) self.reload_image()
def __init__(self, topleft): Sprite.__init__(self) self.font = utils.load_font('GenghisKhan.otf', 26) self.text_line_1 = 'You found all foxes. Congratulations!' self.text_line_2 = 'Play again?' self.image = self._render_text() image_rect = self.image.get_rect() self.rect = Rect(topleft, (image_rect.width, image_rect.height))
def icon(cls, size): """Returns an icon to use for the game.""" tile = pygame.Surface((size, size)) tile.fill((237, 194, 46)) label = load_font(cls.BOLD_NAME, int(size / 3.2)).render(cls.NAME, True, (249, 246, 242)) width, height = label.get_size() tile.blit(label, ((size - width) / 2, (size - height) / 2)) return tile
def __init__(self, screen, mode): ''' Constructor Create table to play match a and all necessary variables ''' # Texts font = utils.load_font("monof55.ttf", 18) font_big = utils.load_font("monof55.ttf", 22) score = TextItem("Score", font_big, INFO_X, SCORE_Y) score_val = TextItem("0", font, INFO_X, SCORE_VAL_Y) self.texts = [score, score_val] if mode == MODE_MOVE: self.texts.append(TextItem("Moves", font_big, INFO_X, COUNT_Y)) self.texts.append( TextItem(str(MAX_MOVES), font, INFO_X, COUNT_VAL_Y)) elif mode == MODE_TIME: self.texts.append(TextItem("Time", font_big, INFO_X, COUNT_Y)) self.texts.append( TextItem(str(MAX_TIME), font, INFO_X, COUNT_VAL_Y)) self.move_sound = utils.load_sound("move.wav") self.square_sound = utils.load_sound("square.wav") self.table = [] # Table of squares for r in range(TAB_H): self.table.append([]) for c in range(TAB_W): self.table[r].append(Square(r, c)) self.screen = screen self.mode = mode self.score = 0 self.moves = 0 self.start_time = time.time() # Variables to handle the gameplay self.button_down = False # Is the mouse left button clicked? self.current_color = (0, 0, 0 ) # Color being selected after a mouse click self.chain = [] # Chain of selected squares self.chain_sorted = { } # Useful dictionary to be used when deleting squares self.all_same_color = [ ] # All squares not in chain to be deleted because of a BigSquare self.before_square = None # To store the last place before a square was composed self.count_after_square = 0
def update(self, time_passed): self.timealive += time_passed if self.timealive - 200 > self.lastactiontime and self.flashy and self.timealive > self.initialdelay: self.pos.y -= 4 self.pos.x += 2 * self.xdirection self.size -= self.sizereductionperaction self.font = load_font("audiowide.ttf", self.size) self.font.set_bold(True) self.text = self.font.render(self.textstring, True, self.color)
def __init__(self, app, force_music=False): logging.info('Initializing menu') self.app = app logging.info('Loading fonts') self.title_font = utils.load_font('monofur.ttf', 62) self.normal_font = utils.load_font('monofur.ttf', 18) self.small_font = utils.load_font('monofur.ttf', 15) self.musics_volume = self.app.config.getfloat('connectfour', 'music_volume') if not pygame.mixer.music.get_busy() or force_music: utils.load_music('menu.wav', volume=self.musics_volume) self.load_gui()
def __init__(self, screen): Abstract_Menu.__init__(self, screen) self.font = utils.load_font('chitown.ttf', 24) self.line_height = 40 self.left_margin = 52 self.options = [\ 'CREDITS', 'Game design: kTzAR', 'Game development: kTzAR', ]
def __init__(self, position, score): self.age = 0 pygame.sprite.Sprite.__init__(self) font = utils.load_font('4114blasterc.ttf', 20) score = '{0}'.format(score) surf_text = font.render(score, 2, (255,255,255)) self.image = pygame.Surface(font.size(score)) self.image.blit(surf_text, (0,0)) self.rect = position.copy() self.image.set_colorkey((0,0,0))
def __init__(self, position, score): self.age = 0 #To animate it and decide when to kill() pygame.sprite.Sprite.__init__(self) font = utils.load_font('chitown.ttf', 20) score = '{0}'.format(score) surf_text = font.render(score, 2, (10,10,10)) self.rect = position.copy() self.image = pygame.Surface(font.size(score)) #Blitting into a new Surface is needed to apply alpha, doesn't work in the surface from font.render self.image.blit(surf_text, (0,0)) self.image.set_colorkey((0,0,0))
def _make_tile(self, value, background, text): """Renders a tile, according to its value, and background and foreground colours.""" tile = pygame.Surface((self.cell_width, self.cell_height), pygame.SRCALPHA) pygame.draw.rect(tile, background, (0, 0, self.cell_width, self.cell_height)) # The "zero" tile doesn't have anything inside. if value: label = load_font(self.BOLD_NAME, 50 if value < 1000 else (40 if value < 10000 else 30)).render(str(value), True, text) width, height = label.get_size() tile.blit(label, ((self.cell_width - width) / 2, (self.cell_height - height) / 2)) return tile
def __init__(self, screen): Abstract_Menu.__init__(self, screen) self.font = utils.load_font('saloon.ttf', 16) self.line_height = 40 self.left_margin = 52 self.options = [\ 'CREDITS', 'Game design: kTzAR', 'Game development: kTzAR', 'Music: ORIGAMI by DANJYON KIMURA', ]
def __init__(self, screen, mode): ''' Constructor Create table to play match a and all necessary variables ''' # Texts font = utils.load_font("monof55.ttf", 18) font_big = utils.load_font("monof55.ttf", 22) score = TextItem("Score", font_big, INFO_X, SCORE_Y) score_val = TextItem("0", font, INFO_X, SCORE_VAL_Y) self.texts = [score, score_val] if mode == MODE_MOVE: self.texts.append(TextItem("Moves", font_big, INFO_X, COUNT_Y)) self.texts.append(TextItem(str(MAX_MOVES), font, INFO_X, COUNT_VAL_Y)) elif mode == MODE_TIME: self.texts.append(TextItem("Time", font_big, INFO_X, COUNT_Y)) self.texts.append(TextItem(str(MAX_TIME), font, INFO_X, COUNT_VAL_Y)) self.move_sound = utils.load_sound("move.wav") self.square_sound = utils.load_sound("square.wav") self.table = [] # Table of squares for r in range(TAB_H): self.table.append([]) for c in range(TAB_W): self.table[r].append(Square(r,c)) self.screen = screen self.mode = mode self.score = 0 self.moves = 0 self.start_time = time.time() # Variables to handle the gameplay self.button_down = False # Is the mouse left button clicked? self.current_color = (0,0,0) # Color being selected after a mouse click self.chain = [] # Chain of selected squares self.chain_sorted = {} # Useful dictionary to be used when deleting squares self.all_same_color = [] # All squares not in chain to be deleted because of a BigSquare self.before_square = None # To store the last place before a square was composed self.count_after_square = 0
def __init__(self, screen): self.font = utils.load_font('chitown.ttf', 24) self.background, foo = utils.load_image('background.png') self.logo, foo = utils.load_image('logo.png') self.screen = screen self.chosen_option = 0 self.age = 0 self.selected_option = -1 self.events = [] #So the subclasses can inspect input events self.finished = False self.line_height = 60 self.left_margin = 152
def initialise(self): """this function is called when the program starts. it initializes everything it needs, then runs in a loop until the function returns.""" #Initialize Everything pygame.init() self.screen = pygame.display.set_mode((640, 480)) pygame.display.set_caption('VacuumFire') pygame.mouse.set_visible(0) #icon icon, foo = utils.load_image('icon.png') pygame.display.set_icon(icon) self.game_paused = False #sounds self.sounds = {}; self.sounds['music'] = utils.load_sound('archivo.ogg') self.sounds['warning'] = utils.load_sound('warning.wav') self.sounds['powerup'] = utils.load_sound('powerup.wav') self.sounds['music'].play() #Create The Backgound self.background = Background(self.screen.get_size()) #game variables self.score = 0 #Display The Background self.screen.blit(self.background, (0, 0)) pygame.display.flip() #The player's ship self.ship = Ship() #The player's ship self.lifemeter = LifeMeter() self.player = pygame.sprite.RenderPlain((self.ship)) #group that stores all enemies self.enemies = pygame.sprite.Group() #group that stores all powerups self.powerups = pygame.sprite.Group() #group that stores all the lasers the player shoots self.fire = pygame.sprite.Group() #group for information sprites in the screen, should be rendered the last one self.hud = pygame.sprite.Group() self.explosions = pygame.sprite.Group() self.hud.add(self.lifemeter) #The level self.level = Stage('level_1') self.font = utils.load_font('4114blasterc.ttf', 36) self.clock = pygame.time.Clock() self.game_started = False self.game_finished = False
def __init__(self, screen, score): ''' Constructor Initialisation of all items and determine position ''' self.screen = screen font = utils.load_font("ka1.ttf", 20) scoreItem = MenuItem(str(score), font) backItem = MenuItem("Back", font) self.items = (scoreItem, backItem) for i in range(len(self.items)): self.items[i].setPos(screen.get_width()/2, 30*(i+1))
def initialise(self): """this function is called when the program starts. it initializes everything it needs, then runs in a loop until the function returns.""" #Initialize Everything pygame.display.flip() #Load options try: self.options = pickle.load(open('options.p', 'rb')) except: print "No options" self.options = {'Difficulty':'Hard', 'Music':'Off'} self.game_paused = False #sounds self.sounds = {}; self.sounds['glass'] = utils.load_sound('glass.ogg') self.sounds['throw'] = utils.load_sound('throw.ogg') #Create The Backgound self.background, foo = utils.load_image('back.png') #game variables self.clients_served = 0 self.speed = 50 #the lower the faster self.score = 0 self.mugs = 10 self.time = 0 #to check the stage for clients self.client_score = 500 self.mug_score = 500 #Display The Background self.screen.blit(self.background, (0, 0)) pygame.display.flip() self.level = Stage('level_1') #The player's ship self.bartender = Bartender() #The dash indicators #group that stores all enemies self.beers = pygame.sprite.Group() #group that stores all powerups self.clients = pygame.sprite.Group() #group for information sprites in the screen, should be rendered the last one self.hud = pygame.sprite.Group() self.font = utils.load_font('saloon.ttf', 20) self.game_started = False self.game_finished = False self.level_finished = False
def __init__(self, director): scene.Scene.__init__(self, director) self.background, rect = utils.load_images("creditscene/background.png") self.font = utils.load_font("FreeSans.ttf", 20) self.program = ["Hugo Ruscitti", "Juanxo", "Dokan", "lacabra25", "Juan Carlos", "thepoi", "joksnet"] self.art = ["Walter Velazquez"] self.rendered_program = self.render_authors(self.program) self.rendered_art = self.render_authors(self.art)
def __init__(self, screen): self.font = utils.load_font('saloon.ttf', 20) self.background, foo = utils.load_image('back.png') self.logo, foo = utils.load_image('logo.png') self.screen = screen self.chosen_option = 0 self.age = 0 self.selected_option = -1 self.events = [] #So the subclasses can inspect input events self.finished = False self.line_height = 60 self.left_margin = 152
def __init__(self, app): logging.info('Initializing game') self.app = app self.chips = pygame.sprite.Group() self.current_consecutive_chips = deque(maxlen=4) self.red_player = objects.RedPlayer() self.yellow_player = objects.YellowPlayer() logging.info('Loading images') self.board_cell_image = utils.load_image('board_cell.png') self.board_cell_highlighted_image = utils.load_image( 'board_cell_highlighted.png') logging.info('Loading sounds') self.sounds_volume = self.app.config.getfloat('connectfour', 'sounds_volume') self.musics_volume = self.app.config.getfloat('connectfour', 'music_volume') self.placed_sound = utils.load_sound('placed.wav', volume=self.sounds_volume) self.column_change_sound = utils.load_sound('column_change.wav', volume=self.sounds_volume) self.column_full_sound = utils.load_sound('column_full.wav', volume=self.sounds_volume) self.win_sound = utils.load_sound('win.wav', volume=self.sounds_volume) self.applause_sound = utils.load_sound('applause.wav', volume=self.sounds_volume) self.boo_sound = utils.load_sound('boo.wav', volume=self.sounds_volume) logging.info('Loading fonts') self.title_font = utils.load_font('monofur.ttf', 22) self.normal_font = utils.load_font('monofur.ttf', 16) self.init_new_game()
def _make_title(self): """Draw the header section.""" # Draw the game title. title = pygame.Surface((self.game_width, self.origin[1]), pygame.SRCALPHA) title.fill((0, 0, 0, 0)) label = self.font.render(self.NAME, True, (119, 110, 101)) title.blit(label, (self.BORDER, (90 - label.get_height()) / 2)) # Draw the label for the objective. label = load_font(self.FONT_NAME, 18).render( 'Join the numbers and get to the %d tile!' % self.WIN_TILE, True, (119, 110, 101)) title.blit(label, (self.BORDER, self.origin[1] - label.get_height() - self.BORDER)) # Draw the new game button and calculate its hitbox. x1, y1 = self.WIDTH - self.BORDER - 100, self.origin[1] - self.BORDER - 28 w, h = 100, 30 pygame.draw.rect(title, (238, 228, 218), (x1, y1, w, h)) label = load_font(self.FONT_NAME, 18).render('New Game', True, (119, 110, 101)) w1, h1 = label.get_size() title.blit(label, (x1 + (w - w1) / 2, y1 + (h - h1) / 2)) # Return the title section and its hitbox. return title, (x1, y1, x1 + w, y1 + h)
def create_font(self): """Create the internal font, using the current settings """ if (self.size): try: self.__m_font = load_font(self.font_filename, self.size) except (Exception, e): print("Error creating font: '%s' using file: '%s'" % (str(e), self.font_filename)) print("Trying with default font") self.__m_font = pygame.font.Font(None, self.size) self.update_surface()
def initialise(self): """this function is called when the program starts. it initializes everything it needs, then runs in a loop until the function returns.""" #Initialize Everything pygame.display.flip() #Load options try: self.options = pickle.load(open('options.p', 'rb')) except: print "No options" self.options = {'Difficulty': 'Hard', 'Music': 'Off'} self.game_paused = False #sounds self.sounds = {} self.sounds['glass'] = utils.load_sound('glass.ogg') self.sounds['throw'] = utils.load_sound('throw.ogg') #Create The Backgound self.background, foo = utils.load_image('back.png') #game variables self.clients_served = 0 self.speed = 50 #the lower the faster self.score = 0 self.mugs = 10 self.time = 0 #to check the stage for clients self.client_score = 500 self.mug_score = 500 #Display The Background self.screen.blit(self.background, (0, 0)) pygame.display.flip() self.level = Stage('level_1') #The player's ship self.bartender = Bartender() #The dash indicators #group that stores all enemies self.beers = pygame.sprite.Group() #group that stores all powerups self.clients = pygame.sprite.Group() #group for information sprites in the screen, should be rendered the last one self.hud = pygame.sprite.Group() self.font = utils.load_font('saloon.ttf', 20) self.game_started = False self.game_finished = False self.level_finished = False
def __init__(self, screen): #sounds self.screen = screen self.age = 0 self.font = utils.load_font('4114blasterc.ttf', 36) self.size = self.screen.get_size() self.menu_finished = False self.background, self.background_rect = utils.load_image('intro_bg_1.jpg') self.parallax, self.parallax_rect = utils.load_image('intro_bg_2.png') self.logo, foo = utils.load_image('intro_logo.png') self.screen.blit(self.background, (0, 0)) pygame.display.flip()
def __init__(self, screen): Abstract_Menu.__init__(self, screen) self.font = utils.load_font('chitown.ttf', 24) self.line_height = 40 self.left_margin = 52 highscores_data = Highscores_data() self.highscores = highscores_data.get_highscores() self.options = [ 'HIGH-SCORES' ] for highscore in self.highscores : self.options.append(highscore['name']+': '+str(highscore['score']))
def __init__(self, screen): ''' Constructor Initialisation of all items and determine position ''' self.screen = screen font_title = utils.load_font("ka1.ttf", 25) font = utils.load_font("monof55.ttf", 20) #font.set_bold(True) title = MenuItem("SQUARES", font_title) startMovesItem = MenuItem("Moves Mode", font) startTimeItem = MenuItem("Time Mode", font) exitItem = MenuItem("Exit", font) self.items = (title, startMovesItem, startTimeItem, exitItem) for i in range(len(self.items)): if i == 0: self.items[i].setPos(screen.get_width()/2, 60) else: colors = ['azzurro','azzurro','green','orange','red'] self.items[i].setPos(screen.get_width()/2, 20*(i+4)) self.items[i].setBackCol(square_colors[colors[i]]) self.over_option = None
def __init__(self, screen): Abstract_Menu.__init__(self, screen) self.font = utils.load_font('saloon.ttf', 16) self.line_height = 40 self.left_margin = 52 highscores_data = Highscores_data() self.highscores = highscores_data.get_highscores() self.options = ['HIGH-SCORES'] for highscore in self.highscores: self.options.append(highscore['name'] + ': ' + str(highscore['score']))
def initialise(self): #Initialize Everything pygame.display.flip() self.game_paused = False #sounds self.sounds = {}; self.sounds['plop'] = utils.load_sound('plop.wav') #Create The Backgound self.background, foo = utils.load_image('background.png') #Display The Background self.screen.blit(self.background, (0, 0)) pygame.display.flip() self.level = Level() self.platforms = pygame.sprite.Group() self.sprites = pygame.sprite.Group() self.hud = pygame.sprite.Group() first_platform_x = False #Load the platforms in the level for i in range(len(self.level.data)-1): self.level.scroll += 1 platforms = self.level.platforms() for platform in platforms: if first_platform_x == False: first_platform_x = platform * self.level.ratio self.platforms.add(Platform(pygame.Rect(platform*self.level.ratio, 640 - self.level.scroll * self.level.y_ratio,10,10))) self.player = Player(self) self.player.rect.left = first_platform_x self.sprites.add(self.player) #game variables self.score = Score_Meter((10,10,10,10)) self.hud.add(self.score) self.font = utils.load_font('chitown.ttf', 20) self.game_started = False self.game_finished = False self.level_finished = False
def __init__(self, song): # Set the font based of the settings in the Song self.font = load_font(song.get_font_filename(), 32) # Make it bold self.font.set_bold(True) # Get a list of all the background self.background_list = self._get_all_backgrounds( song.get_bg_image_dir(), song.get_bg_game_header()) # Set other bg variables self.bg_update_interval_time = song.get_bg_image_interval_ms() self.bg_game_header = song.get_bg_game_header() self.current_bg_index = 0 self.last_bg_update_time = pygame.time.get_ticks() self.background = None # In case there is only one bg file don't animate it self._check_for_static_bg()
def __init__(self, allsprites, game_state, song): sprite.Sprite.__init__(self, allsprites) self.game_state = game_state self.font = load_font(song.get_font_filename(), 36) self.score = 0 # Feel free to play around with these variables # Currently they are not used anywhere in the code self.score_streak = 0 self.score_multiplier = 1 # Required to make sure the first note hits correctly self.played_once = False # Flag to see when a score should be saved after an update self.score_is_saved = True # Required Sprite attributes self.image = self.font.render('', 1, (10, 10, 10)) self.pos = (590, 50) # Set the location of the text self.rect = (self.pos, self.image.get_size())
def __init__(self, x, y, width, height, text, function, type, font_filename, allsprites, game_state): pygame.sprite.Sprite.__init__(self, allsprites) self.game_state = game_state self.allsprites = allsprites self.x = x self.y = y self.enabled = True self.width = width self.height = height self.type = type self.onclick_function = function self.color_text = (255, 255, 255) self.dark_bg_rgb = (4, 2, 3, 170) self.light_bg_rgb = (4, 2, 3, 170) self.font = load_font(font_filename, 30) self.text = self.font.render(text, True, self.color_text) dark_button = pygame.Surface((self.width, self.height), pygame.SRCALPHA, 32) dark_button = dark_button.convert_alpha() dark_button.fill(self.dark_bg_rgb) dark_button.blit(self.text, (22, -2)) self.dark_button = dark_button light_button = pygame.Surface((self.width, self.height), pygame.SRCALPHA, 32) light_button = light_button.convert_alpha() light_button.fill(self.light_bg_rgb) light_button.blit(self.text, (21, -1)) self.light_button = light_button self.image = self.dark_button self.pos = (self.x, self.y) self.rect = (self.pos, (self.width, self.height))
def __init__(self, topleft): Sprite.__init__(self) self.image = None self.topleft = topleft self.font = utils.load_font('GenghisKhan.otf', 22)
def __init__(self, screen): self.screen = screen self.game_paused = False #sounds self.sounds = {}; self.sounds['warning'] = utils.load_sound('warning.wav') self.sounds['powerup'] = utils.load_sound('powerup.wav') #Load explosions a = Explosion(pygame.Rect(0,0,10,10)) #Create The Backgound self.background = Background(self.screen.get_size()) #game variables self.score = Score_Meter((10,10)) #Display The Background self.screen.blit(self.background, (0, 0)) font = utils.load_font('4114blasterc.ttf', 36) text_color = (255,255,255) text = font.render("Initialising", 1, text_color) self.screen.blit(text, (200, 300)) pygame.display.flip() if show_dummies: self.dummy = Dummy() self.dummy2 = Dummy() #The player's ship self.ship = Ship() #The dash indicators self.lifemeter = LifeMeter() self.powerup_speed = SpeedMeter(pygame.Rect(500,400,0,0)) self.powerup_weapon = WeaponMeter(pygame.Rect(540,400,0,0)) self.powerup_buddy = BuddyMeter(pygame.Rect(580,400,0,0)) self.player = pygame.sprite.RenderPlain((self.ship)) self.buddies = pygame.sprite.Group() #self.buddies.add(Buddy(self.ship)) # add a testing buddy #self.ship.buddies += 1 #group that stores all enemies self.enemies = pygame.sprite.Group() self.minibosses = pygame.sprite.Group() #group that stores all powerups self.powerups = pygame.sprite.Group() #group that stores all the lasers the player shoots self.fire = pygame.sprite.Group() #group for information sprites in the screen, should be rendered the last one self.hud = pygame.sprite.Group() self.explosions = pygame.sprite.Group() self.enemylasers = pygame.sprite.Group() self.hud.add(self.lifemeter) self.hud.add(self.score) self.hud.add((self.powerup_speed, self.powerup_weapon, self.powerup_buddy)) if show_dummies: self.hud.add(self.dummy) self.hud.add(self.dummy2) #The level self.level = Stage('level_1') self.font = utils.load_font('4114blasterc.ttf', 36) self.game_started = True self.game_finished = False self.level_finished = False self.scene_finished = False
def update_image(self): font = utils.load_font("FreeSans.ttf", 30) text = "Lines: %d" % (self.lines) self.image, self.image_rect = utils.render_text(text, font) self.image_rect.move_ip(self.rect.x + ((self.rect.w - self.image_rect.w) / 2), self.rect.y + 10)
def __init__(self, director): scene.Scene.__init__(self, director) self.font = utils.load_font("FreeSans.ttf", 30) self.message, rect = utils.render_text("Una linea\nDos\nTres", self.font)
def show_message(self, text): font = utils.load_font("FreeSans.ttf", 14) self.current_message, self.current_message_rect = utils.render_text(text, font)
def create_return_message(self): font = utils.load_font("FreeSans.ttf", 14) text = "Pulse ESC para regresar al menu" self.return_message, rect = utils.render_text(text, font)