Changeset 7658


Ignore:
Timestamp:
2016-07-03 15:56:32 (3 years ago)
Author:
sieerinn
Message:
 
Location:
2016/27/ohjaajat/VenienteFragore/VenienteFragore
Files:
2 added
4 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; 
  • 2016/27/ohjaajat/VenienteFragore/VenienteFragore/VenienteFragore/VenienteFragore.cs

    r7653 r7658  
    1515    public override void Begin() 
    1616    { 
    17         // Kirjoita ohjelmakoodisi tähän 
     17        var tileMap = TiledTileMap.FromLevelAsset("testi"); 
     18        tileMap.SetTileMethod("Tile Layer 1", TileMethod); 
     19        tileMap.SetObjectMethod("Object Layer 1", ObjectMethod); 
     20        tileMap.Execute(); 
     21 
     22        Gravity = new Vector(0, -800); 
    1823 
    1924        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
     
    2126 
    2227    } 
     28 
     29    private void ObjectMethod(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties) 
     30    { 
     31        var testObject = new SimplePhysics.Object(TileSize * 0.99, TileSize * 0.99); 
     32        testObject.Position = position; 
     33        testObject.Color = Color.DarkGreen; 
     34        testObject.Shape = Shape.Circle; 
     35        testObject.RestitutionX = 0.5; 
     36        testObject.RestitutionY = 0.5; 
     37        testObject.CollisionIgnoreGroup = 1; 
     38        Add(testObject); 
     39    } 
     40 
     41    private void TileMethod(int x, int y, Image image, string layerName, Dictionary<string, string> properties) 
     42    { 
     43        var tile = new SimplePhysics.Object(TileSize, TileSize) { IsStatic = true }; 
     44        tile.Image = image; 
     45        Add(tile); 
     46        SetTile(x, y, tile); 
     47    } 
    2348} 
  • 2016/27/ohjaajat/VenienteFragore/VenienteFragore/VenienteFragoreContent/VenienteFragoreContent.contentproj

    r7653 r7658  
    4545    <Reference Include="AnimationExtension" /> 
    4646  </ItemGroup> 
     47  <ItemGroup> 
     48    <Compile Include="testi.png"> 
     49      <Name>testi</Name> 
     50      <Importer>TextureImporter</Importer> 
     51      <Processor>TextureProcessor</Processor> 
     52    </Compile> 
     53  </ItemGroup> 
     54  <ItemGroup> 
     55    <None Include="testi.tmx"> 
     56      <Name>testi</Name> 
     57      <CopyToOutputDirectory>Always</CopyToOutputDirectory> 
     58    </None> 
     59  </ItemGroup> 
    4760  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    4861  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
Note: See TracChangeset for help on using the changeset viewer.