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

Revision 6703, 5.3 KB checked in by sieerinn, 8 years ago (diff)

Junaa aloiteltu, puuttuvat .anim tiedostot lisätty.

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