From 6ce99be76534fcfc50516797c902b1d6271c5e8f Mon Sep 17 00:00:00 2001 From: "FunnyMan3595 (Charlie Nolan)" Date: Sat, 13 Oct 2007 05:07:53 -0500 Subject: [PATCH] Changed map functions to tiles. --- engine/game_map.py | 18 +++---- engine/map_functions.py | 2 - engine/tiles.py | 2 + main_game/map_functions.py | 97 ----------------------------------- main_game/maps.py | 1 + main_game/open_plains.map | 0 main_game/start_map.map | 4 +- main_game/start_town.map | 2 +- main_game/tiles.py | 122 +++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 137 insertions(+), 111 deletions(-) delete mode 100644 engine/map_functions.py create mode 100644 engine/tiles.py delete mode 100644 main_game/map_functions.py create mode 100644 main_game/open_plains.map create mode 100644 main_game/tiles.py diff --git a/engine/game_map.py b/engine/game_map.py index 2d3f059..6f1d34f 100644 --- a/engine/game_map.py +++ b/engine/game_map.py @@ -4,7 +4,7 @@ special_keys = ("encounter_frequency", "encounter_delay", "encounter_min_level", from shop import make_shop from random import randint from battle import simple_battle -import map_functions +import tiles class MapException(Exception): pass @@ -81,21 +81,21 @@ class game_map(object): if key in special_keys: continue value = self.map_key[key][0] - if not hasattr(map_functions, value): + if not hasattr(tiles, value): if value not in maps.keys(): - raise MapException("No function or map named %s. (Used by symbol %s in map %s)" % (value, key, self.name)) + raise MapException("No tile or map named %s. (Used by symbol %s in map %s)" % (value, key, self.name)) def go(self, direction): pos = self.pos if pos != None: if pos[0] == 0 and direction == north: - return self.call_map_function("border_north") + return self.go_tile_generic("border_north") elif pos[0] == len(self.game_map) - 1 and direction == south: - return self.call_map_function("border_south") + return self.go_tile_generic("border_south") elif pos[1] == 0 and direction == west: - return self.call_map_function("border_west") + return self.go_tile_generic("border_west") elif pos[1] == len(self.game_map[0]) - 1 and direction == east: - return self.call_map_function("border_east") + return self.go_tile_generic("border_east") else: newpos = pos if direction == north: @@ -106,9 +106,9 @@ class game_map(object): newpos[1] -= 1 elif direction == east: newpos[1] += 1 - return self.call_map_function_at(*newpos) + return self.go_tile_at(*newpos) - def call_map_function_at(self, row, char): + def go_tile_at(self, row, char): return self.call_map_function(self.char_at(row, char)) def get_map_function_at(self, row, char): diff --git a/engine/map_functions.py b/engine/map_functions.py deleted file mode 100644 index 1f76f12..0000000 --- a/engine/map_functions.py +++ /dev/null @@ -1,2 +0,0 @@ -from mod_import import do_mod_import -do_mod_import("map_functions", globals()) diff --git a/engine/tiles.py b/engine/tiles.py new file mode 100644 index 0000000..e2f6258 --- /dev/null +++ b/engine/tiles.py @@ -0,0 +1,2 @@ +from mod_import import do_mod_import +do_mod_import("tiles", globals()) diff --git a/main_game/map_functions.py b/main_game/map_functions.py deleted file mode 100644 index e474e87..0000000 --- a/main_game/map_functions.py +++ /dev/null @@ -1,97 +0,0 @@ -from engine.game_map import special_keys -from random import randint -from engine.battle import simple_battle -from engine.shop import make_shop - -def get_map_specials(game_map, pos): - for key in special_keys: - yield game_map.map_key[key] - -def wall(game_map, pos, *args): - return False -wall.tile = "wall" - -def safe(game_map, pos, *args): - game_map.hp_mp_ticks() - return True -safe.tile = "empty" - -def normal(game_map, pos, *args): - game_map.hp_mp_ticks() - if game_map.delay_left > 0: - game_map.delay_left -= 1 - return True - - (chance, delay, minlvl, maxlvl, mincrits, maxcrits, crittypes, tileset) = \ - get_map_specials(game_map) - - if randint(1,100) < int(chance): - game_map.delay_left = int(delay) - level = randint(int(minlvl),int(maxlvl)) - crits = randint(int(mincrits),int(maxcrits)) - game_map.game.ui.battle_mode(simple_battle(level, crits)) - - return True -normal.tile = "empty" - -def object_tutorial(game_map, pos, main = False, *args): - return True -object_tutorial.tile = "empty" - -def conversation_tutorial(game_map, pos, main = False, *args): - return True -conversation_tutorial.tile = "empty" - -def combat_tutorial(game_map, pos, main = False, *args): - return True -combat_tutorial.tile = "empty" - -def menu_tutorial(game_map, pos, main = False, *args): - return True -menu_tutorial.tile = "empty" - -def start(game_map, pos, *args): - return True -start.tile = "empty" - -def start_and_movement_tutorial(game_map, pos, *args): - return True -start_and_movement_tutorial.tile = "empty" - -def door(game_map, pos, *args): - return True -door.tile = "door" -door.closed = True - -def armor_shop(game_map, pos, level=1, *args): - game_map.game.ui.map_mode(make_shop(level, armor=True)) - return True -armor_shop.tile = "armor_door" -armor_shop.closed = False - -def weapon_shop(game_map, pos, level=1, *args): - game_map.game.ui.map_mode(make_shop(level, weapons=True)) - return True -weapon_shop.tile = "weapon_door" -weapon_shop.closed = False - -def item_shop(game_map, pos, level=1, *args): - game_map.game.ui.map_mode(make_shop(level, other=True)) - return True -item_shop.tile = "item_door" -item_shop.closed = False - -def magic_shop(game_map, pos, level=1, *args): - game_map.game.ui.map_mode(make_shop(level, magic=True)) - return True -magic_shop.tile = "magic_door" -magic_shop.closed = False - -def welcome_to_start_town_ladies(game_map, pos, *args): - game_map.game.ui.conversation_mode('The young lady smiles like a mannequin. "Welcome to Start Town!"') - return False -welcome_to_start_town_ladies.tile = "lady" - -def save_point(game_map, pos, *args): - return False -save_point.tile = "save_point" diff --git a/main_game/maps.py b/main_game/maps.py index 1d5224b..589d679 100644 --- a/main_game/maps.py +++ b/main_game/maps.py @@ -30,3 +30,4 @@ start_map = make_map("start_map") start_town = make_map("start_town") beginner_woods = make_map("beginner_woods") +open_plains = make_map("open_plains") diff --git a/main_game/open_plains.map b/main_game/open_plains.map new file mode 100644 index 0000000..e69de29 diff --git a/main_game/start_map.map b/main_game/start_map.map index 5bbdbf5..d4a3ad1 100644 --- a/main_game/start_map.map +++ b/main_game/start_map.map @@ -90,8 +90,8 @@ encounter_max_critters: 1 ' critter_types is a space-separated list of critter types (as defined in ' /monsters.py) that can appear on this map. Note that this only ' applies to "normal" squares. Triggered encounters can use any critters. -critter_types: all +critter_types: simple ' The map can either use one of the normal tilesets or define its own in ' /tilesets.py. -tileset: cave +tileset: simple_cave diff --git a/main_game/start_town.map b/main_game/start_town.map index 16da60b..42f1d30 100644 --- a/main_game/start_town.map +++ b/main_game/start_town.map @@ -41,6 +41,6 @@ encounter_min_level: 1 encounter_max_level: 1 encounter_min_critters: 1 encounter_max_critters: 1 -critter_types: all +critter_types: simple tileset: simple_town diff --git a/main_game/tiles.py b/main_game/tiles.py new file mode 100644 index 0000000..81196a7 --- /dev/null +++ b/main_game/tiles.py @@ -0,0 +1,122 @@ +from engine.game_map import special_keys +from engine.tile import * +from engine.battle import simple_battle +from engine.shop import make_shop + +def get_map_specials(game_map, pos): + for key in special_keys: + yield game_map.map_key[key] + +class wall(tile): + def __init__(self, map_pos, *args): + tile.__init__(self, map_pos, "wall", passable = False) + +class safe(tile): + def __init__(self, map_pos, *args): + tile.__init__(self, map_pos, "empty", action = safe_action) + +class normal(tile): + def __init__(self, map_pos, *args): + tile.__init__(self, map_pos, "empty") + +def object_tutorial_action(my_tile): + #TODO + pass + +class object_tutorial(tile): + def __init__(self, map_pos, *args): + tile.__init__(self, map_pos, "empty", action = object_tutorial_action) + +def conversation_tutorial_action(my_tile): + #TODO + pass + +class conversation_tutorial(tile): + def __init__(self, map_pos, main_game = False, *args): + tile.__init__(self, map_pos, "empty", action = conversation_tutorial_action, vars={"main_game": main_game}) + +def combat_tutorial_action(my_tile): + #TODO + pass + +class combat_tutorial(tile): + def __init__(self, map_pos, *args): + tile.__init__(self, map_pos, "empty", action = combat_tutorial_action) + +def menu_tutorial_action(my_tile): + #TODO + pass + +class menu_tutorial(tile): + def __init__(self, map_pos, main_game = False, *args): + tile.__init__(self, map_pos, "empty", action = menu_tutorial_action, vars={"main_game": main_game}) + +start = safe + +def movement_tutorial_action(my_tile): + #TODO + pass + +class start_and_movement_tutorial(tile): + def __init__(self, map_pos, *args): + tile.__init__(self, map_pos, "empty", action = movement_tutorial_action) + +def door_open(my_tile): + return my_tile.open + +def open_door(my_tile): + my_tile.open = True + +class door(tile): + def __init__(self, map_pos, *args): + tile.__init__(self, map_pos, "door", passable = door_open, action = open_door, vars = {"open": False}, save = ("open",)) + +class armor_shop(tile): + def __init__(self, map_pos, level=1, *args): + shop = make_shop(level, armor=True) + tile.__init__(self, map_pos, "armor_door", action = "shop_action", vars = {"shop": shop}, save = ("shop",)) + +class weapon_shop(tile): + def __init__(self, map_pos, level=1, *args): + shop = make_shop(level, weapons=True) + tile.__init__(self, map_pos, "weapon_door", action = "shop_action", vars = {"shop": shop}, save = ("shop",)) + +class item_shop(tile): + def __init__(self, map_pos, level=1, *args): + shop = make_shop(level, other=True) + tile.__init__(self, map_pos, "item_door", action = "shop_action", vars = {"shop": shop}, save = ("shop",)) + +class magic_shop(tile): + def __init__(self, map_pos, level=1, *args): + shop = make_shop(level, magic=True) + tile.__init__(self, map_pos, "magic_door", action = "shop_action", vars = {"shop": shop}, save = ("shop",)) + + +def welcome_to_start_town(my_tile): + my_tile.game.ui.conversation_mode('The young lady smiles like a mannequin. "Welcome to Start Town!"') + +class welcome_to_start_town_ladies(tile): + def __init__(self, map_pos, *args): + tile.__init__(self, map_pos, "lady", passable = False, action = welcome_to_start_town) + +class save_point(tile): + def __init__(self, map_pos, *args): + tile.__init__(self, map_pos, "save_point", passable = False, action = save_action) + +class twig(tile): + def __init__(self, map_pos, *args): + tile.__init__(self, map_pos, "twig", passable = 1) + +class branch(tile): + def __init__(self, map_pos, *args): + tile.__init__(self, map_pos, "branch", passable = 2) + +class gate_to_open_plains(tile): + def __init__(self, map_pos, *args): + #TODO: Let the gate be opened. + tile.__init__(self, map_pos, "gate", passable = False) + +class beginner_woods_boss(tile): + def __init__(self, map_pos, *args): + #TODO: Make a boss. + tile.__init__(self, map_pos, "evil_tree", passable = False) -- 2.11.4.GIT