diff options
author | Pablo Moleri <pmoleri@gmail.com> | 2010-12-13 19:05:07 (GMT) |
---|---|---|
committer | Pablo Moleri <pmoleri@gmail.com> | 2010-12-13 19:05:07 (GMT) |
commit | 3977733ab901a3a3c6a2027490ef6dea0212cb0a (patch) | |
tree | 4a32334bb11d42f97226e6909a2f17d86c4df962 /Saludame.activity | |
parent | f60352be94bbee1cd57814371e17c01f60f8efad (diff) |
Sound manager added
Make more room in status bars panel
Animation image load method that allows loading full images or difference patches.
Diffstat (limited to 'Saludame.activity')
-rwxr-xr-x | Saludame.activity/animation.py | 38 | ||||
-rw-r--r-- | Saludame.activity/assets/music/sick.ogg | bin | 0 -> 308811 bytes | |||
-rwxr-xr-x | Saludame.activity/game.py | 11 | ||||
-rwxr-xr-x | Saludame.activity/imagepatch.so | bin | 0 -> 5500 bytes | |||
-rwxr-xr-x | Saludame.activity/main_window.py | 2 | ||||
-rwxr-xr-x | Saludame.activity/menu.py | 2 | ||||
-rw-r--r-- | Saludame.activity/sound_manager.py | 57 | ||||
-rwxr-xr-x | Saludame.activity/status_bars.py | 10 |
8 files changed, 102 insertions, 18 deletions
diff --git a/Saludame.activity/animation.py b/Saludame.activity/animation.py index 0637895..75ea11f 100755 --- a/Saludame.activity/animation.py +++ b/Saludame.activity/animation.py @@ -39,6 +39,7 @@ class Kid(Window): self.action_index = -1 # Default action_index (no-action) self.action = None + self.sprite = None self.set_animation() ##### Moods ##### @@ -75,19 +76,16 @@ class Kid(Window): self.index = 0 # Sequence number of the current animation if self.action and self.action.kid_animation_path: # An action with animation is enabled directory = "%s/%s/%s" % (self.action.kid_animation_path, sex, clothes) - dirList = os.listdir(directory) - dirList.sort() - self.file_list = [os.path.join("%s/%s/%s" % (self.action.kid_animation_path, sex, clothes), fname) for fname in dirList if '.png' in fname] + self.file_list = get_image_list(directory) else: directory = "%s/%s/%s" % (self.mood.kid_animation_path, sex, clothes) - dirList = os.listdir(directory) - dirList.sort() - self.file_list = [os.path.join(directory, fname) for fname in dirList if '.png' in fname] + self.file_list = get_image_list(directory) ##### Draw ##### def pre_draw(self, screen): - file = self.file_list[self.index] - self.sprite = pygame.image.load(file) + filename = self.file_list[self.index] + #self.sprite = pygame.image.load(file) + self.sprite = load_animation(self.sprite, filename) maps = self.character.mappings self.change_color(COLORS_HAIR + COLORS_SKIN + COLORS_SOCKS + COLORS_SHOES, maps["hair"] + maps["skin"] + maps["socks"] + maps["shoes"]) @@ -143,6 +141,8 @@ class ActionAnimation(Widget): class FPS: def __init__(self, container, rect, frame_rate, clock): + self.register_id = "" + self.buttons = [] self.rect = rect self.frame_rate = frame_rate self.clock = clock @@ -156,3 +156,25 @@ class FPS: screen.blit(text_surf, self.rect) return [self.rect] +def get_image_list(directory): + dirList = os.listdir(directory) + dirList.sort() + return [os.path.join(directory, fname) for fname in dirList if fname.endswith('.png') or fname.endswith('.diff.gz')] + +import gzip +import imagepatch +def load_animation(last_image, new_filename): + if new_filename.endswith('.png'): + new = pygame.image.load(new_filename) + else: + f = gzip.open(new_filename, 'r') + diff = f.read() + f.close() + + new_buffer = imagepatch.patch(last_image.get_buffer().raw, diff) + + new = last_image # both point to the same surface + new.get_buffer().write(new_buffer, 0) # Instead of using a copy modifies the same surface + + return new +
\ No newline at end of file diff --git a/Saludame.activity/assets/music/sick.ogg b/Saludame.activity/assets/music/sick.ogg Binary files differnew file mode 100644 index 0000000..86a8821 --- /dev/null +++ b/Saludame.activity/assets/music/sick.ogg diff --git a/Saludame.activity/game.py b/Saludame.activity/game.py index 2fd85b2..2db2e6d 100755 --- a/Saludame.activity/game.py +++ b/Saludame.activity/game.py @@ -29,6 +29,7 @@ import customization import app_init import challenges_creator import os +import sound_manager log = logging.getLogger('saludame') log.setLevel(logging.DEBUG) @@ -60,7 +61,10 @@ class Main(): import gtk # Optimizes sound quality and buffer for quick loading - pygame.mixer.pre_init(22050, -16, 8, 256) + pygame.mixer.quit() # When executting from sugar pygame it's already initialized + pygame.mixer.pre_init(22050, -16, 1, 512) + + pygame.mixer.music.set_endevent(pygame.USEREVENT) # Inits PyGame module pygame.init() @@ -95,6 +99,9 @@ class Main(): # Main loop update = True # The first time the screen need to be updated + sound_manager.SoundManager() + sound_manager.instance.set_music("sick") + while running: if from_sugar: @@ -121,6 +128,8 @@ class Main(): self.windows_controller.handle_mouse_down(pygame.mouse.get_pos()) elif event.type == pygame.VIDEOEXPOSE: self.windows_controller.reload_main = True + elif event.type == pygame.USEREVENT and event.code == 0: # Music ended + sound_manager.instance.start_playing() self.windows_controller.handle_mouse_over(pygame.mouse.get_pos()) diff --git a/Saludame.activity/imagepatch.so b/Saludame.activity/imagepatch.so Binary files differnew file mode 100755 index 0000000..6964773 --- /dev/null +++ b/Saludame.activity/imagepatch.so diff --git a/Saludame.activity/main_window.py b/Saludame.activity/main_window.py index 46c3901..48d7c13 100755 --- a/Saludame.activity/main_window.py +++ b/Saludame.activity/main_window.py @@ -28,7 +28,7 @@ class MainWindow(Window): self.windows.append(self.kidW) #self.windows.append(animation.Apple(pygame.Rect((700, 90), (150, 172)), 10)) - #self.windows.append(animation.FPS(container, pygame.Rect((1100, 550), (50, 20)), 15, self.clock)) + self.windows.append(animation.FPS(container, pygame.Rect((1150, 0), (50, 20)), 15, self.clock)) self.windows.append(status_bars.BarsWindow(container, pygame.Rect(0, 0, 227, 590), 5, windows_controller, bars_loader)) self.add_child(Clock(container, pygame.Rect(0, 528, 1, 1), 1, game_man)) diff --git a/Saludame.activity/menu.py b/Saludame.activity/menu.py index 816436d..c1d83ea 100755 --- a/Saludame.activity/menu.py +++ b/Saludame.activity/menu.py @@ -231,7 +231,7 @@ class Menu(Window): self.__calculate_items_position(self.actual_selection) def __calculate_items_position(self, item_list): - if(len(item_list) > 0): + if len(item_list) > 0: angle = (2 * math.pi) / len(item_list) else: angle = 0 diff --git a/Saludame.activity/sound_manager.py b/Saludame.activity/sound_manager.py new file mode 100644 index 0000000..a07ec54 --- /dev/null +++ b/Saludame.activity/sound_manager.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- + +import pygame + +music = { + "happy": "assets/music/sick.ogg", + "normal": "assets/music/sick.ogg", + "sad": "assets/music/sick.ogg", + "angry": "assets/music/sick.ogg", + "sick": "assets/music/sick.ogg", +} + +instance = None + +class SoundManager: + + IDLE = 0 + PLAYING = 1 + FADE_OUT = 2 + FADE_IN = 3 + + def __init__(self): + global instance + instance = self + + self.current_music_name = "" + self.next_music_name = "" + self.state = SoundManager.IDLE + + def set_music(self, name): + if self.state == SoundManager.IDLE: + self.current_music_name = name + self.state = SoundManager.PLAYING + self.start_playing() + + if self.state == SoundManager.PLAYING: + if name <> self.current_music_name: + self.state = FADE_OUT + self.next_music_name = name + + elif self.state == SoundManager.FADE_OUT: + if name == self.current_music_name: + self.state = FADE_IN + self.next_music_name = "" + else: + self.next_music_name = name + + elif self.state == SoundManager.FADE_IN: + if name <> self.current_music_name: + self.state = FADE_OUT + self.next_music_name = name + + def start_playing(self): + global music + path = music[self.current_music_name] + pygame.mixer.music.load(path) + pygame.mixer.music.play() diff --git a/Saludame.activity/status_bars.py b/Saludame.activity/status_bars.py index ed3bdd5..000fcd2 100755 --- a/Saludame.activity/status_bars.py +++ b/Saludame.activity/status_bars.py @@ -10,7 +10,7 @@ import game_manager SECTION_OFFSET_X = 0 SECTION_WIDTH = 220 -SECTION_MIN_HEIGHT = 52 +SECTION_MIN_HEIGHT = 50 SECTION_TOP_PADDING = 18 BAR_OFFSET_X = 30 @@ -55,7 +55,7 @@ class BarsWindow(Window): y = 50 self.overall_section = BarSection(windows_controller, self.rect, _(u"TOTAL"), bars_loader.get_overall_bar(), [] , (SECTION_WIDTH, SECTION_MIN_HEIGHT), (SECTION_OFFSET_X, y), "assets/layout/icon_total.png") - y = 120 + y = 110 self.physica_section = BarSection(windows_controller, self.rect, _(u"ESTADO FĂSICO"), self.bars[0], self.bars[0].children_list, (SECTION_WIDTH, SECTION_MIN_HEIGHT), (SECTION_OFFSET_X, y), "assets/layout/icon_physica.png") y += SECTION_MIN_HEIGHT @@ -244,13 +244,9 @@ class BarSection(Window): display_list = [] for status_bar in self.children_bar: width = self.rect.width - display = BarDisplay(BAR_HEIGHT, width, (BAR_OFFSET_X, 1), status_bar, SUB_BAR_PARTITIONS) + display = BarDisplay(BAR_HEIGHT, width, (BAR_OFFSET_X, 0), status_bar, SUB_BAR_PARTITIONS) display_list.append(display) return display_list - - #def draw(self, screen, frames): - #screen.fill((0,0,0), self.rect) - #return [] class BarDisplay(Widget): """ |