diff options
author | Walter Bender <walter.bender@gmail.com> | 2012-04-26 15:04:27 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2012-04-26 15:04:27 (GMT) |
commit | fc7a9dd034da7547fc12899a324d98463dec1bb1 (patch) | |
tree | 5aac8a2f34975a0078108a968b6989b5b3f8fe36 | |
parent | 524fbf2015e5398877d228ac4d6489aa5a26cbd6 (diff) |
refactoring to use less memory
-rw-r--r-- | VisualMatchActivity.py | 32 | ||||
-rw-r--r-- | card.py | 43 | ||||
-rw-r--r-- | constants.py | 1 | ||||
-rw-r--r-- | deck.py | 66 | ||||
-rw-r--r-- | game.py | 237 |
5 files changed, 209 insertions, 170 deletions
diff --git a/VisualMatchActivity.py b/VisualMatchActivity.py index d6f7ebc..e490e02 100644 --- a/VisualMatchActivity.py +++ b/VisualMatchActivity.py @@ -91,7 +91,7 @@ class VisualMatchActivity(activity.Activity): def __init__(self, handle): ''' Initialize the Sugar activity ''' super(VisualMatchActivity, self).__init__(handle) - + self.ready_to_play = False self._prompt = '' self._read_journal_data() self._setup_toolbars(_NEW_SUGAR_SYSTEM) @@ -101,6 +101,7 @@ class VisualMatchActivity(activity.Activity): if not hasattr(self, '_saved_state'): self._saved_state = None self.vmw.new_game(self._saved_state, self._deck_index) + self.ready_to_play = True if self._saved_state == None: # Launch animated help self.vmw.help_animation() @@ -117,12 +118,13 @@ class VisualMatchActivity(activity.Activity): if self.vmw.joiner(): # joiner cannot change level return self.vmw.card_type = card_type - self._prompt = PROMPT_DICT[card_type] - self._notify_new_game(self._prompt) - if card_type == 'custom' and self.vmw.custom_paths[0] is None: - self.image_import_cb() - else: - self.vmw.new_game() + if self.ready_to_play: + self._prompt = PROMPT_DICT[card_type] + self._notify_new_game(self._prompt) + if card_type == 'custom' and self.vmw.custom_paths[0] is None: + self.image_import_cb() + else: + self.vmw.new_game() def _robot_cb(self, button=None): ''' Toggle robot assist on/off ''' @@ -141,13 +143,15 @@ class VisualMatchActivity(activity.Activity): if self.vmw.joiner(): # joiner cannot change level return self.vmw.level = level - self._notify_new_game(self._prompt) + if self.ready_to_play: + self._notify_new_game(self._prompt) self.set_level_label() def set_level_label(self): self.level_label.set_text(self.calc_level_label(self.vmw.low_score, self.vmw.level)) - self.vmw.new_game() + if self.ready_to_play: + self.vmw.new_game() def calc_level_label(self, low_score, play_level): ''' Show the score. ''' @@ -173,8 +177,9 @@ class VisualMatchActivity(activity.Activity): return self.vmw.numberO = numberO self.vmw.card_type = 'number' - self._notify_new_game(self._prompt) - self.vmw.new_game() + if self.ready_to_play: + self._notify_new_game(self._prompt) + self.vmw.new_game() def _number_card_C_cb(self, button, numberC): ''' Choose between C-card list for numbers game. ''' @@ -182,8 +187,9 @@ class VisualMatchActivity(activity.Activity): return self.vmw.numberC = numberC self.vmw.card_type = 'number' - self._notify_new_game(self._prompt) - self.vmw.new_game() + if self.ready_to_play: + self._notify_new_game(self._prompt) + self.vmw.new_game() def _robot_time_spin_cb(self, button): ''' Set delay for robot. ''' @@ -26,16 +26,19 @@ from sprites import Sprite class Card: ''' Individual cards ''' - - def __init__(self, sprites, string, attributes, file_path=None, - scale=1.0): + def __init__(self, scale=1.0): ''' Create the card and store its attributes ''' - if attributes[0] == SELECTMASK: - self.spr = Sprite(sprites, 0, 0, svg_str_to_pixbuf(string)) - self.index = SELECTMASK - elif attributes[0] == MATCHMASK: - self.spr = Sprite(sprites, 0, 0, svg_str_to_pixbuf(string)) - self.index = MATCHMASK + self.spr = None + self.index = None # Calculated index + self._scale = scale + + def create(self, string, attributes=None, sprites=None, file_path=None): + if attributes is None: + if self.spr is None: + self.spr = Sprite(sprites, 0, 0, svg_str_to_pixbuf(string)) + else: + self.spr.set_image(svg_str_to_pixbuf(string)) + self.index = None else: self.shape = attributes[0] self.color = attributes[1] @@ -45,20 +48,28 @@ class Card: self.color * NUMBER * FILLS + \ self.num * FILLS + \ self.fill - self.spr = Sprite(sprites, 0, 0, svg_str_to_pixbuf(string)) + if self.spr is None: + self.spr = Sprite(sprites, 0, 0, svg_str_to_pixbuf(string)) + else: + self.spr.set_image(svg_str_to_pixbuf(string)) + if file_path is not None: - self.spr.set_image(load_image(file_path, scale), i=1, - dx=int(scale * CARD_WIDTH * .125), - dy=int(scale * CARD_HEIGHT * .125)) + self.spr.set_image(load_image(file_path, self._scale), i=1, + dx=int(self._scale * CARD_WIDTH * .125), + dy=int(self._scale * CARD_HEIGHT * .125)) + self.spr.set_label_attributes(self._scale * 24) + self.spr.set_label('') def show_card(self): ''' Show the card ''' - self.spr.set_layer(2000) - self.spr.draw() + if self.spr is not None: + self.spr.set_layer(2000) + self.spr.draw() def hide_card(self): ''' Hide a card ''' - self.spr.hide() + if self.spr is not None: + self.spr.hide() def svg_str_to_pixbuf(string): diff --git a/constants.py b/constants.py index ba488a5..9cdddb7 100644 --- a/constants.py +++ b/constants.py @@ -17,6 +17,7 @@ SHAPES = 3 COLORS = 3 NUMBER = 3 FILLS = 3 +CARDS_IN_A_MATCH = 3 DECKSIZE = SHAPES * COLORS * NUMBER * FILLS DEAL = 12 EXTRAS = 3 @@ -25,11 +25,16 @@ from gencards import generate_pattern_card, generate_number_card, \ class Deck: """ Class for defining deck of card """ - def __init__(self, sprites, card_type, numbers_type, lists, scale, - level=HIGH): - """ Create the deck of cards. - 'lists' is either a list of words or paths """ - self.cards = [] + def __init__(self, cards, scale=1.0): + self.cards = cards + self.index = 0 + self._scale = scale + self._number_of_cards = 0 + + def create(self, sprites, card_type, numbers_type, lists, level=HIGH): + """ Create the deck of cards. 'lists' is either a list of + words or paths""" + # If level is 'simple', only generate one fill type shape_range = SHAPES color_range = COLORS @@ -40,6 +45,7 @@ class Deck: elif level == LOW: fill_range = 1 shape_range = 1 + # Initialize the deck of cards by looping through all the patterns i = 0 for shape in range(0, shape_range): @@ -47,46 +53,46 @@ class Deck: for color in range(0, color_range): for num in range(0, number_range): i = self._make(sprites, card_type, numbers_type, i, - lists, scale, shape, color, num, fill) + lists, shape, color, num, fill) + self._number_of_cards = i # Remember the current position in the deck. self.index = 0 - def _make(self, sprites, card_type, numbers_type, i, lists, scale, shape, + def _make(self, sprites, card_type, numbers_type, i, lists, shape, color, num, fill): if card_type == 'pattern': - self.cards.append(Card(sprites, generate_pattern_card(shape, color, - num, fill, scale), [shape, color, num, fill])) + self.cards[i].create( + generate_pattern_card(shape, color, num, fill, self._scale), + sprites=sprites, attributes=[shape, color, num, fill]) elif card_type == 'number': - self.cards.append(Card(sprites, generate_number_card(shape, color, - num, fill, numbers_type, scale), [shape, color, num, fill])) + self.cards[i].create( + generate_number_card( + shape, color, num, fill, numbers_type, self._scale), + sprites=sprites, attributes=[shape, color, num, fill]) elif card_type == 'custom': if len(lists) == 9: index = shape * 3 + num else: index = i - self.cards.append(Card(sprites, generate_word_card(shape, color, - num, fill, scale), [shape, color, num, fill], - file_path=lists[index], scale=scale)) - i += 1 + self.cards[i].create( + generate_word_card(shape, color, num, fill, self._scale), + sprites=sprites, attributes=[shape, color, num, fill], + file_path=lists[index]) else: - self.cards.append(Card(sprites, generate_word_card(shape, color, - num, fill, scale), [shape, color, num, fill])) - self.cards[len(self.cards) - 1].spr.set_label(lists[shape][num]) - self.cards[len(self.cards) - 1].spr.set_label_attributes( - scale * 24) + self.cards[i].create( + generate_word_card(shape, color, num, fill, self._scale), + sprites=sprites, attributes=[shape, color, num, fill]) + self.cards[i].spr.set_label(lists[shape][num]) if fill == 0: - self.cards[len(self.cards) - 1].spr.set_font('Sans Bold') - self.cards[len(self.cards) - 1].spr.set_label_color( - COLOR_PAIRS[color][0]) + self.cards[i].spr.set_font('Sans Bold') + self.cards[i].spr.set_label_color(COLOR_PAIRS[color][0]) elif fill == 1: - self.cards[len(self.cards) - 1].spr.set_label_color( - COLOR_PAIRS[color][1]) + self.cards[i].spr.set_label_color(COLOR_PAIRS[color][1]) elif fill == 2: - self.cards[len(self.cards) - 1].spr.set_font('Sans Italic') - self.cards[len(self.cards) - 1].spr.set_label_color( - COLOR_PAIRS[color][1]) - return i + self.cards[i].spr.set_font('Sans Italic') + self.cards[i].spr.set_label_color(COLOR_PAIRS[color][1]) + return i + 1 def shuffle(self): """ Shuffle the deck (Knuth algorithm). """ @@ -163,4 +169,4 @@ class Deck: def count(self): """ Return the length of the deck. """ - return len(self.cards) + return self._number_of_cards @@ -41,7 +41,8 @@ except ImportError: from constants import LOW, MEDIUM, HIGH, MATCHMASK, ROW, COL, \ WORD_CARD_INDICIES, DEAD_DICTS, DEAD_KEYS, WHITE_SPACE, \ NOISE_KEYS, WORD_CARD_MAP, KEYMAP, CARD_HEIGHT, CARD_WIDTH, DEAL, \ - DIFFICULTY_LEVEL, BACKGROUNDMASK, DECKSIZE, CUSTOM_CARD_INDICIES + DIFFICULTY_LEVEL, BACKGROUNDMASK, DECKSIZE, CUSTOM_CARD_INDICIES, \ + SHAPES, COLORS, NUMBER, FILLS, CARDS_IN_A_MATCH from grid import Grid from deck import Deck @@ -137,7 +138,7 @@ class Game(): self._press = None self.matches = 0 self.robot_matches = 0 - self._match_display_area = [] + self._match_area = [] self._matches_on_display = False self._smiley = [] self._frowny = [] @@ -163,71 +164,70 @@ class Game(): self.level = 0 self.card_type = 'pattern' self.buddies = [] + self._the_game_is_over = False + + self.grid = Grid(self._width, self._height, self._card_width, + self._card_height) + + self._cards = [] + for i in range(DECKSIZE): + self._cards.append(Card(scale=self._scale)) + + self.deck = Deck(self._cards, scale=self._scale) + + for i in range(CARDS_IN_A_MATCH): + self.clicked.append(Click()) + self._match_area.append(Card(scale=self._scale)) + self._match_area[-1].create( + generate_match_card(self._scale), sprites=self._sprites) + self._match_area[-1].spr.move(self.grid.match_to_xy(i)) + + for i in range((ROW - 1) * COL): + self._smiley.append(Card(scale=self._scale)) + self._smiley[-1].create( + generate_smiley(self._scale), sprites=self._sprites) + self._smiley[-1].spr.move(self.grid.grid_to_xy(i)) + self._smiley.append(Card(scale=self._scale)) + self._smiley[-1].create( + generate_smiley(self._scale), sprites=self._sprites) + self._smiley[-1].spr.move(self.grid.match_to_xy(3)) + self._smiley[-1].spr.hide() + + # A different frowny face for each type of error + self._frowny.append(Card(self._scale)) + self._frowny[-1].create( + generate_frowny_shape(self._scale), sprites=self._sprites) + self._frowny[-1].spr.move(self.grid.match_to_xy(3)) + self._frowny.append(Card(self._scale)) + self._frowny[-1].create( + generate_frowny_color(self._scale), sprites=self._sprites) + self._frowny[-1].spr.move(self.grid.match_to_xy(3)) + self._frowny.append(Card(self._scale)) + self._frowny[-1].create( + generate_frowny_texture(self._scale), sprites=self._sprites) + self._frowny[-1].spr.move(self.grid.match_to_xy(3)) + self._frowny.append(Card(self._scale)) + self._frowny[-1].create( + generate_frowny_number(self._scale), sprites=self._sprites) + self._frowny[-1].spr.move(self.grid.match_to_xy(3)) def new_game(self, saved_state=None, deck_index=0): ''' Start a new game ''' # If we were editing the word list, time to stop + self.grid.stop_animation = True self.editing_word_list = False self.editing_custom_cards = False self._edit_card = None + self._saved_state = saved_state + self._deck_index = deck_index + # Wait for any animations to stop before starting new game + timeout = gobject.timeout_add(200, self._prepare_new_game) + def _prepare_new_game(self): # If there is already a deck, hide it. if hasattr(self, 'deck'): self.deck.hide() - # The first time through, initialize the grid, and overlays. - if not hasattr(self, 'grid'): - self.grid = Grid(self._width, self._height, self._card_width, - self._card_height) - - for i in range(3): - self.clicked.append(Click()) - - for i in range(3): - self._match_display_area.append(Card(self._sprites, - generate_match_card(self._scale), - [MATCHMASK, 0, 0, 0])) - self._match_display_area[-1].spr.move(self.grid.match_to_xy(i)) - - for i in range((ROW - 1) * COL): - self._smiley.append( - Card(self._sprites, generate_smiley(self._scale), - [BACKGROUNDMASK, 0, 0, 0])) - self._smiley[-1].spr.move(self.grid.grid_to_xy(i)) - self._smiley.append(Card(self._sprites, - generate_smiley(self._scale), - [BACKGROUNDMASK, 0, 0, 0])) - self._smiley[-1].spr.move(self.grid.match_to_xy(3)) - self._smiley[-1].spr.hide() - - # A different frowny face for each type of error - self._frowny.append( - Card(self._sprites, generate_frowny_shape(self._scale), - [BACKGROUNDMASK, 0, 0, 0])) - self._frowny[-1].spr.move(self.grid.match_to_xy(3)) - self._frowny.append( - Card(self._sprites, generate_frowny_color(self._scale), - [BACKGROUNDMASK, 0, 0, 0])) - self._frowny[-1].spr.move(self.grid.match_to_xy(3)) - self._frowny.append( - Card(self._sprites, generate_frowny_texture(self._scale), - [BACKGROUNDMASK, 0, 0, 0])) - self._frowny[-1].spr.move(self.grid.match_to_xy(3)) - self._frowny.append( - Card(self._sprites, generate_frowny_number(self._scale), - [BACKGROUNDMASK, 0, 0, 0])) - self._frowny[-1].spr.move(self.grid.match_to_xy(3)) - - if self._sugar: - for i in range(22): - path = os.path.join(activity.get_bundle_path(), - 'images', 'help-%d.svg' % i) - svg_str = svg_from_file(path) - pixbuf = svg_str_to_pixbuf(svg_str, int(self._width), - int(self._height)) - self._help.append(Sprite(self._sprites, 0, 0, pixbuf)) - self._help[-1].hide() - for c in self.clicked: c.hide() @@ -236,39 +236,40 @@ class Game(): c.spr.hide() self._smiley[-1].spr.hide() - if saved_state is not None: - _logger.debug('Restoring state: %s' % (str(saved_state))) + if self._saved_state is not None: + _logger.debug('Restoring state: %s' % (str(self._saved_state))) if self.card_type == 'custom': - self.deck = Deck(self._sprites, self.card_type, - [self.numberO, self.numberC], self.custom_paths, - self._scale, DIFFICULTY_LEVEL[self.level]) + self.deck.create(self._sprites, self.card_type, + [self.numberO, self.numberC], + self.custom_paths, + DIFFICULTY_LEVEL[self.level]) else: - self.deck = Deck(self._sprites, self.card_type, - [self.numberO, self.numberC], self.word_lists, - self._scale, DIFFICULTY_LEVEL[self.level]) + self.deck.create(self._sprites, self.card_type, + [self.numberO, self.numberC], self.word_lists, + DIFFICULTY_LEVEL[self.level]) self.deck.hide() - self.deck.index = deck_index + self.deck.index = self._deck_index deck_start = ROW * COL + 3 deck_stop = deck_start + self.deck.count() - self._restore_word_list(saved_state[deck_stop + \ - 3 * self.matches:]) - self.deck.restore(saved_state[deck_start: deck_stop]) - self.grid.restore(self.deck, saved_state[0: ROW * COL]) - self._restore_matches(saved_state[deck_stop: deck_stop + \ + self._restore_word_list(self._saved_state[deck_stop + \ + 3 * self.matches:]) + self.deck.restore(self._saved_state[deck_start: deck_stop]) + self.grid.restore(self.deck, self._saved_state[0: ROW * COL]) + self._restore_matches(self._saved_state[deck_stop: deck_stop + \ 3 * self.matches]) - self._restore_clicked(saved_state[ROW * COL: ROW * COL + 3]) + self._restore_clicked(self._saved_state[ROW * COL: ROW * COL + 3]) elif not self.joiner(): _logger.debug('Starting new game.') if self.card_type == 'custom': - self.deck = Deck(self._sprites, self.card_type, + self.deck.create(self._sprites, self.card_type, [self.numberO, self.numberC], - self.custom_paths, self._scale, + self.custom_paths, DIFFICULTY_LEVEL[self.level]) else: - self.deck = Deck(self._sprites, self.card_type, + self.deck.create(self._sprites, self.card_type, [self.numberO, self.numberC], self.word_lists, - self._scale, DIFFICULTY_LEVEL[self.level]) + DIFFICULTY_LEVEL[self.level]) self.deck.hide() self.deck.shuffle() self.grid.deal(self.deck) @@ -284,6 +285,9 @@ class Game(): self.activity._send_event('J') self._update_labels() + + self._the_game_is_over = False + if self._game_over(): if hasattr(self, 'timeout_id') and self.timeout_id is not None: gobject.source_remove(self.timeout_id) @@ -329,10 +333,9 @@ class Game(): if len(self.custom_paths) < 3: for i in range(len(self.custom_paths), 81): self.custom_paths.append(None) - self.deck = Deck(self._sprites, self.card_type, - [self.numberO, self.numberC], - self.custom_paths, - self._scale, DIFFICULTY_LEVEL.index(HIGH)) + self.deck.create(self._sprites, self.card_type, + [self.numberO, self.numberC], self.custom_paths, + DIFFICULTY_LEVEL.index(HIGH)) self.deck.hide() self.matches = 0 self.robot_matches = 0 @@ -361,9 +364,9 @@ class Game(): c.hide() self.deck.hide() self.card_type = 'word' - self.deck = Deck(self._sprites, self.card_type, + self.deck.create(self._sprites, self.card_type, [self.numberO, self.numberC], self.word_lists, - self._scale, DIFFICULTY_LEVEL.index(HIGH)) + DIFFICULTY_LEVEL.index(HIGH)) self.deck.hide() self.matches = 0 self.robot_matches = 0 @@ -387,6 +390,10 @@ class Game(): # Turn off help animation self._stop_help = True + # Don't do anything if the game is over + if self._the_game_is_over: + return + # Keep track of starting drag position. x, y = map(int, event.get_coords()) self._drag_pos = [x, y] @@ -581,7 +588,7 @@ class Game(): i = self._where_in_clicked(spr) if x < self.grid.left: # Moving a card to the match area self.grid.grid[self.grid.spr_to_grid(spr)] = None - spr.move(self._match_display_area[i].spr.get_xy()) + spr.move(self._match_area[i].spr.get_xy()) else: # Shuffle positions in match area j = self.grid.xy_to_grid((x, y)) k = self.grid.xy_to_grid(self.clicked[i].pos) @@ -616,10 +623,9 @@ class Game(): self._edit_card = self.deck.spr_to_card(spr) self._choose_custom_card() # Regenerate the deck with the new card definitions - self.deck = Deck(self._sprites, self.card_type, + self.deck.create(self._sprites, self.card_type, [self.numberO, self.numberC], - self.custom_paths, self._scale, - DIFFICULTY_LEVEL[1]) + self.custom_paths, DIFFICULTY_LEVEL[1]) self.deck.hide() self.grid.restore(self.deck, CUSTOM_CARD_INDICIES) elif self._none_in_clicked() == None: @@ -682,14 +688,14 @@ class Game(): self._smiley[i].show_card() self.match_timeout_id = gobject.timeout_add( 2000, self._show_matches, 0) - return True + self._the_game_is_over = True elif self.grid.cards_in_grid() == DEAL + 3 \ and not self._find_a_match(): self.set_label('deck', '') self.set_label('clock', '') self.set_label('status', _('unsolvable')) - return True - return False + self._the_game_is_over = True + return self._the_game_is_over def _test_for_a_match(self): ''' If we have a match, then we have work to do. ''' @@ -922,13 +928,6 @@ class Game(): for i in saved_match_list_indices: if i is not None: self.match_list.append(self.deck.index_to_card(i).spr) - ''' - if self.matches > 0: - l = len(self.match_list) - for j in range(3): - self.grid.display_match(self.match_list[l - 3 + j], j) - self._matches_on_display = True - ''' def _restore_word_list(self, saved_word_list): ''' Restore the word list upon resume or share. ''' @@ -954,9 +953,11 @@ class Game(): def _show_matches(self, i): ''' Show all the matches as a simple animation. ''' - if i < self.matches: - for j in range(3): - self.grid.display_match(self.match_list[i * 3 + j], j) + if i < self.matches and \ + i * CARDS_IN_A_MATCH < len(self.match_list): + for j in range(CARDS_IN_A_MATCH): + self.grid.display_match( + self.match_list[i * CARDS_IN_A_MATCH + j], j) self.match_timeout_id = gobject.timeout_add( 2000, self._show_matches, i + 1) @@ -971,13 +972,12 @@ class Game(): self._smiley[-1].spr.hide() self._matches_on_display = False else: - for j in range(3): - if self.clicked[j].spr is not None: - k = self.grid.xy_to_grid(self.clicked[j].pos) - self.clicked[j].spr.move(self.clicked[j].pos) - self.grid.grid[k] = self.deck.spr_to_card( - self.clicked[j].spr) - self.clicked[j].reset() + for c in self.clicked: + if c.spr is not None: + i = self.grid.xy_to_grid(c.pos) + c.spr.move(c.pos) + self.grid.grid[i] = self.deck.spr_to_card(c.spr) + c.reset() a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] for i in Permutation(a): # TODO: really should be combination @@ -986,22 +986,26 @@ class Game(): self.grid.grid[i[2]]] if self._match_check(cardarray, self.card_type): if robot_match: - # Turn off any current animations + # Stop animations before moving robot match self.grid.stop_animation = True - # Wait to move robot match to match area - timeout = gobject.timeout_add(200, self._robot_match, i) + self._robot_match(i) return True return False def _robot_match(self, i): ''' Robot finds a match ''' - for j in range(3): - self.clicked[j].spr = self.grid.grid[i[j]].spr - self.grid.grid[i[j]].spr.move( - self.grid.match_to_xy(j)) + for j in range(CARDS_IN_A_MATCH): + # WARNING: Sometimes there is a race condition between the + # robot delay and shoing a robot match. + if self.grid.grid[i[j]] is not None: + self.clicked[j].spr = self.grid.grid[i[j]].spr + self.grid.grid[i[j]].spr.move(self.grid.match_to_xy(j)) + else: + _logger.debug('in robot match, grid[%d] is None' % (i[j])) self.grid.grid[i[j]] = None self.robot_matches += 1 self._test_for_a_match() + self._smiley[-1].spr.set_layer(100) self._matches_on_display = True def _match_check(self, cardarray, card_type): @@ -1122,6 +1126,16 @@ class Game(): def help_animation(self): ''' Simple explanatory animation at start of play ''' + for i in range(22): + path = os.path.join(activity.get_bundle_path(), + 'images', 'help-%d.svg' % i) + svg_str = svg_from_file(path) + pixbuf = svg_str_to_pixbuf(svg_str, int(self._width / 2), + int(self._height / 2)) + self._help.append(Sprite(self._sprites, int(self._width / 4), + int(self._height / 4), pixbuf)) + self._help[-1].hide() + self._help_index = 0 self._stop_help = False self._help[self._help_index].set_layer(5000) @@ -1131,6 +1145,7 @@ class Game(): ''' Load the next frame in the animation ''' self._help[self._help_index].hide() if self._stop_help: + self._help = [] return self._help_index += 1 self._help_index %= len(self._help) |