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

Revision 6697, 4.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;
6using Jypeli.Assets;
7
8/*
9 *Klassisia muistutuksia
10 * 3
11 * 2    Pelaajan päällä näkyvät elementit
12 * 1    Pelaaja
13 * 0    Lisäkoriste
14 * -1   Perustiili
15 * -2
16 */
17
18
19public partial class TheLegendOfGabriel : PhysicsGame
20{
21    /// <summary>
22    /// Luo kentän .tmx tiedostosta.
23    /// </summary>
24    void CreateLevel(string levelName)
25    {
26        var level = TiledTileMap.FromLevelAsset(levelName);
27        level.SetTileMethod("base", CreateBaseTile);
28        level.SetTileMethod("foreground", CreateForegroundTile);
29        level.SetObjectMethod("exit", CreateExit);
30        level.SetTileMethod("decoration", CreateDecoration);
31        //level.SetObjectMethod("player", CreatePlayer);
32        level.SetObjectMethod("blockade", CreateBlock);
33        level.SetObjectMethod("coyote", CreateCoyote);
34        level.Execute();
35
36        Level.Background.Color = Color.Black;
37    }
38
39    /// <summary>
40    /// Näkymättömiä esteitä.
41    /// </summary>
42    void CreateBlock(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
43    {
44        PhysicsObject block = PhysicsObject.CreateStaticObject(width, height);
45        block.Position = position;
46        block.IsVisible = false;
47        Add(block);
48
49    }
50
51    void CreateCoyote(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
52    {
53        var enemy = new Creature(width, height, 1);
54        enemy.MoveAnimations = DirectionalAnimations(coyoteLeft, coyoteRight, coyoteUp, coyoteDown);
55        enemy.Position = position;
56        enemy.Tag = "enemy";
57        enemy.Brain = new FollowerBrain(player) { Speed = 50 };
58        Add(enemy, 1);
59        enemies.Add(enemy);
60
61        AddCollisionHandler(enemy, "playerattack", delegate(PhysicsObject e, PhysicsObject a)
62        {
63            enemy.Health.Value--;
64        });
65
66        enemy.Health.LowerLimit += enemy.Destroy;
67
68    }
69
70    /// <summary>
71    /// Maassa oleva tiili.
72    /// </summary>
73    void CreateBaseTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
74    {
75        CreateBasicTile(position, width, height, image, -1, properties);
76    }
77
78    /// <summary>
79    /// Pohjan päällä, pelaajan alla näkyvä tiili.
80    /// </summary>
81    void CreateDecoration(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
82    {
83        CreateBasicTile(position, width, height, image, 0, properties);
84    }
85
86    /// <summary>
87    /// Pelaajan päällä näkyvä tiili.
88    /// </summary>
89    void CreateForegroundTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
90    {
91        CreateBasicTile(position, width, height, image, 2, properties);
92    }
93
94    /// <summary>
95    /// Luo tavallisen tiilen.
96    /// </summary>
97    void CreateBasicTile(Vector position, double width, double height, Image image, int layer, Dictionary<string, string> properties)
98    {
99        var tile = properties.ContainsKey("collide") ? new PhysicsObject(width, height) : new GameObject(width, height);
100        tile.Image = image;
101        tile.Position = position;
102        Add(tile, layer);
103    }
104
105    /// <summary>
106    /// Luo uloskäynnin, joka vie toiseen kenttään.
107    /// </summary>
108    void CreateExit(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
109    {
110        var target = properties["goto"].Split('@'); // Jos peli kaatuaa tälle riville niin joltain exitiltä puuttuu goto-property.
111        var exit = new Exit(width, height);
112        exit.Position = position;
113        exit.TargetLevel = target[0];
114        exit.TargetExitName = target[1];
115        exit.Name = name;
116        Add(exit);
117        exits.Add(exit);
118    }
119}
Note: See TracBrowser for help on using the repository browser.