Changeset 6538 for 2015/27


Ignore:
Timestamp:
2015-06-29 16:51:35 (4 years ago)
Author:
sieerinn
Message:

Uusi testikenttä. Osa tiilistä voi olla PhysicsObjecteja?.

Location:
2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/LevelCreation.cs

    r6536 r6538  
    77public partial class TheLegendOfGabriel : PhysicsGame 
    88{ 
     9    /// <summary> 
     10    /// Luo pelaajan. 
     11    /// </summary> 
     12    void CreatePlayer(Vector position) 
     13    { 
     14        player = new Creature(TILE_SIZE, TILE_SIZE); 
     15        player.MovementSpeed = 2300; 
     16        player.Position = position; 
     17        Add(player); 
     18    } 
     19 
    920    /// <summary> 
    1021    /// Luo kentän .tmx tiedostosta. 
     
    2132 
    2233    /// <summary> 
    23     /// Maassa oleva perus tiili, jonka läpi voi kävellä. 
     34    /// Maassa oleva perus tiili. 
    2435    /// </summary> 
    25     void CreateBaseTile(Vector position, double width, double height, Image image, string layerName) 
     36    void CreateBaseTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties) 
    2637    { 
    27         CreateBasicTile(position, width, height, image, -1); 
     38        CreateBasicTile(position, width, height, image, -1, properties); 
    2839    } 
    2940 
     
    3142    /// Pelaajan päällä näkyvä perus tiili. 
    3243    /// </summary> 
    33     void CreateForegroundTile(Vector position, double width, double height, Image image, string layerName) 
     44    void CreateForegroundTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties) 
    3445    { 
    35         CreateBasicTile(position, width, height, image, 1); 
     46        CreateBasicTile(position, width, height, image, 1, properties); 
    3647    } 
    3748 
    3849    /// <summary> 
    39     /// Luo tavallisen tiilen jonka läpi voi kävellä. 
     50    /// Luo tavallisen tiilen. 
    4051    /// </summary> 
    41     void CreateBasicTile(Vector position, double width, double height, Image image, int layer) 
     52    void CreateBasicTile(Vector position, double width, double height, Image image, int layer, Dictionary<string, string> properties) 
    4253    { 
    43         var tile = new GameObject(width, height); 
     54        var tile = properties.ContainsKey("collide")? new PhysicsObject(width, height) : new GameObject(width, height); 
    4455        tile.Image = image; 
    4556        tile.Position = position; 
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel.cs

    r6536 r6538  
    77using Jypeli.Widgets; 
    88 
     9class Creature : PhysicsObject 
     10{ 
     11    public double MovementSpeed { get; set; } 
     12 
     13    public Creature(double width, double height) 
     14        : base(width, height) 
     15    { 
     16        LinearDamping = 0.5; 
     17    } 
     18 
     19    public void Move(Direction direction) 
     20    { 
     21        Push(direction.GetVector() * MovementSpeed); 
     22    } 
     23} 
     24 
    925public partial class TheLegendOfGabriel : PhysicsGame 
    1026{ 
     27    public const int TILE_SIZE = 20; 
     28 
     29    private Creature player; 
     30 
    1131    public override void Begin() 
    1232    { 
     
    1838    { 
    1939        ClearAll(); 
    20         CreateLevel("testlevel"); 
     40        CreateLevel("testlevel2"); 
     41        CreatePlayer(new Vector(30, -30)); 
    2142        SetControls(); 
    2243        Camera.ZoomToLevel(); 
     
    2546    void SetControls() 
    2647    { 
     48        Keyboard.Listen(Key.Left, ButtonState.Down, player.Move, null, Direction.Left); 
     49        Keyboard.Listen(Key.Right, ButtonState.Down, player.Move, null, Direction.Right); 
     50        Keyboard.Listen(Key.Up, ButtonState.Down, player.Move, null, Direction.Up); 
     51        Keyboard.Listen(Key.Down, ButtonState.Down, player.Move, null, Direction.Down); 
     52 
    2753        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, null); 
    2854    } 
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/TiledTileMap.cs

    r6536 r6538  
    1111{ 
    1212    public delegate void ObjectMethod( 
    13         Vector position, double width, double height, Angle angle, Shape shape, 
    14         Dictionary<string, string> properties); 
     13        Vector position, double width, double height, Angle angle, Shape shape, Dictionary<string, string> properties); 
    1514 
    16     public delegate void TileMethod(Vector position, double width, double height, Image image, string layerName); 
     15    public delegate void TileMethod( 
     16        Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties); 
    1717 
    1818    private readonly Dictionary<string, ObjectMethod> objectLegend = new Dictionary<string, ObjectMethod>(); 
     
    8282            double realX = game.Level.Left + (tile.X * tileWidth) + (tileWidth / 2); 
    8383            double realY = game.Level.Top - (tile.Y * tileHeight) - (tileHeight / 2); 
    84             method(new Vector(realX, realY), tileWidth, tileHeight, tileImages[tileIndex], layer.Name); 
     84            Dictionary<string,string> props = level.Tilesets[0].Tiles.Where(t => level.Tilesets[0].FirstGid + t.Id == tile.Gid).Select(t => t.Properties).FirstOrDefault(); 
     85            props = props ?? new Dictionary<string, string>(); 
     86            method(new Vector(realX, realY), tileWidth, tileHeight, tileImages[tileIndex], layer.Name, props); 
    8587        } 
    8688    } 
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabrielContent/LegendOfGabrielTileset.tsx

    r6536 r6538  
    22<tileset name="LegendOfGabrielTileset" tilewidth="20" tileheight="20"> 
    33 <image source="tileset.png" width="200" height="200"/> 
     4 <tile id="2"> 
     5  <properties> 
     6   <property name="collide" value="true"/> 
     7  </properties> 
     8 </tile> 
    49</tileset> 
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabrielContent/TheLegendOfGabrielContent.contentproj

    r6536 r6538  
    6868    </Compile> 
    6969  </ItemGroup> 
     70  <ItemGroup> 
     71    <Compile Include="testlevel2.tmx"> 
     72      <Name>testlevel2</Name> 
     73      <CopyToOutputDirectory>Always</CopyToOutputDirectory> 
     74      <Importer>TextFileImporter</Importer> 
     75      <Processor>TextFileContentProcessor</Processor> 
     76    </Compile> 
     77  </ItemGroup> 
    7078  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    7179  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabrielContent/testlevel.tmx

    r6536 r6538  
    11<?xml version="1.0" encoding="UTF-8"?> 
    2 <map version="1.0" orientation="orthogonal" renderorder="right-down" width="20" height="15" tilewidth="20" tileheight="20" nextobjectid="1"> 
     2<map version="1.0" orientation="orthogonal" renderorder="right-down" width="20" height="15" tilewidth="20" tileheight="20" nextobjectid="2"> 
    33 <tileset firstgid="1" source="LegendOfGabrielTileset.tsx"/> 
    44 <layer name="base" width="20" height="15"> 
    55  <data encoding="base64" compression="zlib"> 
    6    eJxjYmBgYBqmmBkJU8MMZiQxSswjRmygzCPWDmq7Dz18ccUbMxY2NrWk2otuBrnmERsOuNIVPnfgcx+x7kS3l1AeoUV6JdZubBgA7ucClg== 
     6   eJxjYmBgYAJiZijNhIM/FDEzEqaGGcxIYpSYR4zYQJlHrB3Udh96+OKKN2YsbGxqSbUX3QxyzSM2HHClK3zuwOc+Yt2Jbi+hPEKL9Eqs3dgwAPgnApg= 
    77  </data> 
    88 </layer> 
     9 <objectgroup color="#65e2d8" name="exit"> 
     10  <object id="1" x="60" y="0" width="60" height="20"> 
     11   <properties> 
     12    <property name="goto" value="testlevel2@bottom"/> 
     13   </properties> 
     14  </object> 
     15 </objectgroup> 
    916</map> 
Note: See TracChangeset for help on using the changeset viewer.