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

Revision 6544, 3.1 KB checked in by empaheik, 4 years ago (diff)
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.SetTileMethod("decoration", CreateDecoration);
19        level.SetObjectMethod("player", CreatePlayer);
20        level.Execute();
21
22        Level.Background.Color = Color.Black;
23    }
24
25    /// <summary>
26    /// Luo pelaajan.
27    /// </summary>
28    void CreatePlayer(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
29    {
30        player = new Creature(TILE_SIZE, TILE_SIZE);
31        player.MovementSpeed = 2300;
32        player.Position = position;
33        Add(player, 1);
34
35        AddCollisionHandler(player, "exit", CollidesWithExit);
36    }
37
38    /// <summary>
39    /// Maassa oleva tiili.
40    /// </summary>
41    void CreateBaseTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
42    {
43        CreateBasicTile(position, width, height, image, -1, properties);
44    }
45
46    /// <summary>
47    /// Pohjan päällä, pelaajan alla näkyvä tiili.
48    /// </summary>
49    void CreateDecoration(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
50    {
51        CreateBasicTile(position, width, height, image, 0, properties);
52    }
53
54        /// <summary>
55    /// Pelaajan päällä näkyvä tiili.
56    /// </summary>
57    void CreateForegroundTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
58    {
59        CreateBasicTile(position, width, height, image, 2, properties);
60    }
61
62    /// <summary>
63    /// Luo tavallisen tiilen.
64    /// </summary>
65    void CreateBasicTile(Vector position, double width, double height, Image image, int layer, Dictionary<string, string> properties)
66    {
67        var tile = properties.ContainsKey("collide")? new PhysicsObject(width, height) : new GameObject(width, height);
68        tile.Image = image;
69        tile.Position = position;
70        Add(tile, layer);
71    }
72
73    /// <summary>
74    /// Luo uloskäynnin, joka vie toiseen kenttään.
75    /// </summary>
76    void CreateExit(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
77    {
78        var target = properties["goto"].Split('@'); // Jos peli kaatuaa tälle riville niin joltain exitiltä puuttuu goto-property.
79        var exit = new Exit(width, height);
80        exit.Position = position;
81        exit.TargetLevel = target[0];
82        exit.TargetExitName = target[1];
83        exit.Name = name;
84        Add(exit);
85        exits.Add(exit);
86    }
87}
Note: See TracBrowser for help on using the repository browser.