diff options
author | Pablo Moleri <pmoleri@gmail.com> | 2010-12-01 22:38:59 (GMT) |
---|---|---|
committer | Pablo Moleri <pmoleri@gmail.com> | 2010-12-01 22:38:59 (GMT) |
commit | 3a83d30923a0659b11f730d485ad6371c068bc25 (patch) | |
tree | cbd4fc769977705ee3839035c60542734add1a0a | |
parent | 56814a5676072cfb802637433df9ff938e9e640e (diff) |
Fix exposure problem when executing in sugar.
Logic now supports multiple Events of the same type.
-rwxr-xr-x | Saludame.activity/app_init.py | 15 | ||||
-rw-r--r-- | Saludame.activity/assets/events/unkown.png | bin | 0 -> 1358 bytes | |||
-rwxr-xr-x | Saludame.activity/game.py | 6 | ||||
-rwxr-xr-x | Saludame.activity/game_manager.py | 89 | ||||
-rwxr-xr-x | Saludame.activity/main_window.py | 2 | ||||
-rwxr-xr-x | Saludame.activity/status_bars.py | 12 | ||||
-rwxr-xr-x | Saludame.activity/sugargame/event.py | 8 | ||||
-rwxr-xr-x | Saludame.activity/windows_controller.py | 2 |
8 files changed, 76 insertions, 58 deletions
diff --git a/Saludame.activity/app_init.py b/Saludame.activity/app_init.py index d8c933a..e1519f4 100755 --- a/Saludame.activity/app_init.py +++ b/Saludame.activity/app_init.py @@ -95,7 +95,7 @@ class AppLoader: event = events.PersonalEvent("caries.jpg", None, "caries", _("Caries"), 5, 15, "personal", probability, effect, "Me duele una muela", 5, 50) _events.append(event) - probability = [] + probability = [("overall_bar", "constant", 100.0, 15.0)] effect = effects.Effect(bars_controller, [("nutrition", -0.3), ("energy", -1.0), ("resistencia", -0.9), ("fat", -0.5)]) event = events.PersonalEvent("ill.jpg", "assets/events/stomach_ache", "stomach_ache", _("Stomach ache"), 5, 15, "personal", probability, effect, "Me duele la panza! :(", 2, 50) _events.append(event) @@ -105,14 +105,17 @@ class AppLoader: probability = [("b_teeth", "indirect", 50.0, 70.0), ("dulces", "direct", 75.0, 30.0)] #editar parametros: - event = events.SocialEvent("caries.jpg", "assets/characters/teacher.png", "p_caries", _("Prevenir caries"), 5.0, 15, probability, u"Deberías lavarte los \ndientes", 100) + event = events.SocialEvent("caries.jpg", "assets/characters/teacher.png", "p_caries", _("Prevenir caries"), 5.0, 20, probability, u"Deberías lavarte los \ndientes", 100) _events.append(event) - #(picture, person_path, name, description, appereance_probability, time_span, condicioned_bars, message, message_time_span) - probability = [("responsability", "indirect", 50.0, 70.0)] - event = events.SocialEvent("unkown.png", "assets/characters/teacher.png", "study", _("Estudiar"), 5.0, 15, probability, u"¿Hiciste los deberes?", 100) + probability = [("responsability", "indirect", 60.0, 70.0)] + event = events.SocialEvent("unkown.png", "assets/characters/teacher.png", "study", _("Estudiar"), 5.0, 20, probability, u"¿Hiciste los deberes?", 100) _events.append(event) - + + probability = [("responsability", "indirect", 70.0, 70.0)] + event = events.SocialEvent("unkown.png", "assets/characters/teacher.png", "health_check", _("Control médico"), 5.0, 30, probability, u"¿Este año fuiste al doctor?", 100) + _events.append(event) + return _events def __load_moods(self): diff --git a/Saludame.activity/assets/events/unkown.png b/Saludame.activity/assets/events/unkown.png Binary files differnew file mode 100644 index 0000000..fbf3f3d --- /dev/null +++ b/Saludame.activity/assets/events/unkown.png diff --git a/Saludame.activity/game.py b/Saludame.activity/game.py index 8af49d1..0523195 100755 --- a/Saludame.activity/game.py +++ b/Saludame.activity/game.py @@ -56,8 +56,6 @@ class Main(): """ global running, pauses - print "A" - if from_sugar: import gtk @@ -76,8 +74,6 @@ class Main(): pygame.display.update() - print "B" - # This clock is used to keep the game at the desired FPS. clock = pygame.time.Clock() @@ -119,6 +115,8 @@ class Main(): running = False elif event.type == pygame.MOUSEBUTTONDOWN: self.windows_controller.handle_mouse_down(pygame.mouse.get_pos()) + elif event.type == pygame.VIDEOEXPOSE: + self.windows_controller.reload_main = True self.windows_controller.handle_mouse_over(pygame.mouse.get_pos()) diff --git a/Saludame.activity/game_manager.py b/Saludame.activity/game_manager.py index 12453ea..3992e2d 100755 --- a/Saludame.activity/game_manager.py +++ b/Saludame.activity/game_manager.py @@ -43,8 +43,8 @@ class GameManager: #character states self.active_char_action = None #Active character action, Action instance - self.active_event = None - self.active_social_event = None + self.active_events = [] + self.active_social_events = [] self.active_mood = None self.__check_active_mood() # sets active_mood @@ -195,9 +195,9 @@ class GameManager: self.active_char_action = None self.windows_controller.stop_actual_action_animation() - if(action_id): + if action_id: action = self.get_action(action_id) - if(action): + if action: self.active_char_action = action def add_background_action(self, action_id): @@ -205,7 +205,7 @@ class GameManager: Add a background action. """ action = self.get_action(action_id) - if(action): + if action: self.background_actions.append(action) def get_active_action(self): @@ -263,20 +263,22 @@ class GameManager: overall_bar_percent = self.bars_controller.get_overall_percent() overall_bar_mood = 9 # set in normal mood - if(overall_bar_percent < 0.33): + if overall_bar_percent < 0.33: overall_bar_mood = 5 #set mood in sad grade 1 - elif(overall_bar_percent > 0.66): + elif overall_bar_percent > 0.66: overall_bar_mood = 10 #set mood in happy 3 - if(self.active_event): - event_preferred_mood = self.active_event.preferred_mood + event_preferred_moods = [event.preferred_mood for event in self.active_events] + #event_preferred_moods += [event.preferred_mood for event in self.active_social_events] + if event_preferred_moods: + event_preferred_mood = min(event_preferred_moods) - if(event_preferred_mood <= overall_bar_mood): # choose the lowest value + if event_preferred_mood <= overall_bar_mood: # choose the lowest value mood = self.moods_list[event_preferred_mood] else: mood = self.moods_list[overall_bar_mood] - if(mood <> self.active_mood): + if mood <> self.active_mood: self.active_mood = mood self.windows_controller.set_mood(mood) print "cambio estado de animo a: ", self.active_mood.name @@ -289,18 +291,24 @@ class GameManager: """ self.__handle_personal_events() self.__handle_social_events() - + if self.events_interval == 0: if random.randint(0, 1): # add personal - self.active_event = self.__get_random_event(self.personal_events_list) #get a new random event - self.windows_controller.add_personal_event(self.active_event) #notify windows controller - print "se disparó el evento: ", self.active_event.name + if len(self.active_events) <= 1: + event = self.__get_random_event(self.personal_events_list) #get a new random event + if event and not (event in self.active_events): + self.active_events.append(event) + self.windows_controller.add_personal_event(event) #notify windows controller + print "se disparó el evento: ", event.name else: # add social - self.active_social_event = self.__get_random_event(self.social_events_list) - self.windows_controller.add_social_event(self.active_social_event) - print "se disparó el evento: ", self.active_social_event.name + if len(self.active_social_events) <= 1: + event = self.__get_random_event(self.social_events_list) + if event and not (event in self.active_social_events): + self.active_social_events.append(event) + self.windows_controller.add_social_event(event) + print "se disparó el evento: ", event.name self.events_interval = EVENTS_OCCURRENCE_INTERVAL else: @@ -311,27 +319,27 @@ class GameManager: """ Handle social events """ - if(self.active_social_event): + for event in self.active_social_events: - if(self.active_social_event.time_left): - self.active_social_event.perform() - else: - self.windows_controller.remove_social_event(self.active_social_event) - self.active_social_event.reset() - self.active_social_event = None + if event.time_left: + event.perform() + else: + self.windows_controller.remove_social_event(event) + event.reset() + self.active_social_events.remove(event) def __handle_personal_events(self): """ Handle personal events """ - if(self.active_event): + for event in self.active_events: - if(self.active_event.time_left): - self.active_event.perform() + if event.time_left: + event.perform() else: - self.windows_controller.remove_personal_event(self.active_event) - self.active_event.reset() - self.active_event = None + self.windows_controller.remove_personal_event(event) + event.reset() + self.active_events.remove(event) def __get_random_event(self, events_list): """ @@ -339,14 +347,21 @@ class GameManager: """ self.__update_events_probability(events_list) # it updates the probabilities of the list's events - max_rand = self.__calculate_max_rand(events_list) # get the max_rand for the events_list + #max_rand = self.__calculate_max_rand(events_list) # get the max_rand for the events_list probability_ranges = self.__calculate_ranges(events_list) # calculate the ranges for these events + max_rand = probability_ranges[-1][1] # Second member of last event + + print probability_ranges - rand = random.randint(0, max_rand) - for i in range(0, len(probability_ranges)): - if(rand >= probability_ranges[i][0] and rand <= probability_ranges[i][1]): - return events_list[i] + if max_rand == 0: + # There aren't events with probability + return None + else: + rand = random.random()*max_rand + for i in range(0, len(probability_ranges)): + if rand >= probability_ranges[i][0] and rand <= probability_ranges[i][1]: + return events_list[i] def __update_events_probability(self, events_list): """ @@ -374,7 +389,7 @@ class GameManager: ranges = [] for event in events_list: ranges += [(previous, previous + event.get_probability())] - previous += event.get_probability() + 1 + previous += event.get_probability() return ranges def __get_social_events(self, events_list): diff --git a/Saludame.activity/main_window.py b/Saludame.activity/main_window.py index df5db2d..87fa876 100755 --- a/Saludame.activity/main_window.py +++ b/Saludame.activity/main_window.py @@ -29,7 +29,7 @@ class MainWindow(Window): #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(status_bars.BarsWindow(container, pygame.Rect(0, 0, 227, 590), 1, windows_controller, bars_loader)) + 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/status_bars.py b/Saludame.activity/status_bars.py index d82d5bb..6786ba7 100755 --- a/Saludame.activity/status_bars.py +++ b/Saludame.activity/status_bars.py @@ -372,14 +372,14 @@ class BarsController: break def calculate_score(self): - if(self.overall_bar.value > self.overall_bar.max / 2): - if(self.overall_bar.value > (self.overall_bar.max / 2) + (self.overall_bar.max / 4)): #more than 3/4 - self.score_bar.increase(5) + if self.overall_bar.value > self.overall_bar.max / 2: + if self.overall_bar.value > (self.overall_bar.max / 2) + (self.overall_bar.max / 4): #more than 3/4 + self.score_bar.increase(3) else: #more than a half. - self.score_bar.increase(2) + self.score_bar.increase(1) else: - if(self.overall_bar.value < (self.overall_bar.max / 2) - (self.overall_bar.max / 4)): #less than 1/4 - self.score_bar.increase(-5) + if self.overall_bar.value < (self.overall_bar.max / 2) - (self.overall_bar.max / 4): #less than 1/4 + self.score_bar.increase(-3) else: # less than 1/2 self.score_bar.increase(-1) diff --git a/Saludame.activity/sugargame/event.py b/Saludame.activity/sugargame/event.py index 60eeb47..6af2411 100755 --- a/Saludame.activity/sugargame/event.py +++ b/Saludame.activity/sugargame/event.py @@ -51,6 +51,7 @@ class Translator(object): # Enable events # (add instead of set here because the main window is already realized) self._mainwindow.add_events( + gtk.gdk.EXPOSURE_MASK | \ gtk.gdk.KEY_PRESS_MASK | \ gtk.gdk.KEY_RELEASE_MASK \ ) @@ -70,12 +71,13 @@ class Translator(object): self._mainwindow.connect('unrealize', self._quit_cb) self._mainwindow.connect('key_press_event', self._keydown_cb) self._mainwindow.connect('key_release_event', self._keyup_cb) + self._mainwindow.connect('expose-event', self._expose_cb) + self._inner_evb.connect('key_press_event', self._keydown_cb) self._inner_evb.connect('key_release_event', self._keyup_cb) self._inner_evb.connect('button_press_event', self._mousedown_cb) self._inner_evb.connect('button_release_event', self._mouseup_cb) self._inner_evb.connect('motion-notify-event', self._mousemove_cb) - self._inner_evb.connect('expose-event', self._expose_cb) self._inner_evb.connect('configure-event', self._resize_cb) # Internal data @@ -102,8 +104,8 @@ class Translator(object): def _expose_cb(self, event, widget): if pygame.display.get_init(): pygame.event.post(pygame.event.Event(pygame.VIDEOEXPOSE)) - return True - + return False # continue processing + def _resize_cb(self, widget, event): evt = pygame.event.Event(pygame.VIDEORESIZE, size=(event.width,event.height), width=event.width, height=event.height) diff --git a/Saludame.activity/windows_controller.py b/Saludame.activity/windows_controller.py index 6f7bc54..815cecb 100755 --- a/Saludame.activity/windows_controller.py +++ b/Saludame.activity/windows_controller.py @@ -52,7 +52,7 @@ class WindowsController: # Activate Main window self.set_active_window("main_window") - self.update(1) + self.update(0) # Activate Customization over main window self.set_active_window("customization_window") |