all repos — Legends-RPG @ 5a42cedfef57b4e82debdde9de1dd8a881ee0e59

A fantasy mini-RPG built with Python and Pygame.

Finished town map
Justin Armstrong justinmeister@gmail.com
Mon, 14 Apr 2014 18:56:13 -0700
commit

5a42cedfef57b4e82debdde9de1dd8a881ee0e59

parent

322ed0813ca073c324e0476bbf9412b05c1d71e0

2 files changed, 187 insertions(+), 28 deletions(-)

jump to
M data/states/levels.pydata/states/levels.py

@@ -1,8 +1,8 @@

-__author__ = 'justinarmstrong' """ -This is the base class all level states (i.e. states -where the player can move around the screen) inherit -from. This class inherits from the generic state class +This is the base class for all level states (i.e. states +where the player can move around the screen). Levels are +differentiated by self.name and self.tmx_map. +This class inherits from the generic state class found in the tools.py module. """

@@ -20,11 +20,11 @@ def __init__(self, name):

super(LevelState, self).__init__() self.name = name self.tmx_map = setup.TMX[name] - self.map_width = None - self.map_height = None def startup(self, current_time, game_data): - """Called when the State object is created""" + """ + Call when the State object is flipped to. + """ self.game_data = game_data self.current_time = current_time self.state = 'normal'

@@ -45,19 +45,22 @@

self.collision_handler = collision.CollisionHandler(self.player, self.blockers, self.sprites) - self.dialogue_handler = textbox.TextHandler(self) self.state_dict = self.make_state_dict() self.portals = self.make_level_portals() self.menu_screen = player_menu.Player_Menu(game_data, self) def make_viewport(self, map_image): - """Create the viewport to view the level through""" + """ + Create the viewport to view the level through. + """ map_rect = map_image.get_rect() return setup.SCREEN.get_rect(bottom=map_rect.bottom) def make_level_surface(self, map_image): - """Creates the surface all images are blitted to""" + """ + Create the surface all images are blitted to. + """ map_rect = map_image.get_rect() map_width = map_rect.width if self.name == 'town':

@@ -65,10 +68,13 @@ map_height = map_rect.height - 32

else: map_height = map_rect.height size = map_width, map_height + return pg.Surface(size).convert() def make_player(self): - """Makes the player and sets location""" + """ + Make the player and sets location. + """ player = person.Player(self.game_data['last direction']) last_state = self.game_data['last state']

@@ -84,7 +90,9 @@

return player def make_blockers(self): - """Make the blockers for the level""" + """ + Make the blockers for the level. + """ blockers = [] for object in self.renderer.tmx_data.getObjects():

@@ -109,12 +117,21 @@ if properties['name'] == 'sprite':

x = properties['x'] * 2 y = ((properties['y']) * 2) - 32 - sprite_dict = {'oldman': person.Person('oldman', x, y, 'down'), - 'bluedressgirl': person.Person('femalevillager', x, y, 'right', 'resting', 1), - 'femalewarrior': person.Person('femvillager2', x, y, 'down', 'autoresting'), - 'devil': person.Person('devil', x, y, 'down', 'autoresting'), - 'oldmanbrother': person.Person('oldmanbrother', x, y, 'down')} - + sprite_dict = {'oldman': person.Person('oldman', + x, y, 'down'), + 'bluedressgirl': person.Person('femalevillager', + x, y, 'right', + 'resting', 1), + 'femalewarrior': person.Person('femvillager2', + x, y, 'down', + 'autoresting'), + 'devil': person.Person('devil', x, y, + 'down', 'autoresting'), + 'oldmanbrother': person.Person('oldmanbrother', + x, y, 'down'), + 'soldier': person.Person('soldier', + x, y, 'down')} + sprite = sprite_dict[properties['type']] self.assign_dialogue(sprite, properties) sprites.add(sprite)

@@ -131,7 +148,9 @@ dialogue_list.append(property_dict['dialogue'+str(i)])

sprite.dialogue = dialogue_list def make_state_dict(self): - """Make a dictionary of states the level can be in""" + """ + Make a dictionary of states the level can be in. + """ state_dict = {'normal': self.running_normally, 'dialogue': self.handling_dialogue, 'menu': self.goto_menu}

@@ -139,7 +158,9 @@

return state_dict def make_level_portals(self): - """Make the portals to switch state""" + """ + Make the portals to switch state. + """ portal_group = pg.sprite.Group() for object in self.renderer.tmx_data.getObjects():

@@ -206,7 +227,9 @@ self.set_new_start_pos()

def set_new_start_pos(self): - """Set new start position based on previous state""" + """ + Set new start position based on previous state. + """ location = copy.deepcopy(self.game_data['last location']) direction = self.game_data['last direction']

@@ -224,34 +247,47 @@

def handling_dialogue(self, surface, keys, current_time): - """Update only dialogue boxes""" + """ + Update only dialogue boxes. + """ self.dialogue_handler.update(keys, current_time) self.draw_level(surface) def goto_menu(self, surface, keys, *args): - """Go to menu screen""" + """ + Go to menu screen. + """ self.menu_screen.update(surface, keys) self.menu_screen.draw(surface) def check_for_dialogue(self): - """Check if the level needs to freeze""" + """ + Check if the level needs to freeze. + """ if self.dialogue_handler.textbox: self.state = 'dialogue' def update(self, surface, keys, current_time): - """Updates state""" + """ + Update state. + """ state_function = self.state_dict[self.state] state_function(surface, keys, current_time) def viewport_update(self): - """Viewport stays centered on character, unless at edge of map""" + """ + Update viewport so it stays centered on character, + unless at edge of map. + """ self.viewport.center = self.player.rect.center self.viewport.clamp_ip(self.level_rect) def draw_level(self, surface): - """Blits all images to screen""" + """ + Blit all images to screen. + """ self.level_surface.blit(self.map_image, self.viewport, self.viewport) self.level_surface.blit(self.player.image, self.player.rect) self.sprites.draw(self.level_surface)
M resources/tmx/town.tmxresources/tmx/town.tmx

@@ -12,6 +12,12 @@ </tileset>

<tileset firstgid="177" name="shopsigns" tilewidth="16" tileheight="16"> <image source="../graphics/shopsigns.png" width="64" height="16"/> </tileset> + <tileset firstgid="181" name="tileset3" tilewidth="16" tileheight="16"> + <image source="../graphics/tileset3.png" width="176" height="192"/> + </tileset> + <tileset firstgid="313" name="castledoor" tilewidth="16" tileheight="16"> + <image source="../graphics/castledoor.png" width="32" height="48"/> + </tileset> <layer name="Tile Layer 1" width="25" height="51"> <data encoding="base64" compression="zlib"> eJztlc8KgCAMh733Rl58gB2jl4q6Rc+bBwOJmVv5Z8iC7yDu54eOGBhjQFEGZ/Vs6iBxeE4BPcNwDL5kXMb/ZA7UvLM6xnHsEdg656DkWziWCGydc1DyLRyAZLGz3nrOyZdkxP+Dev4UqOGJz2/lqf1eUntuGdwOTsYO9Fbq6ONIzU9OjQRHav5xaiQ4gLCfqynp6DHHOff4izrqO1p8Fz0Qegc=

@@ -19,7 +25,22 @@ </data>

</layer> <layer name="Tile Layer 2" width="25" height="51"> <data encoding="base64" compression="zlib"> - eJztVkkKwzAMnGf0XHz2k9p+sIcuD2wKDhjhRbI9LjUZEEJEmUGWFcWBC7eZn8DvJvCzdCQ/47yOOvSYUYfUYYE9H0BbHadgVh0LWjS+sJzVOZiVn9lzgN9z4KjDghXreItnLyPXU8SP4OM6LiJHxjXk3p/Zj1n/Jgywdy3QttOvm906+Gs6O79Gp8Tvo5ySTi8/0HcHfOSdiBlgf6ckmHd39yvO4Eg9zR3uxb/zI8M/qg/34Jl1yB2bqsO6x3P4Vb9XmYsRc+4K/EjEWi35ba3tVi/yNTqps9DsVut+TOXP3oEfnVUuIg== + eJztVksOwiAQ5RiuDeseSb2gCz9Rqxs/1YOoW+0VnCaQTCYDHQSqNr7khSHCexlhmGqVFxpYoPkGWAK3wB3wCrwB78IY78X6GnmcgBXwDLwAH8AnsBbGeC/Wpz4YtZAcqH4z7hN7cHmk9vimPGIgzSOlj0VTHyvgmolLtM7WQOmILVz1cQAembhC62wNVI7Yl0cbBoYhCNF/16OBq8Y5DA1D9UNzCYXvrUqFfx5y9DGPJfltEag1J/OZGXEeI7KGztvg2t/leeTyoT0qByTfPrGQfmNhjIGTCP02H6sv8fHpF2iNzydWX6m4O1CgUZN5DuR+pyhy3l079rEGU/pJ7nAsfl1fOfRTncPUjDnzoD2WyyO0j7vwqfPuS12kqHPt0VfMXOpF39a23lqQ9RIf7r+Q9NbQ/sit77oHvgDuCY9D + </data> + </layer> + <layer name="Tile Layer 3" width="25" height="51"> + <data encoding="base64" compression="zlib"> + eJzt0zsOgEAIBFC4glqqpVqqnd/7H8s5AGTZSDkvmY4MCQkiIg3SIp3853X1yICMCTu8rgmZkSVhh9e1IhuyJ+yo6bLueqjIqeW5KOuuF/pvLc9FWXd90P9qeS4qetfoXOZ/eDL/w5P5H57M/yAiIiIiIiKieh8VTwlk + </data> + </layer> + <layer name="Tile Layer 4" width="25" height="51"> + <data encoding="base64" compression="zlib"> + eJztzTEOQBEAREGHkajdv1E7lQv8fIRCmCm32BfCXcrGr/qxxU4jDW5/jZ48uK00Zmm81wAAAADO0wDcCwil + </data> + </layer> + <layer name="Tile Layer 5" width="25" height="51"> + <data encoding="base64" compression="zlib"> + eJztzkEOQwAQRmGKKku1xErKSnD/w/WdQLowjcj7kredf5LkGlJ6UEYvqqgOuJ1TQU8qf9gaT/rhyPKHDV1DQ29qAzc66mkI3PjQRHPgxkob7YEbkiRJkiTdzReuiwJD </data> </layer> <objectgroup name="Object Layer 1" width="25" height="51">

@@ -259,6 +280,108 @@ <property name="dialogue length" value="3"/>

<property name="dialogue0" value="Don't be frightened. I'm a friendly Demon."/> <property name="dialogue1" value="My brothers and sisters, however, are not so nice."/> <property name="dialogue2" value="Be careful not to run into them."/> + </properties> + </object> + <object name="blocker" gid="120" x="208" y="176"/> + <object name="blocker" gid="120" x="208" y="160"/> + <object name="blocker" gid="120" x="240" y="160"/> + <object name="blocker" gid="120" x="224" y="160"/> + <object name="blocker" gid="120" x="272" y="160"/> + <object name="blocker" gid="120" x="256" y="160"/> + <object name="blocker" gid="120" x="256" y="176"/> + <object name="blocker" gid="120" x="240" y="176"/> + <object name="blocker" gid="120" x="224" y="176"/> + <object name="blocker" gid="120" x="272" y="176"/> + <object name="blocker" gid="120" x="304" y="176"/> + <object name="blocker" gid="120" x="288" y="176"/> + <object name="blocker" gid="120" x="320" y="192"/> + <object name="blocker" gid="120" x="288" y="160"/> + <object name="blocker" gid="120" x="304" y="160"/> + <object name="blocker" gid="120" x="320" y="160"/> + <object name="blocker" gid="120" x="320" y="144"/> + <object name="blocker" gid="120" x="336" y="128"/> + <object name="blocker" gid="120" x="336" y="96"/> + <object name="blocker" gid="120" x="336" y="112"/> + <object name="blocker" gid="120" x="336" y="80"/> + <object name="blocker" gid="120" x="320" y="64"/> + <object name="blocker" gid="120" x="304" y="48"/> + <object name="blocker" gid="120" x="288" y="48"/> + <object name="blocker" gid="120" x="272" y="48"/> + <object name="blocker" gid="120" x="256" y="64"/> + <object name="blocker" gid="120" x="272" y="80"/> + <object name="blocker" gid="120" x="288" y="80"/> + <object name="blocker" gid="120" x="288" y="96"/> + <object name="blocker" gid="120" x="288" y="112"/> + <object name="blocker" gid="120" x="288" y="112"/> + <object name="blocker" gid="120" x="288" y="128"/> + <object name="blocker" gid="120" x="272" y="128"/> + <object name="blocker" gid="120" x="256" y="112"/> + <object name="blocker" gid="120" x="256" y="128"/> + <object name="blocker" gid="120" x="240" y="112"/> + <object name="blocker" gid="120" x="224" y="112"/> + <object name="blocker" gid="120" x="208" y="112"/> + <object name="blocker" gid="120" x="160" y="112"/> + <object name="blocker" gid="120" x="144" y="112"/> + <object name="blocker" gid="120" x="128" y="128"/> + <object name="blocker" gid="120" x="112" y="128"/> + <object name="blocker" gid="120" x="96" y="112"/> + <object name="blocker" gid="120" x="96" y="128"/> + <object name="blocker" gid="120" x="96" y="96"/> + <object name="blocker" gid="120" x="96" y="80"/> + <object name="blocker" gid="120" x="112" y="64"/> + <object name="blocker" gid="120" x="96" y="48"/> + <object name="blocker" gid="120" x="80" y="48"/> + <object name="blocker" gid="120" x="64" y="48"/> + <object name="blocker" gid="120" x="48" y="64"/> + <object name="blocker" gid="120" x="32" y="80"/> + <object name="blocker" gid="120" x="32" y="96"/> + <object name="blocker" gid="120" x="32" y="96"/> + <object name="blocker" gid="120" x="32" y="112"/> + <object name="blocker" gid="120" x="32" y="128"/> + <object name="blocker" gid="120" x="48" y="144"/> + <object name="blocker" gid="120" x="64" y="160"/> + <object name="blocker" gid="120" x="80" y="160"/> + <object name="blocker" gid="120" x="96" y="160"/> + <object name="blocker" gid="120" x="112" y="160"/> + <object name="blocker" gid="120" x="144" y="160"/> + <object name="blocker" gid="120" x="128" y="160"/> + <object name="blocker" gid="120" x="160" y="160"/> + <object name="blocker" gid="120" x="160" y="176"/> + <object name="blocker" gid="120" x="144" y="176"/> + <object name="blocker" gid="120" x="144" y="176"/> + <object name="blocker" gid="120" x="128" y="176"/> + <object name="blocker" gid="120" x="112" y="176"/> + <object name="blocker" gid="120" x="96" y="176"/> + <object name="blocker" gid="120" x="80" y="176"/> + <object name="blocker" gid="120" x="64" y="160"/> + <object name="blocker" gid="120" x="64" y="176"/> + <object name="blocker" gid="120" x="48" y="192"/> + <object name="sprite" type="soldier" gid="124" x="160" y="128"> + <properties> + <property name="dialogue length" value="2"/> + <property name="dialogue0" value="I have heard rumours that the King has lost something..."/> + <property name="dialogue1" value="Perhaps you should pay him a visit."/> + </properties> + </object> + <object name="sprite" type="soldier" gid="124" x="208" y="128"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Welcome to the castle, citizen."/> + </properties> + </object> + <object name="sprite" type="soldier" gid="124" x="160" y="224"> + <properties> + <property name="dialogue length" value="2"/> + <property name="dialogue0" value="Only those given special permission by the King can leave this town."/> + <property name="dialogue1" value="It is for our own good, as few could survive in the outside world."/> + </properties> + </object> + <object name="sprite" type="soldier" gid="124" x="208" y="224"> + <properties> + <property name="dialogue length" value="3"/> + <property name="dialogue0" value="Be careful. There are monsters surrounding our town."/> + <property name="dialogue1" value="Make sure to equip sufficient armor and weapons."/> + <property name="dialogue2" value="Spells and potions are useful too."/> </properties> </object> </objectgroup>