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

Revision 6549, 3.9 KB checked in by sieerinn, 4 years ago (diff)

Miekan heiluttelu kirjoitettu uusiksi.

Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Jypeli;
6
7/*
8 *Klassisia muistutuksia
9 * 3
10 * 2    Pelaajan päällä näkyvät elementit
11 * 1    Pelaaja
12 * 0    Lisäkoriste
13 * -1   Perustiili
14 * -2
15 */
16
17
18public partial class TheLegendOfGabriel : PhysicsGame
19{
20    /// <summary>
21    /// Luo kentän .tmx tiedostosta.
22    /// </summary>
23    void CreateLevel(string levelName)
24    {
25        var level = TiledTileMap.FromLevelAsset(levelName);
26        level.SetTileMethod("base", CreateBaseTile);
27        level.SetTileMethod("foreground", CreateForegroundTile);
28        level.SetObjectMethod("exit", CreateExit);
29        level.SetTileMethod("decoration", CreateDecoration);
30        level.SetObjectMethod("player", CreatePlayer);
31        level.Execute();
32
33        Level.Background.Color = Color.Black;
34    }
35
36    /// <summary>
37    /// Luo pelaajan.
38    /// </summary>
39    void CreatePlayer(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
40    {
41        player = new Player();
42        player.CanRotate = false;
43        player.MovementSpeed = 2300;
44        player.Position = position;
45        player.MoveAnimations[Direction.Left] = playerWalkLeft;
46        player.MoveAnimations[Direction.Right] = playerWalkRight;
47        player.MoveAnimations[Direction.Up] = playerWalkUp;
48        player.MoveAnimations[Direction.Down] = playerWalkDown;
49        player.SwingAnimations[Direction.Left] = playerSwingLeft;
50        player.SwingAnimations[Direction.Right] = playerSwingRight;
51        player.SwingAnimations[Direction.Up] = playerSwingUp;
52        player.SwingAnimations[Direction.Down] = playerSwingDown;
53        player.Image = playerWalkDown.CurrentFrame;
54        Add(player, 1);
55
56        player.ActiveItem = new Sword(player);
57
58        AddCollisionHandler(player, "exit", CollidesWithExit);
59    }
60
61    /// <summary>
62    /// Maassa oleva tiili.
63    /// </summary>
64    void CreateBaseTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
65    {
66        CreateBasicTile(position, width, height, image, -1, properties);
67    }
68
69    /// <summary>
70    /// Pohjan päällä, pelaajan alla näkyvä tiili.
71    /// </summary>
72    void CreateDecoration(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
73    {
74        CreateBasicTile(position, width, height, image, 0, properties);
75    }
76
77        /// <summary>
78    /// Pelaajan päällä näkyvä tiili.
79    /// </summary>
80    void CreateForegroundTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
81    {
82        CreateBasicTile(position, width, height, image, 2, properties);
83    }
84
85    /// <summary>
86    /// Luo tavallisen tiilen.
87    /// </summary>
88    void CreateBasicTile(Vector position, double width, double height, Image image, int layer, Dictionary<string, string> properties)
89    {
90        var tile = properties.ContainsKey("collide")? new PhysicsObject(width, height) : new GameObject(width, height);
91        tile.Image = image;
92        tile.Position = position;
93        Add(tile, layer);
94    }
95
96    /// <summary>
97    /// Luo uloskäynnin, joka vie toiseen kenttään.
98    /// </summary>
99    void CreateExit(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
100    {
101        var target = properties["goto"].Split('@'); // Jos peli kaatuaa tälle riville niin joltain exitiltä puuttuu goto-property.
102        var exit = new Exit(width, height);
103        exit.Position = position;
104        exit.TargetLevel = target[0];
105        exit.TargetExitName = target[1];
106        exit.Name = name;
107        Add(exit);
108        exits.Add(exit);
109    }
110}
Note: See TracBrowser for help on using the repository browser.