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

Revision 6539, 2.2 KB checked in by sieerinn, 4 years ago (diff)

Kenttäsiirtymä on melko valmis.

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 kentän .tmx tiedostosta.
11    /// </summary>
12    void CreateLevel(string levelName)
13    {
14        var level = TiledTileMap.FromLevelAsset(levelName);
15        level.SetTileMethod("base", CreateBaseTile);
16        level.SetTileMethod("foreground", CreateForegroundTile);
17        level.SetObjectMethod("exit", CreateExit);
18        level.Execute();
19
20        Level.Background.Color = Color.Black;
21    }
22
23    /// <summary>
24    /// Maassa oleva perus tiili.
25    /// </summary>
26    void CreateBaseTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
27    {
28        CreateBasicTile(position, width, height, image, -1, properties);
29    }
30
31    /// <summary>
32    /// Pelaajan päällä näkyvä perus tiili.
33    /// </summary>
34    void CreateForegroundTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
35    {
36        CreateBasicTile(position, width, height, image, 1, properties);
37    }
38
39    /// <summary>
40    /// Luo tavallisen tiilen.
41    /// </summary>
42    void CreateBasicTile(Vector position, double width, double height, Image image, int layer, Dictionary<string, string> properties)
43    {
44        var tile = properties.ContainsKey("collide")? new PhysicsObject(width, height) : new GameObject(width, height);
45        tile.Image = image;
46        tile.Position = position;
47        Add(tile, layer);
48    }
49
50    /// <summary>
51    /// Luo uloskäynnin, joka vie toiseen kenttään.
52    /// </summary>
53    void CreateExit(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
54    {
55        var target = properties["goto"].Split('@'); // Jos peli kaatuaa tälle riville niin joltain exitiltä puuttuu goto-property.
56        var exit = new Exit(width, height);
57        exit.Position = position;
58        exit.TargetLevel = target[0];
59        exit.TargetExitName = target[1];
60        exit.Name = name;
61        Add(exit);
62        exits.Add(exit);
63    }
64}
Note: See TracBrowser for help on using the repository browser.