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

Revision 6701, 4.8 KB checked in by sieerinn, 7 years ago (diff)

Pelaajalla näkyy taas sydämmet, monokkeli toimii.

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