source: 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/LevelCreation.cs @ 6538

Revision 6538, 1.8 KB checked in by sieerinn, 4 years ago (diff)

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

Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Jypeli;
6
7public partial class TheLegendOfGabriel : PhysicsGame
8{
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
20    /// <summary>
21    /// Luo kentän .tmx tiedostosta.
22    /// </summary>
23    void CreateLevel(string levelName)
24    {
25        var level = TiledTileMap.FromLevelAsset(levelName);
26        level.SetTileMethod("base", CreateBaseTile);
27        level.SetTileMethod("foreground", CreateForegroundTile);
28        level.Execute();
29
30        Level.Background.Color = Color.Black;
31    }
32
33    /// <summary>
34    /// Maassa oleva perus tiili.
35    /// </summary>
36    void CreateBaseTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
37    {
38        CreateBasicTile(position, width, height, image, -1, properties);
39    }
40
41    /// <summary>
42    /// Pelaajan päällä näkyvä perus tiili.
43    /// </summary>
44    void CreateForegroundTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
45    {
46        CreateBasicTile(position, width, height, image, 1, properties);
47    }
48
49    /// <summary>
50    /// Luo tavallisen tiilen.
51    /// </summary>
52    void CreateBasicTile(Vector position, double width, double height, Image image, int layer, Dictionary<string, string> properties)
53    {
54        var tile = properties.ContainsKey("collide")? new PhysicsObject(width, height) : new GameObject(width, height);
55        tile.Image = image;
56        tile.Position = position;
57        Add(tile, layer);
58    }
59}
Note: See TracBrowser for help on using the repository browser.