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

Revision 6699, 4.4 KB checked in by empaheik, 6 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, kojootit
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        Level.CreateVerticalBorders(1.0, false, Color.Yellow);
27        PhysicsObject leftBorder = Level.CreateLeftBorder(0.0, false);
28        PhysicsObject rightBorder = Level.CreateRightBorder(0.0, false);
29        leftBorder.X += Level.Width * 0.25;
30        rightBorder.X -= Level.Width * 0.25;
31
32        var level = TiledTileMap.FromLevelAsset(levelName);
33        level.SetTileMethod("base", CreateBaseTile);
34        level.SetTileMethod("foreground", CreateForegroundTile);
35        level.SetObjectMethod("exit", CreateExit);
36        level.SetTileMethod("decoration", CreateDecoration);
37        //level.SetObjectMethod("player", CreatePlayer);
38        level.SetObjectMethod("blockade", CreateBlock);
39        level.SetObjectMethod("coyote", CreateCoyote);
40        level.Execute();
41
42        Level.Background.Color = Color.Black;
43    }
44
45    /// <summary>
46    /// Näkymättömiä esteitä.
47    /// </summary>
48    void CreateBlock(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
49    {
50        PhysicsObject block = PhysicsObject.CreateStaticObject(width, height);
51        block.Position = position;
52        block.IsVisible = false;
53        Add(block);
54
55    }
56
57    void CreateCoyote(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
58    {
59        var enemy = new Creature(width, height, 1);
60        enemy.MoveAnimations = DirectionalAnimations(coyoteLeft, coyoteRight, coyoteUp, coyoteDown);
61        enemy.Position = position;
62        enemy.Tag = "enemy";
63        enemy.Brain = new FollowerBrain(player) { Speed = 50 };
64        Add(enemy, 1);
65        enemies.Add(enemy);
66
67        AddCollisionHandler(enemy, "playerattack", delegate(PhysicsObject e, PhysicsObject a)
68        {
69            enemy.Health.Value--;
70        });
71
72        enemy.Health.LowerLimit += enemy.Destroy;
73    }
74
75    /// <summary>
76    /// Maassa oleva tiili.
77    /// </summary>
78    void CreateBaseTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
79    {
80        CreateBasicTile(position, width, height, image, -1, properties);
81    }
82
83    /// <summary>
84    /// Pohjan päällä, pelaajan alla näkyvä tiili.
85    /// </summary>
86    void CreateDecoration(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
87    {
88        CreateBasicTile(position, width, height, image, 0, properties);
89    }
90
91        /// <summary>
92    /// Pelaajan päällä näkyvä tiili.
93    /// </summary>
94    void CreateForegroundTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
95    {
96        CreateBasicTile(position, width, height, image, 2, properties);
97    }
98
99    /// <summary>
100    /// Luo tavallisen tiilen.
101    /// </summary>
102    void CreateBasicTile(Vector position, double width, double height, Image image, int layer, Dictionary<string, string> properties)
103    {
104        var tile = properties.ContainsKey("collide") ? new PhysicsObject(width, height) : new GameObject(width, height);
105        tile.Image = image;
106        tile.Position = position;
107        Add(tile, layer);
108    }
109
110    /// <summary>
111    /// Luo uloskäynnin, joka vie toiseen kenttään.
112    /// </summary>
113    void CreateExit(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
114    {
115        var target = properties["goto"].Split('@'); // Jos peli kaatuu tälle riville niin joltain exitiltä puuttuu goto-property.
116        var exit = new Exit(width, height);
117        exit.Position = position;
118        exit.TargetLevel = target[0];
119        exit.TargetExitName = target[1];
120        exit.Name = name;
121        Add(exit);
122        exits.Add(exit);
123    }
124}
Note: See TracBrowser for help on using the repository browser.