From fd405313e9093b101116e6fe821d57bf6427bd94 Mon Sep 17 00:00:00 2001 From: echinelli Date: Sun, 26 Dec 2010 21:22:27 +0000 Subject: environment effects on character by environment: place + clothes + weather. Improvements in load, save and reset game. --- diff --git a/Saludame.activity/app_init.py b/Saludame.activity/app_init.py index 8f62630..ac5b4f1 100755 --- a/Saludame.activity/app_init.py +++ b/Saludame.activity/app_init.py @@ -33,7 +33,7 @@ class AppLoader: ### game manager - self.game_man = game_manager.GameManager(self.character, self.status_bars_controller, None, self.events_list, None, character_loader.get_environments_dictionary(), self.moods_list, windows_controller) + self.game_man = game_manager.GameManager(self.character, self.status_bars_controller, None, self.events_list, character_loader.get_places(), character_loader.get_environments_dictionary(), character_loader.get_weather_effects(), self.moods_list, windows_controller) actions_loader = actions_creator.ActionsLoader(self.bars_loader.get_bar_controller(), self.game_man) self.actions_list = actions_loader.get_actions_list() self.game_man.actions_list = self.actions_list @@ -148,3 +148,4 @@ class AppLoader: m_normal, m_happy3, m_happy2, m_happy1] return moods_list + diff --git a/Saludame.activity/character.py b/Saludame.activity/character.py index 7fd07ac..1a6a23b 100755 --- a/Saludame.activity/character.py +++ b/Saludame.activity/character.py @@ -37,16 +37,6 @@ class Character: Get the character current status, and returns a dictionary. """ - #status = {"hair_color" : self.hair_color, - # "socks_color" : self.socks_color, - # "skin_color" : self.skin_color, - # "shoes_color" : self.shoes_color, - # "current_place" : self.current_place, - # "name" : self.name, - # "level" : self.level, - # "grade" : self.grade, - # "clothes" : self.clothes - # } status = {"character_colors" : self.mappings, # add by CustomizatedKid in module customization. "current_place" : self.current_place, "name" : self.name, @@ -127,3 +117,4 @@ class Clothes: self.texture_path = texture_path self.weather_effects_list = weather_effects_list #list of tuples (id_weather, effect_indoor, effect_outdoor) + diff --git a/Saludame.activity/character_creator.py b/Saludame.activity/character_creator.py index 7197cc1..e98d902 100755 --- a/Saludame.activity/character_creator.py +++ b/Saludame.activity/character_creator.py @@ -28,9 +28,10 @@ import pygame class CharacterLoader: def __init__(self): - self.clothes_list = self.__load_clothes() - self.character = self.__load_character(SEX, NAME, LEVEL, SCORE, self.clothes_list[0]) - self.environments_dictionary = self.__load_environments() + self.character = self.__load_character(SEX, NAME, LEVEL, SCORE, "school") + self.environments_dictionary = self.__load_environments() + self.places = self.__load_places() + self.weather_effects = self.__load_weather_effects() def get_character(self): return self.character @@ -38,8 +39,11 @@ class CharacterLoader: def get_environments_dictionary(self): return self.environments_dictionary - def __load_clothes(self): - return ["a clothes"] + def get_places(self): + return self.places + + def get_weather_effects(self): + return self.weather_effects def __load_character(self, sex, name, level, score, clothes): hair_color = [pygame.Color(color) for color in HAIR_COLOR] @@ -50,6 +54,53 @@ class CharacterLoader: char = character.Character(sex, name, level, score, hair_color, socks_color, skin_color, shoes_color, clothes) return char + def __load_weather_effects(self): + weather_effects = { + # (clothes_id, weather_id, boolean indoor outdoor) : list of tuples [(id_bar, rate)] + #school clothes + ("school", "sunny", True) : [("fun", 1.0)], + ("school", "sunny", False) : [("physica", 1.0)], + ("school", "rainy", True) : [("physica", 1.0)], + ("school", "rainy", False) : [("physica", 1.0)], + ("school", "normal", True) : [("physica", 1.0)], + ("school", "normal", False) : [("physica", 1.0)], + ("school", "cold", True) : [("physica", 1.0)], + ("school", "cold", False) : [("physica", 1.0)], + #sunny clothes + ("sunny", "sunny", True) : [("physica", 1.0)], + ("sunny", "sunny", False) : [("physica", 1.0)], + ("sunny", "rainy", True) : [("physica", 1.0)], + ("sunny", "rainy", False) : [("physica", 1.0)], + ("sunny", "normal", True) : [("physica", 1.0)], + ("sunny", "normal", False) : [("physica", 1.0)], + ("sunny", "cold", True) : [("physica", 1.0)], + ("sunny", "cold", False) : [("physica", 1.0)], + #rainy clothes + ("rainy", "sunny", True) : [("physica", 1.0)], + ("rainy", "sunny", False) : [("physica", 1.0)], + ("rainy", "rainy", True) : [("physica", 1.0)], + ("rainy", "rainy", False) : [("physica", 1.0)], + ("rainy", "normal", True) : [("physica", 1.0)], + ("rainy", "normal", False) : [("physica", 1.0)], + ("rainy", "cold", True) : [("physica", 1.0)], + ("rainy", "cold", False) : [("physica", 1.0)], + } + return weather_effects + + def __load_places(self): + places = { #schoolyard + "schoolyard" : {"outdoor": True}, + #square + "square" : {"outdoor": True}, + #classroom + "classroom" : {"outdoor": False}, + #home + "home": {"outdoor": False}, + #country + "country": {"outdoor": True} + } + return places + def __load_environments(self): environments = {#schoolyard "schoolyard_sunny" : character.Environment("assets/background/schoolyard_sunny.png", "music_path"), @@ -79,3 +130,4 @@ class CharacterLoader: } return environments + diff --git a/Saludame.activity/game_manager.py b/Saludame.activity/game_manager.py index 4e78d46..e096898 100755 --- a/Saludame.activity/game_manager.py +++ b/Saludame.activity/game_manager.py @@ -22,7 +22,7 @@ class GameManager: y los eventos del juego. """ - def __init__(self, character, bars_controller, actions_list, events_list, places_list, environments_dictionary, moods_list, windows_controller): + def __init__(self, character, bars_controller, actions_list, events_list, places_dictionary, environments_dictionary, weather_effects, moods_list, windows_controller): """ Constructor de la clase """ @@ -52,7 +52,7 @@ class GameManager: self.active_mood = None self.__check_active_mood() # sets active_mood - self.places_list = places_list + self.places_dictionary = places_dictionary #for events handling: self.events_interval = EVENTS_OCCURRENCE_INTERVAL @@ -74,7 +74,9 @@ class GameManager: #for weather self.p_i = 0 - + self.weather_effects = weather_effects + self.environment_effect = None # this is an Effect that represents the effect on the character by the environment: weather + place + clothes + self.update_environment_effect() # management def pause_game(self): @@ -97,6 +99,11 @@ class GameManager: self.__check_active_mood() # check if the active character mood self.__handle_time() + if self.environment_effect: + self.environment_effect.activate() + else: + self.update_environment_effect() + self.count = 0 ## Environment handling @@ -110,6 +117,18 @@ class GameManager: self.environment = self.environments_dictionary[environment_id] self.windows_controller.set_environment(self.environment) + + def update_environment_effect(self): + """ + Create and action with the effect on the character by the environment, taking current_place + + clothes + current_weather. + """ + outdoor = self.places_dictionary[self.character.current_place]["outdoor"] + affected_bars = self.weather_effects[(self.character.clothes, self.current_weather, outdoor)] + effect = effects.Effect(self.bars_controller, affected_bars) + + self.environment_effect = effect + print "environment effect updated: ", affected_bars ### time of day @@ -140,6 +159,7 @@ class GameManager: Set the current weather. """ self.current_weather = weather + self.update_environment_effect() def get_random_weather(self): """ @@ -166,14 +186,13 @@ class GameManager: self.character.current_place = place_id self.update_environment() + self.update_environment_effect() def get_place(self, place_id): """ - Returns the place asociated to the place_id + (not implemented) Returns the place asociated to the place_id """ - for place in self.places_list: - if(place.id == place_id): - return place + None ### Clothes def set_character_clothes(self, clothes_id): @@ -181,8 +200,10 @@ class GameManager: Set the character clothes. """ self.character.set_clothes(clothes_id) - self.windows_controller.update_clothes() print "character's clothes: ", clothes_id + + self.update_environment_effect() + self.windows_controller.update_clothes() ## Actions handling @@ -487,10 +508,13 @@ class GameManager: # weather self.current_weather = "sunny" # default weather self.update_environment() + self.update_environment_effect() + self.windows_controller.update_clothes() # hour self.hour = 2 self.hour_count = HOUR_COUNT_CYCLE self.current_time = self.day_dic[self.hour] + print "game reseted successfully... " def save_game(self): """ @@ -525,10 +549,14 @@ class GameManager: #load bars status self.bars_controller.load_bars_status(game_status) + print "status bars loaded..." #character properties self.character.load_properties(game_status) - + print "character properties loaded..." + self.update_environment() + self.update_environment_effect() + self.windows_controller.update_clothes() print "se cargo la partida con exito. Version ", game_status["version"] except: @@ -561,3 +589,4 @@ class GameManager: return self.current_time + -- cgit v0.9.1