Ignore:
Timestamp:
2016-07-03 15:56:32 (3 years ago)
Author:
sieerinn
Message:
 
Location:
2016/27/ohjaajat/VenienteFragore/VenienteFragore/VenienteFragore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 2016/27/ohjaajat/VenienteFragore/VenienteFragore/VenienteFragore

    • Property svn:global-ignores
      •  

        old new  
         1*.cachefile 
        12bin 
        23obj 
  • 2016/27/ohjaajat/VenienteFragore/VenienteFragore/VenienteFragore/TiledTileMap.cs

    r7653 r7658  
    1414 
    1515    public delegate void TileMethod( 
    16         Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties); 
     16        int x, int y, Image image, string layerName, Dictionary<string, string> properties); 
    1717 
    1818    private readonly Dictionary<string, ObjectMethod> objectLegend = new Dictionary<string, ObjectMethod>(); 
     
    2626    private TiledTileMap(TmxMap tmxMap) 
    2727    { 
    28         this.level = tmxMap; 
     28        level = tmxMap; 
    2929    } 
    3030 
    3131    public static TiledTileMap FromLevelAsset(string assetName) 
    3232    { 
    33         TmxMap tmxMap = new TmxMap(string.Format("Content/{0}.tmx", assetName)); 
    34         TiledTileMap map = new TiledTileMap(tmxMap); 
     33        var tmxMap = new TmxMap(string.Format("Content/{0}.tmx", assetName)); 
     34        var map = new TiledTileMap(tmxMap); 
    3535        map.LoadTileImages(); 
    3636        return map; 
     
    4949    public void Execute() 
    5050    { 
    51         Game game = Game.Instance; 
     51        var game = (SimplePhysics.Game)Game.Instance; 
     52        game.InitializeTileMap(level.Width, level.Height); 
    5253        game.Level.Width = level.Width * level.TileWidth; 
    5354        game.Level.Height = level.Height * level.TileHeight; 
     
    5556        foreach (var tmxLayer in level.Layers) 
    5657        { 
    57             CreateTile(tmxLayer, game); 
     58            CreateTileLayer(tmxLayer, game); 
    5859        } 
    5960 
    6061        foreach (var group in level.ObjectGroups) 
    6162        { 
    62             CreateObject(group, game); 
     63            CreateObjectLayer(group, game); 
    6364        } 
    6465    } 
    6566 
    66     private void CreateTile(TmxLayer layer, Game game) 
     67    private void CreateTileLayer(TmxLayer layer, Game game) 
    6768    { 
    6869        TileMethod method; 
    6970        if (!tileLegend.TryGetValue(layer.Name, out method)) return; 
    7071 
    71         double tileWidth = level.TileWidth; 
    72         double tileHeight = level.TileHeight; 
     72        //double tileWidth = level.TileWidth; 
     73        //double tileHeight = level.TileHeight; 
    7374 
    74         for (int i = 0; i < layer.Tiles.Count; i++) 
     75        foreach (var tile in layer.Tiles) 
    7576        { 
    76             var tile = layer.Tiles[i]; 
    7777            int gid = tile.Gid; 
    7878            if (gid == 0) 
     
    8080 
    8181            int tileIndex = tile.Gid - 1; 
    82             double realX = game.Level.Left + (tile.X * tileWidth) + (tileWidth / 2); 
    83             double realY = game.Level.Top - (tile.Y * tileHeight) - (tileHeight / 2); 
    84             Dictionary<string,string> props = level.Tilesets[0].Tiles.Where(t => level.Tilesets[0].FirstGid + t.Id == tile.Gid).Select(t => t.Properties).FirstOrDefault(); 
     82            var tile1 = tile; 
     83            Dictionary<string, string> props = level.Tilesets[0].Tiles.Where(t => level.Tilesets[0].FirstGid + t.Id == tile1.Gid).Select(t => t.Properties).FirstOrDefault(); 
    8584            props = props ?? new Dictionary<string, string>(); 
    86             method(new Vector(realX, realY), tileWidth, tileHeight, tileImages[tileIndex], layer.Name, props); 
     85            method(tile.X, tile.Y, tileImages[tileIndex], layer.Name, props); 
    8786        } 
    8887    } 
    8988 
    90     private void CreateObject(TmxObjectGroup group, Game game) 
     89    private void CreateObjectLayer(TmxObjectGroup group, Game game) 
    9190    { 
    9291        ObjectMethod method; 
     
    113112        foreach (var tileSet in level.Tilesets) 
    114113        { 
    115             Image tilesetImage = Game.LoadImage(Path.GetFileNameWithoutExtension(tileSet.Image.Source)); 
     114            var tilesetImage = Game.LoadImage(Path.GetFileNameWithoutExtension(tileSet.Image.Source)); 
    116115            int tilesW = tileSet.Image.Width.Value / tileSet.TileWidth; 
    117116            int tilesH = tileSet.Image.Height.Value / tileSet.TileHeight; 
Note: See TracChangeset for help on using the changeset viewer.