Source

Fat x Fast / FatxFast / tilemap / editor / layer.py

Full commit

# This file is part of FatxFast.
#
#    FatxFast is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    FatxFast is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with FatxFast.  If not, see <http://www.gnu.org/licenses/>.

# Versioning based on: 
# http://en.wikipedia.org/wiki/Versioning#Designating_development_stage
__author__ = "dryatu (c) 2013"
__version__ = "1.2.5"

from FatxFast.tilemap.editor import tile

GROUND_LAYER = 0
ROOF_LAYER = 1
COLLIDE_LAYER = 2
OBJECT_LAYER = 3

class Layer(object):
    
    def __init__(self, **kwargs):
        self._level = kwargs.get("level", 0)
        self.num_tiles_x = kwargs.get("num_tiles_x", 0)
        self.num_tiles_y = kwargs.get("num_tiles_y", 0)
        self.bottom_margin = 0
        self.tilewidth = tile.TILEWIDTH
        self.tileheight = tile.TILEHEIGHT

        self.paralax_factor_x = 1.0
        self.paralax_factor_y = 1.0
        
        self.position_x = 0
        self.position_y = 0
       
        self.visible = kwargs.get("visible", 0)
        self.content2D = []
        self.is_object_group = False
        self.sprites = []
        default_tile = kwargs.get("default_image", None)
        default_id = kwargs.get("entity_id", tile.FLOOR_ID)
        for ypos in xrange(self.num_tiles_y):
            xtiles = []
            for xpos in xrange(self.num_tiles_x):
                try:
                    if default_tile:
                        new_tile = tile.Tile(xpos, ypos, default_tile, 
                            entity_id=default_id)
                    else:
                        new_tile = default_tile
                    #self.sprites.append(tile)
                except TypeError:
                    new_tile = None
                xtiles.append(new_tile)
            self.content2D.append(xtiles)